@fuel-ts/account 0.0.0-rc-1976-20240409134753 → 0.0.0-rc-2021-20240409151049

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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +5 -4
  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 +870 -617
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +850 -611
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +692 -454
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +10 -2
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +888 -322
  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/fuel-graphql-subscriber.d.ts.map +1 -1
  26. package/dist/providers/message.d.ts +3 -1
  27. package/dist/providers/message.d.ts.map +1 -1
  28. package/dist/providers/provider.d.ts +45 -34
  29. package/dist/providers/provider.d.ts.map +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 +9 -29
  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/test-utils/launchNode.d.ts.map +1 -1
  47. package/dist/test-utils.global.js +1585 -1118
  48. package/dist/test-utils.global.js.map +1 -1
  49. package/dist/test-utils.js +826 -608
  50. package/dist/test-utils.js.map +1 -1
  51. package/dist/test-utils.mjs +684 -466
  52. package/dist/test-utils.mjs.map +1 -1
  53. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  54. package/package.json +17 -17
@@ -58,39 +58,42 @@ 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");
65
66
  var import_errors16 = require("@fuel-ts/errors");
66
67
  var import_interfaces = require("@fuel-ts/interfaces");
67
- var import_math18 = require("@fuel-ts/math");
68
- var import_utils28 = require("@fuel-ts/utils");
68
+ var import_math19 = require("@fuel-ts/math");
69
+ var import_utils27 = require("@fuel-ts/utils");
70
+ var import_ramda4 = require("ramda");
69
71
 
70
72
  // src/providers/coin-quantity.ts
73
+ var import_configs = require("@fuel-ts/address/configs");
71
74
  var import_math = require("@fuel-ts/math");
72
75
  var import_utils = require("@fuel-ts/utils");
73
76
  var coinQuantityfy = (coinQuantityLike) => {
74
77
  let assetId;
75
78
  let amount;
76
- let max2;
79
+ let max;
77
80
  if (Array.isArray(coinQuantityLike)) {
78
81
  amount = coinQuantityLike[0];
79
- assetId = coinQuantityLike[1];
80
- max2 = coinQuantityLike[2];
82
+ assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
83
+ max = coinQuantityLike[2] ?? void 0;
81
84
  } else {
82
85
  amount = coinQuantityLike.amount;
83
- assetId = coinQuantityLike.assetId;
84
- max2 = coinQuantityLike.max ?? void 0;
86
+ assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
87
+ max = coinQuantityLike.max ?? void 0;
85
88
  }
86
89
  const bnAmount = (0, import_math.bn)(amount);
87
90
  return {
88
91
  assetId: (0, import_utils.hexlify)(assetId),
89
92
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
90
- max: max2 ? (0, import_math.bn)(max2) : void 0
93
+ max: max ? (0, import_math.bn)(max) : void 0
91
94
  };
92
95
  };
93
- var addAmountToAsset = (params) => {
96
+ var addAmountToCoinQuantities = (params) => {
94
97
  const { amount, assetId } = params;
95
98
  const coinQuantities = [...params.coinQuantities];
96
99
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -105,12 +108,12 @@ var addAmountToAsset = (params) => {
105
108
  // src/providers/provider.ts
106
109
  var import_address3 = require("@fuel-ts/address");
107
110
  var import_errors14 = require("@fuel-ts/errors");
108
- var import_math15 = require("@fuel-ts/math");
109
- var import_transactions18 = require("@fuel-ts/transactions");
110
- var import_utils23 = require("@fuel-ts/utils");
111
+ var import_math16 = require("@fuel-ts/math");
112
+ var import_transactions19 = require("@fuel-ts/transactions");
113
+ var import_utils22 = require("@fuel-ts/utils");
111
114
  var import_versions = require("@fuel-ts/versions");
112
- var import_utils24 = require("@noble/curves/abstract/utils");
113
- var import_ethers = require("ethers");
115
+ var import_utils23 = require("@noble/curves/abstract/utils");
116
+ var import_ethers2 = require("ethers");
114
117
  var import_graphql_request = require("graphql-request");
115
118
  var import_ramda3 = require("ramda");
116
119
 
@@ -118,14 +121,10 @@ var import_ramda3 = require("ramda");
118
121
  var import_graphql_tag = __toESM(require("graphql-tag"));
119
122
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
120
123
  fragment receiptFragment on Receipt {
121
- contract {
122
- id
123
- }
124
+ id
124
125
  pc
125
126
  is
126
- to {
127
- id
128
- }
127
+ to
129
128
  toAddress
130
129
  amount
131
130
  assetId
@@ -163,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
163
162
  id
164
163
  }
165
164
  time
165
+ receipts {
166
+ ...receiptFragment
167
+ }
166
168
  programState {
167
169
  returnType
168
170
  data
169
171
  }
172
+ receipts {
173
+ ...receiptFragment
174
+ }
170
175
  }
171
176
  ... on FailureStatus {
172
177
  block {
@@ -174,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
174
179
  }
175
180
  time
176
181
  reason
182
+ receipts {
183
+ ...receiptFragment
184
+ }
177
185
  }
178
186
  ... on SqueezedOutStatus {
179
187
  reason
180
188
  }
181
189
  }
182
- `;
190
+ ${ReceiptFragmentFragmentDoc}`;
183
191
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
184
192
  fragment transactionFragment on Transaction {
185
193
  id
186
194
  rawPayload
187
- gasPrice
188
- receipts {
189
- ...receiptFragment
190
- }
191
195
  status {
192
196
  ...transactionStatusFragment
193
197
  }
194
198
  }
195
- ${ReceiptFragmentFragmentDoc}
196
- ${TransactionStatusFragmentFragmentDoc}`;
199
+ ${TransactionStatusFragmentFragmentDoc}`;
197
200
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
198
201
  fragment inputEstimatePredicatesFragment on Input {
199
202
  ... on InputCoin {
@@ -211,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
211
214
  }
212
215
  }
213
216
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
217
+ var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
218
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
219
+ reason
220
+ programState {
221
+ returnType
222
+ data
223
+ }
224
+ }
225
+ `;
226
+ var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
227
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
228
+ programState {
229
+ returnType
230
+ data
231
+ }
232
+ }
233
+ `;
234
+ var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
235
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
236
+ ... on DryRunFailureStatus {
237
+ ...dryRunFailureStatusFragment
238
+ }
239
+ ... on DryRunSuccessStatus {
240
+ ...dryRunSuccessStatusFragment
241
+ }
242
+ }
243
+ ${DryRunFailureStatusFragmentFragmentDoc}
244
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
245
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
246
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
247
+ id
248
+ status {
249
+ ...dryRunTransactionStatusFragment
250
+ }
251
+ receipts {
252
+ ...receiptFragment
253
+ }
254
+ }
255
+ ${DryRunTransactionStatusFragmentFragmentDoc}
256
+ ${ReceiptFragmentFragmentDoc}`;
214
257
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
215
258
  fragment coinFragment on Coin {
216
259
  __typename
@@ -218,7 +261,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
218
261
  owner
219
262
  amount
220
263
  assetId
221
- maturity
222
264
  blockCreated
223
265
  txCreatedIdx
224
266
  }
@@ -263,7 +305,6 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
263
305
  prevRoot
264
306
  time
265
307
  applicationHash
266
- messageReceiptRoot
267
308
  messageReceiptCount
268
309
  }
269
310
  commitBlockHeader {
@@ -275,7 +316,6 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
275
316
  prevRoot
276
317
  time
277
318
  applicationHash
278
- messageReceiptRoot
279
319
  messageReceiptCount
280
320
  }
281
321
  sender
@@ -295,8 +335,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
295
335
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
296
336
  fragment blockFragment on Block {
297
337
  id
338
+ height
298
339
  header {
299
- height
300
340
  time
301
341
  }
302
342
  transactions {
@@ -354,6 +394,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
354
394
  `;
355
395
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
356
396
  fragment GasCostsFragment on GasCosts {
397
+ version {
398
+ ... on Version {
399
+ value
400
+ }
401
+ }
357
402
  add
358
403
  addi
359
404
  aloc
@@ -366,7 +411,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
366
411
  cb
367
412
  cfei
368
413
  cfsi
369
- croo
370
414
  div
371
415
  divi
372
416
  ecr1
@@ -449,6 +493,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
449
493
  ccp {
450
494
  ...DependentCostFragment
451
495
  }
496
+ croo {
497
+ ...DependentCostFragment
498
+ }
452
499
  csiz {
453
500
  ...DependentCostFragment
454
501
  }
@@ -508,6 +555,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
508
555
  ${DependentCostFragmentFragmentDoc}`;
509
556
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
510
557
  fragment consensusParametersFragment on ConsensusParameters {
558
+ version {
559
+ ... on Version {
560
+ value
561
+ }
562
+ }
511
563
  txParams {
512
564
  ...TxParametersFragment
513
565
  }
@@ -567,18 +619,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
567
619
  fragment nodeInfoFragment on NodeInfo {
568
620
  utxoValidation
569
621
  vmBacktrace
570
- minGasPrice
571
622
  maxTx
572
623
  maxDepth
573
624
  nodeVersion
574
- peers {
575
- id
576
- addresses
577
- clientVersion
578
- blockHeight
579
- lastHeartbeatMs
580
- appScore
581
- }
582
625
  }
583
626
  `;
584
627
  var GetVersionDocument = import_graphql_tag.default`
@@ -613,13 +656,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
613
656
  query getTransactionWithReceipts($transactionId: TransactionId!) {
614
657
  transaction(id: $transactionId) {
615
658
  ...transactionFragment
616
- receipts {
617
- ...receiptFragment
618
- }
619
659
  }
620
660
  }
621
- ${TransactionFragmentFragmentDoc}
622
- ${ReceiptFragmentFragmentDoc}`;
661
+ ${TransactionFragmentFragmentDoc}`;
623
662
  var GetTransactionsDocument = import_graphql_tag.default`
624
663
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
625
664
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -747,6 +786,20 @@ var GetBalanceDocument = import_graphql_tag.default`
747
786
  }
748
787
  }
749
788
  ${BalanceFragmentFragmentDoc}`;
789
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
790
+ query getLatestGasPrice {
791
+ latestGasPrice {
792
+ gasPrice
793
+ }
794
+ }
795
+ `;
796
+ var EstimateGasPriceDocument = import_graphql_tag.default`
797
+ query estimateGasPrice($blockHorizon: U32!) {
798
+ estimateGasPrice(blockHorizon: $blockHorizon) {
799
+ gasPrice
800
+ }
801
+ }
802
+ `;
750
803
  var GetBalancesDocument = import_graphql_tag.default`
751
804
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
752
805
  balances(
@@ -801,12 +854,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
801
854
  }
802
855
  `;
803
856
  var DryRunDocument = import_graphql_tag.default`
804
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
805
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
806
- ...receiptFragment
857
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
858
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
859
+ ...dryRunTransactionExecutionStatusFragment
807
860
  }
808
861
  }
809
- ${ReceiptFragmentFragmentDoc}`;
862
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
810
863
  var SubmitDocument = import_graphql_tag.default`
