@fuel-ts/account 0.81.0 → 0.83.0

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

Potentially problematic release.


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

Files changed (57) hide show
  1. package/README.md +3 -3
  2. package/dist/account.d.ts +7 -6
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +1 -1
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +1 -1
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +1 -1
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +890 -619
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +853 -604
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +696 -448
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +12 -24
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +810 -359
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +3 -3
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +7 -1
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +44 -27
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  30. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/input.d.ts +2 -2
  32. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  34. package/dist/providers/transaction-request/transaction-request.d.ts +13 -33
  35. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  36. package/dist/providers/transaction-request/utils.d.ts +3 -0
  37. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  38. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  39. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  40. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  42. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  43. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  44. package/dist/providers/utils/gas.d.ts +8 -2
  45. package/dist/providers/utils/gas.d.ts.map +1 -1
  46. package/dist/providers/utils/merge-quantities.d.ts +1 -1
  47. package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
  48. package/dist/test-utils/launchNode.d.ts +1 -1
  49. package/dist/test-utils/launchNode.d.ts.map +1 -1
  50. package/dist/test-utils.global.js +1615 -1114
  51. package/dist/test-utils.global.js.map +1 -1
  52. package/dist/test-utils.js +841 -596
  53. package/dist/test-utils.js.map +1 -1
  54. package/dist/test-utils.mjs +696 -451
  55. package/dist/test-utils.mjs.map +1 -1
  56. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  57. package/package.json +16 -16
@@ -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_math19 = 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,31 @@ 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_math16 = 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");
113
+ var import_utils23 = require("@noble/curves/abstract/utils");
115
114
  var import_ethers = require("ethers");
116
115
  var import_graphql_request = require("graphql-request");
117
116
  var import_ramda3 = require("ramda");
118
117
 
119
118
  // src/providers/__generated__/operations.ts
120
119
  var import_graphql_tag = __toESM(require("graphql-tag"));
120
+ var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
121
+ fragment transactionStatusSubscriptionFragment on TransactionStatus {
122
+ type: __typename
123
+ ... on SqueezedOutStatus {
124
+ reason
125
+ }
126
+ }
127
+ `;
121
128
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
122
129
  fragment receiptFragment on Receipt {
123
- contract {
124
- id
125
- }
130
+ id
126
131
  pc
127
132
  is
128
- to {
129
- id
130
- }
133
+ to
131
134
  toAddress
132
135
  amount
133
136
  assetId
@@ -165,10 +168,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
165
168
  id
166
169
  }
167
170
  time
171
+ receipts {
172
+ ...receiptFragment
173
+ }
168
174
  programState {
169
175
  returnType
170
176
  data
171
177
  }
178
+ receipts {
179
+ ...receiptFragment
180
+ }
172
181
  }
173
182
  ... on FailureStatus {
174
183
  block {
@@ -176,26 +185,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
176
185
  }
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,46 @@ 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
+ reason
226
+ programState {
227
+ returnType
228
+ data
229
+ }
230
+ }
231
+ `;
232
+ var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
233
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
234
+ programState {
235
+ returnType
236
+ data
237
+ }
238
+ }
239
+ `;
240
+ var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
241
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
242
+ ... on DryRunFailureStatus {
243
+ ...dryRunFailureStatusFragment
244
+ }
245
+ ... on DryRunSuccessStatus {
246
+ ...dryRunSuccessStatusFragment
247
+ }
248
+ }
249
+ ${DryRunFailureStatusFragmentFragmentDoc}
250
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
251
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
252
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
253
+ id
254
+ status {
255
+ ...dryRunTransactionStatusFragment
256
+ }
257
+ receipts {
258
+ ...receiptFragment
259
+ }
260
+ }
261
+ ${DryRunTransactionStatusFragmentFragmentDoc}
262
+ ${ReceiptFragmentFragmentDoc}`;
216
263
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
217
264
  fragment coinFragment on Coin {
218
265
  __typename
@@ -220,7 +267,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
220
267
  owner
221
268
  amount
222
269
  assetId
223
- maturity
224
270
  blockCreated
225
271
  txCreatedIdx
226
272
  }
@@ -259,26 +305,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
259
305
  messageBlockHeader {
260
306
  id
261
307
  daHeight
308
+ consensusParametersVersion
309
+ stateTransitionBytecodeVersion
262
310
  transactionsCount
311
+ messageReceiptCount
263
312
  transactionsRoot
313
+ messageOutboxRoot
314
+ eventInboxRoot
264
315
  height
265
316
  prevRoot
266
317
  time
267
318
  applicationHash
268
- messageReceiptRoot
269
- messageReceiptCount
270
319
  }
271
320
  commitBlockHeader {
272
321
  id
273
322
  daHeight
323
+ consensusParametersVersion
324
+ stateTransitionBytecodeVersion
274
325
  transactionsCount
326
+ messageReceiptCount
275
327
  transactionsRoot
328
+ messageOutboxRoot
329
+ eventInboxRoot
276
330
  height
277
331
  prevRoot
278
332
  time
279
333
  applicationHash
280
- messageReceiptRoot
281
- messageReceiptCount
282
334
  }
283
335
  sender
284
336
  recipient
