@fuel-ts/account 0.0.0-rc-1976-20240408114146 → 0.0.0-rc-2021-20240409111335

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