811
864
  mutation submit($encodedTransaction: HexString!) {
812
865
  submit(tx: $encodedTransaction) {
@@ -889,6 +942,12 @@ function getSdk(requester) {
889
942
  getBalance(variables, options) {
890
943
  return requester(GetBalanceDocument, variables, options);
891
944
  },
945
+ getLatestGasPrice(variables, options) {
946
+ return requester(GetLatestGasPriceDocument, variables, options);
947
+ },
948
+ estimateGasPrice(variables, options) {
949
+ return requester(EstimateGasPriceDocument, variables, options);
950
+ },
892
951
  getBalances(variables, options) {
893
952
  return requester(GetBalancesDocument, variables, options);
894
953
  },
@@ -958,11 +1017,14 @@ var _FuelGraphqlSubscriber = class {
958
1017
  let data;
959
1018
  let errors;
960
1019
  try {
961
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
1020
+ const sanitizedText = text.replace(/\s/g, "");
1021
+ ({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
962
1022
  } catch (e) {
963
1023
  throw new import_errors.FuelError(
964
1024
  import_errors.ErrorCode.STREAM_PARSING_ERROR,
965
- `Error while parsing stream data response: ${text}`
1025
+ `Error while parsing stream data response: ${text}
1026
+
1027
+ Thrown error: ${e}`
966
1028
  );
967
1029
  }
968
1030
  if (Array.isArray(errors)) {
@@ -1049,7 +1111,7 @@ var MemoryCache = class {
1049
1111
  };
1050
1112
 
1051
1113
  // src/providers/transaction-request/input.ts
1052
- var import_configs = require("@fuel-ts/address/configs");
1114
+ var import_configs2 = require("@fuel-ts/address/configs");
1053
1115
  var import_errors3 = require("@fuel-ts/errors");
1054
1116
  var import_math2 = require("@fuel-ts/math");
1055
1117
  var import_transactions = require("@fuel-ts/transactions");
@@ -1063,7 +1125,7 @@ var inputify = (value) => {
1063
1125
  return {
1064
1126
  type: import_transactions.InputType.Coin,
1065
1127
  txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
1066
- outputIndex: (0, import_utils3.arrayify)(value.id)[32],
1128
+ outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 34)),
1067
1129
  owner: (0, import_utils3.hexlify)(value.owner),
1068
1130
  amount: (0, import_math2.bn)(value.amount),
1069
1131
  assetId: (0, import_utils3.hexlify)(value.assetId),
@@ -1072,10 +1134,9 @@ var inputify = (value) => {
1072
1134
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1073
1135
  },
1074
1136
  witnessIndex: value.witnessIndex,
1075
- maturity: value.maturity ?? 0,
1076
1137
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1077
- predicateLength: predicate.length,
1078
- predicateDataLength: predicateData.length,
1138
+ predicateLength: (0, import_math2.bn)(predicate.length),
1139
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1079
1140
  predicate: (0, import_utils3.hexlify)(predicate),
1080
1141
  predicateData: (0, import_utils3.hexlify)(predicateData)
1081
1142
  };
@@ -1083,10 +1144,10 @@ var inputify = (value) => {
1083
1144
  case import_transactions.InputType.Contract: {
1084
1145
  return {
1085
1146
  type: import_transactions.InputType.Contract,
1086
- txID: import_configs.ZeroBytes32,
1147
+ txID: import_configs2.ZeroBytes32,
1087
1148
  outputIndex: 0,
1088
- balanceRoot: import_configs.ZeroBytes32,
1089
- stateRoot: import_configs.ZeroBytes32,
1149
+ balanceRoot: import_configs2.ZeroBytes32,
1150
+ stateRoot: import_configs2.ZeroBytes32,
1090
1151
  txPointer: {
1091
1152
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1092
1153
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1106,8 +1167,8 @@ var inputify = (value) => {
1106
1167
  nonce: (0, import_utils3.hexlify)(value.nonce),
1107
1168
  witnessIndex: value.witnessIndex,
1108
1169
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1109
- predicateLength: predicate.length,
1110
- predicateDataLength: predicateData.length,
1170
+ predicateLength: (0, import_math2.bn)(predicate.length),
1171
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1111
1172
  predicate: (0, import_utils3.hexlify)(predicate),
1112
1173
  predicateData: (0, import_utils3.hexlify)(predicateData),
1113
1174
  data: (0, import_utils3.hexlify)(data),
@@ -1124,7 +1185,7 @@ var inputify = (value) => {
1124
1185
  };
1125
1186
 
1126
1187
  // src/providers/transaction-request/output.ts
1127
- var import_configs2 = require("@fuel-ts/address/configs");
1188
+ var import_configs3 = require("@fuel-ts/address/configs");
1128
1189
  var import_errors4 = require("@fuel-ts/errors");
1129
1190
  var import_math3 = require("@fuel-ts/math");
1130
1191
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1144,8 +1205,8 @@ var outputify = (value) => {
1144
1205
  return {
1145
1206
  type: import_transactions2.OutputType.Contract,
1146
1207
  inputIndex: value.inputIndex,
1147
- balanceRoot: import_configs2.ZeroBytes32,
1148
- stateRoot: import_configs2.ZeroBytes32
1208
+ balanceRoot: import_configs3.ZeroBytes32,
1209
+ stateRoot: import_configs3.ZeroBytes32
1149
1210
  };
1150
1211
  }
1151
1212
  case import_transactions2.OutputType.Change: {
@@ -1159,9 +1220,9 @@ var outputify = (value) => {
1159
1220
  case import_transactions2.OutputType.Variable: {
1160
1221
  return {
1161
1222
  type: import_transactions2.OutputType.Variable,
1162
- to: import_configs2.ZeroBytes32,
1223
+ to: import_configs3.ZeroBytes32,
1163
1224
  amount: (0, import_math3.bn)(0),
1164
- assetId: import_configs2.ZeroBytes32
1225
+ assetId: import_configs3.ZeroBytes32
1165
1226
  };
1166
1227
  }
1167
1228
  case import_transactions2.OutputType.ContractCreated: {
@@ -1182,22 +1243,23 @@ var outputify = (value) => {
1182
1243
 
1183
1244
  // src/providers/transaction-request/transaction-request.ts
1184
1245
  var import_address = require("@fuel-ts/address");
1185
- var import_configs6 = require("@fuel-ts/address/configs");
1246
+ var import_configs7 = require("@fuel-ts/address/configs");
1186
1247
  var import_math7 = require("@fuel-ts/math");
1187
1248
  var import_transactions6 = require("@fuel-ts/transactions");
1188
1249
  var import_utils9 = require("@fuel-ts/utils");
1250
+ var import_ethers = require("ethers");
1189
1251
 
1190
1252
  // src/providers/resource.ts
1191
1253
  var isCoin = (resource) => "id" in resource;
1192
1254
 
1193
1255
  // src/providers/utils/receipts.ts
1194
- var import_configs3 = require("@fuel-ts/address/configs");
1256
+ var import_configs4 = require("@fuel-ts/address/configs");
1195
1257
  var import_errors5 = require("@fuel-ts/errors");
1196
1258
  var import_math4 = require("@fuel-ts/math");
1197
1259
  var import_transactions3 = require("@fuel-ts/transactions");
1198
- var import_configs4 = require("@fuel-ts/transactions/configs");
1260
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1199
1261
  var import_utils5 = require("@fuel-ts/utils");
1200
- var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1262
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1201
1263
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1202
1264
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1203
1265
  (memo, receipt) => {
@@ -1214,15 +1276,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1214
1276
  missingOutputContractIds: []
1215
1277
  }
1216
1278
  );
1217
- var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1279
+ var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1218
1280
  function assembleReceiptByType(receipt) {
1219
1281
  const { receiptType } = receipt;
1220
1282
  switch (receiptType) {
1221
1283
  case "CALL" /* Call */: {
1222
1284
  const callReceipt = {
1223
1285
  type: import_transactions3.ReceiptType.Call,
1224
- from: hexOrZero(receipt.contract?.id),
1225
- to: hexOrZero(receipt?.to?.id),
1286
+ from: hexOrZero(receipt.id || receipt.contractId),
1287
+ to: hexOrZero(receipt?.to),
1226
1288
  amount: (0, import_math4.bn)(receipt.amount),
1227
1289
  assetId: hexOrZero(receipt.assetId),
1228
1290
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1236,7 +1298,7 @@ function assembleReceiptByType(receipt) {
1236
1298
  case "RETURN" /* Return */: {
1237
1299
  const returnReceipt = {
1238
1300
  type: import_transactions3.ReceiptType.Return,
1239
- id: hexOrZero(receipt.contract?.id),
1301
+ id: hexOrZero(receipt.id || receipt.contractId),
1240
1302
  val: (0, import_math4.bn)(receipt.val),
1241
1303
  pc: (0, import_math4.bn)(receipt.pc),
1242
1304
  is: (0, import_math4.bn)(receipt.is)
@@ -1246,7 +1308,7 @@ function assembleReceiptByType(receipt) {
1246
1308
  case "RETURN_DATA" /* ReturnData */: {
1247
1309
  const returnDataReceipt = {
1248
1310
  type: import_transactions3.ReceiptType.ReturnData,
1249
- id: hexOrZero(receipt.contract?.id),
1311
+ id: hexOrZero(receipt.id || receipt.contractId),
1250
1312
  ptr: (0, import_math4.bn)(receipt.ptr),
1251
1313
  len: (0, import_math4.bn)(receipt.len),
1252
1314
  digest: hexOrZero(receipt.digest),
@@ -1258,7 +1320,7 @@ function assembleReceiptByType(receipt) {
1258
1320
  case "PANIC" /* Panic */: {
1259
1321
  const panicReceipt = {
1260
1322
  type: import_transactions3.ReceiptType.Panic,
1261
- id: hexOrZero(receipt.contract?.id),
1323
+ id: hexOrZero(receipt.id),
1262
1324
  reason: (0, import_math4.bn)(receipt.reason),
1263
1325
  pc: (0, import_math4.bn)(receipt.pc),
1264
1326
  is: (0, import_math4.bn)(receipt.is),
@@ -1269,7 +1331,7 @@ function assembleReceiptByType(receipt) {
1269
1331
  case "REVERT" /* Revert */: {
1270
1332
  const revertReceipt = {
1271
1333
  type: import_transactions3.ReceiptType.Revert,
1272
- id: hexOrZero(receipt.contract?.id),
1334
+ id: hexOrZero(receipt.id || receipt.contractId),
1273
1335
  val: (0, import_math4.bn)(receipt.ra),
1274
1336
  pc: (0, import_math4.bn)(receipt.pc),
1275
1337
  is: (0, import_math4.bn)(receipt.is)
@@ -1279,7 +1341,7 @@ function assembleReceiptByType(receipt) {
1279
1341
  case "LOG" /* Log */: {
1280
1342
  const logReceipt = {
1281
1343
  type: import_transactions3.ReceiptType.Log,
1282
- id: hexOrZero(receipt.contract?.id),
1344
+ id: hexOrZero(receipt.id || receipt.contractId),
1283
1345
  val0: (0, import_math4.bn)(receipt.ra),
1284
1346
  val1: (0, import_math4.bn)(receipt.rb),
1285
1347
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1292,7 +1354,7 @@ function assembleReceiptByType(receipt) {
1292
1354
  case "LOG_DATA" /* LogData */: {
1293
1355
  const logDataReceipt = {
1294
1356
  type: import_transactions3.ReceiptType.LogData,
1295
- id: hexOrZero(receipt.contract?.id),
1357
+ id: hexOrZero(receipt.id || receipt.contractId),
1296
1358
  val0: (0, import_math4.bn)(receipt.ra),
1297
1359
  val1: (0, import_math4.bn)(receipt.rb),
1298
1360
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1306,8 +1368,8 @@ function assembleReceiptByType(receipt) {
1306
1368
  case "TRANSFER" /* Transfer */: {
1307
1369
  const transferReceipt = {
1308
1370
  type: import_transactions3.ReceiptType.Transfer,
1309
- from: hexOrZero(receipt.contract?.id),
1310
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1371
+ from: hexOrZero(receipt.id || receipt.contractId),
1372
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1311
1373
  amount: (0, import_math4.bn)(receipt.amount),
1312
1374
  assetId: hexOrZero(receipt.assetId),
1313
1375
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1318,8 +1380,8 @@ function assembleReceiptByType(receipt) {
1318
1380
  case "TRANSFER_OUT" /* TransferOut */: {
1319
1381
  const transferOutReceipt = {
1320
1382
  type: import_transactions3.ReceiptType.TransferOut,
1321
- from: hexOrZero(receipt.contract?.id),
1322
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1383
+ from: hexOrZero(receipt.id || receipt.contractId),
1384
+ to: hexOrZero(receipt.toAddress || receipt.to),
1323
1385
  amount: (0, import_math4.bn)(receipt.amount),
1324
1386
  assetId: hexOrZero(receipt.assetId),
1325
1387
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1362,7 +1424,7 @@ function assembleReceiptByType(receipt) {
1362
1424
  return receiptMessageOut;
1363
1425
  }
1364
1426
  case "MINT" /* Mint */: {
1365
- const contractId = hexOrZero(receipt.contract?.id);
1427
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1366
1428
  const subId = hexOrZero(receipt.subId);
1367
1429
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1368
1430
  const mintReceipt = {
@@ -1377,7 +1439,7 @@ function assembleReceiptByType(receipt) {
1377
1439
  return mintReceipt;
1378
1440
  }
1379
1441
  case "BURN" /* Burn */: {
1380
- const contractId = hexOrZero(receipt.contract?.id);
1442
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1381
1443
  const subId = hexOrZero(receipt.subId);
1382
1444
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1383
1445
  const burnReceipt = {
@@ -1403,7 +1465,6 @@ var import_errors6 = require("@fuel-ts/errors");
1403
1465
  var import_math5 = require("@fuel-ts/math");
1404
1466
  var import_transactions4 = require("@fuel-ts/transactions");
1405
1467
  var import_utils6 = require("@fuel-ts/utils");
1406
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1407
1468
  var getGasUsedFromReceipts = (receipts) => {
1408
1469
  const scriptResult = receipts.filter(
1409
1470
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1424,18 +1485,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1424
1485
  }
1425
1486
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1426
1487
  const witnessCache = [];
1427
- const totalGas = inputs.reduce((total, input) => {
1488
+ const chargeableInputs = inputs.filter((input) => {
1489
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1490
+ if (isCoinOrMessage) {
1491
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1492
+ return true;
1493
+ }
1494
+ if (!witnessCache.includes(input.witnessIndex)) {
1495
+ witnessCache.push(input.witnessIndex);
1496
+ return true;
1497
+ }
1498
+ }
1499
+ return false;
1500
+ });
1501
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1502
+ const totalGas = chargeableInputs.reduce((total, input) => {
1428
1503
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1429
1504
  return total.add(
1430
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1505
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1431
1506
  );
1432
1507
  }
1433
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1434
- witnessCache.push(input.witnessIndex);
1435
- return total.add(gasCosts.ecr1);
1436
- }
1437
- return total;
1438
- }, (0, import_math5.bn)());
1508
+ return total.add(gasCosts.ecr1);
1509
+ }, (0, import_math5.bn)(0));
1439
1510
  return totalGas;
1440
1511
  }
1441
1512
  function getMinGas(params) {
@@ -1447,12 +1518,20 @@ function getMinGas(params) {
1447
1518
  return minGas;
1448
1519
  }
1449
1520
  function getMaxGas(params) {
1450
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1521
+ const {
1522
+ gasPerByte,
1523
+ witnessesLength,
1524
+ witnessLimit,
1525
+ minGas,
1526
+ gasLimit = (0, import_math5.bn)(0),
1527
+ maxGasPerTx
1528
+ } = params;
1451
1529
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1452
1530
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1453
1531
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1454
1532
  }
1455
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1533
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1534
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1456
1535
  }
1457
1536
  function calculateMetadataGasForTxCreate({
1458
1537
  gasCosts,
@@ -1474,6 +1553,10 @@ function calculateMetadataGasForTxScript({
1474
1553
  }) {
1475
1554
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1476
1555
  }
1556
+ var calculateGasFee = (params) => {
1557
+ const { gas, gasPrice, priceFactor, tip } = params;
1558
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1559
+ };
1477
1560
 
1478
1561
  // src/providers/utils/json.ts
1479
1562
  var import_utils7 = require("@fuel-ts/utils");
@@ -1519,16 +1602,16 @@ function sleep(time) {
1519
1602
  var import_errors7 = require("@fuel-ts/errors");
1520
1603
  var import_math6 = require("@fuel-ts/math");
1521
1604
  var import_transactions5 = require("@fuel-ts/transactions");
1522
- var import_configs5 = require("@fuel-ts/transactions/configs");
1605
+ var import_configs6 = require("@fuel-ts/transactions/configs");
1523
1606
  var assemblePanicError = (status) => {
1524
1607
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1525
1608
  const reason = status.reason;
1526
- if (import_configs5.PANIC_REASONS.includes(status.reason)) {
1609
+ if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1527
1610
  errorMessage = `${errorMessage}
1528
1611
 
1529
1612
  You can read more about this error at:
1530
1613
 
1531
- ${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
1614
+ ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1532
1615
  }
1533
1616
  return { errorMessage, reason };
1534
1617
  };
@@ -1540,28 +1623,28 @@ var assembleRevertError = (receipts, logs) => {
1540
1623
  if (revertReceipt) {
1541
1624
  const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1542
1625
  switch (reasonHex) {
1543
- case import_configs5.FAILED_REQUIRE_SIGNAL: {
1626
+ case import_configs6.FAILED_REQUIRE_SIGNAL: {
1544
1627
  reason = "require";
1545
1628
  errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1546
1629
  break;
1547
1630
  }
1548
- case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
1631
+ case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1549
1632
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1550
1633
  reason = "assert_eq";
1551
1634
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1552
1635
  break;
1553
1636
  }
1554
- case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
1637
+ case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1555
1638
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1556
1639
  reason = "assert_ne";
1557
1640
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1558
1641
  break;
1559
1642
  }
1560
- case import_configs5.FAILED_ASSERT_SIGNAL:
1643
+ case import_configs6.FAILED_ASSERT_SIGNAL:
1561
1644
  reason = "assert";
1562
1645
  errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1563
1646
  break;
1564
- case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1647
+ case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1565
1648
  reason = "MissingOutputChange";
1566
1649
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1567
1650
  break;
@@ -1610,7 +1693,7 @@ var witnessify = (value) => {
1610
1693
  // src/providers/transaction-request/transaction-request.ts
1611
1694
  var BaseTransactionRequest = class {
1612
1695
  /** Gas price for transaction */
1613
- gasPrice;
1696
+ tip;
1614
1697
  /** Block until which tx cannot be included */
1615
1698
  maturity;
1616
1699
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1623,38 +1706,34 @@ var BaseTransactionRequest = class {
1623
1706
  outputs = [];
1624
1707
  /** List of witnesses */
1625
1708
  witnesses = [];
1626
- /** Base asset ID - should be fetched from the chain */
1627
- baseAssetId = import_configs6.ZeroBytes32;
1628
1709
  /**
1629
1710
  * Constructor for initializing a base transaction request.
1630
1711
  *
1631
1712
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1632
1713
  */
1633
1714
  constructor({
1634
- gasPrice,
1715
+ tip,
1635
1716
  maturity,
1636
1717
  maxFee,
1637
1718
  witnessLimit,
1638
1719
  inputs,
1639
1720
  outputs,
1640
- witnesses,
1641
- baseAssetId
1721
+ witnesses
1642
1722
  } = {}) {
1643
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1723
+ this.tip = (0, import_math7.bn)(tip);
1644
1724
  this.maturity = maturity ?? 0;
1645
1725
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1646
1726
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
1647
1727
  this.inputs = inputs ?? [];
1648
1728
  this.outputs = outputs ?? [];
1649
1729
  this.witnesses = witnesses ?? [];
1650
- this.baseAssetId = baseAssetId ?? import_configs6.ZeroBytes32;
1651
1730
  }
1652
1731
  static getPolicyMeta(req) {
1653
1732
  let policyTypes = 0;
1654
1733
  const policies = [];
1655
- if (req.gasPrice) {
1656
- policyTypes += import_transactions6.PolicyType.GasPrice;
1657
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1734
+ if (req.tip) {
1735
+ policyTypes += import_transactions6.PolicyType.Tip;
1736
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1658
1737
  }
1659
1738
  if (req.witnessLimit) {
1660
1739
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -1740,7 +1819,7 @@ var BaseTransactionRequest = class {
1740
1819
  * @returns The index of the created witness.
1741
1820
  */
1742
1821
  addEmptyWitness() {
1743
- this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1822
+ this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
1744
1823
  return this.witnesses.length - 1;
1745
1824
  }
1746
1825
  /**
@@ -1841,10 +1920,10 @@ var BaseTransactionRequest = class {
1841
1920
  * @param predicate - Predicate bytes.
1842
1921
  * @param predicateData - Predicate data bytes.
1843
1922
  */
1844
- addCoinInput(coin, predicate) {
1923
+ addCoinInput(coin) {
1845
1924
  const { assetId, owner, amount } = coin;
1846
1925
  let witnessIndex;
1847
- if (predicate) {
1926
+ if (coin.predicate) {
1848
1927
  witnessIndex = 0;
1849
1928
  } else {
1850
1929
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1859,9 +1938,7 @@ var BaseTransactionRequest = class {
1859
1938
  amount,
1860
1939
  assetId,
1861
1940
  txPointer: "0x00000000000000000000000000000000",
1862
- witnessIndex,
1863
- predicate: predicate?.bytes,
1864
- predicateData: predicate?.predicateDataBytes
1941
+ witnessIndex
1865
1942
  };
1866
1943
  this.pushInput(input);
1867
1944
  this.addChangeOutput(owner, assetId);
@@ -1872,11 +1949,13 @@ var BaseTransactionRequest = class {
1872
1949
  *
1873
1950
  * @param message - Message resource.
1874
1951
  * @param predicate - Predicate bytes.
1952
+ * @param predicateData - Predicate data bytes.
1875
1953
  */
1876
- addMessageInput(message, predicate) {
1954
+ addMessageInput(message) {
1877
1955
  const { recipient, sender, amount } = message;
1956
+ const assetId = import_configs7.BaseAssetId;
1878
1957
  let witnessIndex;
1879
- if (predicate) {
1958
+ if (message.predicate) {
1880
1959
  witnessIndex = 0;
1881
1960
  } else {
1882
1961
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1890,12 +1969,10 @@ var BaseTransactionRequest = class {
1890
1969
  sender: sender.toB256(),
1891
1970
  recipient: recipient.toB256(),
1892
1971
  amount,
1893
- witnessIndex,
1894
- predicate: predicate?.bytes,
1895
- predicateData: predicate?.predicateDataBytes
1972
+ witnessIndex
1896
1973
  };
1897
1974
  this.pushInput(input);
1898
- this.addChangeOutput(recipient, this.baseAssetId);
1975
+ this.addChangeOutput(recipient, assetId);
1899
1976
  }
1900
1977
  /**
1901
1978
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1923,32 +2000,6 @@ var BaseTransactionRequest = class {
1923
2000
  resources.forEach((resource) => this.addResource(resource));
1924
2001
  return this;
1925
2002
  }
1926
- /**
1927
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1928
- * outputs from the related assetIds.
1929
- *
1930
- * @param resources - The resources to add.
1931
- * @returns This transaction.
1932
- */
1933
- addPredicateResource(resource, predicate) {
1934
- if (isCoin(resource)) {
1935
- this.addCoinInput(resource, predicate);
1936
- } else {
1937
- this.addMessageInput(resource, predicate);
1938
- }
1939
- return this;
1940
- }
1941
- /**
1942
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
1943
- * from the related assetIds.
1944
- *
1945
- * @param resources - The resources to add.
1946
- * @returns This transaction.
1947
- */
1948
- addPredicateResources(resources, predicate) {
1949
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1950
- return this;
1951
- }
1952
2003
  /**
1953
2004
  * Adds a coin output to the transaction.
1954
2005
  *
@@ -1956,12 +2007,12 @@ var BaseTransactionRequest = class {
1956
2007
  * @param amount - Amount of coin.
1957
2008
  * @param assetId - Asset ID of coin.
1958
2009
  */
1959
- addCoinOutput(to, amount, assetId) {
2010
+ addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
1960
2011
  this.pushOutput({
1961
2012
  type: import_transactions6.OutputType.Coin,
1962
2013
  to: (0, import_address.addressify)(to).toB256(),
1963
2014
  amount,
1964
- assetId: assetId ?? this.baseAssetId
2015
+ assetId
1965
2016
  });
1966
2017
  return this;
1967
2018
  }
@@ -1988,7 +2039,7 @@ var BaseTransactionRequest = class {
1988
2039
  * @param to - Address of the owner.
1989
2040
  * @param assetId - Asset ID of coin.
1990
2041
  */
1991
- addChangeOutput(to, assetId) {
2042
+ addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
1992
2043
  const changeOutput = this.getChangeOutputs().find(
1993
2044
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
1994
2045
  );
@@ -1996,7 +2047,7 @@ var BaseTransactionRequest = class {
1996
2047
  this.pushOutput({
1997
2048
  type: import_transactions6.OutputType.Change,
1998
2049
  to: (0, import_address.addressify)(to).toB256(),
1999
- assetId: assetId ?? this.baseAssetId
2050
+ assetId
2000
2051
  });
2001
2052
  }
2002
2053
  }
@@ -2028,7 +2079,7 @@ var BaseTransactionRequest = class {
2028
2079
  }
2029
2080
  calculateMaxGas(chainInfo, minGas) {
2030
2081
  const { consensusParameters } = chainInfo;
2031
- const { gasPerByte } = consensusParameters;
2082
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2032
2083
  const witnessesLength = this.toTransaction().witnesses.reduce(
2033
2084
  (acc, wit) => acc + wit.dataLength,
2034
2085
  0
@@ -2037,7 +2088,8 @@ var BaseTransactionRequest = class {
2037
2088
  gasPerByte,
2038
2089
  minGas,
2039
2090
  witnessesLength,
2040
- witnessLimit: this.witnessLimit
2091
+ witnessLimit: this.witnessLimit,
2092
+ maxGasPerTx
2041
2093
  });
2042
2094
  }
2043
2095
  /**
@@ -2047,12 +2099,6 @@ var BaseTransactionRequest = class {
2047
2099
  * @param quantities - CoinQuantity Array.
2048
2100
  */
2049
2101
  fundWithFakeUtxos(quantities, resourcesOwner) {
2050
- let idCounter = 0;
2051
- const generateId = () => {
2052
- const counterString = String(idCounter++);
2053
- const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2054
- return id;
2055
- };
2056
2102
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2057
2103
  if ("assetId" in input) {
2058
2104
  return input.assetId === assetId;
@@ -2061,24 +2107,27 @@ var BaseTransactionRequest = class {
2061
2107
  });
2062
2108
  const updateAssetInput = (assetId, quantity) => {
2063
2109
  const assetInput = findAssetInput(assetId);
2110
+ let usedQuantity = quantity;
2111
+ if (assetId === import_configs7.BaseAssetId) {
2112
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2113
+ }
2064
2114
  if (assetInput && "assetId" in assetInput) {
2065
- assetInput.id = generateId();
2066
- assetInput.amount = quantity;
2115
+ assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34));
2116
+ assetInput.amount = usedQuantity;
2067
2117
  } else {
2068
2118
  this.addResources([
2069
2119
  {
2070
- id: generateId(),
2071
- amount: quantity,
2120
+ id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34)),
2121
+ amount: usedQuantity,
2072
2122
  assetId,
2073
2123
  owner: resourcesOwner || import_address.Address.fromRandom(),
2074
- maturity: 0,
2075
2124
  blockCreated: (0, import_math7.bn)(1),
2076
2125
  txCreatedIdx: (0, import_math7.bn)(1)
2077
2126
  }
2078
2127
  ]);
2079
2128
  }
2080
2129
  };
2081
- updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
2130
+ updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2082
2131
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2083
2132
  }
2084
2133
  /**
@@ -2103,7 +2152,7 @@ var BaseTransactionRequest = class {
2103
2152
  toJSON() {
2104
2153
  return normalizeJSON(this);
2105
2154
  }
2106
- updatePredicateInputs(inputs) {
2155
+ updatePredicateGasUsed(inputs) {
2107
2156
  this.inputs.forEach((i) => {
2108
2157
  let correspondingInput;
2109
2158
  switch (i.type) {
@@ -2125,16 +2174,25 @@ var BaseTransactionRequest = class {
2125
2174
  }
2126
2175
  });
2127
2176
  }
2177
+ shiftPredicateData() {
2178
+ this.inputs.forEach((input) => {
2179
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2180
+ input.predicateData = input.paddPredicateData(
2181
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2182
+ );
2183
+ }
2184
+ });
2185
+ }
2128
2186
  };
2129
2187
 
2130
2188
  // src/providers/transaction-request/create-transaction-request.ts
2131
- var import_configs8 = require("@fuel-ts/address/configs");
2189
+ var import_configs9 = require("@fuel-ts/address/configs");
2132
2190
  var import_math9 = require("@fuel-ts/math");
2133
2191
  var import_transactions8 = require("@fuel-ts/transactions");
2134
2192
  var import_utils13 = require("@fuel-ts/utils");
2135
2193
 
2136
2194
  // src/providers/transaction-request/hash-transaction.ts
2137
- var import_configs7 = require("@fuel-ts/address/configs");
2195
+ var import_configs8 = require("@fuel-ts/address/configs");
2138
2196
  var import_hasher = require("@fuel-ts/hasher");
2139
2197
  var import_math8 = require("@fuel-ts/math");
2140
2198
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2143,7 +2201,7 @@ var import_ramda2 = require("ramda");
2143
2201
  function hashTransaction(transactionRequest, chainId) {
2144
2202
  const transaction = transactionRequest.toTransaction();
2145
2203
  if (transaction.type === import_transactions7.TransactionType.Script) {
2146
- transaction.receiptsRoot = import_configs7.ZeroBytes32;
2204
+ transaction.receiptsRoot = import_configs8.ZeroBytes32;
2147
2205
  }
2148
2206
  transaction.inputs = transaction.inputs.map((input) => {
2149
2207
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2165,10 +2223,10 @@ function hashTransaction(transactionRequest, chainId) {
2165
2223
  blockHeight: 0,
2166
2224
  txIndex: 0
2167
2225
  };
2168
- inputClone.txID = import_configs7.ZeroBytes32;
2226
+ inputClone.txID = import_configs8.ZeroBytes32;
2169
2227
  inputClone.outputIndex = 0;
2170
- inputClone.balanceRoot = import_configs7.ZeroBytes32;
2171
- inputClone.stateRoot = import_configs7.ZeroBytes32;
2228
+ inputClone.balanceRoot = import_configs8.ZeroBytes32;
2229
+ inputClone.stateRoot = import_configs8.ZeroBytes32;
2172
2230
  return inputClone;
2173
2231
  }
2174
2232
  default:
@@ -2179,8 +2237,8 @@ function hashTransaction(transactionRequest, chainId) {
2179
2237
  const outputClone = (0, import_ramda2.clone)(output);
2180
2238
  switch (outputClone.type) {
2181
2239
  case import_transactions7.OutputType.Contract: {
2182
- outputClone.balanceRoot = import_configs7.ZeroBytes32;
2183
- outputClone.stateRoot = import_configs7.ZeroBytes32;
2240
+ outputClone.balanceRoot = import_configs8.ZeroBytes32;
2241
+ outputClone.stateRoot = import_configs8.ZeroBytes32;
2184
2242
  return outputClone;
2185
2243
  }
2186
2244
  case import_transactions7.OutputType.Change: {
@@ -2188,9 +2246,9 @@ function hashTransaction(transactionRequest, chainId) {
2188
2246
  return outputClone;
2189
2247
  }
2190
2248
  case import_transactions7.OutputType.Variable: {
2191
- outputClone.to = import_configs7.ZeroBytes32;
2249
+ outputClone.to = import_configs8.ZeroBytes32;
2192
2250
  outputClone.amount = (0, import_math8.bn)(0);
2193
- outputClone.assetId = import_configs7.ZeroBytes32;
2251
+ outputClone.assetId = import_configs8.ZeroBytes32;
2194
2252
  return outputClone;
2195
2253
  }
2196
2254
  default:
@@ -2256,7 +2314,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2256
2314
  } = {}) {
2257
2315
  super(rest);
2258
2316
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2259
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2317
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2260
2318
  this.storageSlots = [...storageSlots ?? []];
2261
2319
  }
2262
2320
  /**
@@ -2271,10 +2329,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2271
2329
  return {
2272
2330
  type: import_transactions8.TransactionType.Create,
2273
2331
  ...baseTransaction,
2274
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2275
2332
  bytecodeWitnessIndex,
2276
- storageSlotsCount: storageSlots.length,
2277
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2333
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2334
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2278
2335
  storageSlots
2279
2336
  };
2280
2337
  }
@@ -2324,7 +2381,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2324
2381
  // src/providers/transaction-request/script-transaction-request.ts
2325
2382
  var import_abi_coder = require("@fuel-ts/abi-coder");
2326
2383
  var import_address2 = require("@fuel-ts/address");
2327
- var import_configs9 = require("@fuel-ts/address/configs");
2384
+ var import_configs10 = require("@fuel-ts/address/configs");
2328
2385
  var import_math10 = require("@fuel-ts/math");
2329
2386
  var import_transactions9 = require("@fuel-ts/transactions");
2330
2387
  var import_utils15 = require("@fuel-ts/utils");
@@ -2396,9 +2453,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2396
2453
  type: import_transactions9.TransactionType.Script,
2397
2454
  scriptGasLimit: this.gasLimit,
2398
2455
  ...super.getBaseTransaction(),
2399
- scriptLength: script.length,
2400
- scriptDataLength: scriptData.length,
2401
- receiptsRoot: import_configs9.ZeroBytes32,
2456
+ scriptLength: (0, import_math10.bn)(script.length),
2457
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2458
+ receiptsRoot: import_configs10.ZeroBytes32,
2402
2459
  script: (0, import_utils15.hexlify)(script),
2403
2460
  scriptData: (0, import_utils15.hexlify)(scriptData)
2404
2461
  };
@@ -2461,7 +2518,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2461
2518
  }
2462
2519
  calculateMaxGas(chainInfo, minGas) {
2463
2520
  const { consensusParameters } = chainInfo;
2464
- const { gasPerByte } = consensusParameters;
2521
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2465
2522
  const witnessesLength = this.toTransaction().witnesses.reduce(
2466
2523
  (acc, wit) => acc + wit.dataLength,
2467
2524
  0
@@ -2471,7 +2528,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2471
2528
  minGas,
2472
2529
  witnessesLength,
2473
2530
  witnessLimit: this.witnessLimit,
2474
- gasLimit: this.gasLimit
2531
+ gasLimit: this.gasLimit,
2532
+ maxGasPerTx
2475
2533
  });
2476
2534
  }
2477
2535
  /**
@@ -2546,15 +2604,32 @@ var transactionRequestify = (obj) => {
2546
2604
  }
2547
2605
  }
2548
2606
  };
2607
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2608
+ (acc, input) => {
2609
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2610
+ acc.utxos.push(input.id);
2611
+ }
2612
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2613
+ acc.messages.push(input.nonce);
2614
+ }
2615
+ return acc;
2616
+ },
2617
+ {
2618
+ utxos: [],
2619
+ messages: []
2620
+ }
2621
+ );
2549
2622
 
2550
2623
  // src/providers/transaction-response/transaction-response.ts
2551
2624
  var import_errors13 = require("@fuel-ts/errors");
2552
- var import_math14 = require("@fuel-ts/math");
2553
- var import_transactions17 = require("@fuel-ts/transactions");
2554
- var import_utils21 = require("@fuel-ts/utils");
2625
+ var import_math15 = require("@fuel-ts/math");
2626
+ var import_transactions18 = require("@fuel-ts/transactions");
2627
+ var import_utils20 = require("@fuel-ts/utils");
2555
2628
 
2556
2629
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2557
- var import_utils19 = require("@fuel-ts/utils");
2630
+ var import_math14 = require("@fuel-ts/math");
2631
+ var import_transactions16 = require("@fuel-ts/transactions");
2632
+ var import_utils18 = require("@fuel-ts/utils");
2558
2633
 
2559
2634
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2560
2635
  var import_math11 = require("@fuel-ts/math");
@@ -2562,9 +2637,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
2562
2637
  var import_utils16 = require("@fuel-ts/utils");
2563
2638
  var calculateTransactionFee = (params) => {
2564
2639
  const {
2565
- gasUsed,
2640
+ gasPrice,
2566
2641
  rawPayload,
2567
- consensusParameters: { gasCosts, feeParams }
2642
+ tip,
2643
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2568
2644
  } = params;
2569
2645
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2570
2646
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2574,8 +2650,7 @@ var calculateTransactionFee = (params) => {
2574
2650
  return {
2575
2651
  fee: (0, import_math11.bn)(0),
2576
2652
  minFee: (0, import_math11.bn)(0),
2577
- maxFee: (0, import_math11.bn)(0),
2578
- feeFromGasUsed: (0, import_math11.bn)(0)
2653
+ maxFee: (0, import_math11.bn)(0)
2579
2654
  };
2580
2655
  }
2581
2656
  const { type, witnesses, inputs, policies } = transaction;
@@ -2607,7 +2682,6 @@ var calculateTransactionFee = (params) => {
2607
2682
  metadataGas,
2608
2683
  txBytesSize: transactionBytes.length
2609
2684
  });
2610
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2611
2685
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2612
2686
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2613
2687
  const maxGas = getMaxGas({
@@ -2615,22 +2689,30 @@ var calculateTransactionFee = (params) => {
2615
2689
  minGas,
2616
2690
  witnessesLength,
2617
2691
  gasLimit,
2618
- witnessLimit
2692
+ witnessLimit,
2693
+ maxGasPerTx
2694
+ });
2695
+ const minFee = calculateGasFee({
2696
+ gasPrice,
2697
+ gas: minGas,
2698
+ priceFactor: gasPriceFactor,
2699
+ tip
2700
+ });
2701
+ const maxFee = calculateGasFee({
2702
+ gasPrice,
2703
+ gas: maxGas,
2704
+ priceFactor: gasPriceFactor,
2705
+ tip
2619
2706
  });
2620
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2621
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2622
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2623
- const fee = minFee.add(feeFromGasUsed);
2624
2707
  return {
2625
- fee,
2626
2708
  minFee,
2627
2709
  maxFee,
2628
- feeFromGasUsed
2710
+ fee: maxFee
2629
2711
  };
2630
2712
  };
2631
2713
 
2632
2714
  // src/providers/transaction-summary/operations.ts
2633
- var import_configs10 = require("@fuel-ts/address/configs");
2715
+ var import_configs11 = require("@fuel-ts/address/configs");
2634
2716
  var import_errors11 = require("@fuel-ts/errors");
2635
2717
  var import_math13 = require("@fuel-ts/math");
2636
2718
  var import_transactions14 = require("@fuel-ts/transactions");
@@ -2928,7 +3010,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
2928
3010
  const { to: toAddress, assetId, amount } = receipt;
2929
3011
  let { from: fromAddress } = receipt;
2930
3012
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
2931
- if (import_configs10.ZeroBytes32 === fromAddress) {
3013
+ if (import_configs11.ZeroBytes32 === fromAddress) {
2932
3014
  const change = changeOutputs.find((output) => output.assetId === assetId);
2933
3015
  fromAddress = change?.to || fromAddress;
2934
3016
  }
@@ -3192,10 +3274,12 @@ function assembleTransactionSummary(params) {
3192
3274
  gqlTransactionStatus,
3193
3275
  abiMap = {},
3194
3276
  maxInputs,
3195
- gasCosts
3277
+ gasCosts,
3278
+ maxGasPerTx,
3279
+ gasPrice
3196
3280
  } = params;
3197
3281
  const gasUsed = getGasUsedFromReceipts(receipts);
3198
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3282
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3199
3283
  const operations = getOperations({
3200
3284
  transactionType: transaction.type,
3201
3285
  inputs: transaction.inputs || [],
@@ -3206,11 +3290,14 @@ function assembleTransactionSummary(params) {
3206
3290
  maxInputs
3207
3291
  });
3208
3292
  const typeName = getTransactionTypeName(transaction.type);
3293
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3209
3294
  const { fee } = calculateTransactionFee({
3210
- gasUsed,
3295
+ gasPrice,
3211
3296
  rawPayload,
3297
+ tip,
3212
3298
  consensusParameters: {
3213
3299
  gasCosts,
3300
+ maxGasPerTx,
3214
3301
  feeParams: {
3215
3302
  gasPerByte,
3216
3303
  gasPriceFactor
@@ -3222,7 +3309,7 @@ function assembleTransactionSummary(params) {
3222
3309
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3223
3310
  let date;
3224
3311
  if (time) {
3225
- date = import_utils19.DateTime.fromTai64(time);
3312
+ date = import_utils18.DateTime.fromTai64(time);
3226
3313
  }
3227
3314
  const transactionSummary = {
3228
3315
  id,
@@ -3250,12 +3337,12 @@ function assembleTransactionSummary(params) {
3250
3337
 
3251
3338
  // src/providers/transaction-response/getDecodedLogs.ts
3252
3339
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
3253
- var import_transactions16 = require("@fuel-ts/transactions");
3340
+ var import_transactions17 = require("@fuel-ts/transactions");
3254
3341
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3255
3342
  return receipts.reduce((logs, receipt) => {
3256
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3343
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3257
3344
  const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3258
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3345
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3259
3346
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3260
3347
  logs.push(decodedLog);
3261
3348
  }
@@ -3270,7 +3357,7 @@ var TransactionResponse = class {
3270
3357
  /** Current provider */
3271
3358
  provider;
3272
3359
  /** Gas used on the transaction */
3273
- gasUsed = (0, import_math14.bn)(0);
3360
+ gasUsed = (0, import_math15.bn)(0);
3274
3361
  /** The graphql Transaction with receipts object. */
3275
3362
  gqlTransaction;
3276
3363
  abis;
@@ -3328,8 +3415,8 @@ var TransactionResponse = class {
3328
3415
  * @returns The decoded transaction.
3329
3416
  */
3330
3417
  decodeTransaction(transactionWithReceipts) {
3331
- return new import_transactions17.TransactionCoder().decode(
3332
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3418
+ return new import_transactions18.TransactionCoder().decode(
3419
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3333
3420
  0
3334
3421
  )?.[0];
3335
3422
  }
@@ -3348,20 +3435,27 @@ var TransactionResponse = class {
3348
3435
  const decodedTransaction = this.decodeTransaction(
3349
3436
  transaction
3350
3437
  );
3351
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3352
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3438
+ let txReceipts = [];
3439
+ if (transaction?.status && "receipts" in transaction.status) {
3440
+ txReceipts = transaction.status.receipts;
3441
+ }
3442
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3443
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3444
+ const gasPrice = await this.provider.getLatestGasPrice();
3353
3445
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3354
3446
  const transactionSummary = assembleTransactionSummary({
3355
3447
  id: this.id,
3356
3448
  receipts,
3357
3449
  transaction: decodedTransaction,
3358
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3450
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3359
3451
  gqlTransactionStatus: transaction.status,
3360
3452
  gasPerByte,
3361
3453
  gasPriceFactor,
3362
3454
  abiMap: contractsAbiMap,
3363
3455
  maxInputs,
3364
- gasCosts
3456
+ gasCosts,
3457
+ maxGasPerTx,
3458
+ gasPrice
3365
3459
  });
3366
3460
  return transactionSummary;
3367
3461
  }
@@ -3488,30 +3582,29 @@ var processGqlChain = (chain) => {
3488
3582
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3489
3583
  return {
3490
3584
  name,
3491
- baseChainHeight: (0, import_math15.bn)(daHeight),
3585
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3492
3586
  consensusParameters: {
3493
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3494
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3495
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3496
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3497
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3498
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3499
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3500
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3501
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3502
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3503
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3504
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3505
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3506
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3507
- chainId: (0, import_math15.bn)(consensusParameters.chainId),
3508
- baseAssetId: consensusParameters.baseAssetId,
3587
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3588
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3589
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3590
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3591
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3592
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3593
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3594
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3595
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3596
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3597
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3598
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3599
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3600
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3601
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3509
3602
  gasCosts
3510
3603
  },
3511
3604
  gasCosts,
3512
3605
  latestBlock: {
3513
3606
  id: latestBlock.id,
3514
- height: (0, import_math15.bn)(latestBlock.header.height),
3607
+ height: (0, import_math16.bn)(latestBlock.height),
3515
3608
  time: latestBlock.header.time,
3516
3609
  transactions: latestBlock.transactions.map((i) => ({
3517
3610
  id: i.id
@@ -3605,10 +3698,8 @@ var _Provider = class {
3605
3698
  * Returns some helpful parameters related to gas fees.
3606
3699
  */
3607
3700
  getGasConfig() {
3608
- const { minGasPrice } = this.getNode();
3609
3701
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3610
3702
  return {
3611
- minGasPrice,
3612
3703
  maxGasPerTx,
3613
3704
  maxGasPerPredicate,
3614
3705
  gasPriceFactor,
@@ -3696,7 +3787,7 @@ var _Provider = class {
3696
3787
  name,
3697
3788
  consensusParameters: { chainId }
3698
3789
  } = await this.getChain();
3699
- const network = new import_ethers.Network(name, chainId.toNumber());
3790
+ const network = new import_ethers2.Network(name, chainId.toNumber());
3700
3791
  return Promise.resolve(network);
3701
3792
  }
3702
3793
  /**
@@ -3706,7 +3797,7 @@ var _Provider = class {
3706
3797
  */
3707
3798
  async getBlockNumber() {
3708
3799
  const { chain } = await this.operations.getChain();
3709
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
3800
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3710
3801
  }
3711
3802
  /**
3712
3803
  * Returns the chain information.
@@ -3716,13 +3807,11 @@ var _Provider = class {
3716
3807
  async fetchNode() {
3717
3808
  const { nodeInfo } = await this.operations.getNodeInfo();
3718
3809
  const processedNodeInfo = {
3719
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3720
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3721
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
3810
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
3811
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3722
3812
  nodeVersion: nodeInfo.nodeVersion,
3723
3813
  utxoValidation: nodeInfo.utxoValidation,
3724
- vmBacktrace: nodeInfo.vmBacktrace,
3725
- peers: nodeInfo.peers
3814
+ vmBacktrace: nodeInfo.vmBacktrace
3726
3815
  };
3727
3816
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3728
3817
  return processedNodeInfo;
@@ -3748,17 +3837,6 @@ var _Provider = class {
3748
3837
  } = this.getChain();
3749
3838
  return chainId.toNumber();
3750
3839
  }
3751
- /**
3752
- * Returns the base asset ID
3753
- *
3754
- * @returns A promise that resolves to the base asset ID
3755
- */
3756
- getBaseAssetId() {
3757
- const {
3758
- consensusParameters: { baseAssetId }
3759
- } = this.getChain();
3760
- return baseAssetId;
3761
- }
3762
3840
  /**
3763
3841
  * Submits a transaction to the chain to be executed.
3764
3842
  *
@@ -3775,9 +3853,9 @@ var _Provider = class {
3775
3853
  if (estimateTxDependencies) {
3776
3854
  await this.estimateTxDependencies(transactionRequest);
3777
3855
  }
3778
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3856
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3779
3857
  let abis;
3780
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
3858
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
3781
3859
  abis = transactionRequest.abis;
3782
3860
  }
3783
3861
  if (awaitExecution) {
@@ -3818,15 +3896,14 @@ var _Provider = class {
3818
3896
  if (estimateTxDependencies) {
3819
3897
  return this.estimateTxDependencies(transactionRequest);
3820
3898
  }
3821
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3822
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3823
- encodedTransaction,
3899
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3900
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
3901
+ encodedTransactions: encodedTransaction,
3824
3902
  utxoValidation: utxoValidation || false
3825
3903
  });
3826
- const receipts = gqlReceipts.map(processGqlReceipt);
3827
- return {
3828
- receipts
3829
- };
3904
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
3905
+ const receipts = rawReceipts.map(processGqlReceipt);
3906
+ return { receipts, dryrunStatus: status };
3830
3907
  }
3831
3908
  /**
3832
3909
  * Verifies whether enough gas is available to complete transaction.
@@ -3837,13 +3914,13 @@ var _Provider = class {
3837
3914
  async estimatePredicates(transactionRequest) {
3838
3915
  const shouldEstimatePredicates = Boolean(
3839
3916
  transactionRequest.inputs.find(
3840
- (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()
3917
+ (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()
3841
3918
  )
3842
3919
  );
3843
3920
  if (!shouldEstimatePredicates) {
3844
3921
  return transactionRequest;
3845
3922
  }
3846
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3923
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3847
3924
  const response = await this.operations.estimatePredicates({
3848
3925
  encodedTransaction
3849
3926
  });
@@ -3852,7 +3929,7 @@ var _Provider = class {
3852
3929
  } = response;
3853
3930
  if (inputs) {
3854
3931
  inputs.forEach((input, index) => {
3855
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
3932
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
3856
3933
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3857
3934
  }
3858
3935
  });
@@ -3865,31 +3942,31 @@ var _Provider = class {
3865
3942
  * If there are missing variable outputs,
3866
3943
  * `addVariableOutputs` is called on the transaction.
3867
3944
  *
3868
- * @privateRemarks
3869
- * TODO: Investigate support for missing contract IDs
3870
- * TODO: Add support for missing output messages
3871
3945
  *
3872
3946
  * @param transactionRequest - The transaction request object.
3873
3947
  * @returns A promise.
3874
3948
  */
3875
3949
  async estimateTxDependencies(transactionRequest) {
3876
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
3950
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
3877
3951
  return {
3878
3952
  receipts: [],
3879
3953
  outputVariables: 0,
3880
3954
  missingContractIds: []
3881
3955
  };
3882
3956
  }
3883
- await this.estimatePredicates(transactionRequest);
3884
3957
  let receipts = [];
3885
3958
  const missingContractIds = [];
3886
3959
  let outputVariables = 0;
3960
+ let dryrunStatus;
3887
3961
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3888
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3889
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
3962
+ const {
3963
+ dryRun: [{ receipts: rawReceipts, status }]
3964
+ } = await this.operations.dryRun({
3965
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
3890
3966
  utxoValidation: false
3891
3967
  });
3892
- receipts = gqlReceipts.map(processGqlReceipt);
3968
+ receipts = rawReceipts.map(processGqlReceipt);
3969
+ dryrunStatus = status;
3893
3970
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3894
3971
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3895
3972
  if (hasMissingOutputs) {
@@ -3899,6 +3976,11 @@ var _Provider = class {
3899
3976
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
3900
3977
  missingContractIds.push(contractId);
3901
3978
  });
3979
+ const { maxFee } = await this.estimateTxGasAndFee({
3980
+ transactionRequest,
3981
+ optimizeGas: false
3982
+ });
3983
+ transactionRequest.maxFee = maxFee;
3902
3984
  } else {
3903
3985
  break;
3904
3986
  }
@@ -3906,7 +3988,133 @@ var _Provider = class {
3906
3988
  return {
3907
3989
  receipts,
3908
3990
  outputVariables,
3909
- missingContractIds
3991
+ missingContractIds,
3992
+ dryrunStatus
3993
+ };
3994
+ }
3995
+ /**
3996
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
3997
+ *
3998
+ * Transactions are dry run in batches. After each dry run, transactions requiring
3999
+ * further modifications are identified. The method iteratively updates these transactions
4000
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4001
+ *
4002
+ * @param transactionRequests - Array of transaction request objects.
4003
+ * @returns A promise that resolves to an array of results for each transaction.
4004
+ */
4005
+ async estimateMultipleTxDependencies(transactionRequests) {
4006
+ const results = transactionRequests.map(() => ({
4007
+ receipts: [],
4008
+ outputVariables: 0,
4009
+ missingContractIds: [],
4010
+ dryrunStatus: void 0
4011
+ }));
4012
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4013
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4014
+ allRequests.forEach((req, index) => {
4015
+ if (req.type === import_transactions19.TransactionType.Script) {
4016
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4017
+ }
4018
+ });
4019
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4020
+ let attempt = 0;
4021
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4022
+ const encodedTransactions = transactionsToProcess.map(
4023
+ (index) => serializedTransactionsMap.get(index)
4024
+ );
4025
+ const dryRunResults = await this.operations.dryRun({
4026
+ encodedTransactions,
4027
+ utxoValidation: false
4028
+ });
4029
+ const nextRoundTransactions = [];
4030
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4031
+ const currentResultIndex = transactionsToProcess[i];
4032
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4033
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4034
+ results[currentResultIndex].dryrunStatus = status;
4035
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4036
+ results[currentResultIndex].receipts
4037
+ );
4038
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4039
+ const requestToProcess = allRequests[currentResultIndex];
4040
+ if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4041
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4042
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4043
+ missingOutputContractIds.forEach(({ contractId }) => {
4044
+ requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4045
+ results[currentResultIndex].missingContractIds.push(contractId);
4046
+ });
4047
+ const { maxFee } = await this.estimateTxGasAndFee({
4048
+ transactionRequest: requestToProcess,
4049
+ optimizeGas: false
4050
+ });
4051
+ requestToProcess.maxFee = maxFee;
4052
+ serializedTransactionsMap.set(
4053
+ currentResultIndex,
4054
+ (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4055
+ );
4056
+ nextRoundTransactions.push(currentResultIndex);
4057
+ allRequests[currentResultIndex] = requestToProcess;
4058
+ }
4059
+ }
4060
+ transactionsToProcess = nextRoundTransactions;
4061
+ attempt += 1;
4062
+ }
4063
+ return results;
4064
+ }
4065
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4066
+ if (estimateTxDependencies) {
4067
+ return this.estimateMultipleTxDependencies(transactionRequests);
4068
+ }
4069
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4070
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4071
+ encodedTransactions,
4072
+ utxoValidation: utxoValidation || false
4073
+ });
4074
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4075
+ const receipts = rawReceipts.map(processGqlReceipt);
4076
+ return { receipts, dryrunStatus: status };
4077
+ });
4078
+ return results;
4079
+ }
4080
+ async estimateTxGasAndFee(params) {
4081
+ const { transactionRequest, optimizeGas = true } = params;
4082
+ let { gasPrice } = params;
4083
+ const chainInfo = this.getChain();
4084
+ const { gasPriceFactor } = this.getGasConfig();
4085
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
4086
+ if (!gasPrice) {
4087
+ gasPrice = await this.estimateGasPrice(10);
4088
+ }
4089
+ const minFee = calculateGasFee({
4090
+ gasPrice: (0, import_math16.bn)(gasPrice),
4091
+ gas: minGas,
4092
+ priceFactor: gasPriceFactor,
4093
+ tip: transactionRequest.tip
4094
+ }).add(1);
4095
+ let gasLimit = (0, import_math16.bn)(0);
4096
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4097
+ gasLimit = transactionRequest.gasLimit;
4098
+ if (!optimizeGas) {
4099
+ transactionRequest.gasLimit = minGas;
4100
+ gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
4101
+ transactionRequest.gasLimit = gasLimit;
4102
+ }
4103
+ }
4104
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4105
+ const maxFee = calculateGasFee({
4106
+ gasPrice: (0, import_math16.bn)(gasPrice),
4107
+ gas: maxGas,
4108
+ priceFactor: gasPriceFactor,
4109
+ tip: transactionRequest.tip
4110
+ }).add(1);
4111
+ return {
4112
+ minGas,
4113
+ minFee,
4114
+ maxGas,
4115
+ maxFee,
4116
+ gasPrice,
4117
+ gasLimit
3910
4118
  };
3911
4119
  }
3912
4120
  /**
@@ -3924,15 +4132,17 @@ var _Provider = class {
3924
4132
  if (estimateTxDependencies) {
3925
4133
  return this.estimateTxDependencies(transactionRequest);
3926
4134
  }
3927
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3928
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3929
- encodedTransaction,
4135
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4136
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4137
+ encodedTransactions,
3930
4138
  utxoValidation: true
3931
4139
  });
3932
- const receipts = gqlReceipts.map(processGqlReceipt);
3933
- return {
3934
- receipts
3935
- };
4140
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4141
+ const { id, receipts, status } = dryRunStatus;
4142
+ const processedReceipts = receipts.map(processGqlReceipt);
4143
+ return { id, receipts: processedReceipts, status };
4144
+ });
4145
+ return { receipts: callResult[0].receipts };
3936
4146
  }
3937
4147
  /**
3938
4148
  * Returns a transaction cost to enable user
@@ -3949,80 +4159,80 @@ var _Provider = class {
3949
4159
  * @param tolerance - The tolerance to add on top of the gasUsed.
3950
4160
  * @returns A promise that resolves to the transaction cost object.
3951
4161
  */
3952
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3953
- estimateTxDependencies = true,
3954
- estimatePredicates = true,
3955
- resourcesOwner,
3956
- signatureCallback
3957
- } = {}) {
4162
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3958
4163
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
3959
- const chainInfo = this.getChain();
3960
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3961
- const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
3962
- const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4164
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
3963
4165
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3964
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4166
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
3965
4167
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3966
- if (estimatePredicates) {
3967
- if (isScriptTransaction) {
3968
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
3969
- }
3970
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3971
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
3972
- }
3973
- await this.estimatePredicates(txRequestClone);
4168
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
4169
+ if (isScriptTransaction) {
4170
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
3974
4171
  }
3975
- if (signatureCallback && isScriptTransaction) {
3976
- await signatureCallback(txRequestClone);
4172
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4173
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
3977
4174
  }
3978
- const minGas = txRequestClone.calculateMinGas(chainInfo);
3979
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4175
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4176
+ let addedSignatures = 0;
4177
+ if (signatureCallback && isScriptTransaction) {
4178
+ const lengthBefore = signedRequest.witnesses.length;
4179
+ await signatureCallback(signedRequest);
4180
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4181
+ }
4182
+ await this.estimatePredicates(signedRequest);
4183
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4184
+ transactionRequest: signedRequest,
4185
+ optimizeGas: false
4186
+ });
4187
+ txRequestClone.maxFee = maxFee;
3980
4188
  let receipts = [];
3981
4189
  let missingContractIds = [];
3982
4190
  let outputVariables = 0;
3983
- if (isScriptTransaction && estimateTxDependencies) {
3984
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
3985
- txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4191
+ let gasUsed = (0, import_math16.bn)(0);
4192
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4193
+ if (isScriptTransaction) {
4194
+ if (signatureCallback) {
4195
+ await signatureCallback(txRequestClone);
4196
+ }
4197
+ txRequestClone.gasLimit = gasLimit;
3986
4198
  const result = await this.estimateTxDependencies(txRequestClone);
3987
4199
  receipts = result.receipts;
3988
4200
  outputVariables = result.outputVariables;
3989
4201
  missingContractIds = result.missingContractIds;
4202
+ gasUsed = getGasUsedFromReceipts(receipts);
4203
+ txRequestClone.gasLimit = gasUsed;
4204
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4205
+ transactionRequest: txRequestClone,
4206
+ gasPrice
4207
+ }));
3990
4208
  }
3991
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3992
- const usedFee = calculatePriceWithFactor(
3993
- gasUsed,
3994
- gasPrice,
3995
- gasPriceFactor
3996
- ).normalizeZeroToOne();
3997
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3998
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3999
4209
  return {
4000
4210
  requiredQuantities: allQuantities,
4001
4211
  receipts,
4002
4212
  gasUsed,
4003
- minGasPrice,
4004
4213
  gasPrice,
4005
4214
  minGas,
4006
4215
  maxGas,
4007
- usedFee,
4008
4216
  minFee,
4009
4217
  maxFee,
4010
- estimatedInputs: txRequestClone.inputs,
4011
4218
  outputVariables,
4012
- missingContractIds
4219
+ missingContractIds,
4220
+ addedSignatures,
4221
+ estimatedPredicates: txRequestClone.inputs
4013
4222
  };
4014
4223
  }
4015
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4224
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4016
4225
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4017
4226
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4018
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4227
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4228
+ quantitiesToContract
4229
+ });
4019
4230
  transactionRequest.addResources(
4020
4231
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4021
4232
  );
4022
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4023
- transactionRequest,
4024
- forwardingQuantities
4025
- );
4233
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4234
+ quantitiesToContract
4235
+ });
4026
4236
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4027
4237
  return {
4028
4238
  resources,
@@ -4038,17 +4248,16 @@ var _Provider = class {
4038
4248
  const result = await this.operations.getCoins({
4039
4249
  first: 10,
4040
4250
  ...paginationArgs,
4041
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4251
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4042
4252
  });
4043
4253
  const coins = result.coins.edges.map((edge) => edge.node);
4044
4254
  return coins.map((coin) => ({
4045
4255
  id: coin.utxoId,
4046
4256
  assetId: coin.assetId,
4047
- amount: (0, import_math15.bn)(coin.amount),
4257
+ amount: (0, import_math16.bn)(coin.amount),
4048
4258
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4049
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4050
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4051
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4259
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4260
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4052
4261
  }));
4053
4262
  }
4054
4263
  /**
@@ -4062,19 +4271,19 @@ var _Provider = class {
4062
4271
  async getResourcesToSpend(owner, quantities, excludedIds) {
4063
4272
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4064
4273
  const excludeInput = {
4065
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4066
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4274
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4275
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4067
4276
  };
4068
4277
  if (this.cache) {
4069
4278
  const uniqueUtxos = new Set(
4070
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4279
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4071
4280
  );
4072
4281
  excludeInput.utxos = Array.from(uniqueUtxos);
4073
4282
  }
4074
4283
  const coinsQuery = {
4075
4284
  owner: ownerAddress.toB256(),
4076
4285
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4077
- assetId: (0, import_utils23.hexlify)(assetId),
4286
+ assetId: (0, import_utils22.hexlify)(assetId),
4078
4287
  amount: amount.toString(10),
4079
4288
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4080
4289
  })),
@@ -4085,9 +4294,9 @@ var _Provider = class {
4085
4294
  switch (coin.__typename) {
4086
4295
  case "MessageCoin":
4087
4296
  return {
4088
- amount: (0, import_math15.bn)(coin.amount),
4297
+ amount: (0, import_math16.bn)(coin.amount),
4089
4298
  assetId: coin.assetId,
4090
- daHeight: (0, import_math15.bn)(coin.daHeight),
4299
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4091
4300
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4092
4301
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4093
4302
  nonce: coin.nonce
@@ -4095,12 +4304,11 @@ var _Provider = class {
4095
4304
  case "Coin":
4096
4305
  return {
4097
4306
  id: coin.utxoId,
4098
- amount: (0, import_math15.bn)(coin.amount),
4307
+ amount: (0, import_math16.bn)(coin.amount),
4099
4308
  assetId: coin.assetId,
4100
4309
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4101
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4102
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4103
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4310
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4311
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4104
4312
  };
4105
4313
  default:
4106
4314
  return null;
@@ -4117,13 +4325,13 @@ var _Provider = class {
4117
4325
  async getBlock(idOrHeight) {
4118
4326
  let variables;
4119
4327
  if (typeof idOrHeight === "number") {
4120
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4328
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4121
4329
  } else if (idOrHeight === "latest") {
4122
4330
  variables = { height: (await this.getBlockNumber()).toString(10) };
4123
4331
  } else if (idOrHeight.length === 66) {
4124
4332
  variables = { blockId: idOrHeight };
4125
4333
  } else {
4126
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4334
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4127
4335
  }
4128
4336
  const { block } = await this.operations.getBlock(variables);
4129
4337
  if (!block) {
@@ -4131,7 +4339,7 @@ var _Provider = class {
4131
4339
  }
4132
4340
  return {
4133
4341
  id: block.id,
4134
- height: (0, import_math15.bn)(block.header.height),
4342
+ height: (0, import_math16.bn)(block.height),
4135
4343
  time: block.header.time,
4136
4344
  transactionIds: block.transactions.map((tx) => tx.id)
4137
4345
  };
@@ -4146,7 +4354,7 @@ var _Provider = class {
4146
4354
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4147
4355
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4148
4356
  id: block.id,
4149
- height: (0, import_math15.bn)(block.header.height),
4357
+ height: (0, import_math16.bn)(block.height),
4150
4358
  time: block.header.time,
4151
4359
  transactionIds: block.transactions.map((tx) => tx.id)
4152
4360
  }));
@@ -4161,7 +4369,7 @@ var _Provider = class {
4161
4369
  async getBlockWithTransactions(idOrHeight) {
4162
4370
  let variables;
4163
4371
  if (typeof idOrHeight === "number") {
4164
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4372
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4165
4373
  } else if (idOrHeight === "latest") {
4166
4374
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4167
4375
  } else {
@@ -4173,11 +4381,11 @@ var _Provider = class {
4173
4381
  }
4174
4382
  return {
4175
4383
  id: block.id,
4176
- height: (0, import_math15.bn)(block.header.height, 10),
4384
+ height: (0, import_math16.bn)(block.height, 10),
4177
4385
  time: block.header.time,
4178
4386
  transactionIds: block.transactions.map((tx) => tx.id),
4179
4387
  transactions: block.transactions.map(
4180
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4388
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4181
4389
  )
4182
4390
  };
4183
4391
  }
@@ -4192,8 +4400,8 @@ var _Provider = class {
4192
4400
  if (!transaction) {
4193
4401
  return null;
4194
4402
  }
4195
- return new import_transactions18.TransactionCoder().decode(
4196
- (0, import_utils23.arrayify)(transaction.rawPayload),
4403
+ return new import_transactions19.TransactionCoder().decode(
4404
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4197
4405
  0
4198
4406
  )?.[0];
4199
4407
  }
@@ -4220,9 +4428,9 @@ var _Provider = class {
4220
4428
  async getContractBalance(contractId, assetId) {
4221
4429
  const { contractBalance } = await this.operations.getContractBalance({
4222
4430
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4223
- asset: (0, import_utils23.hexlify)(assetId)
4431
+ asset: (0, import_utils22.hexlify)(assetId)
4224
4432
  });
4225
- return (0, import_math15.bn)(contractBalance.amount, 10);
4433
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4226
4434
  }
4227
4435
  /**
4228
4436
  * Returns the balance for the given owner for the given asset ID.
@@ -4234,9 +4442,9 @@ var _Provider = class {
4234
4442
  async getBalance(owner, assetId) {
4235
4443
  const { balance } = await this.operations.getBalance({
4236
4444
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4237
- assetId: (0, import_utils23.hexlify)(assetId)
4445
+ assetId: (0, import_utils22.hexlify)(assetId)
4238
4446
  });
4239
- return (0, import_math15.bn)(balance.amount, 10);
4447
+ return (0, import_math16.bn)(balance.amount, 10);
4240
4448
  }
4241
4449
  /**
4242
4450
  * Returns balances for the given owner.
@@ -4254,7 +4462,7 @@ var _Provider = class {
4254
4462
  const balances = result.balances.edges.map((edge) => edge.node);
4255
4463
  return balances.map((balance) => ({
4256
4464
  assetId: balance.assetId,
4257
- amount: (0, import_math15.bn)(balance.amount)
4465
+ amount: (0, import_math16.bn)(balance.amount)
4258
4466
  }));
4259
4467
  }
4260
4468
  /**
@@ -4272,19 +4480,19 @@ var _Provider = class {
4272
4480
  });
4273
4481
  const messages = result.messages.edges.map((edge) => edge.node);
4274
4482
  return messages.map((message) => ({
4275
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4483
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4276
4484
  sender: message.sender,
4277
4485
  recipient: message.recipient,
4278
4486
  nonce: message.nonce,
4279
- amount: (0, import_math15.bn)(message.amount),
4487
+ amount: (0, import_math16.bn)(message.amount),
4280
4488
  data: message.data
4281
4489
  }),
4282
4490
  sender: import_address3.Address.fromAddressOrString(message.sender),
4283
4491
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4284
4492
  nonce: message.nonce,
4285
- amount: (0, import_math15.bn)(message.amount),
4286
- data: import_transactions18.InputMessageCoder.decodeData(message.data),
4287
- daHeight: (0, import_math15.bn)(message.daHeight)
4493
+ amount: (0, import_math16.bn)(message.amount),
4494
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4495
+ daHeight: (0, import_math16.bn)(message.daHeight)
4288
4496
  }));
4289
4497
  }
4290
4498
  /**
@@ -4337,44 +4545,52 @@ var _Provider = class {
4337
4545
  } = result.messageProof;
4338
4546
  return {
4339
4547
  messageProof: {
4340
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4548
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4341
4549
  proofSet: messageProof.proofSet
4342
4550
  },
4343
4551
  blockProof: {
4344
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4552
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4345
4553
  proofSet: blockProof.proofSet
4346
4554
  },
4347
4555
  messageBlockHeader: {
4348
4556
  id: messageBlockHeader.id,
4349
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4350
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4557
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4558
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4351
4559
  transactionsRoot: messageBlockHeader.transactionsRoot,
4352
- height: (0, import_math15.bn)(messageBlockHeader.height),
4560
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4353
4561
  prevRoot: messageBlockHeader.prevRoot,
4354
4562
  time: messageBlockHeader.time,
4355
4563
  applicationHash: messageBlockHeader.applicationHash,
4356
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4357
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4564
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount)
4358
4565
  },
4359
4566
  commitBlockHeader: {
4360
4567
  id: commitBlockHeader.id,
4361
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4362
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4568
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4569
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4363
4570
  transactionsRoot: commitBlockHeader.transactionsRoot,
4364
- height: (0, import_math15.bn)(commitBlockHeader.height),
4571
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4365
4572
  prevRoot: commitBlockHeader.prevRoot,
4366
4573
  time: commitBlockHeader.time,
4367
4574
  applicationHash: commitBlockHeader.applicationHash,
4368
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4369
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4575
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount)
4370
4576
  },
4371
4577
  sender: import_address3.Address.fromAddressOrString(sender),
4372
4578
  recipient: import_address3.Address.fromAddressOrString(recipient),
4373
4579
  nonce,
4374
- amount: (0, import_math15.bn)(amount),
4580
+ amount: (0, import_math16.bn)(amount),
4375
4581
  data
4376
4582
  };
4377
4583
  }
4584
+ async getLatestGasPrice() {
4585
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4586
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4587
+ }
4588
+ async estimateGasPrice(blockHorizon) {
4589
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4590
+ blockHorizon: String(blockHorizon)
4591
+ });
4592
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4593
+ }
4378
4594
  /**
4379
4595
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4380
4596
  *
@@ -4394,10 +4610,10 @@ var _Provider = class {
4394
4610
  */
4395
4611
  async produceBlocks(amount, startTime) {
4396
4612
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4397
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4398
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4613
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4614
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4399
4615
  });
4400
- return (0, import_math15.bn)(latestBlockHeight);
4616
+ return (0, import_math16.bn)(latestBlockHeight);
4401
4617
  }
4402
4618
  // eslint-disable-next-line @typescript-eslint/require-await
4403
4619
  async getTransactionResponse(transactionId) {
@@ -4411,7 +4627,7 @@ cacheInputs_fn = function(inputs) {
4411
4627
  return;
4412
4628
  }
4413
4629
  inputs.forEach((input) => {
4414
- if (input.type === import_transactions18.InputType.Coin) {
4630
+ if (input.type === import_transactions19.InputType.Coin) {
4415
4631
  this.cache?.set(input.id);
4416
4632
  }
4417
4633
  });
@@ -4421,9 +4637,9 @@ __publicField(Provider, "nodeInfoCache", {});
4421
4637
 
4422
4638
  // src/providers/transaction-summary/get-transaction-summary.ts
4423
4639
  var import_errors15 = require("@fuel-ts/errors");
4424
- var import_math16 = require("@fuel-ts/math");
4425
- var import_transactions19 = require("@fuel-ts/transactions");
4426
- var import_utils26 = require("@fuel-ts/utils");
4640
+ var import_math17 = require("@fuel-ts/math");
4641
+ var import_transactions20 = require("@fuel-ts/transactions");
4642
+ var import_utils25 = require("@fuel-ts/utils");
4427
4643
 
4428
4644
  // src/providers/chains.ts
4429
4645
  var CHAIN_IDS = {
@@ -4472,17 +4688,17 @@ var assets = [
4472
4688
 
4473
4689
  // src/utils/formatTransferToContractScriptData.ts
4474
4690
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
4475
- var import_math17 = require("@fuel-ts/math");
4476
- var import_utils27 = require("@fuel-ts/utils");
4691
+ var import_math18 = require("@fuel-ts/math");
4692
+ var import_utils26 = require("@fuel-ts/utils");
4477
4693
  var asm = __toESM(require("@fuels/vm-asm"));
4478
4694
  var formatTransferToContractScriptData = (params) => {
4479
4695
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4480
4696
  const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4481
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4697
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4482
4698
  const scriptData = Uint8Array.from([
4483
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
4699
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4484
4700
  ...encoded,
4485
- ...(0, import_utils27.arrayify)(assetId)
4701
+ ...(0, import_utils26.arrayify)(assetId)
4486
4702
  ]);
4487
4703
  return scriptData;
4488
4704
  };
@@ -4629,9 +4845,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4629
4845
  * @param assetId - The asset ID to check the balance for.
4630
4846
  * @returns A promise that resolves to the balance amount.
4631
4847
  */
4632
- async getBalance(assetId) {
4633
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4634
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4848
+ async getBalance(assetId = import_configs12.BaseAssetId) {
4849
+ const amount = await this.provider.getBalance(this.address, assetId);
4635
4850
  return amount;
4636
4851
  }
4637
4852
  /**
@@ -4668,37 +4883,33 @@ var Account = class extends import_interfaces.AbstractAccount {
4668
4883
  * @param fee - The estimated transaction fee.
4669
4884
  * @returns A promise that resolves when the resources are added to the transaction.
4670
4885
  */
4671
- async fund(request, coinQuantities, fee) {
4672
- const baseAssetId = this.provider.getBaseAssetId();
4673
- const updatedQuantities = addAmountToAsset({
4674
- amount: (0, import_math18.bn)(fee),
4675
- assetId: baseAssetId,
4676
- coinQuantities
4886
+ async fund(request, params) {
4887
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4888
+ const txRequest = request;
4889
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4890
+ amount: (0, import_math19.bn)(fee),
4891
+ assetId: import_configs12.BaseAssetId,
4892
+ coinQuantities: requiredQuantities
4677
4893
  });
4678
4894
  const quantitiesDict = {};
4679
- updatedQuantities.forEach(({ amount, assetId }) => {
4895
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4680
4896
  quantitiesDict[assetId] = {
4681
4897
  required: amount,
4682
- owned: (0, import_math18.bn)(0)
4898
+ owned: (0, import_math19.bn)(0)
4683
4899
  };
4684
4900
  });
4685
- const cachedUtxos = [];
4686
- const cachedMessages = [];
4687
- const owner = this.address.toB256();
4688
- request.inputs.forEach((input) => {
4901
+ txRequest.inputs.forEach((input) => {
4689
4902
  const isResource = "amount" in input;
4690
4903
  if (isResource) {
4691
4904
  const isCoin2 = "owner" in input;
4692
4905
  if (isCoin2) {
4693
4906
  const assetId = String(input.assetId);
4694
- if (input.owner === owner && quantitiesDict[assetId]) {
4695
- const amount = (0, import_math18.bn)(input.amount);
4907
+ if (quantitiesDict[assetId]) {
4908
+ const amount = (0, import_math19.bn)(input.amount);
4696
4909
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4697
- cachedUtxos.push(input.id);
4698
4910
  }
4699
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4700
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4701
- cachedMessages.push(input.nonce);
4911
+ } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
4912
+ quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
4702
4913
  }
4703
4914
  }
4704
4915
  });
@@ -4713,12 +4924,23 @@ var Account = class extends import_interfaces.AbstractAccount {
4713
4924
  });
4714
4925
  const needsToBeFunded = missingQuantities.length;
4715
4926
  if (needsToBeFunded) {
4716
- const resources = await this.getResourcesToSpend(missingQuantities, {
4717
- messages: cachedMessages,
4718
- utxos: cachedUtxos
4719
- });
4720
- request.addResources(resources);
4927
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
4928
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4929
+ txRequest.addResources(resources);
4930
+ }
4931
+ txRequest.shiftPredicateData();
4932
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
4933
+ const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
4934
+ if (addedSignatures) {
4935
+ Array.from({ length: addedSignatures }).forEach(
4936
+ () => requestToBeReEstimate.addEmptyWitness()
4937
+ );
4721
4938
  }
4939
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
4940
+ transactionRequest: requestToBeReEstimate
4941
+ });
4942
+ txRequest.maxFee = maxFee;
4943
+ return txRequest;
4722
4944
  }
4723
4945
  /**
4724
4946
  * A helper that creates a transfer transaction request and returns it.
@@ -4726,29 +4948,25 @@ var Account = class extends import_interfaces.AbstractAccount {
4726
4948
  * @param destination - The address of the destination.
4727
4949
  * @param amount - The amount of coins to transfer.
4728
4950
  * @param assetId - The asset ID of the coins to transfer.
4729
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4951
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4730
4952
  * @returns A promise that resolves to the prepared transaction request.
4731
4953
  */
4732
- async createTransfer(destination, amount, assetId, txParams = {}) {
4733
- const { minGasPrice } = this.provider.getGasConfig();
4734
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4735
- const params = { gasPrice: minGasPrice, ...txParams };
4736
- const request = new ScriptTransactionRequest(params);
4737
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
4738
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4954
+ async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4955
+ const request = new ScriptTransactionRequest(txParams);
4956
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
4957
+ const txCost = await this.provider.getTransactionCost(request, {
4739
4958
  estimateTxDependencies: true,
4740
4959
  resourcesOwner: this
4741
4960
  });
4742
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
4743
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
4744
- this.validateGas({
4745
- gasUsed,
4746
- gasPrice: request.gasPrice,
4747
- gasLimit: request.gasLimit,
4748
- minGasPrice
4749
- });
4750
- await this.fund(request, requiredQuantities, maxFee);
4751
- request.updatePredicateInputs(estimatedInputs);
4961
+ if ("gasLimit" in txParams) {
4962
+ this.validateGas({
4963
+ gasUsed: txCost.gasUsed,
4964
+ gasLimit: request.gasLimit
4965
+ });
4966
+ }
4967
+ request.gasLimit = txCost.gasUsed;
4968
+ request.maxFee = txCost.maxFee;
4969
+ await this.fund(request, txCost);
4752
4970
  return request;
4753
4971
  }
4754
4972
  /**
@@ -4760,15 +4978,14 @@ var Account = class extends import_interfaces.AbstractAccount {
4760
4978
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4761
4979
  * @returns A promise that resolves to the transaction response.
4762
4980
  */
4763
- async transfer(destination, amount, assetId, txParams = {}) {
4764
- if ((0, import_math18.bn)(amount).lte(0)) {
4981
+ async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4982
+ if ((0, import_math19.bn)(amount).lte(0)) {
4765
4983
  throw new import_errors16.FuelError(
4766
4984
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4767
4985
  "Transfer amount must be a positive number."
4768
4986
  );
4769
4987
  }
4770
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4771
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4988
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4772
4989
  return this.sendTransaction(request, { estimateTxDependencies: false });
4773
4990
  }
4774
4991
  /**
@@ -4780,40 +4997,38 @@ var Account = class extends import_interfaces.AbstractAccount {
4780
4997
  * @param txParams - The optional transaction parameters.
4781
4998
  * @returns A promise that resolves to the transaction response.
4782
4999
  */
4783
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4784
- if ((0, import_math18.bn)(amount).lte(0)) {
5000
+ async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5001
+ if ((0, import_math19.bn)(amount).lte(0)) {
4785
5002
  throw new import_errors16.FuelError(
4786
5003
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4787
5004
  "Transfer amount must be a positive number."
4788
5005
  );
4789
5006
  }
4790
5007
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4791
- const { minGasPrice } = this.provider.getGasConfig();
4792
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4793
- const params = { gasPrice: minGasPrice, ...txParams };
4794
5008
  const { script, scriptData } = await assembleTransferToContractScript({
4795
5009
  hexlifiedContractId: contractAddress.toB256(),
4796
- amountToTransfer: (0, import_math18.bn)(amount),
4797
- assetId: assetIdToTransfer
5010
+ amountToTransfer: (0, import_math19.bn)(amount),
5011
+ assetId
4798
5012
  });
4799
5013
  const request = new ScriptTransactionRequest({
4800
- ...params,
5014
+ ...txParams,
4801
5015
  script,
4802
5016
  scriptData
4803
5017
  });
4804
5018
  request.addContractInputAndOutput(contractAddress);
4805
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4806
- request,
4807
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
4808
- );
4809
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4810
- this.validateGas({
4811
- gasUsed,
4812
- gasPrice: request.gasPrice,
4813
- gasLimit: request.gasLimit,
4814
- minGasPrice
5019
+ const txCost = await this.provider.getTransactionCost(request, {
5020
+ resourcesOwner: this,
5021
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
4815
5022
  });
4816
- await this.fund(request, requiredQuantities, maxFee);
5023
+ if (txParams.gasLimit) {
5024
+ this.validateGas({
5025
+ gasUsed: txCost.gasUsed,
5026
+ gasLimit: request.gasLimit
5027
+ });
5028
+ }
5029
+ request.gasLimit = txCost.gasUsed;
5030
+ request.maxFee = txCost.maxFee;
5031
+ await this.fund(request, txCost);
4817
5032
  return this.sendTransaction(request);
4818
5033
  }
4819
5034
  /**
@@ -4825,35 +5040,31 @@ var Account = class extends import_interfaces.AbstractAccount {
4825
5040
  * @returns A promise that resolves to the transaction response.
4826
5041
  */
4827
5042
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4828
- const { minGasPrice } = this.provider.getGasConfig();
4829
- const baseAssetId = this.provider.getBaseAssetId();
4830
5043
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
4831
- const recipientDataArray = (0, import_utils28.arrayify)(
5044
+ const recipientDataArray = (0, import_utils27.arrayify)(
4832
5045
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4833
5046
  );
4834
- const amountDataArray = (0, import_utils28.arrayify)(
4835
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5047
+ const amountDataArray = (0, import_utils27.arrayify)(
5048
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
4836
5049
  );
4837
5050
  const script = new Uint8Array([
4838
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5051
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
4839
5052
  ...recipientDataArray,
4840
5053
  ...amountDataArray
4841
5054
  ]);
4842
- const params = { script, gasPrice: minGasPrice, ...txParams };
5055
+ const params = { script, ...txParams };
4843
5056
  const request = new ScriptTransactionRequest(params);
4844
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
4845
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4846
- request,
4847
- forwardingQuantities
4848
- );
4849
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4850
- this.validateGas({
4851
- gasUsed,
4852
- gasPrice: request.gasPrice,
4853
- gasLimit: request.gasLimit,
4854
- minGasPrice
4855
- });
4856
- await this.fund(request, requiredQuantities, maxFee);
5057
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5058
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5059
+ if (txParams.gasLimit) {
5060
+ this.validateGas({
5061
+ gasUsed: txCost.gasUsed,
5062
+ gasLimit: request.gasLimit
5063
+ });
5064
+ }
5065
+ request.maxFee = txCost.maxFee;
5066
+ request.gasLimit = txCost.gasUsed;
5067
+ await this.fund(request, txCost);
4857
5068
  return this.sendTransaction(request);
4858
5069
  }
4859
5070
  async signMessage(message) {
@@ -4911,18 +5122,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4911
5122
  }
4912
5123
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
4913
5124
  }
4914
- validateGas({
4915
- gasUsed,
4916
- gasPrice,
4917
- gasLimit,
4918
- minGasPrice
4919
- }) {
4920
- if (minGasPrice.gt(gasPrice)) {
4921
- throw new import_errors16.FuelError(
4922
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
4923
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
4924
- );
4925
- }
5125
+ validateGas({ gasUsed, gasLimit }) {
4926
5126
  if (gasUsed.gt(gasLimit)) {
4927
5127
  throw new import_errors16.FuelError(
4928
5128
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -4936,8 +5136,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4936
5136
  var import_address5 = require("@fuel-ts/address");
4937
5137
  var import_crypto = require("@fuel-ts/crypto");
4938
5138
  var import_hasher2 = require("@fuel-ts/hasher");
4939
- var import_math19 = require("@fuel-ts/math");
4940
- var import_utils29 = require("@fuel-ts/utils");
5139
+ var import_math20 = require("@fuel-ts/math");
5140
+ var import_utils28 = require("@fuel-ts/utils");
4941
5141
  var import_secp256k1 = require("@noble/curves/secp256k1");
4942
5142
  var Signer = class {
4943
5143
  address;
@@ -4956,10 +5156,10 @@ var Signer = class {
4956
5156
  privateKey = `0x${privateKey}`;
4957
5157
  }
4958
5158
  }
4959
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
4960
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
4961
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
4962
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5159
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5160
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5161
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5162
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
4963
5163
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
4964
5164
  }
4965
5165
  /**
@@ -4973,11 +5173,11 @@ var Signer = class {
4973
5173
  * @returns hashed signature
4974
5174
  */
4975
5175
  sign(data) {
4976
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
4977
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
4978
- const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5176
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5177
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5178
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
4979
5179
  s[0] |= (signature.recovery || 0) << 7;
4980
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5180
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
4981
5181
  }
4982
5182
  /**
4983
5183
  * Add point on the current elliptic curve
@@ -4986,8 +5186,8 @@ var Signer = class {
4986
5186
  * @returns compressed point on the curve
4987
5187
  */
4988
5188
  addPoint(point) {
4989
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
4990
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5189
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5190
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
4991
5191
  const result = p0.add(p1);
4992
5192
  return `0x${result.toHex(true)}`;
4993
5193
  }
@@ -4999,16 +5199,16 @@ var Signer = class {
4999
5199
  * @returns public key from signature from the
5000
5200
  */
5001
5201
  static recoverPublicKey(data, signature) {
5002
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5202
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5003
5203
  const r = signedMessageBytes.slice(0, 32);
5004
5204
  const s = signedMessageBytes.slice(32, 64);
5005
5205
  const recoveryParam = (s[0] & 128) >> 7;
5006
5206
  s[0] &= 127;
5007
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5207
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5008
5208
  recoveryParam
5009
5209
  );
5010
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5011
- return (0, import_utils29.hexlify)(publicKey);
5210
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5211
+ return (0, import_utils28.hexlify)(publicKey);
5012
5212
  }
5013
5213
  /**
5014
5214
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5027,7 +5227,7 @@ var Signer = class {
5027
5227
  * @returns random 32-byte hashed
5028
5228
  */
5029
5229
  static generatePrivateKey(entropy) {
5030
- return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
5230
+ return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
5031
5231
  }
5032
5232
  /**
5033
5233
  * Extended publicKey from a compact publicKey
@@ -5036,8 +5236,8 @@ var Signer = class {
5036
5236
  * @returns extended publicKey
5037
5237
  */
5038
5238
  static extendPublicKey(publicKey) {
5039
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5040
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5239
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5240
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5041
5241
  }
5042
5242
  };
5043
5243
 
@@ -5045,7 +5245,7 @@ var Signer = class {
5045
5245
  var import_address6 = require("@fuel-ts/address");
5046
5246
  var import_crypto2 = require("@fuel-ts/crypto");
5047
5247
  var import_errors17 = require("@fuel-ts/errors");
5048
- var import_utils30 = require("@fuel-ts/utils");
5248
+ var import_utils29 = require("@fuel-ts/utils");
5049
5249
  var import_uuid = require("uuid");
5050
5250
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5051
5251
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5128,7 +5328,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5128
5328
  );
5129
5329
  }
5130
5330
  const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5131
- const privateKey = (0, import_utils30.hexlify)(buffer);
5331
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5132
5332
  return privateKey;
5133
5333
  }
5134
5334
 
@@ -5173,7 +5373,7 @@ var BaseWalletUnlocked = class extends Account {
5173
5373
  */
5174
5374
  async signMessage(message) {
5175
5375
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5176
- return (0, import_utils31.hexlify)(signedMessage);
5376
+ return (0, import_utils30.hexlify)(signedMessage);
5177
5377
  }
5178
5378
  /**
5179
5379
  * Signs a transaction with the wallet's private key.
@@ -5186,7 +5386,7 @@ var BaseWalletUnlocked = class extends Account {
5186
5386
  const chainId = this.provider.getChainId();
5187
5387
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5188
5388
  const signature = await this.signer().sign(hashedTransaction);
5189
- return (0, import_utils31.hexlify)(signature);
5389
+ return (0, import_utils30.hexlify)(signature);
5190
5390
  }
5191
5391
  /**
5192
5392
  * Populates a transaction with the witnesses signature.
@@ -5206,7 +5406,7 @@ var BaseWalletUnlocked = class extends Account {
5206
5406
  * @param transactionRequestLike - The transaction request to send.
5207
5407
  * @returns A promise that resolves to the TransactionResponse object.
5208
5408
  */
5209
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5409
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5210
5410
  const transactionRequest = transactionRequestify(transactionRequestLike);
5211
5411
  if (estimateTxDependencies) {
5212
5412
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5247,16 +5447,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5247
5447
  // src/hdwallet/hdwallet.ts
5248
5448
  var import_errors20 = require("@fuel-ts/errors");
5249
5449
  var import_hasher6 = require("@fuel-ts/hasher");
5250
- var import_math20 = require("@fuel-ts/math");
5251
- var import_utils35 = require("@fuel-ts/utils");
5252
- var import_ethers3 = require("ethers");
5450
+ var import_math21 = require("@fuel-ts/math");
5451
+ var import_utils34 = require("@fuel-ts/utils");
5452
+ var import_ethers4 = require("ethers");
5253
5453
 
5254
5454
  // src/mnemonic/mnemonic.ts
5255
5455
  var import_crypto3 = require("@fuel-ts/crypto");
5256
5456
  var import_errors19 = require("@fuel-ts/errors");
5257
5457
  var import_hasher5 = require("@fuel-ts/hasher");
5258
- var import_utils33 = require("@fuel-ts/utils");
5259
- var import_ethers2 = require("ethers");
5458
+ var import_utils32 = require("@fuel-ts/utils");
5459
+ var import_ethers3 = require("ethers");
5260
5460
 
5261
5461
  // src/wordlists/words/english.ts
5262
5462
  var english = [
@@ -7313,7 +7513,7 @@ var english = [
7313
7513
  // src/mnemonic/utils.ts
7314
7514
  var import_errors18 = require("@fuel-ts/errors");
7315
7515
  var import_hasher4 = require("@fuel-ts/hasher");
7316
- var import_utils32 = require("@fuel-ts/utils");
7516
+ var import_utils31 = require("@fuel-ts/utils");
7317
7517
  function toUtf8Bytes(stri) {
7318
7518
  const str = stri.normalize("NFKD");
7319
7519
  const result = [];
@@ -7380,14 +7580,14 @@ function entropyToMnemonicIndices(entropy) {
7380
7580
  }
7381
7581
  }
7382
7582
  const checksumBits = entropy.length / 4;
7383
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7583
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7384
7584
  indices[indices.length - 1] <<= checksumBits;
7385
7585
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7386
7586
  return indices;
7387
7587
  }
7388
7588
  function mnemonicWordsToEntropy(words, wordlist) {
7389
7589
  const size = Math.ceil(11 * words.length / 8);
7390
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7590
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7391
7591
  let offset = 0;
7392
7592
  for (let i = 0; i < words.length; i += 1) {
7393
7593
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7407,7 +7607,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7407
7607
  const entropyBits = 32 * words.length / 3;
7408
7608
  const checksumBits = words.length / 3;
7409
7609
  const checksumMask = getUpperMask(checksumBits);
7410
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7610
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7411
7611
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7412
7612
  throw new import_errors18.FuelError(
7413
7613
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7482,7 +7682,7 @@ var Mnemonic = class {
7482
7682
  static mnemonicToEntropy(phrase, wordlist = english) {
7483
7683
  const words = getWords(phrase);
7484
7684
  assertMnemonic(words);
7485
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7685
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7486
7686
  }
7487
7687
  /**
7488
7688
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7490,7 +7690,7 @@ var Mnemonic = class {
7490
7690
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7491
7691
  */
7492
7692
  static entropyToMnemonic(entropy, wordlist = english) {
7493
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
7693
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7494
7694
  assertWordList(wordlist);
7495
7695
  assertEntropy(entropyBytes);
7496
7696
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7504,7 +7704,7 @@ var Mnemonic = class {
7504
7704
  assertMnemonic(getWords(phrase));
7505
7705
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7506
7706
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7507
- return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7707
+ return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7508
7708
  }
7509
7709
  /**
7510
7710
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7559,14 +7759,14 @@ var Mnemonic = class {
7559
7759
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7560
7760
  */
7561
7761
  static masterKeysFromSeed(seed) {
7562
- const seedArray = (0, import_utils33.arrayify)(seed);
7762
+ const seedArray = (0, import_utils32.arrayify)(seed);
7563
7763
  if (seedArray.length < 16 || seedArray.length > 64) {
7564
7764
  throw new import_errors19.FuelError(
7565
7765
  import_errors19.ErrorCode.INVALID_SEED,
7566
7766
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7567
7767
  );
7568
7768
  }
7569
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7769
+ return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
7570
7770
  }
7571
7771
  /**
7572
7772
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7577,22 +7777,22 @@ var Mnemonic = class {
7577
7777
  */
7578
7778
  static seedToExtendedKey(seed, testnet = false) {
7579
7779
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7580
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7780
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7581
7781
  const depth = "0x00";
7582
7782
  const fingerprint = "0x00000000";
7583
7783
  const index = "0x00000000";
7584
7784
  const chainCode = masterKey.slice(32);
7585
7785
  const privateKey = masterKey.slice(0, 32);
7586
- const extendedKey = (0, import_utils33.concat)([
7786
+ const extendedKey = (0, import_utils32.concat)([
7587
7787
  prefix,
7588
7788
  depth,
7589
7789
  fingerprint,
7590
7790
  index,
7591
7791
  chainCode,
7592
- (0, import_utils33.concat)(["0x00", privateKey])
7792
+ (0, import_utils32.concat)(["0x00", privateKey])
7593
7793
  ]);
7594
- const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7595
- return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
7794
+ const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7795
+ return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7596
7796
  }
7597
7797
  /**
7598
7798
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7607,7 +7807,7 @@ var Mnemonic = class {
7607
7807
  * @returns A randomly generated mnemonic
7608
7808
  */
7609
7809
  static generate(size = 32, extraEntropy = "") {
7610
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7810
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7611
7811
  return Mnemonic.entropyToMnemonic(entropy);
7612
7812
  }
7613
7813
  };
@@ -7615,12 +7815,12 @@ var mnemonic_default = Mnemonic;
7615
7815
 
7616
7816
  // src/hdwallet/hdwallet.ts
7617
7817
  var HARDENED_INDEX = 2147483648;
7618
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
7619
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
7620
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
7621
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
7818
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
7819
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7820
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7821
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7622
7822
  function base58check(data) {
7623
- 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)]));
7823
+ return (0, import_ethers4.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7624
7824
  }
7625
7825
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7626
7826
  if (isPublic) {
@@ -7629,11 +7829,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7629
7829
  return testnet ? TestnetPRV2 : MainnetPRV2;
7630
7830
  }
7631
7831
  function isPublicExtendedKey(extendedKey) {
7632
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
7832
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
7633
7833
  }
7634
7834
  function isValidExtendedKey(extendedKey) {
7635
7835
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
7636
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
7836
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
7637
7837
  );
7638
7838
  }
7639
7839
  function parsePath(path2, depth = 0) {
@@ -7651,8 +7851,8 @@ function parsePath(path2, depth = 0) {
7651
7851
  var HDWallet = class {
7652
7852
  depth = 0;
7653
7853
  index = 0;
7654
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
7655
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
7854
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
7855
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
7656
7856
  privateKey;
7657
7857
  publicKey;
7658
7858
  chainCode;
@@ -7664,8 +7864,8 @@ var HDWallet = class {
7664
7864
  constructor(config) {
7665
7865
  if (config.privateKey) {
7666
7866
  const signer = new Signer(config.privateKey);
7667
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
7668
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
7867
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
7868
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
7669
7869
  } else {
7670
7870
  if (!config.publicKey) {
7671
7871
  throw new import_errors20.FuelError(
@@ -7673,10 +7873,10 @@ var HDWallet = class {
7673
7873
  "Both public and private Key cannot be missing. At least one should be provided."
7674
7874
  );
7675
7875
  }
7676
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
7876
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7677
7877
  }
7678
7878
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7679
- this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7879
+ this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7680
7880
  this.depth = config.depth || this.depth;
7681
7881
  this.index = config.index || this.index;
7682
7882
  this.chainCode = config.chainCode;
@@ -7692,9 +7892,9 @@ var HDWallet = class {
7692
7892
  * @returns A new instance of HDWallet on the derived index
7693
7893
  */
7694
7894
  deriveIndex(index) {
7695
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
7696
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
7697
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
7895
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
7896
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
7897
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
7698
7898
  const data = new Uint8Array(37);
7699
7899
  if (index & HARDENED_INDEX) {
7700
7900
  if (!privateKey) {
@@ -7705,15 +7905,15 @@ var HDWallet = class {
7705
7905
  }
7706
7906
  data.set(privateKey, 1);
7707
7907
  } else {
7708
- data.set((0, import_utils35.arrayify)(this.publicKey));
7908
+ data.set((0, import_utils34.arrayify)(this.publicKey));
7709
7909
  }
7710
- data.set((0, import_math20.toBytes)(index, 4), 33);
7711
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7910
+ data.set((0, import_math21.toBytes)(index, 4), 33);
7911
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
7712
7912
  const IL = bytes.slice(0, 32);
7713
7913
  const IR = bytes.slice(32);
7714
7914
  if (privateKey) {
7715
7915
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7716
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
7916
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
7717
7917
  return new HDWallet({
7718
7918
  privateKey: ki,
7719
7919
  chainCode: IR,
@@ -7722,7 +7922,7 @@ var HDWallet = class {
7722
7922
  parentFingerprint: this.fingerprint
7723
7923
  });
7724
7924
  }
7725
- const signer = new Signer((0, import_utils35.hexlify)(IL));
7925
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
7726
7926
  const Ki = signer.addPoint(publicKey);
7727
7927
  return new HDWallet({
7728
7928
  publicKey: Ki,
@@ -7757,12 +7957,12 @@ var HDWallet = class {
7757
7957
  );
7758
7958
  }
7759
7959
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
7760
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
7960
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
7761
7961
  const parentFingerprint = this.parentFingerprint;
7762
- const index = (0, import_math20.toHex)(this.index, 4);
7962
+ const index = (0, import_math21.toHex)(this.index, 4);
7763
7963
  const chainCode = this.chainCode;
7764
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
7765
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7964
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
7965
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7766
7966
  return base58check(extendedKey);
7767
7967
  }
7768
7968
  /**
@@ -7774,13 +7974,13 @@ var HDWallet = class {
7774
7974
  static fromSeed(seed) {
7775
7975
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
7776
7976
  return new HDWallet({
7777
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
7778
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
7977
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
7978
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
7779
7979
  });
7780
7980
  }
7781
7981
  static fromExtendedKey(extendedKey) {
7782
- const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7783
- const bytes = (0, import_utils35.arrayify)(decoded);
7982
+ const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
7983
+ const bytes = (0, import_utils34.arrayify)(decoded);
7784
7984
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7785
7985
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7786
7986
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -7789,9 +7989,9 @@ var HDWallet = class {
7789
7989
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7790
7990
  }
7791
7991
  const depth = bytes[4];
7792
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
7793
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7794
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
7992
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
7993
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7994
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
7795
7995
  const key = bytes.slice(45, 78);
7796
7996
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7797
7997
  throw new import_errors20.FuelError(
@@ -7984,14 +8184,15 @@ var seedTestWallet = async (wallet, quantities) => {
7984
8184
  process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
7985
8185
  wallet.provider
7986
8186
  );
7987
- const resources = await genesisWallet.getResourcesToSpend(quantities);
7988
- const { minGasPrice } = genesisWallet.provider.getGasConfig();
7989
- const request = new ScriptTransactionRequest({
7990
- gasLimit: 1e4,
7991
- gasPrice: minGasPrice
8187
+ const request = new ScriptTransactionRequest();
8188
+ quantities.forEach((quantity) => {
8189
+ const { amount, assetId } = coinQuantityfy(quantity);
8190
+ request.addCoinOutput(wallet.address, amount, assetId);
7992
8191
  });
7993
- request.addResources(resources);
7994
- quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
8192
+ const txCost = await genesisWallet.provider.getTransactionCost(request);
8193
+ request.gasLimit = txCost.gasUsed;
8194
+ request.maxFee = txCost.maxFee;
8195
+ await genesisWallet.fund(request, txCost);
7995
8196
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
7996
8197
  };
7997
8198
 
@@ -8005,12 +8206,12 @@ var generateTestWallet = async (provider, quantities) => {
8005
8206
  };
8006
8207
 
8007
8208
  // src/test-utils/launchNode.ts
8008
- var import_configs11 = require("@fuel-ts/address/configs");
8009
- var import_math21 = require("@fuel-ts/math");
8010
- var import_utils36 = require("@fuel-ts/utils");
8209
+ var import_configs13 = require("@fuel-ts/address/configs");
8210
+ var import_utils35 = require("@fuel-ts/utils");
8011
8211
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8012
8212
  var import_child_process = require("child_process");
8013
8213
  var import_crypto5 = require("crypto");
8214
+ var import_ethers5 = require("ethers");
8014
8215
  var import_fs = require("fs");
8015
8216
  var import_os = __toESM(require("os"));
8016
8217
  var import_path = __toESM(require("path"));
@@ -8059,13 +8260,13 @@ var launchNode = async ({
8059
8260
  // eslint-disable-next-line no-async-promise-executor
8060
8261
  new Promise(async (resolve, reject) => {
8061
8262
  const remainingArgs = extractRemainingArgs(args, [
8062
- "--chain",
8263
+ "--snapshot",
8063
8264
  "--consensus-key",
8064
8265
  "--db-type",
8065
8266
  "--poa-instant"
8066
8267
  ]);
8067
- const chainConfigPath = getFlagValueFromArgs(args, "--chain");
8068
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8268
+ const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
8269
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
8069
8270
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8070
8271
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8071
8272
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
@@ -8083,36 +8284,54 @@ var launchNode = async ({
8083
8284
  let chainConfigPathToUse;
8084
8285
  const prefix = basePath || import_os.default.tmpdir();
8085
8286
  const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
8086
- const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
8287
+ const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "chainConfigs");
8087
8288
  if (chainConfigPath) {
8088
8289
  chainConfigPathToUse = chainConfigPath;
8089
8290
  } else {
8090
8291
  if (!(0, import_fs.existsSync)(tempDirPath)) {
8091
8292
  (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8092
8293
  }
8093
- const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
8094
- let chainConfig = import_utils36.defaultChainConfig;
8294
+ let { stateConfigJson } = import_utils35.defaultChainConfigs;
8295
+ const { chainConfigJson, metadataJson } = import_utils35.defaultChainConfigs;
8296
+ stateConfigJson = {
8297
+ ...stateConfigJson,
8298
+ coins: [
8299
+ ...stateConfigJson.coins.map((coin) => ({
8300
+ ...coin,
8301
+ amount: "18446744073709551615"
8302
+ }))
8303
+ ],
8304
+ messages: stateConfigJson.messages.map((message) => ({
8305
+ ...message,
8306
+ amount: "18446744073709551615"
8307
+ }))
8308
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8309
+ };
8095
8310
  if (!process.env.GENESIS_SECRET) {
8096
8311
  const pk = Signer.generatePrivateKey();
8097
8312
  const signer = new Signer(pk);
8098
- process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8099
- chainConfig = {
8100
- ...import_utils36.defaultChainConfig,
8101
- initial_state: {
8102
- ...import_utils36.defaultChainConfig.initial_state,
8103
- coins: [
8104
- ...import_utils36.defaultChainConfig.initial_state.coins,
8105
- {
8106
- owner: signer.address.toHexString(),
8107
- amount: (0, import_math21.toHex)(1e9),
8108
- asset_id: import_utils36.defaultChainConfig?.consensus_parameters?.base_asset_id ?? import_configs11.ZeroBytes32
8109
- }
8110
- ]
8111
- }
8112
- };
8313
+ process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
8314
+ stateConfigJson.coins.push({
8315
+ tx_id: (0, import_utils35.hexlify)((0, import_ethers5.randomBytes)(34)),
8316
+ owner: signer.address.toHexString(),
8317
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8318
+ amount: "18446744073709551615",
8319
+ asset_id: import_configs13.BaseAssetId,
8320
+ output_index: 0,
8321
+ tx_pointer_block_height: 0,
8322
+ tx_pointer_tx_idx: 0
8323
+ });
8113
8324
  }
8114
- (0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
8115
- chainConfigPathToUse = tempChainConfigFilePath;
8325
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8326
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8327
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8328
+ const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8329
+ const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8330
+ const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8331
+ (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8332
+ (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8333
+ (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8334
+ chainConfigPathToUse = tempDirPath;
8116
8335
  }
8117
8336
  const child = (0, import_child_process.spawn)(
8118
8337
  command,
@@ -8121,10 +8340,10 @@ var launchNode = async ({
8121
8340
  ["--ip", ipToUse],
8122
8341
  ["--port", portToUse],
8123
8342
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8124
- ["--min-gas-price", "0"],
8343
+ ["--min-gas-price", "1"],
8125
8344
  poaInstant ? ["--poa-instant", "true"] : [],
8126
8345
  ["--consensus-key", consensusKey],
8127
- ["--chain", chainConfigPathToUse],
8346
+ ["--snapshot", chainConfigPathToUse],
8128
8347
  "--vm-backtrace",
8129
8348
  "--utxo-validation",
8130
8349
  "--debug",
@@ -8171,10 +8390,9 @@ var launchNode = async ({
8171
8390
  })
8172
8391
  );
8173
8392
  var generateWallets = async (count, provider) => {
8174
- const baseAssetId = provider.getBaseAssetId();
8175
8393
  const wallets = [];
8176
8394
  for (let i = 0; i < count; i += 1) {
8177
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8395
+ const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
8178
8396
  wallets.push(wallet);
8179
8397
  }
8180
8398
  return wallets;
@@ -8184,7 +8402,7 @@ var launchNodeAndGetWallets = async ({
8184
8402
  walletCount = 10
8185
8403
  } = {}) => {
8186
8404
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8187
- const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8405
+ const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8188
8406
  const wallets = await generateWallets(walletCount, provider);
8189
8407
  const cleanup = () => {
8190
8408
  closeNode();