@@ -297,8 +349,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
297
349
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
298
350
  fragment blockFragment on Block {
299
351
  id
352
+ height
300
353
  header {
301
- height
302
354
  time
303
355
  }
304
356
  transactions {
@@ -308,6 +360,7 @@ var BlockFragmentFragmentDoc = import_graphql_tag.default`
308
360
  `;
309
361
  var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
310
362
  fragment TxParametersFragment on TxParameters {
363
+ version
311
364
  maxInputs
312
365
  maxOutputs
313
366
  maxWitnesses
@@ -317,6 +370,7 @@ var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
317
370
  `;
318
371
  var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
319
372
  fragment PredicateParametersFragment on PredicateParameters {
373
+ version
320
374
  maxPredicateLength
321
375
  maxPredicateDataLength
322
376
  maxGasPerPredicate
@@ -325,18 +379,21 @@ var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
325
379
  `;
326
380
  var ScriptParametersFragmentFragmentDoc = import_graphql_tag.default`
327
381
  fragment ScriptParametersFragment on ScriptParameters {
382
+ version
328
383
  maxScriptLength
329
384
  maxScriptDataLength
330
385
  }
331
386
  `;
332
387
  var ContractParametersFragmentFragmentDoc = import_graphql_tag.default`
333
388
  fragment ContractParametersFragment on ContractParameters {
389
+ version
334
390
  contractMaxSize
335
391
  maxStorageSlots
336
392
  }
337
393
  `;
338
394
  var FeeParametersFragmentFragmentDoc = import_graphql_tag.default`
339
395
  fragment FeeParametersFragment on FeeParameters {
396
+ version
340
397
  gasPriceFactor
341
398
  gasPerByte
342
399
  }
@@ -356,6 +413,7 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
356
413
  `;
357
414
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
358
415
  fragment GasCostsFragment on GasCosts {
416
+ version
359
417
  add
360
418
  addi
361
419
  aloc
@@ -368,7 +426,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
368
426
  cb
369
427
  cfei
370
428
  cfsi
371
- croo
372
429
  div
373
430
  divi
374
431
  ecr1
@@ -451,6 +508,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
451
508
  ccp {
452
509
  ...DependentCostFragment
453
510
  }
511
+ croo {
512
+ ...DependentCostFragment
513
+ }
454
514
  csiz {
455
515
  ...DependentCostFragment
456
516
  }
@@ -510,6 +570,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
510
570
  ${DependentCostFragmentFragmentDoc}`;
511
571
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
512
572
  fragment consensusParametersFragment on ConsensusParameters {
573
+ version
513
574
  txParams {
514
575
  ...TxParametersFragment
515
576
  }
@@ -569,18 +630,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
569
630
  fragment nodeInfoFragment on NodeInfo {
570
631
  utxoValidation
571
632
  vmBacktrace
572
- minGasPrice
573
633
  maxTx
574
634
  maxDepth
575
635
  nodeVersion
576
- peers {
577
- id
578
- addresses
579
- clientVersion
580
- blockHeight
581
- lastHeartbeatMs
582
- appScore
583
- }
584
636
  }
585
637
  `;
586
638
  var GetVersionDocument = import_graphql_tag.default`
@@ -615,13 +667,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
615
667
  query getTransactionWithReceipts($transactionId: TransactionId!) {
616
668
  transaction(id: $transactionId) {
617
669
  ...transactionFragment
618
- receipts {
619
- ...receiptFragment
620
- }
621
670
  }
622
671
  }
623
- ${TransactionFragmentFragmentDoc}
624
- ${ReceiptFragmentFragmentDoc}`;
672
+ ${TransactionFragmentFragmentDoc}`;
625
673
  var GetTransactionsDocument = import_graphql_tag.default`
626
674
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
627
675
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -749,6 +797,20 @@ var GetBalanceDocument = import_graphql_tag.default`
749
797
  }
750
798
  }
751
799
  ${BalanceFragmentFragmentDoc}`;
800
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
801
+ query getLatestGasPrice {
802
+ latestGasPrice {
803
+ gasPrice
804
+ }
805
+ }
806
+ `;
807
+ var EstimateGasPriceDocument = import_graphql_tag.default`
808
+ query estimateGasPrice($blockHorizon: U32!) {
809
+ estimateGasPrice(blockHorizon: $blockHorizon) {
810
+ gasPrice
811
+ }
812
+ }
813
+ `;
752
814
  var GetBalancesDocument = import_graphql_tag.default`
753
815
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
754
816
  balances(
@@ -803,12 +865,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
803
865
  }
804
866
  `;
805
867
  var DryRunDocument = import_graphql_tag.default`
806
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
807
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
808
- ...receiptFragment
868
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
869
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
870
+ ...dryRunTransactionExecutionStatusFragment
809
871
  }
810
872
  }
811
- ${ReceiptFragmentFragmentDoc}`;
873
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
812
874
  var SubmitDocument = import_graphql_tag.default`
813
875
  mutation submit($encodedTransaction: HexString!) {
814
876
  submit(tx: $encodedTransaction) {
@@ -827,17 +889,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
827
889
  var SubmitAndAwaitDocument = import_graphql_tag.default`
828
890
  subscription submitAndAwait($encodedTransaction: HexString!) {
829
891
  submitAndAwait(tx: $encodedTransaction) {
830
- ...transactionStatusFragment
892
+ ...transactionStatusSubscriptionFragment
831
893
  }
832
894
  }
833
- ${TransactionStatusFragmentFragmentDoc}`;
895
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
834
896
  var StatusChangeDocument = import_graphql_tag.default`
835
897
  subscription statusChange($transactionId: TransactionId!) {
836
898
  statusChange(id: $transactionId) {
837
- ...transactionStatusFragment
899
+ ...transactionStatusSubscriptionFragment
838
900
  }
839
901
  }
840
- ${TransactionStatusFragmentFragmentDoc}`;
902
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
841
903
  function getSdk(requester) {
842
904
  return {
843
905
  getVersion(variables, options) {
@@ -891,6 +953,12 @@ function getSdk(requester) {
891
953
  getBalance(variables, options) {
892
954
  return requester(GetBalanceDocument, variables, options);
893
955
  },
956
+ getLatestGasPrice(variables, options) {
957
+ return requester(GetLatestGasPriceDocument, variables, options);
958
+ },
959
+ estimateGasPrice(variables, options) {
960
+ return requester(EstimateGasPriceDocument, variables, options);
961
+ },
894
962
  getBalances(variables, options) {
895
963
  return requester(GetBalancesDocument, variables, options);
896
964
  },
@@ -1061,7 +1129,7 @@ var MemoryCache = class {
1061
1129
 
1062
1130
  // src/providers/transaction-request/input.ts
1063
1131
  var import_abi_coder = require("@fuel-ts/abi-coder");
1064
- var import_configs2 = require("@fuel-ts/address/configs");
1132
+ var import_configs = require("@fuel-ts/address/configs");
1065
1133
  var import_errors3 = require("@fuel-ts/errors");
1066
1134
  var import_math2 = require("@fuel-ts/math");
1067
1135
  var import_transactions = require("@fuel-ts/transactions");
@@ -1084,10 +1152,9 @@ var inputify = (value) => {
1084
1152
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1085
1153
  },
1086
1154
  witnessIndex: value.witnessIndex,
1087
- maturity: value.maturity ?? 0,
1088
1155
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1089
- predicateLength: predicate.length,
1090
- predicateDataLength: predicateData.length,
1156
+ predicateLength: (0, import_math2.bn)(predicate.length),
1157
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1091
1158
  predicate: (0, import_utils3.hexlify)(predicate),
1092
1159
  predicateData: (0, import_utils3.hexlify)(predicateData)
1093
1160
  };
@@ -1095,10 +1162,10 @@ var inputify = (value) => {
1095
1162
  case import_transactions.InputType.Contract: {
1096
1163
  return {
1097
1164
  type: import_transactions.InputType.Contract,
1098
- txID: import_configs2.ZeroBytes32,
1165
+ txID: import_configs.ZeroBytes32,
1099
1166
  outputIndex: 0,
1100
- balanceRoot: import_configs2.ZeroBytes32,
1101
- stateRoot: import_configs2.ZeroBytes32,
1167
+ balanceRoot: import_configs.ZeroBytes32,
1168
+ stateRoot: import_configs.ZeroBytes32,
1102
1169
  txPointer: {
1103
1170
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1104
1171
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1118,8 +1185,8 @@ var inputify = (value) => {
1118
1185
  nonce: (0, import_utils3.hexlify)(value.nonce),
1119
1186
  witnessIndex: value.witnessIndex,
1120
1187
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1121
- predicateLength: predicate.length,
1122
- predicateDataLength: predicateData.length,
1188
+ predicateLength: (0, import_math2.bn)(predicate.length),
1189
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1123
1190
  predicate: (0, import_utils3.hexlify)(predicate),
1124
1191
  predicateData: (0, import_utils3.hexlify)(predicateData),
1125
1192
  data: (0, import_utils3.hexlify)(data),
@@ -1136,7 +1203,7 @@ var inputify = (value) => {
1136
1203
  };
1137
1204
 
1138
1205
  // src/providers/transaction-request/output.ts
1139
- var import_configs3 = require("@fuel-ts/address/configs");
1206
+ var import_configs2 = require("@fuel-ts/address/configs");
1140
1207
  var import_errors4 = require("@fuel-ts/errors");
1141
1208
  var import_math3 = require("@fuel-ts/math");
1142
1209
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1156,8 +1223,8 @@ var outputify = (value) => {
1156
1223
  return {
1157
1224
  type: import_transactions2.OutputType.Contract,
1158
1225
  inputIndex: value.inputIndex,
1159
- balanceRoot: import_configs3.ZeroBytes32,
1160
- stateRoot: import_configs3.ZeroBytes32
1226
+ balanceRoot: import_configs2.ZeroBytes32,
1227
+ stateRoot: import_configs2.ZeroBytes32
1161
1228
  };
1162
1229
  }
1163
1230
  case import_transactions2.OutputType.Change: {
@@ -1171,9 +1238,9 @@ var outputify = (value) => {
1171
1238
  case import_transactions2.OutputType.Variable: {
1172
1239
  return {
1173
1240
  type: import_transactions2.OutputType.Variable,
1174
- to: import_configs3.ZeroBytes32,
1241
+ to: import_configs2.ZeroBytes32,
1175
1242
  amount: (0, import_math3.bn)(0),
1176
- assetId: import_configs3.ZeroBytes32
1243
+ assetId: import_configs2.ZeroBytes32
1177
1244
  };
1178
1245
  }
1179
1246
  case import_transactions2.OutputType.ContractCreated: {
@@ -1195,7 +1262,7 @@ var outputify = (value) => {
1195
1262
  // src/providers/transaction-request/transaction-request.ts
1196
1263
  var import_abi_coder2 = require("@fuel-ts/abi-coder");
1197
1264
  var import_address = require("@fuel-ts/address");
1198
- var import_configs7 = require("@fuel-ts/address/configs");
1265
+ var import_configs6 = require("@fuel-ts/address/configs");
1199
1266
  var import_crypto = require("@fuel-ts/crypto");
1200
1267
  var import_math7 = require("@fuel-ts/math");
1201
1268
  var import_transactions6 = require("@fuel-ts/transactions");
@@ -1205,13 +1272,13 @@ var import_utils9 = require("@fuel-ts/utils");
1205
1272
  var isCoin = (resource) => "id" in resource;
1206
1273
 
1207
1274
  // src/providers/utils/receipts.ts
1208
- var import_configs4 = require("@fuel-ts/address/configs");
1275
+ var import_configs3 = require("@fuel-ts/address/configs");
1209
1276
  var import_errors5 = require("@fuel-ts/errors");
1210
1277
  var import_math4 = require("@fuel-ts/math");
1211
1278
  var import_transactions3 = require("@fuel-ts/transactions");
1212
- var import_configs5 = require("@fuel-ts/transactions/configs");
1279
+ var import_configs4 = require("@fuel-ts/transactions/configs");
1213
1280
  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;
1281
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1215
1282
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1216
1283
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1217
1284
  (memo, receipt) => {
@@ -1228,15 +1295,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1228
1295
  missingOutputContractIds: []
1229
1296
  }
1230
1297
  );
1231
- var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1298
+ var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1232
1299
  function assembleReceiptByType(receipt) {
1233
1300
  const { receiptType } = receipt;
1234
1301
  switch (receiptType) {
1235
1302
  case "CALL" /* Call */: {
1236
1303
  const callReceipt = {
1237
1304
  type: import_transactions3.ReceiptType.Call,
1238
- from: hexOrZero(receipt.contract?.id),
1239
- to: hexOrZero(receipt?.to?.id),
1305
+ from: hexOrZero(receipt.id || receipt.contractId),
1306
+ to: hexOrZero(receipt?.to),
1240
1307
  amount: (0, import_math4.bn)(receipt.amount),
1241
1308
  assetId: hexOrZero(receipt.assetId),
1242
1309
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1250,7 +1317,7 @@ function assembleReceiptByType(receipt) {
1250
1317
  case "RETURN" /* Return */: {
1251
1318
  const returnReceipt = {
1252
1319
  type: import_transactions3.ReceiptType.Return,
1253
- id: hexOrZero(receipt.contract?.id),
1320
+ id: hexOrZero(receipt.id || receipt.contractId),
1254
1321
  val: (0, import_math4.bn)(receipt.val),
1255
1322
  pc: (0, import_math4.bn)(receipt.pc),
1256
1323
  is: (0, import_math4.bn)(receipt.is)
@@ -1260,7 +1327,7 @@ function assembleReceiptByType(receipt) {
1260
1327
  case "RETURN_DATA" /* ReturnData */: {
1261
1328
  const returnDataReceipt = {
1262
1329
  type: import_transactions3.ReceiptType.ReturnData,
1263
- id: hexOrZero(receipt.contract?.id),
1330
+ id: hexOrZero(receipt.id || receipt.contractId),
1264
1331
  ptr: (0, import_math4.bn)(receipt.ptr),
1265
1332
  len: (0, import_math4.bn)(receipt.len),
1266
1333
  digest: hexOrZero(receipt.digest),
@@ -1272,7 +1339,7 @@ function assembleReceiptByType(receipt) {
1272
1339
  case "PANIC" /* Panic */: {
1273
1340
  const panicReceipt = {
1274
1341
  type: import_transactions3.ReceiptType.Panic,
1275
- id: hexOrZero(receipt.contract?.id),
1342
+ id: hexOrZero(receipt.id),
1276
1343
  reason: (0, import_math4.bn)(receipt.reason),
1277
1344
  pc: (0, import_math4.bn)(receipt.pc),
1278
1345
  is: (0, import_math4.bn)(receipt.is),
@@ -1283,7 +1350,7 @@ function assembleReceiptByType(receipt) {
1283
1350
  case "REVERT" /* Revert */: {
1284
1351
  const revertReceipt = {
1285
1352
  type: import_transactions3.ReceiptType.Revert,
1286
- id: hexOrZero(receipt.contract?.id),
1353
+ id: hexOrZero(receipt.id || receipt.contractId),
1287
1354
  val: (0, import_math4.bn)(receipt.ra),
1288
1355
  pc: (0, import_math4.bn)(receipt.pc),
1289
1356
  is: (0, import_math4.bn)(receipt.is)
@@ -1293,7 +1360,7 @@ function assembleReceiptByType(receipt) {
1293
1360
  case "LOG" /* Log */: {
1294
1361
  const logReceipt = {
1295
1362
  type: import_transactions3.ReceiptType.Log,
1296
- id: hexOrZero(receipt.contract?.id),
1363
+ id: hexOrZero(receipt.id || receipt.contractId),
1297
1364
  val0: (0, import_math4.bn)(receipt.ra),
1298
1365
  val1: (0, import_math4.bn)(receipt.rb),
1299
1366
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1306,7 +1373,7 @@ function assembleReceiptByType(receipt) {
1306
1373
  case "LOG_DATA" /* LogData */: {
1307
1374
  const logDataReceipt = {
1308
1375
  type: import_transactions3.ReceiptType.LogData,
1309
- id: hexOrZero(receipt.contract?.id),
1376
+ id: hexOrZero(receipt.id || receipt.contractId),
1310
1377
  val0: (0, import_math4.bn)(receipt.ra),
1311
1378
  val1: (0, import_math4.bn)(receipt.rb),
1312
1379
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1320,8 +1387,8 @@ function assembleReceiptByType(receipt) {
1320
1387
  case "TRANSFER" /* Transfer */: {
1321
1388
  const transferReceipt = {
1322
1389
  type: import_transactions3.ReceiptType.Transfer,
1323
- from: hexOrZero(receipt.contract?.id),
1324
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1390
+ from: hexOrZero(receipt.id || receipt.contractId),
1391
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1325
1392
  amount: (0, import_math4.bn)(receipt.amount),
1326
1393
  assetId: hexOrZero(receipt.assetId),
1327
1394
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1332,8 +1399,8 @@ function assembleReceiptByType(receipt) {
1332
1399
  case "TRANSFER_OUT" /* TransferOut */: {
1333
1400
  const transferOutReceipt = {
1334
1401
  type: import_transactions3.ReceiptType.TransferOut,
1335
- from: hexOrZero(receipt.contract?.id),
1336
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1402
+ from: hexOrZero(receipt.id || receipt.contractId),
1403
+ to: hexOrZero(receipt.toAddress || receipt.to),
1337
1404
  amount: (0, import_math4.bn)(receipt.amount),
1338
1405
  assetId: hexOrZero(receipt.assetId),
1339
1406
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1376,7 +1443,7 @@ function assembleReceiptByType(receipt) {
1376
1443
  return receiptMessageOut;
1377
1444
  }
1378
1445
  case "MINT" /* Mint */: {
1379
- const contractId = hexOrZero(receipt.contract?.id);
1446
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1380
1447
  const subId = hexOrZero(receipt.subId);
1381
1448
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1382
1449
  const mintReceipt = {
@@ -1391,7 +1458,7 @@ function assembleReceiptByType(receipt) {
1391
1458
  return mintReceipt;
1392
1459
  }
1393
1460
  case "BURN" /* Burn */: {
1394
- const contractId = hexOrZero(receipt.contract?.id);
1461
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1395
1462
  const subId = hexOrZero(receipt.subId);
1396
1463
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1397
1464
  const burnReceipt = {
@@ -1417,7 +1484,6 @@ var import_errors6 = require("@fuel-ts/errors");
1417
1484
  var import_math5 = require("@fuel-ts/math");
1418
1485
  var import_transactions4 = require("@fuel-ts/transactions");
1419
1486
  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
1487
  var getGasUsedFromReceipts = (receipts) => {
1422
1488
  const scriptResult = receipts.filter(
1423
1489
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1438,18 +1504,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1438
1504
  }
1439
1505
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1440
1506
  const witnessCache = [];
1441
- const totalGas = inputs.reduce((total, input) => {
1507
+ const chargeableInputs = inputs.filter((input) => {
1508
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1509
+ if (isCoinOrMessage) {
1510
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1511
+ return true;
1512
+ }
1513
+ if (!witnessCache.includes(input.witnessIndex)) {
1514
+ witnessCache.push(input.witnessIndex);
1515
+ return true;
1516
+ }
1517
+ }
1518
+ return false;
1519
+ });
1520
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1521
+ const totalGas = chargeableInputs.reduce((total, input) => {
1442
1522
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1443
1523
  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))
1524
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1445
1525
  );
1446
1526
  }
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)());
1527
+ return total.add(gasCosts.ecr1);
1528
+ }, (0, import_math5.bn)(0));
1453
1529
  return totalGas;
1454
1530
  }
1455
1531
  function getMinGas(params) {
@@ -1461,12 +1537,20 @@ function getMinGas(params) {
1461
1537
  return minGas;
1462
1538
  }
1463
1539
  function getMaxGas(params) {
1464
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1540
+ const {
1541
+ gasPerByte,
1542
+ witnessesLength,
1543
+ witnessLimit,
1544
+ minGas,
1545
+ gasLimit = (0, import_math5.bn)(0),
1546
+ maxGasPerTx
1547
+ } = params;
1465
1548
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1466
1549
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1467
1550
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1468
1551
  }
1469
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1552
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1553
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1470
1554
  }
1471
1555
  function calculateMetadataGasForTxCreate({
1472
1556
  gasCosts,
@@ -1488,6 +1572,10 @@ function calculateMetadataGasForTxScript({
1488
1572
  }) {
1489
1573
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1490
1574
  }
1575
+ var calculateGasFee = (params) => {
1576
+ const { gas, gasPrice, priceFactor, tip } = params;
1577
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1578
+ };
1491
1579
 
1492
1580
  // src/providers/utils/json.ts
1493
1581
  var import_utils7 = require("@fuel-ts/utils");
@@ -1533,16 +1621,16 @@ function sleep(time) {
1533
1621
  var import_errors7 = require("@fuel-ts/errors");
1534
1622
  var import_math6 = require("@fuel-ts/math");
1535
1623
  var import_transactions5 = require("@fuel-ts/transactions");
1536
- var import_configs6 = require("@fuel-ts/transactions/configs");
1624
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1537
1625
  var assemblePanicError = (status) => {
1538
1626
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1539
1627
  const reason = status.reason;
1540
- if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1628
+ if (import_configs5.PANIC_REASONS.includes(status.reason)) {
1541
1629
  errorMessage = `${errorMessage}
1542
1630
 
1543
1631
  You can read more about this error at:
1544
1632
 
1545
- ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1633
+ ${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
1546
1634
  }
1547
1635
  return { errorMessage, reason };
1548
1636
  };
@@ -1554,28 +1642,28 @@ var assembleRevertError = (receipts, logs) => {
1554
1642
  if (revertReceipt) {
1555
1643
  const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1556
1644
  switch (reasonHex) {
1557
- case import_configs6.FAILED_REQUIRE_SIGNAL: {
1645
+ case import_configs5.FAILED_REQUIRE_SIGNAL: {
1558
1646
  reason = "require";
1559
1647
  errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1560
1648
  break;
1561
1649
  }
1562
- case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1650
+ case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
1563
1651
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1564
1652
  reason = "assert_eq";
1565
1653
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1566
1654
  break;
1567
1655
  }
1568
- case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1656
+ case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
1569
1657
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1570
1658
  reason = "assert_ne";
1571
1659
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1572
1660
  break;
1573
1661
  }
1574
- case import_configs6.FAILED_ASSERT_SIGNAL:
1662
+ case import_configs5.FAILED_ASSERT_SIGNAL:
1575
1663
  reason = "assert";
1576
1664
  errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1577
1665
  break;
1578
- case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1666
+ case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1579
1667
  reason = "MissingOutputChange";
1580
1668
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1581
1669
  break;
@@ -1624,7 +1712,7 @@ var witnessify = (value) => {
1624
1712
  // src/providers/transaction-request/transaction-request.ts
1625
1713
  var BaseTransactionRequest = class {
1626
1714
  /** Gas price for transaction */
1627
- gasPrice;
1715
+ tip;
1628
1716
  /** Block until which tx cannot be included */
1629
1717
  maturity;
1630
1718
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1643,7 +1731,7 @@ var BaseTransactionRequest = class {
1643
1731
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1644
1732
  */
1645
1733
  constructor({
1646
- gasPrice,
1734
+ tip,
1647
1735
  maturity,
1648
1736
  maxFee,
1649
1737
  witnessLimit,
@@ -1651,7 +1739,7 @@ var BaseTransactionRequest = class {
1651
1739
  outputs,
1652
1740
  witnesses
1653
1741
  } = {}) {
1654
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1742
+ this.tip = (0, import_math7.bn)(tip);
1655
1743
  this.maturity = maturity ?? 0;
1656
1744
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1657
1745
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1662,9 +1750,9 @@ var BaseTransactionRequest = class {
1662
1750
  static getPolicyMeta(req) {
1663
1751
  let policyTypes = 0;
1664
1752
  const policies = [];
1665
- if (req.gasPrice) {
1666
- policyTypes += import_transactions6.PolicyType.GasPrice;
1667
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1753
+ if (req.tip) {
1754
+ policyTypes += import_transactions6.PolicyType.Tip;
1755
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1668
1756
  }
1669
1757
  if (req.witnessLimit) {
1670
1758
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -1750,7 +1838,7 @@ var BaseTransactionRequest = class {
1750
1838
  * @returns The index of the created witness.
1751
1839
  */
1752
1840
  addEmptyWitness() {
1753
- this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
1841
+ this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1754
1842
  return this.witnesses.length - 1;
1755
1843
  }
1756
1844
  /**
@@ -1848,13 +1936,11 @@ var BaseTransactionRequest = class {
1848
1936
  * assetId, if one it was not added yet.
1849
1937
  *
1850
1938
  * @param coin - Coin resource.
1851
- * @param predicate - Predicate bytes.
1852
- * @param predicateData - Predicate data bytes.
1853
1939
  */
1854
- addCoinInput(coin, predicate) {
1940
+ addCoinInput(coin) {
1855
1941
  const { assetId, owner, amount } = coin;
1856
1942
  let witnessIndex;
1857
- if (predicate) {
1943
+ if (coin.predicate) {
1858
1944
  witnessIndex = 0;
1859
1945
  } else {
1860
1946
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1869,25 +1955,21 @@ var BaseTransactionRequest = class {
1869
1955
  amount,
1870
1956
  assetId,
1871
1957
  txPointer: "0x00000000000000000000000000000000",
1872
- witnessIndex,
1873
- predicate: predicate?.bytes
1958
+ witnessIndex
1874
1959
  };
1875
1960
  this.pushInput(input);
1876
1961
  this.addChangeOutput(owner, assetId);
1877
1962
  }
1878
1963
  /**
1879
1964
  * Adds a single message input to the transaction and a change output for the
1880
- * baseAssetId, if one it was not added yet.
1965
+ * asset against the message
1881
1966
  *
1882
1967
  * @param message - Message resource.
1883
- * @param predicate - Predicate bytes.
1884
- * @param predicateData - Predicate data bytes.
1885
1968
  */
1886
- addMessageInput(message, predicate) {
1887
- const { recipient, sender, amount } = message;
1888
- const assetId = import_configs7.BaseAssetId;
1969
+ addMessageInput(message) {
1970
+ const { recipient, sender, amount, assetId } = message;
1889
1971
  let witnessIndex;
1890
- if (predicate) {
1972
+ if (message.predicate) {
1891
1973
  witnessIndex = 0;
1892
1974
  } else {
1893
1975
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1901,8 +1983,7 @@ var BaseTransactionRequest = class {
1901
1983
  sender: sender.toB256(),
1902
1984
  recipient: recipient.toB256(),
1903
1985
  amount,
1904
- witnessIndex,
1905
- predicate: predicate?.bytes
1986
+ witnessIndex
1906
1987
  };
1907
1988
  this.pushInput(input);
1908
1989
  this.addChangeOutput(recipient, assetId);
@@ -1933,32 +2014,6 @@ var BaseTransactionRequest = class {
1933
2014
  resources.forEach((resource) => this.addResource(resource));
1934
2015
  return this;
1935
2016
  }
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
2017
  /**
1963
2018
  * Adds a coin output to the transaction.
1964
2019
  *
@@ -1966,7 +2021,7 @@ var BaseTransactionRequest = class {
1966
2021
  * @param amount - Amount of coin.
1967
2022
  * @param assetId - Asset ID of coin.
1968
2023
  */
1969
- addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2024
+ addCoinOutput(to, amount, assetId) {
1970
2025
  this.pushOutput({
1971
2026
  type: import_transactions6.OutputType.Coin,
1972
2027
  to: (0, import_address.addressify)(to).toB256(),
@@ -1998,7 +2053,7 @@ var BaseTransactionRequest = class {
1998
2053
  * @param to - Address of the owner.
1999
2054
  * @param assetId - Asset ID of coin.
2000
2055
  */
2001
- addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2056
+ addChangeOutput(to, assetId) {
2002
2057
  const changeOutput = this.getChangeOutputs().find(
2003
2058
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2004
2059
  );
@@ -2038,7 +2093,7 @@ var BaseTransactionRequest = class {
2038
2093
  }
2039
2094
  calculateMaxGas(chainInfo, minGas) {
2040
2095
  const { consensusParameters } = chainInfo;
2041
- const { gasPerByte } = consensusParameters;
2096
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2042
2097
  const witnessesLength = this.toTransaction().witnesses.reduce(
2043
2098
  (acc, wit) => acc + wit.dataLength,
2044
2099
  0
@@ -2047,7 +2102,8 @@ var BaseTransactionRequest = class {
2047
2102
  gasPerByte,
2048
2103
  minGas,
2049
2104
  witnessesLength,
2050
- witnessLimit: this.witnessLimit
2105
+ witnessLimit: this.witnessLimit,
2106
+ maxGasPerTx
2051
2107
  });
2052
2108
  }
2053
2109
  /**
@@ -2055,8 +2111,9 @@ var BaseTransactionRequest = class {
2055
2111
  * quantities array.
2056
2112
  *
2057
2113
  * @param quantities - CoinQuantity Array.
2114
+ * @param baseAssetId - The base asset to fund the transaction.
2058
2115
  */
2059
- fundWithFakeUtxos(quantities, resourcesOwner) {
2116
+ fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
2060
2117
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2061
2118
  if ("assetId" in input) {
2062
2119
  return input.assetId === assetId;
@@ -2065,24 +2122,27 @@ var BaseTransactionRequest = class {
2065
2122
  });
2066
2123
  const updateAssetInput = (assetId, quantity) => {
2067
2124
  const assetInput = findAssetInput(assetId);
2125
+ let usedQuantity = quantity;
2126
+ if (assetId === baseAssetId) {
2127
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2128
+ }
2068
2129
  if (assetInput && "assetId" in assetInput) {
2069
2130
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2070
- assetInput.amount = quantity;
2131
+ assetInput.amount = usedQuantity;
2071
2132
  } else {
2072
2133
  this.addResources([
2073
2134
  {
2074
2135
  id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2075
- amount: quantity,
2136
+ amount: usedQuantity,
2076
2137
  assetId,
2077
2138
  owner: resourcesOwner || import_address.Address.fromRandom(),
2078
- maturity: 0,
2079
2139
  blockCreated: (0, import_math7.bn)(1),
2080
2140
  txCreatedIdx: (0, import_math7.bn)(1)
2081
2141
  }
2082
2142
  ]);
2083
2143
  }
2084
2144
  };
2085
- updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2145
+ updateAssetInput(baseAssetId, (0, import_math7.bn)(1e11));
2086
2146
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2087
2147
  }
2088
2148
  /**
@@ -2107,7 +2167,7 @@ var BaseTransactionRequest = class {
2107
2167
  toJSON() {
2108
2168
  return normalizeJSON(this);
2109
2169
  }
2110
- updatePredicateInputs(inputs) {
2170
+ updatePredicateGasUsed(inputs) {
2111
2171
  this.inputs.forEach((i) => {
2112
2172
  let correspondingInput;
2113
2173
  switch (i.type) {
@@ -2129,16 +2189,25 @@ var BaseTransactionRequest = class {
2129
2189
  }
2130
2190
  });
2131
2191
  }
2192
+ shiftPredicateData() {
2193
+ this.inputs.forEach((input) => {
2194
+ if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
2195
+ input.predicateData = input.padPredicateData(
2196
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2197
+ );
2198
+ }
2199
+ });
2200
+ }
2132
2201
  };
2133
2202
 
2134
2203
  // src/providers/transaction-request/create-transaction-request.ts
2135
- var import_configs9 = require("@fuel-ts/address/configs");
2204
+ var import_configs8 = require("@fuel-ts/address/configs");
2136
2205
  var import_math9 = require("@fuel-ts/math");
2137
2206
  var import_transactions8 = require("@fuel-ts/transactions");
2138
2207
  var import_utils13 = require("@fuel-ts/utils");
2139
2208
 
2140
2209
  // src/providers/transaction-request/hash-transaction.ts
2141
- var import_configs8 = require("@fuel-ts/address/configs");
2210
+ var import_configs7 = require("@fuel-ts/address/configs");
2142
2211
  var import_hasher = require("@fuel-ts/hasher");
2143
2212
  var import_math8 = require("@fuel-ts/math");
2144
2213
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2147,7 +2216,7 @@ var import_ramda2 = require("ramda");
2147
2216
  function hashTransaction(transactionRequest, chainId) {
2148
2217
  const transaction = transactionRequest.toTransaction();
2149
2218
  if (transaction.type === import_transactions7.TransactionType.Script) {
2150
- transaction.receiptsRoot = import_configs8.ZeroBytes32;
2219
+ transaction.receiptsRoot = import_configs7.ZeroBytes32;
2151
2220
  }
2152
2221
  transaction.inputs = transaction.inputs.map((input) => {
2153
2222
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2169,10 +2238,10 @@ function hashTransaction(transactionRequest, chainId) {
2169
2238
  blockHeight: 0,
2170
2239
  txIndex: 0
2171
2240
  };
2172
- inputClone.txID = import_configs8.ZeroBytes32;
2241
+ inputClone.txID = import_configs7.ZeroBytes32;
2173
2242
  inputClone.outputIndex = 0;
2174
- inputClone.balanceRoot = import_configs8.ZeroBytes32;
2175
- inputClone.stateRoot = import_configs8.ZeroBytes32;
2243
+ inputClone.balanceRoot = import_configs7.ZeroBytes32;
2244
+ inputClone.stateRoot = import_configs7.ZeroBytes32;
2176
2245
  return inputClone;
2177
2246
  }
2178
2247
  default:
@@ -2183,8 +2252,8 @@ function hashTransaction(transactionRequest, chainId) {
2183
2252
  const outputClone = (0, import_ramda2.clone)(output);
2184
2253
  switch (outputClone.type) {
2185
2254
  case import_transactions7.OutputType.Contract: {
2186
- outputClone.balanceRoot = import_configs8.ZeroBytes32;
2187
- outputClone.stateRoot = import_configs8.ZeroBytes32;
2255
+ outputClone.balanceRoot = import_configs7.ZeroBytes32;
2256
+ outputClone.stateRoot = import_configs7.ZeroBytes32;
2188
2257
  return outputClone;
2189
2258
  }
2190
2259
  case import_transactions7.OutputType.Change: {
@@ -2192,9 +2261,9 @@ function hashTransaction(transactionRequest, chainId) {
2192
2261
  return outputClone;
2193
2262
  }
2194
2263
  case import_transactions7.OutputType.Variable: {
2195
- outputClone.to = import_configs8.ZeroBytes32;
2264
+ outputClone.to = import_configs7.ZeroBytes32;
2196
2265
  outputClone.amount = (0, import_math8.bn)(0);
2197
- outputClone.assetId = import_configs8.ZeroBytes32;
2266
+ outputClone.assetId = import_configs7.ZeroBytes32;
2198
2267
  return outputClone;
2199
2268
  }
2200
2269
  default:
@@ -2252,15 +2321,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2252
2321
  *
2253
2322
  * @param createTransactionRequestLike - The initial values for the instance
2254
2323
  */
2255
- constructor({
2256
- bytecodeWitnessIndex,
2257
- salt,
2258
- storageSlots,
2259
- ...rest
2260
- } = {}) {
2324
+ constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2261
2325
  super(rest);
2262
2326
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2263
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2327
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2264
2328
  this.storageSlots = [...storageSlots ?? []];
2265
2329
  }
2266
2330
  /**
@@ -2275,10 +2339,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2275
2339
  return {
2276
2340
  type: import_transactions8.TransactionType.Create,
2277
2341
  ...baseTransaction,
2278
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2279
2342
  bytecodeWitnessIndex,
2280
- storageSlotsCount: storageSlots.length,
2281
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2343
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2344
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2282
2345
  storageSlots
2283
2346
  };
2284
2347
  }
@@ -2328,7 +2391,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2328
2391
  // src/providers/transaction-request/script-transaction-request.ts
2329
2392
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
2330
2393
  var import_address2 = require("@fuel-ts/address");
2331
- var import_configs10 = require("@fuel-ts/address/configs");
2394
+ var import_configs9 = require("@fuel-ts/address/configs");
2332
2395
  var import_math10 = require("@fuel-ts/math");
2333
2396
  var import_transactions9 = require("@fuel-ts/transactions");
2334
2397
  var import_utils15 = require("@fuel-ts/utils");
@@ -2400,9 +2463,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2400
2463
  type: import_transactions9.TransactionType.Script,
2401
2464
  scriptGasLimit: this.gasLimit,
2402
2465
  ...super.getBaseTransaction(),
2403
- scriptLength: script.length,
2404
- scriptDataLength: scriptData.length,
2405
- receiptsRoot: import_configs10.ZeroBytes32,
2466
+ scriptLength: (0, import_math10.bn)(script.length),
2467
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2468
+ receiptsRoot: import_configs9.ZeroBytes32,
2406
2469
  script: (0, import_utils15.hexlify)(script),
2407
2470
  scriptData: (0, import_utils15.hexlify)(scriptData)
2408
2471
  };
@@ -2465,7 +2528,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2465
2528
  }
2466
2529
  calculateMaxGas(chainInfo, minGas) {
2467
2530
  const { consensusParameters } = chainInfo;
2468
- const { gasPerByte } = consensusParameters;
2531
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2469
2532
  const witnessesLength = this.toTransaction().witnesses.reduce(
2470
2533
  (acc, wit) => acc + wit.dataLength,
2471
2534
  0
@@ -2475,7 +2538,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2475
2538
  minGas,
2476
2539
  witnessesLength,
2477
2540
  witnessLimit: this.witnessLimit,
2478
- gasLimit: this.gasLimit
2541
+ gasLimit: this.gasLimit,
2542
+ maxGasPerTx
2479
2543
  });
2480
2544
  }
2481
2545
  /**
@@ -2550,15 +2614,32 @@ var transactionRequestify = (obj) => {
2550
2614
  }
2551
2615
  }
2552
2616
  };
2617
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2618
+ (acc, input) => {
2619
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2620
+ acc.utxos.push(input.id);
2621
+ }
2622
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2623
+ acc.messages.push(input.nonce);
2624
+ }
2625
+ return acc;
2626
+ },
2627
+ {
2628
+ utxos: [],
2629
+ messages: []
2630
+ }
2631
+ );
2553
2632
 
2554
2633
  // src/providers/transaction-response/transaction-response.ts
2555
2634
  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");
2635
+ var import_math15 = require("@fuel-ts/math");
2636
+ var import_transactions18 = require("@fuel-ts/transactions");
2637
+ var import_utils20 = require("@fuel-ts/utils");
2559
2638
 
2560
2639
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2561
- var import_utils19 = require("@fuel-ts/utils");
2640
+ var import_math14 = require("@fuel-ts/math");
2641
+ var import_transactions16 = require("@fuel-ts/transactions");
2642
+ var import_utils18 = require("@fuel-ts/utils");
2562
2643
 
2563
2644
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2564
2645
  var import_math11 = require("@fuel-ts/math");
@@ -2566,9 +2647,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
2566
2647
  var import_utils16 = require("@fuel-ts/utils");
2567
2648
  var calculateTransactionFee = (params) => {
2568
2649
  const {
2569
- gasUsed,
2650
+ gasPrice,
2570
2651
  rawPayload,
2571
- consensusParameters: { gasCosts, feeParams }
2652
+ tip,
2653
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2572
2654
  } = params;
2573
2655
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2574
2656
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2578,8 +2660,7 @@ var calculateTransactionFee = (params) => {
2578
2660
  return {
2579
2661
  fee: (0, import_math11.bn)(0),
2580
2662
  minFee: (0, import_math11.bn)(0),
2581
- maxFee: (0, import_math11.bn)(0),
2582
- feeFromGasUsed: (0, import_math11.bn)(0)
2663
+ maxFee: (0, import_math11.bn)(0)
2583
2664
  };
2584
2665
  }
2585
2666
  const { type, witnesses, inputs, policies } = transaction;
@@ -2611,7 +2692,6 @@ var calculateTransactionFee = (params) => {
2611
2692
  metadataGas,
2612
2693
  txBytesSize: transactionBytes.length
2613
2694
  });
2614
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2615
2695
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2616
2696
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2617
2697
  const maxGas = getMaxGas({
@@ -2619,22 +2699,30 @@ var calculateTransactionFee = (params) => {
2619
2699
  minGas,
2620
2700
  witnessesLength,
2621
2701
  gasLimit,
2622
- witnessLimit
2702
+ witnessLimit,
2703
+ maxGasPerTx
2704
+ });
2705
+ const minFee = calculateGasFee({
2706
+ gasPrice,
2707
+ gas: minGas,
2708
+ priceFactor: gasPriceFactor,
2709
+ tip
2710
+ });
2711
+ const maxFee = calculateGasFee({
2712
+ gasPrice,
2713
+ gas: maxGas,
2714
+ priceFactor: gasPriceFactor,
2715
+ tip
2623
2716
  });
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
2717
  return {
2629
- fee,
2630
2718
  minFee,
2631
2719
  maxFee,
2632
- feeFromGasUsed
2720
+ fee: maxFee
2633
2721
  };
2634
2722
  };
2635
2723
 
2636
2724
  // src/providers/transaction-summary/operations.ts
2637
- var import_configs11 = require("@fuel-ts/address/configs");
2725
+ var import_configs10 = require("@fuel-ts/address/configs");
2638
2726
  var import_errors11 = require("@fuel-ts/errors");
2639
2727
  var import_math13 = require("@fuel-ts/math");
2640
2728
  var import_transactions14 = require("@fuel-ts/transactions");
@@ -2932,7 +3020,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
2932
3020
  const { to: toAddress, assetId, amount } = receipt;
2933
3021
  let { from: fromAddress } = receipt;
2934
3022
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
2935
- if (import_configs11.ZeroBytes32 === fromAddress) {
3023
+ if (import_configs10.ZeroBytes32 === fromAddress) {
2936
3024
  const change = changeOutputs.find((output) => output.assetId === assetId);
2937
3025
  fromAddress = change?.to || fromAddress;
2938
3026
  }
@@ -3196,10 +3284,12 @@ function assembleTransactionSummary(params) {
3196
3284
  gqlTransactionStatus,
3197
3285
  abiMap = {},
3198
3286
  maxInputs,
3199
- gasCosts
3287
+ gasCosts,
3288
+ maxGasPerTx,
3289
+ gasPrice
3200
3290
  } = params;
3201
3291
  const gasUsed = getGasUsedFromReceipts(receipts);
3202
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3292
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3203
3293
  const operations = getOperations({
3204
3294
  transactionType: transaction.type,
3205
3295
  inputs: transaction.inputs || [],
@@ -3210,11 +3300,14 @@ function assembleTransactionSummary(params) {
3210
3300
  maxInputs
3211
3301
  });
3212
3302
  const typeName = getTransactionTypeName(transaction.type);
3303
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3213
3304
  const { fee } = calculateTransactionFee({
3214
- gasUsed,
3305
+ gasPrice,
3215
3306
  rawPayload,
3307
+ tip,
3216
3308
  consensusParameters: {
3217
3309
  gasCosts,
3310
+ maxGasPerTx,
3218
3311
  feeParams: {
3219
3312
  gasPerByte,
3220
3313
  gasPriceFactor
@@ -3226,7 +3319,7 @@ function assembleTransactionSummary(params) {
3226
3319
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3227
3320
  let date;
3228
3321
  if (time) {
3229
- date = import_utils19.DateTime.fromTai64(time);
3322
+ date = import_utils18.DateTime.fromTai64(time);
3230
3323
  }
3231
3324
  const transactionSummary = {
3232
3325
  id,
@@ -3254,12 +3347,12 @@ function assembleTransactionSummary(params) {
3254
3347
 
3255
3348
  // src/providers/transaction-response/getDecodedLogs.ts
3256
3349
  var import_abi_coder5 = require("@fuel-ts/abi-coder");
3257
- var import_transactions16 = require("@fuel-ts/transactions");
3350
+ var import_transactions17 = require("@fuel-ts/transactions");
3258
3351
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3259
3352
  return receipts.reduce((logs, receipt) => {
3260
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3353
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3261
3354
  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;
3355
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3263
3356
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3264
3357
  logs.push(decodedLog);
3265
3358
  }
@@ -3274,7 +3367,7 @@ var TransactionResponse = class {
3274
3367
  /** Current provider */
3275
3368
  provider;
3276
3369
  /** Gas used on the transaction */
3277
- gasUsed = (0, import_math14.bn)(0);
3370
+ gasUsed = (0, import_math15.bn)(0);
3278
3371
  /** The graphql Transaction with receipts object. */
3279
3372
  gqlTransaction;
3280
3373
  abis;
@@ -3332,8 +3425,8 @@ var TransactionResponse = class {
3332
3425
  * @returns The decoded transaction.
3333
3426
  */
3334
3427
  decodeTransaction(transactionWithReceipts) {
3335
- return new import_transactions17.TransactionCoder().decode(
3336
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3428
+ return new import_transactions18.TransactionCoder().decode(
3429
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3337
3430
  0
3338
3431
  )?.[0];
3339
3432
  }
@@ -3352,20 +3445,27 @@ var TransactionResponse = class {
3352
3445
  const decodedTransaction = this.decodeTransaction(
3353
3446
  transaction
3354
3447
  );
3355
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3356
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3448
+ let txReceipts = [];
3449
+ if (transaction?.status && "receipts" in transaction.status) {
3450
+ txReceipts = transaction.status.receipts;
3451
+ }
3452
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3453
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3454
+ const gasPrice = await this.provider.getLatestGasPrice();
3357
3455
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3358
3456
  const transactionSummary = assembleTransactionSummary({
3359
3457
  id: this.id,
3360
3458
  receipts,
3361
3459
  transaction: decodedTransaction,
3362
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3460
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3363
3461
  gqlTransactionStatus: transaction.status,
3364
3462
  gasPerByte,
3365
3463
  gasPriceFactor,
3366
3464
  abiMap: contractsAbiMap,
3367
3465
  maxInputs,
3368
- gasCosts
3466
+ gasCosts,
3467
+ maxGasPerTx,
3468
+ gasPrice
3369
3469
  });
3370
3470
  return transactionSummary;
3371
3471
  }
@@ -3471,7 +3571,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3471
3571
  }
3472
3572
 
3473
3573
  // src/providers/utils/merge-quantities.ts
3474
- var mergeQuantities = (arr1, arr2) => {
3574
+ var mergeQuantities = (...coinQuantities) => {
3475
3575
  const resultMap = {};
3476
3576
  function addToMap({ amount, assetId }) {
3477
3577
  if (resultMap[assetId]) {
@@ -3480,8 +3580,7 @@ var mergeQuantities = (arr1, arr2) => {
3480
3580
  resultMap[assetId] = amount;
3481
3581
  }
3482
3582
  }
3483
- arr1.forEach(addToMap);
3484
- arr2.forEach(addToMap);
3583
+ coinQuantities.forEach((arr) => arr.forEach(addToMap));
3485
3584
  return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3486
3585
  };
3487
3586
 
@@ -3492,29 +3591,30 @@ var processGqlChain = (chain) => {
3492
3591
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3493
3592
  return {
3494
3593
  name,
3495
- baseChainHeight: (0, import_math15.bn)(daHeight),
3594
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3496
3595
  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),
3596
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3597
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3598
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3599
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3600
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3601
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3602
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3603
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3604
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3605
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3606
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3607
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3608
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3609
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3610
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3611
+ baseAssetId: consensusParameters.baseAssetId,
3512
3612
  gasCosts
3513
3613
  },
3514
3614
  gasCosts,
3515
3615
  latestBlock: {
3516
3616
  id: latestBlock.id,
3517
- height: (0, import_math15.bn)(latestBlock.header.height),
3617
+ height: (0, import_math16.bn)(latestBlock.height),
3518
3618
  time: latestBlock.header.time,
3519
3619
  transactions: latestBlock.transactions.map((i) => ({
3520
3620
  id: i.id
@@ -3608,10 +3708,8 @@ var _Provider = class {
3608
3708
  * Returns some helpful parameters related to gas fees.
3609
3709
  */
3610
3710
  getGasConfig() {
3611
- const { minGasPrice } = this.getNode();
3612
3711
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3613
3712
  return {
3614
- minGasPrice,
3615
3713
  maxGasPerTx,
3616
3714
  maxGasPerPredicate,
3617
3715
  gasPriceFactor,
@@ -3709,7 +3807,7 @@ var _Provider = class {
3709
3807
  */
3710
3808
  async getBlockNumber() {
3711
3809
  const { chain } = await this.operations.getChain();
3712
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
3810
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3713
3811
  }
3714
3812
  /**
3715
3813
  * Returns the chain information.
@@ -3719,13 +3817,11 @@ var _Provider = class {
3719
3817
  async fetchNode() {
3720
3818
  const { nodeInfo } = await this.operations.getNodeInfo();
3721
3819
  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),
3820
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
3821
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3725
3822
  nodeVersion: nodeInfo.nodeVersion,
3726
3823
  utxoValidation: nodeInfo.utxoValidation,
3727
- vmBacktrace: nodeInfo.vmBacktrace,
3728
- peers: nodeInfo.peers
3824
+ vmBacktrace: nodeInfo.vmBacktrace
3729
3825
  };
3730
3826
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3731
3827
  return processedNodeInfo;
@@ -3751,6 +3847,17 @@ var _Provider = class {
3751
3847
  } = this.getChain();
3752
3848
  return chainId.toNumber();
3753
3849
  }
3850
+ /**
3851
+ * Returns the base asset ID for the current provider network
3852
+ *
3853
+ * @returns the base asset ID
3854
+ */
3855
+ getBaseAssetId() {
3856
+ const {
3857
+ consensusParameters: { baseAssetId }
3858
+ } = this.getChain();
3859
+ return baseAssetId;
3860
+ }
3754
3861
  /**
3755
3862
  * Submits a transaction to the chain to be executed.
3756
3863
  *
@@ -3767,9 +3874,9 @@ var _Provider = class {
3767
3874
  if (estimateTxDependencies) {
3768
3875
  await this.estimateTxDependencies(transactionRequest);
3769
3876
  }
3770
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3877
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3771
3878
  let abis;
3772
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
3879
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
3773
3880
  abis = transactionRequest.abis;
3774
3881
  }
3775
3882
  if (awaitExecution) {
@@ -3810,15 +3917,14 @@ var _Provider = class {
3810
3917
  if (estimateTxDependencies) {
3811
3918
  return this.estimateTxDependencies(transactionRequest);
3812
3919
  }
3813
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3814
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3815
- encodedTransaction,
3920
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3921
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
3922
+ encodedTransactions: encodedTransaction,
3816
3923
  utxoValidation: utxoValidation || false
3817
3924
  });
3818
- const receipts = gqlReceipts.map(processGqlReceipt);
3819
- return {
3820
- receipts
3821
- };
3925
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
3926
+ const receipts = rawReceipts.map(processGqlReceipt);
3927
+ return { receipts, dryrunStatus: status };
3822
3928
  }
3823
3929
  /**
3824
3930
  * Verifies whether enough gas is available to complete transaction.
@@ -3829,13 +3935,13 @@ var _Provider = class {
3829
3935
  async estimatePredicates(transactionRequest) {
3830
3936
  const shouldEstimatePredicates = Boolean(
3831
3937
  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()
3938
+ (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
3833
3939
  )
3834
3940
  );
3835
3941
  if (!shouldEstimatePredicates) {
3836
3942
  return transactionRequest;
3837
3943
  }
3838
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3944
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3839
3945
  const response = await this.operations.estimatePredicates({
3840
3946
  encodedTransaction
3841
3947
  });
@@ -3844,7 +3950,7 @@ var _Provider = class {
3844
3950
  } = response;
3845
3951
  if (inputs) {
3846
3952
  inputs.forEach((input, index) => {
3847
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
3953
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
3848
3954
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3849
3955
  }
3850
3956
  });
@@ -3857,31 +3963,31 @@ var _Provider = class {
3857
3963
  * If there are missing variable outputs,
3858
3964
  * `addVariableOutputs` is called on the transaction.
3859
3965
  *
3860
- * @privateRemarks
3861
- * TODO: Investigate support for missing contract IDs
3862
- * TODO: Add support for missing output messages
3863
3966
  *
3864
3967
  * @param transactionRequest - The transaction request object.
3865
3968
  * @returns A promise.
3866
3969
  */
3867
3970
  async estimateTxDependencies(transactionRequest) {
3868
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
3971
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
3869
3972
  return {
3870
3973
  receipts: [],
3871
3974
  outputVariables: 0,
3872
3975
  missingContractIds: []
3873
3976
  };
3874
3977
  }
3875
- await this.estimatePredicates(transactionRequest);
3876
3978
  let receipts = [];
3877
3979
  const missingContractIds = [];
3878
3980
  let outputVariables = 0;
3981
+ let dryrunStatus;
3879
3982
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3880
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3881
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
3983
+ const {
3984
+ dryRun: [{ receipts: rawReceipts, status }]
3985
+ } = await this.operations.dryRun({
3986
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
3882
3987
  utxoValidation: false
3883
3988
  });
3884
- receipts = gqlReceipts.map(processGqlReceipt);
3989
+ receipts = rawReceipts.map(processGqlReceipt);
3990
+ dryrunStatus = status;
3885
3991
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3886
3992
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3887
3993
  if (hasMissingOutputs) {
@@ -3891,6 +3997,10 @@ var _Provider = class {
3891
3997
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
3892
3998
  missingContractIds.push(contractId);
3893
3999
  });
4000
+ const { maxFee } = await this.estimateTxGasAndFee({
4001
+ transactionRequest
4002
+ });
4003
+ transactionRequest.maxFee = maxFee;
3894
4004
  } else {
3895
4005
  break;
3896
4006
  }
@@ -3898,37 +4008,136 @@ var _Provider = class {
3898
4008
  return {
3899
4009
  receipts,
3900
4010
  outputVariables,
3901
- missingContractIds
4011
+ missingContractIds,
4012
+ dryrunStatus
3902
4013
  };
3903
4014
  }
4015
+ /**
4016
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4017
+ *
4018
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4019
+ * further modifications are identified. The method iteratively updates these transactions
4020
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4021
+ *
4022
+ * @param transactionRequests - Array of transaction request objects.
4023
+ * @returns A promise that resolves to an array of results for each transaction.
4024
+ */
4025
+ async estimateMultipleTxDependencies(transactionRequests) {
4026
+ const results = transactionRequests.map(() => ({
4027
+ receipts: [],
4028
+ outputVariables: 0,
4029
+ missingContractIds: [],
4030
+ dryrunStatus: void 0
4031
+ }));
4032
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4033
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4034
+ allRequests.forEach((req, index) => {
4035
+ if (req.type === import_transactions19.TransactionType.Script) {
4036
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4037
+ }
4038
+ });
4039
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4040
+ let attempt = 0;
4041
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4042
+ const encodedTransactions = transactionsToProcess.map(
4043
+ (index) => serializedTransactionsMap.get(index)
4044
+ );
4045
+ const dryRunResults = await this.operations.dryRun({
4046
+ encodedTransactions,
4047
+ utxoValidation: false
4048
+ });
4049
+ const nextRoundTransactions = [];
4050
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4051
+ const requestIdx = transactionsToProcess[i];
4052
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4053
+ const result = results[requestIdx];
4054
+ result.receipts = rawReceipts.map(processGqlReceipt);
4055
+ result.dryrunStatus = status;
4056
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4057
+ result.receipts
4058
+ );
4059
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4060
+ const request = allRequests[requestIdx];
4061
+ if (hasMissingOutputs && request?.type === import_transactions19.TransactionType.Script) {
4062
+ result.outputVariables += missingOutputVariables.length;
4063
+ request.addVariableOutputs(missingOutputVariables.length);
4064
+ missingOutputContractIds.forEach(({ contractId }) => {
4065
+ request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4066
+ result.missingContractIds.push(contractId);
4067
+ });
4068
+ const { maxFee } = await this.estimateTxGasAndFee({
4069
+ transactionRequest: request
4070
+ });
4071
+ request.maxFee = maxFee;
4072
+ serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
4073
+ nextRoundTransactions.push(requestIdx);
4074
+ }
4075
+ }
4076
+ transactionsToProcess = nextRoundTransactions;
4077
+ attempt += 1;
4078
+ }
4079
+ return results;
4080
+ }
4081
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4082
+ if (estimateTxDependencies) {
4083
+ return this.estimateMultipleTxDependencies(transactionRequests);
4084
+ }
4085
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4086
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4087
+ encodedTransactions,
4088
+ utxoValidation: utxoValidation || false
4089
+ });
4090
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4091
+ const receipts = rawReceipts.map(processGqlReceipt);
4092
+ return { receipts, dryrunStatus: status };
4093
+ });
4094
+ return results;
4095
+ }
3904
4096
  /**
3905
4097
  * Estimates the transaction gas and fee based on the provided transaction request.
3906
4098
  * @param transactionRequest - The transaction request object.
3907
4099
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3908
4100
  */
3909
- estimateTxGasAndFee(params) {
4101
+ async estimateTxGasAndFee(params) {
3910
4102
  const { transactionRequest } = params;
3911
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4103
+ let { gasPrice } = params;
3912
4104
  const chainInfo = this.getChain();
3913
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3914
- transactionRequest.gasPrice = gasPrice;
4105
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
3915
4106
  const minGas = transactionRequest.calculateMinGas(chainInfo);
3916
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3917
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4107
+ if (!gasPrice) {
4108
+ gasPrice = await this.estimateGasPrice(10);
4109
+ }
4110
+ const minFee = calculateGasFee({
4111
+ gasPrice: (0, import_math16.bn)(gasPrice),
4112
+ gas: minGas,
4113
+ priceFactor: gasPriceFactor,
4114
+ tip: transactionRequest.tip
4115
+ }).add(1);
4116
+ let gasLimit = (0, import_math16.bn)(0);
4117
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4118
+ gasLimit = transactionRequest.gasLimit;
3918
4119
  if (transactionRequest.gasLimit.eq(0)) {
3919
4120
  transactionRequest.gasLimit = minGas;
3920
4121
  transactionRequest.gasLimit = maxGasPerTx.sub(
3921
4122
  transactionRequest.calculateMaxGas(chainInfo, minGas)
3922
4123
  );
4124
+ gasLimit = transactionRequest.gasLimit;
3923
4125
  }
3924
4126
  }
3925
4127
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3926
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4128
+ const maxFee = calculateGasFee({
4129
+ gasPrice: (0, import_math16.bn)(gasPrice),
4130
+ gas: maxGas,
4131
+ priceFactor: gasPriceFactor,
4132
+ tip: transactionRequest.tip
4133
+ }).add(1);
3927
4134
  return {
3928
4135
  minGas,
3929
4136
  minFee,
3930
4137
  maxGas,
3931
- maxFee
4138
+ maxFee,
4139
+ gasPrice,
4140
+ gasLimit
3932
4141
  };
3933
4142
  }
3934
4143
  /**
@@ -3946,15 +4155,17 @@ var _Provider = class {
3946
4155
  if (estimateTxDependencies) {
3947
4156
  return this.estimateTxDependencies(transactionRequest);
3948
4157
  }
3949
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3950
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3951
- encodedTransaction,
4158
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4159
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4160
+ encodedTransactions,
3952
4161
  utxoValidation: true
3953
4162
  });
3954
- const receipts = gqlReceipts.map(processGqlReceipt);
3955
- return {
3956
- receipts
3957
- };
4163
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4164
+ const { id, receipts, status } = dryRunStatus;
4165
+ const processedReceipts = receipts.map(processGqlReceipt);
4166
+ return { id, receipts: processedReceipts, status };
4167
+ });
4168
+ return { receipts: callResult[0].receipts };
3958
4169
  }
3959
4170
  /**
3960
4171
  * Returns a transaction cost to enable user
@@ -3971,77 +4182,80 @@ var _Provider = class {
3971
4182
  * @param tolerance - The tolerance to add on top of the gasUsed.
3972
4183
  * @returns A promise that resolves to the transaction cost object.
3973
4184
  */
3974
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3975
- estimateTxDependencies = true,
3976
- estimatePredicates = true,
3977
- resourcesOwner,
3978
- signatureCallback
3979
- } = {}) {
4185
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3980
4186
  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;
4187
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4188
+ const baseAssetId = this.getBaseAssetId();
3984
4189
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3985
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3986
- txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4190
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4191
+ txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4192
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
3987
4193
  if (isScriptTransaction) {
3988
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4194
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
3989
4195
  }
3990
- if (estimatePredicates) {
3991
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3992
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
3993
- }
3994
- await this.estimatePredicates(txRequestClone);
4196
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4197
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
3995
4198
  }
4199
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4200
+ let addedSignatures = 0;
3996
4201
  if (signatureCallback && isScriptTransaction) {
3997
- await signatureCallback(txRequestClone);
4202
+ const lengthBefore = signedRequest.witnesses.length;
4203
+ await signatureCallback(signedRequest);
4204
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
3998
4205
  }
3999
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4000
- transactionRequest: txRequestClone
4206
+ await this.estimatePredicates(signedRequest);
4207
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4208
+ transactionRequest: signedRequest
4001
4209
  });
4002
4210
  let receipts = [];
4003
4211
  let missingContractIds = [];
4004
4212
  let outputVariables = 0;
4005
- let gasUsed = (0, import_math15.bn)(0);
4006
- if (isScriptTransaction && estimateTxDependencies) {
4007
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
4213
+ let gasUsed = (0, import_math16.bn)(0);
4214
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4215
+ txRequestClone.maxFee = maxFee;
4216
+ if (isScriptTransaction) {
4217
+ txRequestClone.gasLimit = gasLimit;
4218
+ if (signatureCallback) {
4219
+ await signatureCallback(txRequestClone);
4220
+ }
4008
4221
  const result = await this.estimateTxDependencies(txRequestClone);
4009
4222
  receipts = result.receipts;
4010
4223
  outputVariables = result.outputVariables;
4011
4224
  missingContractIds = result.missingContractIds;
4012
4225
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4013
4226
  txRequestClone.gasLimit = gasUsed;
4014
- txRequestClone.gasPrice = setGasPrice;
4015
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4016
- transactionRequest: txRequestClone
4227
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4228
+ transactionRequest: txRequestClone,
4229
+ gasPrice
4017
4230
  }));
4018
4231
  }
4019
4232
  return {
4020
4233
  requiredQuantities: allQuantities,
4021
4234
  receipts,
4022
4235
  gasUsed,
4023
- minGasPrice,
4024
- gasPrice: setGasPrice,
4236
+ gasPrice,
4025
4237
  minGas,
4026
4238
  maxGas,
4027
4239
  minFee,
4028
4240
  maxFee,
4029
- estimatedInputs: txRequestClone.inputs,
4030
4241
  outputVariables,
4031
- missingContractIds
4242
+ missingContractIds,
4243
+ addedSignatures,
4244
+ estimatedPredicates: txRequestClone.inputs
4032
4245
  };
4033
4246
  }
4034
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4247
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4035
4248
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4036
4249
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4037
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4250
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4251
+ quantitiesToContract
4252
+ });
4038
4253
  transactionRequest.addResources(
4039
4254
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4040
4255
  );
4041
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4042
- transactionRequest,
4043
- forwardingQuantities
4044
- );
4256
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4257
+ quantitiesToContract
4258
+ });
4045
4259
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4046
4260
  return {
4047
4261
  resources,
@@ -4057,17 +4271,16 @@ var _Provider = class {
4057
4271
  const result = await this.operations.getCoins({
4058
4272
  first: 10,
4059
4273
  ...paginationArgs,
4060
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4274
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4061
4275
  });
4062
4276
  const coins = result.coins.edges.map((edge) => edge.node);
4063
4277
  return coins.map((coin) => ({
4064
4278
  id: coin.utxoId,
4065
4279
  assetId: coin.assetId,
4066
- amount: (0, import_math15.bn)(coin.amount),
4280
+ amount: (0, import_math16.bn)(coin.amount),
4067
4281
  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)
4282
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4283
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4071
4284
  }));
4072
4285
  }
4073
4286
  /**
@@ -4081,19 +4294,19 @@ var _Provider = class {
4081
4294
  async getResourcesToSpend(owner, quantities, excludedIds) {
4082
4295
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4083
4296
  const excludeInput = {
4084
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4085
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4297
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4298
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4086
4299
  };
4087
4300
  if (this.cache) {
4088
4301
  const uniqueUtxos = new Set(
4089
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4302
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4090
4303
  );
4091
4304
  excludeInput.utxos = Array.from(uniqueUtxos);
4092
4305
  }
4093
4306
  const coinsQuery = {
4094
4307
  owner: ownerAddress.toB256(),
4095
4308
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4096
- assetId: (0, import_utils23.hexlify)(assetId),
4309
+ assetId: (0, import_utils22.hexlify)(assetId),
4097
4310
  amount: amount.toString(10),
4098
4311
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4099
4312
  })),
@@ -4104,9 +4317,9 @@ var _Provider = class {
4104
4317
  switch (coin.__typename) {
4105
4318
  case "MessageCoin":
4106
4319
  return {
4107
- amount: (0, import_math15.bn)(coin.amount),
4320
+ amount: (0, import_math16.bn)(coin.amount),
4108
4321
  assetId: coin.assetId,
4109
- daHeight: (0, import_math15.bn)(coin.daHeight),
4322
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4110
4323
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4111
4324
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4112
4325
  nonce: coin.nonce
@@ -4114,12 +4327,11 @@ var _Provider = class {
4114
4327
  case "Coin":
4115
4328
  return {
4116
4329
  id: coin.utxoId,
4117
- amount: (0, import_math15.bn)(coin.amount),
4330
+ amount: (0, import_math16.bn)(coin.amount),
4118
4331
  assetId: coin.assetId,
4119
4332
  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)
4333
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4334
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4123
4335
  };
4124
4336
  default:
4125
4337
  return null;
@@ -4136,13 +4348,13 @@ var _Provider = class {
4136
4348
  async getBlock(idOrHeight) {
4137
4349
  let variables;
4138
4350
  if (typeof idOrHeight === "number") {
4139
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4351
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4140
4352
  } else if (idOrHeight === "latest") {
4141
4353
  variables = { height: (await this.getBlockNumber()).toString(10) };
4142
4354
  } else if (idOrHeight.length === 66) {
4143
4355
  variables = { blockId: idOrHeight };
4144
4356
  } else {
4145
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4357
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4146
4358
  }
4147
4359
  const { block } = await this.operations.getBlock(variables);
4148
4360
  if (!block) {
@@ -4150,7 +4362,7 @@ var _Provider = class {
4150
4362
  }
4151
4363
  return {
4152
4364
  id: block.id,
4153
- height: (0, import_math15.bn)(block.header.height),
4365
+ height: (0, import_math16.bn)(block.height),
4154
4366
  time: block.header.time,
4155
4367
  transactionIds: block.transactions.map((tx) => tx.id)
4156
4368
  };
@@ -4165,7 +4377,7 @@ var _Provider = class {
4165
4377
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4166
4378
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4167
4379
  id: block.id,
4168
- height: (0, import_math15.bn)(block.header.height),
4380
+ height: (0, import_math16.bn)(block.height),
4169
4381
  time: block.header.time,
4170
4382
  transactionIds: block.transactions.map((tx) => tx.id)
4171
4383
  }));
@@ -4180,7 +4392,7 @@ var _Provider = class {
4180
4392
  async getBlockWithTransactions(idOrHeight) {
4181
4393
  let variables;
4182
4394
  if (typeof idOrHeight === "number") {
4183
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4395
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4184
4396
  } else if (idOrHeight === "latest") {
4185
4397
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4186
4398
  } else {
@@ -4192,11 +4404,11 @@ var _Provider = class {
4192
4404
  }
4193
4405
  return {
4194
4406
  id: block.id,
4195
- height: (0, import_math15.bn)(block.header.height, 10),
4407
+ height: (0, import_math16.bn)(block.height, 10),
4196
4408
  time: block.header.time,
4197
4409
  transactionIds: block.transactions.map((tx) => tx.id),
4198
4410
  transactions: block.transactions.map(
4199
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4411
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4200
4412
  )
4201
4413
  };
4202
4414
  }
@@ -4211,8 +4423,8 @@ var _Provider = class {
4211
4423
  if (!transaction) {
4212
4424
  return null;
4213
4425
  }
4214
- return new import_transactions18.TransactionCoder().decode(
4215
- (0, import_utils23.arrayify)(transaction.rawPayload),
4426
+ return new import_transactions19.TransactionCoder().decode(
4427
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4216
4428
  0
4217
4429
  )?.[0];
4218
4430
  }
@@ -4239,9 +4451,9 @@ var _Provider = class {
4239
4451
  async getContractBalance(contractId, assetId) {
4240
4452
  const { contractBalance } = await this.operations.getContractBalance({
4241
4453
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4242
- asset: (0, import_utils23.hexlify)(assetId)
4454
+ asset: (0, import_utils22.hexlify)(assetId)
4243
4455
  });
4244
- return (0, import_math15.bn)(contractBalance.amount, 10);
4456
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4245
4457
  }
4246
4458
  /**
4247
4459
  * Returns the balance for the given owner for the given asset ID.
@@ -4253,9 +4465,9 @@ var _Provider = class {
4253
4465
  async getBalance(owner, assetId) {
4254
4466
  const { balance } = await this.operations.getBalance({
4255
4467
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4256
- assetId: (0, import_utils23.hexlify)(assetId)
4468
+ assetId: (0, import_utils22.hexlify)(assetId)
4257
4469
  });
4258
- return (0, import_math15.bn)(balance.amount, 10);
4470
+ return (0, import_math16.bn)(balance.amount, 10);
4259
4471
  }
4260
4472
  /**
4261
4473
  * Returns balances for the given owner.
@@ -4273,7 +4485,7 @@ var _Provider = class {
4273
4485
  const balances = result.balances.edges.map((edge) => edge.node);
4274
4486
  return balances.map((balance) => ({
4275
4487
  assetId: balance.assetId,
4276
- amount: (0, import_math15.bn)(balance.amount)
4488
+ amount: (0, import_math16.bn)(balance.amount)
4277
4489
  }));
4278
4490
  }
4279
4491
  /**
@@ -4291,19 +4503,19 @@ var _Provider = class {
4291
4503
  });
4292
4504
  const messages = result.messages.edges.map((edge) => edge.node);
4293
4505
  return messages.map((message) => ({
4294
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4506
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4295
4507
  sender: message.sender,
4296
4508
  recipient: message.recipient,
4297
4509
  nonce: message.nonce,
4298
- amount: (0, import_math15.bn)(message.amount),
4510
+ amount: (0, import_math16.bn)(message.amount),
4299
4511
  data: message.data
4300
4512
  }),
4301
4513
  sender: import_address3.Address.fromAddressOrString(message.sender),
4302
4514
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4303
4515
  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)
4516
+ amount: (0, import_math16.bn)(message.amount),
4517
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4518
+ daHeight: (0, import_math16.bn)(message.daHeight)
4307
4519
  }));
4308
4520
  }
4309
4521
  /**
@@ -4356,44 +4568,60 @@ var _Provider = class {
4356
4568
  } = result.messageProof;
4357
4569
  return {
4358
4570
  messageProof: {
4359
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4571
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4360
4572
  proofSet: messageProof.proofSet
4361
4573
  },
4362
4574
  blockProof: {
4363
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4575
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4364
4576
  proofSet: blockProof.proofSet
4365
4577
  },
4366
4578
  messageBlockHeader: {
4367
4579
  id: messageBlockHeader.id,
4368
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4369
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4580
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4581
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4370
4582
  transactionsRoot: messageBlockHeader.transactionsRoot,
4371
- height: (0, import_math15.bn)(messageBlockHeader.height),
4583
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4372
4584
  prevRoot: messageBlockHeader.prevRoot,
4373
4585
  time: messageBlockHeader.time,
4374
4586
  applicationHash: messageBlockHeader.applicationHash,
4375
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4376
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4587
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
4588
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4589
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4590
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4591
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4377
4592
  },
4378
4593
  commitBlockHeader: {
4379
4594
  id: commitBlockHeader.id,
4380
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4381
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4595
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4596
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4382
4597
  transactionsRoot: commitBlockHeader.transactionsRoot,
4383
- height: (0, import_math15.bn)(commitBlockHeader.height),
4598
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4384
4599
  prevRoot: commitBlockHeader.prevRoot,
4385
4600
  time: commitBlockHeader.time,
4386
4601
  applicationHash: commitBlockHeader.applicationHash,
4387
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4388
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4602
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
4603
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4604
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4605
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4606
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4389
4607
  },
4390
4608
  sender: import_address3.Address.fromAddressOrString(sender),
4391
4609
  recipient: import_address3.Address.fromAddressOrString(recipient),
4392
4610
  nonce,
4393
- amount: (0, import_math15.bn)(amount),
4611
+ amount: (0, import_math16.bn)(amount),
4394
4612
  data
4395
4613
  };
4396
4614
  }
4615
+ async getLatestGasPrice() {
4616
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4617
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4618
+ }
4619
+ async estimateGasPrice(blockHorizon) {
4620
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4621
+ blockHorizon: String(blockHorizon)
4622
+ });
4623
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4624
+ }
4397
4625
  /**
4398
4626
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4399
4627
  *
@@ -4413,10 +4641,10 @@ var _Provider = class {
4413
4641
  */
4414
4642
  async produceBlocks(amount, startTime) {
4415
4643
  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
4644
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4645
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4418
4646
  });
4419
- return (0, import_math15.bn)(latestBlockHeight);
4647
+ return (0, import_math16.bn)(latestBlockHeight);
4420
4648
  }
4421
4649
  // eslint-disable-next-line @typescript-eslint/require-await
4422
4650
  async getTransactionResponse(transactionId) {
@@ -4430,7 +4658,7 @@ cacheInputs_fn = function(inputs) {
4430
4658
  return;
4431
4659
  }
4432
4660
  inputs.forEach((input) => {
4433
- if (input.type === import_transactions18.InputType.Coin) {
4661
+ if (input.type === import_transactions19.InputType.Coin) {
4434
4662
  this.cache?.set(input.id);
4435
4663
  }
4436
4664
  });
@@ -4440,9 +4668,9 @@ __publicField(Provider, "nodeInfoCache", {});
4440
4668
 
4441
4669
  // src/providers/transaction-summary/get-transaction-summary.ts
4442
4670
  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");
4671
+ var import_math17 = require("@fuel-ts/math");
4672
+ var import_transactions20 = require("@fuel-ts/transactions");
4673
+ var import_utils25 = require("@fuel-ts/utils");
4446
4674
 
4447
4675
  // src/providers/chains.ts
4448
4676
  var CHAIN_IDS = {
@@ -4491,17 +4719,17 @@ var assets = [
4491
4719
 
4492
4720
  // src/utils/formatTransferToContractScriptData.ts
4493
4721
  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");
4722
+ var import_math18 = require("@fuel-ts/math");
4723
+ var import_utils26 = require("@fuel-ts/utils");
4496
4724
  var asm = __toESM(require("@fuels/vm-asm"));
4497
4725
  var formatTransferToContractScriptData = (params) => {
4498
4726
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4499
4727
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4500
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4728
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4501
4729
  const scriptData = Uint8Array.from([
4502
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
4730
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4503
4731
  ...encoded,
4504
- ...(0, import_utils27.arrayify)(assetId)
4732
+ ...(0, import_utils26.arrayify)(assetId)
4505
4733
  ]);
4506
4734
  return scriptData;
4507
4735
  };
@@ -4648,8 +4876,9 @@ var Account = class extends import_interfaces.AbstractAccount {
4648
4876
  * @param assetId - The asset ID to check the balance for.
4649
4877
  * @returns A promise that resolves to the balance amount.
4650
4878
  */
4651
- async getBalance(assetId = import_configs12.BaseAssetId) {
4652
- const amount = await this.provider.getBalance(this.address, assetId);
4879
+ async getBalance(assetId) {
4880
+ const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4881
+ const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4653
4882
  return amount;
4654
4883
  }
4655
4884
  /**
@@ -4686,37 +4915,31 @@ var Account = class extends import_interfaces.AbstractAccount {
4686
4915
  * @param fee - The estimated transaction fee.
4687
4916
  * @returns A promise that resolves when the resources are added to the transaction.
4688
4917
  */
4689
- async fund(request, coinQuantities, fee) {
4690
- const updatedQuantities = addAmountToAsset({
4691
- amount: (0, import_math18.bn)(fee),
4692
- assetId: import_configs12.BaseAssetId,
4693
- coinQuantities
4918
+ async fund(request, params) {
4919
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4920
+ const baseAssetId = this.provider.getBaseAssetId();
4921
+ const txRequest = request;
4922
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4923
+ amount: (0, import_math19.bn)(fee),
4924
+ assetId: baseAssetId,
4925
+ coinQuantities: requiredQuantities
4694
4926
  });
4695
4927
  const quantitiesDict = {};
4696
- updatedQuantities.forEach(({ amount, assetId }) => {
4928
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4697
4929
  quantitiesDict[assetId] = {
4698
4930
  required: amount,
4699
- owned: (0, import_math18.bn)(0)
4931
+ owned: (0, import_math19.bn)(0)
4700
4932
  };
4701
4933
  });
4702
- const cachedUtxos = [];
4703
- const cachedMessages = [];
4704
- const owner = this.address.toB256();
4705
- request.inputs.forEach((input) => {
4934
+ txRequest.inputs.forEach((input) => {
4706
4935
  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
- }
4936
+ if (!isResource) {
4937
+ return;
4938
+ }
4939
+ const isCoin2 = "owner" in input;
4940
+ const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
4941
+ if (quantitiesDict[assetId]) {
4942
+ quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
4720
4943
  }
4721
4944
  });
4722
4945
  const missingQuantities = [];
@@ -4730,12 +4953,21 @@ var Account = class extends import_interfaces.AbstractAccount {
4730
4953
  });
4731
4954
  const needsToBeFunded = missingQuantities.length;
4732
4955
  if (needsToBeFunded) {
4733
- const resources = await this.getResourcesToSpend(missingQuantities, {
4734
- messages: cachedMessages,
4735
- utxos: cachedUtxos
4736
- });
4737
- request.addResources(resources);
4738
- }
4956
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
4957
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4958
+ txRequest.addResources(resources);
4959
+ }
4960
+ txRequest.shiftPredicateData();
4961
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
4962
+ const requestToReestimate = (0, import_ramda4.clone)(txRequest);
4963
+ if (addedSignatures) {
4964
+ Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
4965
+ }
4966
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
4967
+ transactionRequest: requestToReestimate
4968
+ });
4969
+ txRequest.maxFee = maxFee;
4970
+ return txRequest;
4739
4971
  }
4740
4972
  /**
4741
4973
  * A helper that creates a transfer transaction request and returns it.
@@ -4743,28 +4975,25 @@ var Account = class extends import_interfaces.AbstractAccount {
4743
4975
  * @param destination - The address of the destination.
4744
4976
  * @param amount - The amount of coins to transfer.
4745
4977
  * @param assetId - The asset ID of the coins to transfer.
4746
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4978
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4747
4979
  * @returns A promise that resolves to the prepared transaction request.
4748
4980
  */
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, [], {
4981
+ async createTransfer(destination, amount, assetId, txParams = {}) {
4982
+ const request = new ScriptTransactionRequest(txParams);
4983
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4984
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
4985
+ const txCost = await this.provider.getTransactionCost(request, {
4755
4986
  estimateTxDependencies: true,
4756
4987
  resourcesOwner: this
4757
4988
  });
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
4989
+ this.validateGasLimitAndMaxFee({
4990
+ gasUsed: txCost.gasUsed,
4991
+ maxFee: txCost.maxFee,
4992
+ txParams
4765
4993
  });
4766
- await this.fund(request, requiredQuantities, maxFee);
4767
- request.updatePredicateInputs(estimatedInputs);
4994
+ request.gasLimit = txCost.gasUsed;
4995
+ request.maxFee = txCost.maxFee;
4996
+ await this.fund(request, txCost);
4768
4997
  return request;
4769
4998
  }
4770
4999
  /**
@@ -4773,17 +5002,18 @@ var Account = class extends import_interfaces.AbstractAccount {
4773
5002
  * @param destination - The address of the destination.
4774
5003
  * @param amount - The amount of coins to transfer.
4775
5004
  * @param assetId - The asset ID of the coins to transfer.
4776
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5005
+ * @param txParams - The transaction parameters (gasLimit, maturity).
4777
5006
  * @returns A promise that resolves to the transaction response.
4778
5007
  */
4779
- async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4780
- if ((0, import_math18.bn)(amount).lte(0)) {
5008
+ async transfer(destination, amount, assetId, txParams = {}) {
5009
+ if ((0, import_math19.bn)(amount).lte(0)) {
4781
5010
  throw new import_errors16.FuelError(
4782
5011
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4783
5012
  "Transfer amount must be a positive number."
4784
5013
  );
4785
5014
  }
4786
- const request = await this.createTransfer(destination, amount, assetId, txParams);
5015
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5016
+ const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4787
5017
  return this.sendTransaction(request, { estimateTxDependencies: false });
4788
5018
  }
4789
5019
  /**
@@ -4795,39 +5025,38 @@ var Account = class extends import_interfaces.AbstractAccount {
4795
5025
  * @param txParams - The optional transaction parameters.
4796
5026
  * @returns A promise that resolves to the transaction response.
4797
5027
  */
4798
- async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4799
- if ((0, import_math18.bn)(amount).lte(0)) {
5028
+ async transferToContract(contractId, amount, assetId, txParams = {}) {
5029
+ if ((0, import_math19.bn)(amount).lte(0)) {
4800
5030
  throw new import_errors16.FuelError(
4801
5031
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4802
5032
  "Transfer amount must be a positive number."
4803
5033
  );
4804
5034
  }
4805
5035
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4806
- const { minGasPrice } = this.provider.getGasConfig();
4807
- const params = { gasPrice: minGasPrice, ...txParams };
5036
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4808
5037
  const { script, scriptData } = await assembleTransferToContractScript({
4809
5038
  hexlifiedContractId: contractAddress.toB256(),
4810
- amountToTransfer: (0, import_math18.bn)(amount),
4811
- assetId
5039
+ amountToTransfer: (0, import_math19.bn)(amount),
5040
+ assetId: assetIdToTransfer
4812
5041
  });
4813
5042
  const request = new ScriptTransactionRequest({
4814
- ...params,
5043
+ ...txParams,
4815
5044
  script,
4816
5045
  scriptData
4817
5046
  });
4818
5047
  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
5048
+ const txCost = await this.provider.getTransactionCost(request, {
5049
+ resourcesOwner: this,
5050
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetIdToTransfer) }]
4829
5051
  });
4830
- await this.fund(request, requiredQuantities, maxFee);
5052
+ this.validateGasLimitAndMaxFee({
5053
+ gasUsed: txCost.gasUsed,
5054
+ maxFee: txCost.maxFee,
5055
+ txParams
5056
+ });
5057
+ request.gasLimit = txCost.gasUsed;
5058
+ request.maxFee = txCost.maxFee;
5059
+ await this.fund(request, txCost);
4831
5060
  return this.sendTransaction(request);
4832
5061
  }
4833
5062
  /**
@@ -4839,34 +5068,31 @@ var Account = class extends import_interfaces.AbstractAccount {
4839
5068
  * @returns A promise that resolves to the transaction response.
4840
5069
  */
4841
5070
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4842
- const { minGasPrice } = this.provider.getGasConfig();
4843
5071
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
4844
- const recipientDataArray = (0, import_utils28.arrayify)(
5072
+ const recipientDataArray = (0, import_utils27.arrayify)(
4845
5073
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4846
5074
  );
4847
- const amountDataArray = (0, import_utils28.arrayify)(
4848
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5075
+ const amountDataArray = (0, import_utils27.arrayify)(
5076
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
4849
5077
  );
4850
5078
  const script = new Uint8Array([
4851
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5079
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
4852
5080
  ...recipientDataArray,
4853
5081
  ...amountDataArray
4854
5082
  ]);
4855
- const params = { script, gasPrice: minGasPrice, ...txParams };
5083
+ const params = { script, ...txParams };
5084
+ const baseAssetId = this.provider.getBaseAssetId();
4856
5085
  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
5086
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: baseAssetId }];
5087
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5088
+ this.validateGasLimitAndMaxFee({
5089
+ gasUsed: txCost.gasUsed,
5090
+ maxFee: txCost.maxFee,
5091
+ txParams
4868
5092
  });
4869
- await this.fund(request, requiredQuantities, maxFee);
5093
+ request.maxFee = txCost.maxFee;
5094
+ request.gasLimit = txCost.gasUsed;
5095
+ await this.fund(request, txCost);
4870
5096
  return this.sendTransaction(request);
4871
5097
  }
4872
5098
  async signMessage(message) {
@@ -4924,22 +5150,21 @@ var Account = class extends import_interfaces.AbstractAccount {
4924
5150
  }
4925
5151
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
4926
5152
  }
4927
- validateGas({
5153
+ validateGasLimitAndMaxFee({
5154
+ txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
4928
5155
  gasUsed,
4929
- gasPrice,
4930
- gasLimit,
4931
- minGasPrice
5156
+ maxFee
4932
5157
  }) {
4933
- if (minGasPrice.gt(gasPrice)) {
5158
+ if ((0, import_utils27.isDefined)(setGasLimit) && gasUsed.gt(setGasLimit)) {
4934
5159
  throw new import_errors16.FuelError(
4935
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
4936
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5160
+ import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
5161
+ `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
4937
5162
  );
4938
5163
  }
4939
- if (gasUsed.gt(gasLimit)) {
5164
+ if ((0, import_utils27.isDefined)(setMaxFee) && maxFee.gt(setMaxFee)) {
4940
5165
  throw new import_errors16.FuelError(
4941
- import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
4942
- `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
5166
+ import_errors16.ErrorCode.MAX_FEE_TOO_LOW,
5167
+ `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
4943
5168
  );
4944
5169
  }
4945
5170
  }
@@ -4949,8 +5174,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4949
5174
  var import_address5 = require("@fuel-ts/address");
4950
5175
  var import_crypto2 = require("@fuel-ts/crypto");
4951
5176
  var import_hasher2 = require("@fuel-ts/hasher");
4952
- var import_math19 = require("@fuel-ts/math");
4953
- var import_utils29 = require("@fuel-ts/utils");
5177
+ var import_math20 = require("@fuel-ts/math");
5178
+ var import_utils28 = require("@fuel-ts/utils");
4954
5179
  var import_secp256k1 = require("@noble/curves/secp256k1");
4955
5180
  var Signer = class {
4956
5181
  address;
@@ -4969,10 +5194,10 @@ var Signer = class {
4969
5194
  privateKey = `0x${privateKey}`;
4970
5195
  }
4971
5196
  }
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));
5197
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5198
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5199
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5200
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
4976
5201
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
4977
5202
  }
4978
5203
  /**
@@ -4986,11 +5211,11 @@ var Signer = class {
4986
5211
  * @returns hashed signature
4987
5212
  */
4988
5213
  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);
5214
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5215
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5216
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
4992
5217
  s[0] |= (signature.recovery || 0) << 7;
4993
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5218
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
4994
5219
  }
4995
5220
  /**
4996
5221
  * Add point on the current elliptic curve
@@ -4999,8 +5224,8 @@ var Signer = class {
4999
5224
  * @returns compressed point on the curve
5000
5225
  */
5001
5226
  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));
5227
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5228
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
5004
5229
  const result = p0.add(p1);
5005
5230
  return `0x${result.toHex(true)}`;
5006
5231
  }
@@ -5012,16 +5237,16 @@ var Signer = class {
5012
5237
  * @returns public key from signature from the
5013
5238
  */
5014
5239
  static recoverPublicKey(data, signature) {
5015
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5240
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5016
5241
  const r = signedMessageBytes.slice(0, 32);
5017
5242
  const s = signedMessageBytes.slice(32, 64);
5018
5243
  const recoveryParam = (s[0] & 128) >> 7;
5019
5244
  s[0] &= 127;
5020
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5245
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5021
5246
  recoveryParam
5022
5247
  );
5023
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5024
- return (0, import_utils29.hexlify)(publicKey);
5248
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5249
+ return (0, import_utils28.hexlify)(publicKey);
5025
5250
  }
5026
5251
  /**
5027
5252
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5040,7 +5265,7 @@ var Signer = class {
5040
5265
  * @returns random 32-byte hashed
5041
5266
  */
5042
5267
  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);
5268
+ 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
5269
  }
5045
5270
  /**
5046
5271
  * Extended publicKey from a compact publicKey
@@ -5049,8 +5274,8 @@ var Signer = class {
5049
5274
  * @returns extended publicKey
5050
5275
  */
5051
5276
  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));
5277
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5278
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5054
5279
  }
5055
5280
  };
5056
5281
 
@@ -5058,7 +5283,7 @@ var Signer = class {
5058
5283
  var import_address6 = require("@fuel-ts/address");
5059
5284
  var import_crypto3 = require("@fuel-ts/crypto");
5060
5285
  var import_errors17 = require("@fuel-ts/errors");
5061
- var import_utils30 = require("@fuel-ts/utils");
5286
+ var import_utils29 = require("@fuel-ts/utils");
5062
5287
  var import_uuid = require("uuid");
5063
5288
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5064
5289
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5141,7 +5366,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5141
5366
  );
5142
5367
  }
5143
5368
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5144
- const privateKey = (0, import_utils30.hexlify)(buffer);
5369
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5145
5370
  return privateKey;
5146
5371
  }
5147
5372
 
@@ -5186,7 +5411,7 @@ var BaseWalletUnlocked = class extends Account {
5186
5411
  */
5187
5412
  async signMessage(message) {
5188
5413
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5189
- return (0, import_utils31.hexlify)(signedMessage);
5414
+ return (0, import_utils30.hexlify)(signedMessage);
5190
5415
  }
5191
5416
  /**
5192
5417
  * Signs a transaction with the wallet's private key.
@@ -5199,7 +5424,7 @@ var BaseWalletUnlocked = class extends Account {
5199
5424
  const chainId = this.provider.getChainId();
5200
5425
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5201
5426
  const signature = await this.signer().sign(hashedTransaction);
5202
- return (0, import_utils31.hexlify)(signature);
5427
+ return (0, import_utils30.hexlify)(signature);
5203
5428
  }
5204
5429
  /**
5205
5430
  * Populates a transaction with the witnesses signature.
@@ -5219,7 +5444,7 @@ var BaseWalletUnlocked = class extends Account {
5219
5444
  * @param transactionRequestLike - The transaction request to send.
5220
5445
  * @returns A promise that resolves to the TransactionResponse object.
5221
5446
  */
5222
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5447
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5223
5448
  const transactionRequest = transactionRequestify(transactionRequestLike);
5224
5449
  if (estimateTxDependencies) {
5225
5450
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5260,15 +5485,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5260
5485
  // src/hdwallet/hdwallet.ts
5261
5486
  var import_errors20 = require("@fuel-ts/errors");
5262
5487
  var import_hasher6 = require("@fuel-ts/hasher");
5263
- var import_math20 = require("@fuel-ts/math");
5264
- var import_utils35 = require("@fuel-ts/utils");
5488
+ var import_math21 = require("@fuel-ts/math");
5489
+ var import_utils34 = require("@fuel-ts/utils");
5265
5490
  var import_ethers3 = require("ethers");
5266
5491
 
5267
5492
  // src/mnemonic/mnemonic.ts
5268
5493
  var import_crypto4 = require("@fuel-ts/crypto");
5269
5494
  var import_errors19 = require("@fuel-ts/errors");
5270
5495
  var import_hasher5 = require("@fuel-ts/hasher");
5271
- var import_utils33 = require("@fuel-ts/utils");
5496
+ var import_utils32 = require("@fuel-ts/utils");
5272
5497
  var import_ethers2 = require("ethers");
5273
5498
 
5274
5499
  // src/wordlists/words/english.ts
@@ -7326,7 +7551,7 @@ var english = [
7326
7551
  // src/mnemonic/utils.ts
7327
7552
  var import_errors18 = require("@fuel-ts/errors");
7328
7553
  var import_hasher4 = require("@fuel-ts/hasher");
7329
- var import_utils32 = require("@fuel-ts/utils");
7554
+ var import_utils31 = require("@fuel-ts/utils");
7330
7555
  function toUtf8Bytes(stri) {
7331
7556
  const str = stri.normalize("NFKD");
7332
7557
  const result = [];
@@ -7393,14 +7618,14 @@ function entropyToMnemonicIndices(entropy) {
7393
7618
  }
7394
7619
  }
7395
7620
  const checksumBits = entropy.length / 4;
7396
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7621
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7397
7622
  indices[indices.length - 1] <<= checksumBits;
7398
7623
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7399
7624
  return indices;
7400
7625
  }
7401
7626
  function mnemonicWordsToEntropy(words, wordlist) {
7402
7627
  const size = Math.ceil(11 * words.length / 8);
7403
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7628
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7404
7629
  let offset = 0;
7405
7630
  for (let i = 0; i < words.length; i += 1) {
7406
7631
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7420,7 +7645,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7420
7645
  const entropyBits = 32 * words.length / 3;
7421
7646
  const checksumBits = words.length / 3;
7422
7647
  const checksumMask = getUpperMask(checksumBits);
7423
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7648
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7424
7649
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7425
7650
  throw new import_errors18.FuelError(
7426
7651
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7495,7 +7720,7 @@ var Mnemonic = class {
7495
7720
  static mnemonicToEntropy(phrase, wordlist = english) {
7496
7721
  const words = getWords(phrase);
7497
7722
  assertMnemonic(words);
7498
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7723
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7499
7724
  }
7500
7725
  /**
7501
7726
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7503,7 +7728,7 @@ var Mnemonic = class {
7503
7728
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7504
7729
  */
7505
7730
  static entropyToMnemonic(entropy, wordlist = english) {
7506
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
7731
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7507
7732
  assertWordList(wordlist);
7508
7733
  assertEntropy(entropyBytes);
7509
7734
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7572,14 +7797,14 @@ var Mnemonic = class {
7572
7797
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7573
7798
  */
7574
7799
  static masterKeysFromSeed(seed) {
7575
- const seedArray = (0, import_utils33.arrayify)(seed);
7800
+ const seedArray = (0, import_utils32.arrayify)(seed);
7576
7801
  if (seedArray.length < 16 || seedArray.length > 64) {
7577
7802
  throw new import_errors19.FuelError(
7578
7803
  import_errors19.ErrorCode.INVALID_SEED,
7579
7804
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7580
7805
  );
7581
7806
  }
7582
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7807
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7583
7808
  }
7584
7809
  /**
7585
7810
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7590,22 +7815,22 @@ var Mnemonic = class {
7590
7815
  */
7591
7816
  static seedToExtendedKey(seed, testnet = false) {
7592
7817
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7593
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7818
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7594
7819
  const depth = "0x00";
7595
7820
  const fingerprint = "0x00000000";
7596
7821
  const index = "0x00000000";
7597
7822
  const chainCode = masterKey.slice(32);
7598
7823
  const privateKey = masterKey.slice(0, 32);
7599
- const extendedKey = (0, import_utils33.concat)([
7824
+ const extendedKey = (0, import_utils32.concat)([
7600
7825
  prefix,
7601
7826
  depth,
7602
7827
  fingerprint,
7603
7828
  index,
7604
7829
  chainCode,
7605
- (0, import_utils33.concat)(["0x00", privateKey])
7830
+ (0, import_utils32.concat)(["0x00", privateKey])
7606
7831
  ]);
7607
7832
  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]));
7833
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7609
7834
  }
7610
7835
  /**
7611
7836
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7620,7 +7845,7 @@ var Mnemonic = class {
7620
7845
  * @returns A randomly generated mnemonic
7621
7846
  */
7622
7847
  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);
7848
+ 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
7849
  return Mnemonic.entropyToMnemonic(entropy);
7625
7850
  }
7626
7851
  };
@@ -7628,12 +7853,12 @@ var mnemonic_default = Mnemonic;
7628
7853
 
7629
7854
  // src/hdwallet/hdwallet.ts
7630
7855
  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");
7856
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
7857
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7858
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7859
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7635
7860
  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)]));
7861
+ return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7637
7862
  }
7638
7863
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7639
7864
  if (isPublic) {
@@ -7642,11 +7867,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7642
7867
  return testnet ? TestnetPRV2 : MainnetPRV2;
7643
7868
  }
7644
7869
  function isPublicExtendedKey(extendedKey) {
7645
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
7870
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
7646
7871
  }
7647
7872
  function isValidExtendedKey(extendedKey) {
7648
7873
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
7649
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
7874
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
7650
7875
  );
7651
7876
  }
7652
7877
  function parsePath(path2, depth = 0) {
@@ -7664,8 +7889,8 @@ function parsePath(path2, depth = 0) {
7664
7889
  var HDWallet = class {
7665
7890
  depth = 0;
7666
7891
  index = 0;
7667
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
7668
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
7892
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
7893
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
7669
7894
  privateKey;
7670
7895
  publicKey;
7671
7896
  chainCode;
@@ -7677,8 +7902,8 @@ var HDWallet = class {
7677
7902
  constructor(config) {
7678
7903
  if (config.privateKey) {
7679
7904
  const signer = new Signer(config.privateKey);
7680
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
7681
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
7905
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
7906
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
7682
7907
  } else {
7683
7908
  if (!config.publicKey) {
7684
7909
  throw new import_errors20.FuelError(
@@ -7686,7 +7911,7 @@ var HDWallet = class {
7686
7911
  "Both public and private Key cannot be missing. At least one should be provided."
7687
7912
  );
7688
7913
  }
7689
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
7914
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7690
7915
  }
7691
7916
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7692
7917
  this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
@@ -7705,9 +7930,9 @@ var HDWallet = class {
7705
7930
  * @returns A new instance of HDWallet on the derived index
7706
7931
  */
7707
7932
  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);
7933
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
7934
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
7935
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
7711
7936
  const data = new Uint8Array(37);
7712
7937
  if (index & HARDENED_INDEX) {
7713
7938
  if (!privateKey) {
@@ -7718,15 +7943,15 @@ var HDWallet = class {
7718
7943
  }
7719
7944
  data.set(privateKey, 1);
7720
7945
  } else {
7721
- data.set((0, import_utils35.arrayify)(this.publicKey));
7946
+ data.set((0, import_utils34.arrayify)(this.publicKey));
7722
7947
  }
7723
- data.set((0, import_math20.toBytes)(index, 4), 33);
7724
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7948
+ data.set((0, import_math21.toBytes)(index, 4), 33);
7949
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7725
7950
  const IL = bytes.slice(0, 32);
7726
7951
  const IR = bytes.slice(32);
7727
7952
  if (privateKey) {
7728
7953
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7729
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
7954
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
7730
7955
  return new HDWallet({
7731
7956
  privateKey: ki,
7732
7957
  chainCode: IR,
@@ -7735,7 +7960,7 @@ var HDWallet = class {
7735
7960
  parentFingerprint: this.fingerprint
7736
7961
  });
7737
7962
  }
7738
- const signer = new Signer((0, import_utils35.hexlify)(IL));
7963
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
7739
7964
  const Ki = signer.addPoint(publicKey);
7740
7965
  return new HDWallet({
7741
7966
  publicKey: Ki,
@@ -7770,12 +7995,12 @@ var HDWallet = class {
7770
7995
  );
7771
7996
  }
7772
7997
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
7773
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
7998
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
7774
7999
  const parentFingerprint = this.parentFingerprint;
7775
- const index = (0, import_math20.toHex)(this.index, 4);
8000
+ const index = (0, import_math21.toHex)(this.index, 4);
7776
8001
  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]));
8002
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8003
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7779
8004
  return base58check(extendedKey);
7780
8005
  }
7781
8006
  /**
@@ -7787,13 +8012,13 @@ var HDWallet = class {
7787
8012
  static fromSeed(seed) {
7788
8013
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
7789
8014
  return new HDWallet({
7790
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
7791
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8015
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8016
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
7792
8017
  });
7793
8018
  }
7794
8019
  static fromExtendedKey(extendedKey) {
7795
8020
  const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7796
- const bytes = (0, import_utils35.arrayify)(decoded);
8021
+ const bytes = (0, import_utils34.arrayify)(decoded);
7797
8022
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7798
8023
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7799
8024
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -7802,9 +8027,9 @@ var HDWallet = class {
7802
8027
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7803
8028
  }
7804
8029
  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));
8030
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8031
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8032
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
7808
8033
  const key = bytes.slice(45, 78);
7809
8034
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7810
8035
  throw new import_errors20.FuelError(
@@ -7997,14 +8222,15 @@ var seedTestWallet = async (wallet, quantities) => {
7997
8222
  process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
7998
8223
  wallet.provider
7999
8224
  );
8000
- const resources = await genesisWallet.getResourcesToSpend(quantities);
8001
- const { minGasPrice } = genesisWallet.provider.getGasConfig();
8002
- const request = new ScriptTransactionRequest({
8003
- gasLimit: 1e4,
8004
- gasPrice: minGasPrice
8225
+ const request = new ScriptTransactionRequest();
8226
+ quantities.forEach((quantity) => {
8227
+ const { amount, assetId } = coinQuantityfy(quantity);
8228
+ request.addCoinOutput(wallet.address, amount, assetId);
8005
8229
  });
8006
- request.addResources(resources);
8007
- quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
8230
+ const txCost = await genesisWallet.provider.getTransactionCost(request);
8231
+ request.gasLimit = txCost.gasUsed;
8232
+ request.maxFee = txCost.maxFee;
8233
+ await genesisWallet.fund(request, txCost);
8008
8234
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
8009
8235
  };
8010
8236
 
@@ -8018,12 +8244,12 @@ var generateTestWallet = async (provider, quantities) => {
8018
8244
  };
8019
8245
 
8020
8246
  // 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");
8247
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
8248
+ var import_crypto6 = require("@fuel-ts/crypto");
8249
+ var import_utils35 = require("@fuel-ts/utils");
8024
8250
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8025
8251
  var import_child_process = require("child_process");
8026
- var import_crypto6 = require("crypto");
8252
+ var import_crypto7 = require("crypto");
8027
8253
  var import_fs = require("fs");
8028
8254
  var import_os = __toESM(require("os"));
8029
8255
  var import_path = __toESM(require("path"));
@@ -8072,13 +8298,13 @@ var launchNode = async ({
8072
8298
  // eslint-disable-next-line no-async-promise-executor
8073
8299
  new Promise(async (resolve, reject) => {
8074
8300
  const remainingArgs = extractRemainingArgs(args, [
8075
- "--chain",
8301
+ "--snapshot",
8076
8302
  "--consensus-key",
8077
8303
  "--db-type",
8078
8304
  "--poa-instant"
8079
8305
  ]);
8080
- const chainConfigPath = getFlagValueFromArgs(args, "--chain");
8081
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8306
+ const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8307
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
8082
8308
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8083
8309
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8084
8310
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
@@ -8093,39 +8319,57 @@ var launchNode = async ({
8093
8319
  stopPort: 5e3
8094
8320
  // don't try ports above 5000
8095
8321
  })).toString();
8096
- let chainConfigPathToUse;
8322
+ let snapshotDirToUse;
8097
8323
  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;
8324
+ const suffix = basePath ? "" : (0, import_crypto7.randomUUID)();
8325
+ const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8326
+ if (snapshotDir) {
8327
+ snapshotDirToUse = snapshotDir;
8102
8328
  } else {
8103
8329
  if (!(0, import_fs.existsSync)(tempDirPath)) {
8104
8330
  (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8105
8331
  }
8106
- const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
8107
- let chainConfig = import_utils36.defaultChainConfig;
8332
+ let { stateConfigJson } = import_utils35.defaultSnapshotConfigs;
8333
+ const { chainConfigJson, metadataJson } = import_utils35.defaultSnapshotConfigs;
8334
+ stateConfigJson = {
8335
+ ...stateConfigJson,
8336
+ coins: [
8337
+ ...stateConfigJson.coins.map((coin) => ({
8338
+ ...coin,
8339
+ amount: "18446744073709551615"
8340
+ }))
8341
+ ],
8342
+ messages: stateConfigJson.messages.map((message) => ({
8343
+ ...message,
8344
+ amount: "18446744073709551615"
8345
+ }))
8346
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8347
+ };
8108
8348
  if (!process.env.GENESIS_SECRET) {
8109
8349
  const pk = Signer.generatePrivateKey();
8110
8350
  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
- };
8351
+ process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
8352
+ stateConfigJson.coins.push({
8353
+ tx_id: (0, import_utils35.hexlify)((0, import_crypto6.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8354
+ owner: signer.address.toHexString(),
8355
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8356
+ amount: "18446744073709551615",
8357
+ asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
8358
+ output_index: 0,
8359
+ tx_pointer_block_height: 0,
8360
+ tx_pointer_tx_idx: 0
8361
+ });
8126
8362
  }
8127
- (0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
8128
- chainConfigPathToUse = tempChainConfigFilePath;
8363
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8364
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8365
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8366
+ const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8367
+ const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8368
+ const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8369
+ (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8370
+ (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8371
+ (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8372
+ snapshotDirToUse = tempDirPath;
8129
8373
  }
8130
8374
  const child = (0, import_child_process.spawn)(
8131
8375
  command,
@@ -8134,10 +8378,10 @@ var launchNode = async ({
8134
8378
  ["--ip", ipToUse],
8135
8379
  ["--port", portToUse],
8136
8380
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8137
- ["--min-gas-price", "0"],
8381
+ ["--min-gas-price", "1"],
8138
8382
  poaInstant ? ["--poa-instant", "true"] : [],
8139
8383
  ["--consensus-key", consensusKey],
8140
- ["--chain", chainConfigPathToUse],
8384
+ ["--snapshot", snapshotDirToUse],
8141
8385
  "--vm-backtrace",
8142
8386
  "--utxo-validation",
8143
8387
  "--debug",
@@ -8167,7 +8411,7 @@ var launchNode = async ({
8167
8411
  cleanup: () => killNode(cleanupConfig),
8168
8412
  ip: ipToUse,
8169
8413
  port: portToUse,
8170
- chainConfigPath: chainConfigPathToUse
8414
+ snapshotDir: snapshotDirToUse
8171
8415
  });
8172
8416
  }
8173
8417
  if (/error/i.test(chunk)) {
@@ -8184,9 +8428,10 @@ var launchNode = async ({
8184
8428
  })
8185
8429
  );
8186
8430
  var generateWallets = async (count, provider) => {
8431
+ const baseAssetId = provider.getBaseAssetId();
8187
8432
  const wallets = [];
8188
8433
  for (let i = 0; i < count; i += 1) {
8189
- const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
8434
+ const wallet = await generateTestWallet(provider, [[1e5, baseAssetId]]);
8190
8435
  wallets.push(wallet);
8191
8436
  }
8192
8437
  return wallets;
@@ -8196,7 +8441,7 @@ var launchNodeAndGetWallets = async ({
8196
8441
  walletCount = 10
8197
8442
  } = {}) => {
8198
8443
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8199
- const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8444
+ const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8200
8445
  const wallets = await generateWallets(walletCount, provider);
8201
8446
  const cleanup = () => {
8202
8447
  closeNode();