@fuel-ts/account 0.0.0-rc-2037-20240411135757 → 0.0.0-rc-2021-20240411141803

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 +844 -560
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +786 -518
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +666 -399
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +10 -10
  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 +1 -1
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +2 -1
  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 +2 -1
  27. package/dist/providers/message.d.ts.map +1 -1
  28. package/dist/providers/provider.d.ts +45 -27
  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 +6 -5
  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 +1562 -1046
  48. package/dist/test-utils.global.js.map +1 -1
  49. package/dist/test-utils.js +764 -499
  50. package/dist/test-utils.js.map +1 -1
  51. package/dist/test-utils.mjs +660 -395
  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,15 +58,16 @@ 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
65
  var import_configs12 = require("@fuel-ts/address/configs");
66
66
  var import_errors16 = require("@fuel-ts/errors");
67
67
  var import_interfaces = require("@fuel-ts/interfaces");
68
- var import_math18 = require("@fuel-ts/math");
69
- 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");
70
71
 
71
72
  // src/providers/coin-quantity.ts
72
73
  var import_configs = require("@fuel-ts/address/configs");
@@ -75,24 +76,24 @@ var import_utils = require("@fuel-ts/utils");
75
76
  var coinQuantityfy = (coinQuantityLike) => {
76
77
  let assetId;
77
78
  let amount;
78
- let max2;
79
+ let max;
79
80
  if (Array.isArray(coinQuantityLike)) {
80
81
  amount = coinQuantityLike[0];
81
82
  assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
82
- max2 = coinQuantityLike[2] ?? void 0;
83
+ max = coinQuantityLike[2] ?? void 0;
83
84
  } else {
84
85
  amount = coinQuantityLike.amount;
85
86
  assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
86
- max2 = coinQuantityLike.max ?? void 0;
87
+ max = coinQuantityLike.max ?? void 0;
87
88
  }
88
89
  const bnAmount = (0, import_math.bn)(amount);
89
90
  return {
90
91
  assetId: (0, import_utils.hexlify)(assetId),
91
92
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
92
- max: max2 ? (0, import_math.bn)(max2) : void 0
93
+ max: max ? (0, import_math.bn)(max) : void 0
93
94
  };
94
95
  };
95
- var addAmountToAsset = (params) => {
96
+ var addAmountToCoinQuantities = (params) => {
96
97
  const { amount, assetId } = params;
97
98
  const coinQuantities = [...params.coinQuantities];
98
99
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -107,12 +108,12 @@ var addAmountToAsset = (params) => {
107
108
  // src/providers/provider.ts
108
109
  var import_address3 = require("@fuel-ts/address");
109
110
  var import_errors14 = require("@fuel-ts/errors");
110
- var import_math15 = require("@fuel-ts/math");
111
- var import_transactions18 = require("@fuel-ts/transactions");
112
- var import_utils23 = require("@fuel-ts/utils");
111
+ var import_math16 = require("@fuel-ts/math");
112
+ var import_transactions19 = require("@fuel-ts/transactions");
113
+ var import_utils22 = require("@fuel-ts/utils");
113
114
  var import_versions = require("@fuel-ts/versions");
114
- var import_utils24 = require("@noble/curves/abstract/utils");
115
- var import_ethers = require("ethers");
115
+ var import_utils23 = require("@noble/curves/abstract/utils");
116
+ var import_ethers2 = require("ethers");
116
117
  var import_graphql_request = require("graphql-request");
117
118
  var import_ramda3 = require("ramda");
118
119
 
@@ -120,14 +121,10 @@ var import_ramda3 = require("ramda");
120
121
  var import_graphql_tag = __toESM(require("graphql-tag"));
121
122
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
122
123
  fragment receiptFragment on Receipt {
123
- contract {
124
- id
125
- }
124
+ id
126
125
  pc
127
126
  is
128
- to {
129
- id
130
- }
127
+ to
131
128
  toAddress
132
129
  amount
133
130
  assetId
@@ -165,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
165
162
  id
166
163
  }
167
164
  time
165
+ receipts {
166
+ ...receiptFragment
167
+ }
168
168
  programState {
169
169
  returnType
170
170
  data
171
171
  }
172
+ receipts {
173
+ ...receiptFragment
174
+ }
172
175
  }
173
176
  ... on FailureStatus {
174
177
  block {
@@ -176,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
176
179
  }
177
180
  time
178
181
  reason
182
+ receipts {
183
+ ...receiptFragment
184
+ }
179
185
  }
180
186
  ... on SqueezedOutStatus {
181
187
  reason
182
188
  }
183
189
  }
184
- `;
190
+ ${ReceiptFragmentFragmentDoc}`;
185
191
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
186
192
  fragment transactionFragment on Transaction {
187
193
  id
188
194
  rawPayload
189
- gasPrice
190
- receipts {
191
- ...receiptFragment
192
- }
193
195
  status {
194
196
  ...transactionStatusFragment
195
197
  }
196
198
  }
197
- ${ReceiptFragmentFragmentDoc}
198
- ${TransactionStatusFragmentFragmentDoc}`;
199
+ ${TransactionStatusFragmentFragmentDoc}`;
199
200
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
200
201
  fragment inputEstimatePredicatesFragment on Input {
201
202
  ... on InputCoin {
@@ -213,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
213
214
  }
214
215
  }
215
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}`;
216
257
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
217
258
  fragment coinFragment on Coin {
218
259
  __typename
@@ -220,7 +261,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
220
261
  owner
221
262
  amount
222
263
  assetId
223
- maturity
224
264
  blockCreated
225
265
  txCreatedIdx
226
266
  }
@@ -265,7 +305,6 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
265
305
  prevRoot
266
306
  time
267
307
  applicationHash
268
- messageReceiptRoot
269
308
  messageReceiptCount
270
309
  }
271
310
  commitBlockHeader {
@@ -277,7 +316,6 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
277
316
  prevRoot
278
317
  time
279
318
  applicationHash
280
- messageReceiptRoot
281
319
  messageReceiptCount
282
320
  }
283
321
  sender
@@ -297,8 +335,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
297
335
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
298
336
  fragment blockFragment on Block {
299
337
  id
338
+ height
300
339
  header {
301
- height
302
340
  time
303
341
  }
304
342
  transactions {
@@ -356,6 +394,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
356
394
  `;
357
395
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
358
396
  fragment GasCostsFragment on GasCosts {
397
+ version {
398
+ ... on Version {
399
+ value
400
+ }
401
+ }
359
402
  add
360
403
  addi
361
404
  aloc
@@ -368,7 +411,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
368
411
  cb
369
412
  cfei
370
413
  cfsi
371
- croo
372
414
  div
373
415
  divi
374
416
  ecr1
@@ -451,6 +493,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
451
493
  ccp {
452
494
  ...DependentCostFragment
453
495
  }
496
+ croo {
497
+ ...DependentCostFragment
498
+ }
454
499
  csiz {
455
500
  ...DependentCostFragment
456
501
  }
@@ -510,6 +555,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
510
555
  ${DependentCostFragmentFragmentDoc}`;
511
556
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
512
557
  fragment consensusParametersFragment on ConsensusParameters {
558
+ version {
559
+ ... on Version {
560
+ value
561
+ }
562
+ }
513
563
  txParams {
514
564
  ...TxParametersFragment
515
565
  }
@@ -569,18 +619,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
569
619
  fragment nodeInfoFragment on NodeInfo {
570
620
  utxoValidation
571
621
  vmBacktrace
572
- minGasPrice
573
622
  maxTx
574
623
  maxDepth
575
624
  nodeVersion
576
- peers {
577
- id
578
- addresses
579
- clientVersion
580
- blockHeight
581
- lastHeartbeatMs
582
- appScore
583
- }
584
625
  }
585
626
  `;
586
627
  var GetVersionDocument = import_graphql_tag.default`
@@ -615,13 +656,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
615
656
  query getTransactionWithReceipts($transactionId: TransactionId!) {
616
657
  transaction(id: $transactionId) {
617
658
  ...transactionFragment
618
- receipts {
619
- ...receiptFragment
620
- }
621
659
  }
622
660
  }
623
- ${TransactionFragmentFragmentDoc}
624
- ${ReceiptFragmentFragmentDoc}`;
661
+ ${TransactionFragmentFragmentDoc}`;
625
662
  var GetTransactionsDocument = import_graphql_tag.default`
626
663
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
627
664
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -749,6 +786,20 @@ var GetBalanceDocument = import_graphql_tag.default`
749
786
  }
750
787
  }
751
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
+ `;
752
803
  var GetBalancesDocument = import_graphql_tag.default`
753
804
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
754
805
  balances(
@@ -803,12 +854,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
803
854
  }
804
855
  `;
805
856
  var DryRunDocument = import_graphql_tag.default`
806
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
807
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
808
- ...receiptFragment
857
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
858
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
859
+ ...dryRunTransactionExecutionStatusFragment
809
860
  }
810
861
  }
811
- ${ReceiptFragmentFragmentDoc}`;
862
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
812
863
  var SubmitDocument = import_graphql_tag.default`
813
864
  mutation submit($encodedTransaction: HexString!) {
814
865
  submit(tx: $encodedTransaction) {
@@ -891,6 +942,12 @@ function getSdk(requester) {
891
942
  getBalance(variables, options) {
892
943
  return requester(GetBalanceDocument, variables, options);
893
944
  },
945
+ getLatestGasPrice(variables, options) {
946
+ return requester(GetLatestGasPriceDocument, variables, options);
947
+ },
948
+ estimateGasPrice(variables, options) {
949
+ return requester(EstimateGasPriceDocument, variables, options);
950
+ },
894
951
  getBalances(variables, options) {
895
952
  return requester(GetBalancesDocument, variables, options);
896
953
  },
@@ -960,11 +1017,14 @@ var _FuelGraphqlSubscriber = class {
960
1017
  let data;
961
1018
  let errors;
962
1019
  try {
963
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
1020
+ const sanitizedText = text.replace(/\s/g, "");
1021
+ ({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
964
1022
  } catch (e) {
965
1023
  throw new import_errors.FuelError(
966
1024
  import_errors.ErrorCode.STREAM_PARSING_ERROR,
967
- `Error while parsing stream data response: ${text}`
1025
+ `Error while parsing stream data response: ${text}
1026
+
1027
+ Thrown error: ${e}`
968
1028
  );
969
1029
  }
970
1030
  if (Array.isArray(errors)) {
@@ -1065,7 +1125,7 @@ var inputify = (value) => {
1065
1125
  return {
1066
1126
  type: import_transactions.InputType.Coin,
1067
1127
  txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
1068
- outputIndex: (0, import_utils3.arrayify)(value.id)[32],
1128
+ outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 34)),
1069
1129
  owner: (0, import_utils3.hexlify)(value.owner),
1070
1130
  amount: (0, import_math2.bn)(value.amount),
1071
1131
  assetId: (0, import_utils3.hexlify)(value.assetId),
@@ -1074,10 +1134,9 @@ var inputify = (value) => {
1074
1134
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1075
1135
  },
1076
1136
  witnessIndex: value.witnessIndex,
1077
- maturity: value.maturity ?? 0,
1078
1137
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1079
- predicateLength: predicate.length,
1080
- predicateDataLength: predicateData.length,
1138
+ predicateLength: (0, import_math2.bn)(predicate.length),
1139
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1081
1140
  predicate: (0, import_utils3.hexlify)(predicate),
1082
1141
  predicateData: (0, import_utils3.hexlify)(predicateData)
1083
1142
  };
@@ -1108,8 +1167,8 @@ var inputify = (value) => {
1108
1167
  nonce: (0, import_utils3.hexlify)(value.nonce),
1109
1168
  witnessIndex: value.witnessIndex,
1110
1169
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1111
- predicateLength: predicate.length,
1112
- predicateDataLength: predicateData.length,
1170
+ predicateLength: (0, import_math2.bn)(predicate.length),
1171
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1113
1172
  predicate: (0, import_utils3.hexlify)(predicate),
1114
1173
  predicateData: (0, import_utils3.hexlify)(predicateData),
1115
1174
  data: (0, import_utils3.hexlify)(data),
@@ -1188,6 +1247,7 @@ var import_configs7 = require("@fuel-ts/address/configs");
1188
1247
  var import_math7 = require("@fuel-ts/math");
1189
1248
  var import_transactions6 = require("@fuel-ts/transactions");
1190
1249
  var import_utils9 = require("@fuel-ts/utils");
1250
+ var import_ethers = require("ethers");
1191
1251
 
1192
1252
  // src/providers/resource.ts
1193
1253
  var isCoin = (resource) => "id" in resource;
@@ -1223,8 +1283,8 @@ function assembleReceiptByType(receipt) {
1223
1283
  case "CALL" /* Call */: {
1224
1284
  const callReceipt = {
1225
1285
  type: import_transactions3.ReceiptType.Call,
1226
- from: hexOrZero(receipt.contract?.id),
1227
- to: hexOrZero(receipt?.to?.id),
1286
+ from: hexOrZero(receipt.id || receipt.contractId),
1287
+ to: hexOrZero(receipt?.to),
1228
1288
  amount: (0, import_math4.bn)(receipt.amount),
1229
1289
  assetId: hexOrZero(receipt.assetId),
1230
1290
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1238,7 +1298,7 @@ function assembleReceiptByType(receipt) {
1238
1298
  case "RETURN" /* Return */: {
1239
1299
  const returnReceipt = {
1240
1300
  type: import_transactions3.ReceiptType.Return,
1241
- id: hexOrZero(receipt.contract?.id),
1301
+ id: hexOrZero(receipt.id || receipt.contractId),
1242
1302
  val: (0, import_math4.bn)(receipt.val),
1243
1303
  pc: (0, import_math4.bn)(receipt.pc),
1244
1304
  is: (0, import_math4.bn)(receipt.is)
@@ -1248,7 +1308,7 @@ function assembleReceiptByType(receipt) {
1248
1308
  case "RETURN_DATA" /* ReturnData */: {
1249
1309
  const returnDataReceipt = {
1250
1310
  type: import_transactions3.ReceiptType.ReturnData,
1251
- id: hexOrZero(receipt.contract?.id),
1311
+ id: hexOrZero(receipt.id || receipt.contractId),
1252
1312
  ptr: (0, import_math4.bn)(receipt.ptr),
1253
1313
  len: (0, import_math4.bn)(receipt.len),
1254
1314
  digest: hexOrZero(receipt.digest),
@@ -1260,7 +1320,7 @@ function assembleReceiptByType(receipt) {
1260
1320
  case "PANIC" /* Panic */: {
1261
1321
  const panicReceipt = {
1262
1322
  type: import_transactions3.ReceiptType.Panic,
1263
- id: hexOrZero(receipt.contract?.id),
1323
+ id: hexOrZero(receipt.id),
1264
1324
  reason: (0, import_math4.bn)(receipt.reason),
1265
1325
  pc: (0, import_math4.bn)(receipt.pc),
1266
1326
  is: (0, import_math4.bn)(receipt.is),
@@ -1271,7 +1331,7 @@ function assembleReceiptByType(receipt) {
1271
1331
  case "REVERT" /* Revert */: {
1272
1332
  const revertReceipt = {
1273
1333
  type: import_transactions3.ReceiptType.Revert,
1274
- id: hexOrZero(receipt.contract?.id),
1334
+ id: hexOrZero(receipt.id || receipt.contractId),
1275
1335
  val: (0, import_math4.bn)(receipt.ra),
1276
1336
  pc: (0, import_math4.bn)(receipt.pc),
1277
1337
  is: (0, import_math4.bn)(receipt.is)
@@ -1281,7 +1341,7 @@ function assembleReceiptByType(receipt) {
1281
1341
  case "LOG" /* Log */: {
1282
1342
  const logReceipt = {
1283
1343
  type: import_transactions3.ReceiptType.Log,
1284
- id: hexOrZero(receipt.contract?.id),
1344
+ id: hexOrZero(receipt.id || receipt.contractId),
1285
1345
  val0: (0, import_math4.bn)(receipt.ra),
1286
1346
  val1: (0, import_math4.bn)(receipt.rb),
1287
1347
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1294,7 +1354,7 @@ function assembleReceiptByType(receipt) {
1294
1354
  case "LOG_DATA" /* LogData */: {
1295
1355
  const logDataReceipt = {
1296
1356
  type: import_transactions3.ReceiptType.LogData,
1297
- id: hexOrZero(receipt.contract?.id),
1357
+ id: hexOrZero(receipt.id || receipt.contractId),
1298
1358
  val0: (0, import_math4.bn)(receipt.ra),
1299
1359
  val1: (0, import_math4.bn)(receipt.rb),
1300
1360
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1308,8 +1368,8 @@ function assembleReceiptByType(receipt) {
1308
1368
  case "TRANSFER" /* Transfer */: {
1309
1369
  const transferReceipt = {
1310
1370
  type: import_transactions3.ReceiptType.Transfer,
1311
- from: hexOrZero(receipt.contract?.id),
1312
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1371
+ from: hexOrZero(receipt.id || receipt.contractId),
1372
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1313
1373
  amount: (0, import_math4.bn)(receipt.amount),
1314
1374
  assetId: hexOrZero(receipt.assetId),
1315
1375
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1320,8 +1380,8 @@ function assembleReceiptByType(receipt) {
1320
1380
  case "TRANSFER_OUT" /* TransferOut */: {
1321
1381
  const transferOutReceipt = {
1322
1382
  type: import_transactions3.ReceiptType.TransferOut,
1323
- from: hexOrZero(receipt.contract?.id),
1324
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1383
+ from: hexOrZero(receipt.id || receipt.contractId),
1384
+ to: hexOrZero(receipt.toAddress || receipt.to),
1325
1385
  amount: (0, import_math4.bn)(receipt.amount),
1326
1386
  assetId: hexOrZero(receipt.assetId),
1327
1387
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1364,7 +1424,7 @@ function assembleReceiptByType(receipt) {
1364
1424
  return receiptMessageOut;
1365
1425
  }
1366
1426
  case "MINT" /* Mint */: {
1367
- const contractId = hexOrZero(receipt.contract?.id);
1427
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1368
1428
  const subId = hexOrZero(receipt.subId);
1369
1429
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1370
1430
  const mintReceipt = {
@@ -1379,7 +1439,7 @@ function assembleReceiptByType(receipt) {
1379
1439
  return mintReceipt;
1380
1440
  }
1381
1441
  case "BURN" /* Burn */: {
1382
- const contractId = hexOrZero(receipt.contract?.id);
1442
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1383
1443
  const subId = hexOrZero(receipt.subId);
1384
1444
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1385
1445
  const burnReceipt = {
@@ -1405,7 +1465,6 @@ var import_errors6 = require("@fuel-ts/errors");
1405
1465
  var import_math5 = require("@fuel-ts/math");
1406
1466
  var import_transactions4 = require("@fuel-ts/transactions");
1407
1467
  var import_utils6 = require("@fuel-ts/utils");
1408
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1409
1468
  var getGasUsedFromReceipts = (receipts) => {
1410
1469
  const scriptResult = receipts.filter(
1411
1470
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1426,18 +1485,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1426
1485
  }
1427
1486
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1428
1487
  const witnessCache = [];
1429
- const totalGas = inputs.reduce((total, input) => {
1488
+ const chargeableInputs = inputs.filter((input) => {
1489
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1490
+ if (isCoinOrMessage) {
1491
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1492
+ return true;
1493
+ }
1494
+ if (!witnessCache.includes(input.witnessIndex)) {
1495
+ witnessCache.push(input.witnessIndex);
1496
+ return true;
1497
+ }
1498
+ }
1499
+ return false;
1500
+ });
1501
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1502
+ const totalGas = chargeableInputs.reduce((total, input) => {
1430
1503
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1431
1504
  return total.add(
1432
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1505
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1433
1506
  );
1434
1507
  }
1435
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1436
- witnessCache.push(input.witnessIndex);
1437
- return total.add(gasCosts.ecr1);
1438
- }
1439
- return total;
1440
- }, (0, import_math5.bn)());
1508
+ return total.add(gasCosts.ecr1);
1509
+ }, (0, import_math5.bn)(0));
1441
1510
  return totalGas;
1442
1511
  }
1443
1512
  function getMinGas(params) {
@@ -1449,12 +1518,20 @@ function getMinGas(params) {
1449
1518
  return minGas;
1450
1519
  }
1451
1520
  function getMaxGas(params) {
1452
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1521
+ const {
1522
+ gasPerByte,
1523
+ witnessesLength,
1524
+ witnessLimit,
1525
+ minGas,
1526
+ gasLimit = (0, import_math5.bn)(0),
1527
+ maxGasPerTx
1528
+ } = params;
1453
1529
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1454
1530
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1455
1531
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1456
1532
  }
1457
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1533
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1534
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1458
1535
  }
1459
1536
  function calculateMetadataGasForTxCreate({
1460
1537
  gasCosts,
@@ -1476,6 +1553,10 @@ function calculateMetadataGasForTxScript({
1476
1553
  }) {
1477
1554
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1478
1555
  }
1556
+ var calculateGasFee = (params) => {
1557
+ const { gas, gasPrice, priceFactor, tip } = params;
1558
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1559
+ };
1479
1560
 
1480
1561
  // src/providers/utils/json.ts
1481
1562
  var import_utils7 = require("@fuel-ts/utils");
@@ -1612,7 +1693,7 @@ var witnessify = (value) => {
1612
1693
  // src/providers/transaction-request/transaction-request.ts
1613
1694
  var BaseTransactionRequest = class {
1614
1695
  /** Gas price for transaction */
1615
- gasPrice;
1696
+ tip;
1616
1697
  /** Block until which tx cannot be included */
1617
1698
  maturity;
1618
1699
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1631,7 +1712,7 @@ var BaseTransactionRequest = class {
1631
1712
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1632
1713
  */
1633
1714
  constructor({
1634
- gasPrice,
1715
+ tip,
1635
1716
  maturity,
1636
1717
  maxFee,
1637
1718
  witnessLimit,
@@ -1639,7 +1720,7 @@ var BaseTransactionRequest = class {
1639
1720
  outputs,
1640
1721
  witnesses
1641
1722
  } = {}) {
1642
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1723
+ this.tip = (0, import_math7.bn)(tip);
1643
1724
  this.maturity = maturity ?? 0;
1644
1725
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1645
1726
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1650,9 +1731,9 @@ var BaseTransactionRequest = class {
1650
1731
  static getPolicyMeta(req) {
1651
1732
  let policyTypes = 0;
1652
1733
  const policies = [];
1653
- if (req.gasPrice) {
1654
- policyTypes += import_transactions6.PolicyType.GasPrice;
1655
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1734
+ if (req.tip) {
1735
+ policyTypes += import_transactions6.PolicyType.Tip;
1736
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1656
1737
  }
1657
1738
  if (req.witnessLimit) {
1658
1739
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -1840,9 +1921,9 @@ var BaseTransactionRequest = class {
1840
1921
  * @param predicateData - Predicate data bytes.
1841
1922
  */
1842
1923
  addCoinInput(coin) {
1843
- const { assetId, owner, amount, id, predicate } = coin;
1924
+ const { assetId, owner, amount } = coin;
1844
1925
  let witnessIndex;
1845
- if (predicate) {
1926
+ if (coin.predicate) {
1846
1927
  witnessIndex = 0;
1847
1928
  } else {
1848
1929
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1851,14 +1932,13 @@ var BaseTransactionRequest = class {
1851
1932
  }
1852
1933
  }
1853
1934
  const input = {
1854
- id,
1935
+ ...coin,
1855
1936
  type: import_transactions6.InputType.Coin,
1856
1937
  owner: owner.toB256(),
1857
1938
  amount,
1858
1939
  assetId,
1859
1940
  txPointer: "0x00000000000000000000000000000000",
1860
- witnessIndex,
1861
- predicate
1941
+ witnessIndex
1862
1942
  };
1863
1943
  this.pushInput(input);
1864
1944
  this.addChangeOutput(owner, assetId);
@@ -1872,10 +1952,10 @@ var BaseTransactionRequest = class {
1872
1952
  * @param predicateData - Predicate data bytes.
1873
1953
  */
1874
1954
  addMessageInput(message) {
1875
- const { recipient, sender, amount, predicate, nonce } = message;
1955
+ const { recipient, sender, amount } = message;
1876
1956
  const assetId = import_configs7.BaseAssetId;
1877
1957
  let witnessIndex;
1878
- if (predicate) {
1958
+ if (message.predicate) {
1879
1959
  witnessIndex = 0;
1880
1960
  } else {
1881
1961
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1884,13 +1964,12 @@ var BaseTransactionRequest = class {
1884
1964
  }
1885
1965
  }
1886
1966
  const input = {
1887
- nonce,
1967
+ ...message,
1888
1968
  type: import_transactions6.InputType.Message,
1889
1969
  sender: sender.toB256(),
1890
1970
  recipient: recipient.toB256(),
1891
1971
  amount,
1892
- witnessIndex,
1893
- predicate
1972
+ witnessIndex
1894
1973
  };
1895
1974
  this.pushInput(input);
1896
1975
  this.addChangeOutput(recipient, assetId);
@@ -2000,7 +2079,7 @@ var BaseTransactionRequest = class {
2000
2079
  }
2001
2080
  calculateMaxGas(chainInfo, minGas) {
2002
2081
  const { consensusParameters } = chainInfo;
2003
- const { gasPerByte } = consensusParameters;
2082
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2004
2083
  const witnessesLength = this.toTransaction().witnesses.reduce(
2005
2084
  (acc, wit) => acc + wit.dataLength,
2006
2085
  0
@@ -2009,7 +2088,8 @@ var BaseTransactionRequest = class {
2009
2088
  gasPerByte,
2010
2089
  minGas,
2011
2090
  witnessesLength,
2012
- witnessLimit: this.witnessLimit
2091
+ witnessLimit: this.witnessLimit,
2092
+ maxGasPerTx
2013
2093
  });
2014
2094
  }
2015
2095
  /**
@@ -2019,12 +2099,6 @@ var BaseTransactionRequest = class {
2019
2099
  * @param quantities - CoinQuantity Array.
2020
2100
  */
2021
2101
  fundWithFakeUtxos(quantities, resourcesOwner) {
2022
- let idCounter = 0;
2023
- const generateId = () => {
2024
- const counterString = String(idCounter++);
2025
- const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2026
- return id;
2027
- };
2028
2102
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2029
2103
  if ("assetId" in input) {
2030
2104
  return input.assetId === assetId;
@@ -2033,17 +2107,20 @@ var BaseTransactionRequest = class {
2033
2107
  });
2034
2108
  const updateAssetInput = (assetId, quantity) => {
2035
2109
  const assetInput = findAssetInput(assetId);
2110
+ let usedQuantity = quantity;
2111
+ if (assetId === import_configs7.BaseAssetId) {
2112
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2113
+ }
2036
2114
  if (assetInput && "assetId" in assetInput) {
2037
- assetInput.id = generateId();
2038
- assetInput.amount = quantity;
2115
+ assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34));
2116
+ assetInput.amount = usedQuantity;
2039
2117
  } else {
2040
2118
  this.addResources([
2041
2119
  {
2042
- id: generateId(),
2043
- amount: quantity,
2120
+ id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34)),
2121
+ amount: usedQuantity,
2044
2122
  assetId,
2045
2123
  owner: resourcesOwner || import_address.Address.fromRandom(),
2046
- maturity: 0,
2047
2124
  blockCreated: (0, import_math7.bn)(1),
2048
2125
  txCreatedIdx: (0, import_math7.bn)(1)
2049
2126
  }
@@ -2075,7 +2152,7 @@ var BaseTransactionRequest = class {
2075
2152
  toJSON() {
2076
2153
  return normalizeJSON(this);
2077
2154
  }
2078
- updatePredicateInputs(inputs) {
2155
+ updatePredicateGasUsed(inputs) {
2079
2156
  this.inputs.forEach((i) => {
2080
2157
  let correspondingInput;
2081
2158
  switch (i.type) {
@@ -2097,6 +2174,15 @@ var BaseTransactionRequest = class {
2097
2174
  }
2098
2175
  });
2099
2176
  }
2177
+ shiftPredicateData() {
2178
+ this.inputs.forEach((input) => {
2179
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2180
+ input.predicateData = input.paddPredicateData(
2181
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2182
+ );
2183
+ }
2184
+ });
2185
+ }
2100
2186
  };
2101
2187
 
2102
2188
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2243,9 +2329,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2243
2329
  return {
2244
2330
  type: import_transactions8.TransactionType.Create,
2245
2331
  ...baseTransaction,
2246
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2247
2332
  bytecodeWitnessIndex,
2248
- storageSlotsCount: storageSlots.length,
2333
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2249
2334
  salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2250
2335
  storageSlots
2251
2336
  };
@@ -2368,8 +2453,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2368
2453
  type: import_transactions9.TransactionType.Script,
2369
2454
  scriptGasLimit: this.gasLimit,
2370
2455
  ...super.getBaseTransaction(),
2371
- scriptLength: script.length,
2372
- scriptDataLength: scriptData.length,
2456
+ scriptLength: (0, import_math10.bn)(script.length),
2457
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2373
2458
  receiptsRoot: import_configs10.ZeroBytes32,
2374
2459
  script: (0, import_utils15.hexlify)(script),
2375
2460
  scriptData: (0, import_utils15.hexlify)(scriptData)
@@ -2433,7 +2518,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2433
2518
  }
2434
2519
  calculateMaxGas(chainInfo, minGas) {
2435
2520
  const { consensusParameters } = chainInfo;
2436
- const { gasPerByte } = consensusParameters;
2521
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2437
2522
  const witnessesLength = this.toTransaction().witnesses.reduce(
2438
2523
  (acc, wit) => acc + wit.dataLength,
2439
2524
  0
@@ -2443,7 +2528,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2443
2528
  minGas,
2444
2529
  witnessesLength,
2445
2530
  witnessLimit: this.witnessLimit,
2446
- gasLimit: this.gasLimit
2531
+ gasLimit: this.gasLimit,
2532
+ maxGasPerTx
2447
2533
  });
2448
2534
  }
2449
2535
  /**
@@ -2518,15 +2604,32 @@ var transactionRequestify = (obj) => {
2518
2604
  }
2519
2605
  }
2520
2606
  };
2607
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2608
+ (acc, input) => {
2609
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2610
+ acc.utxos.push(input.id);
2611
+ }
2612
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2613
+ acc.messages.push(input.nonce);
2614
+ }
2615
+ return acc;
2616
+ },
2617
+ {
2618
+ utxos: [],
2619
+ messages: []
2620
+ }
2621
+ );
2521
2622
 
2522
2623
  // src/providers/transaction-response/transaction-response.ts
2523
2624
  var import_errors13 = require("@fuel-ts/errors");
2524
- var import_math14 = require("@fuel-ts/math");
2525
- var import_transactions17 = require("@fuel-ts/transactions");
2526
- var import_utils21 = require("@fuel-ts/utils");
2625
+ var import_math15 = require("@fuel-ts/math");
2626
+ var import_transactions18 = require("@fuel-ts/transactions");
2627
+ var import_utils20 = require("@fuel-ts/utils");
2527
2628
 
2528
2629
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2529
- var import_utils19 = require("@fuel-ts/utils");
2630
+ var import_math14 = require("@fuel-ts/math");
2631
+ var import_transactions16 = require("@fuel-ts/transactions");
2632
+ var import_utils18 = require("@fuel-ts/utils");
2530
2633
 
2531
2634
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2532
2635
  var import_math11 = require("@fuel-ts/math");
@@ -2534,9 +2637,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
2534
2637
  var import_utils16 = require("@fuel-ts/utils");
2535
2638
  var calculateTransactionFee = (params) => {
2536
2639
  const {
2537
- gasUsed,
2640
+ gasPrice,
2538
2641
  rawPayload,
2539
- consensusParameters: { gasCosts, feeParams }
2642
+ tip,
2643
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2540
2644
  } = params;
2541
2645
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2542
2646
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2546,8 +2650,7 @@ var calculateTransactionFee = (params) => {
2546
2650
  return {
2547
2651
  fee: (0, import_math11.bn)(0),
2548
2652
  minFee: (0, import_math11.bn)(0),
2549
- maxFee: (0, import_math11.bn)(0),
2550
- feeFromGasUsed: (0, import_math11.bn)(0)
2653
+ maxFee: (0, import_math11.bn)(0)
2551
2654
  };
2552
2655
  }
2553
2656
  const { type, witnesses, inputs, policies } = transaction;
@@ -2579,7 +2682,6 @@ var calculateTransactionFee = (params) => {
2579
2682
  metadataGas,
2580
2683
  txBytesSize: transactionBytes.length
2581
2684
  });
2582
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2583
2685
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2584
2686
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2585
2687
  const maxGas = getMaxGas({
@@ -2587,17 +2689,25 @@ var calculateTransactionFee = (params) => {
2587
2689
  minGas,
2588
2690
  witnessesLength,
2589
2691
  gasLimit,
2590
- witnessLimit
2692
+ witnessLimit,
2693
+ maxGasPerTx
2694
+ });
2695
+ const minFee = calculateGasFee({
2696
+ gasPrice,
2697
+ gas: minGas,
2698
+ priceFactor: gasPriceFactor,
2699
+ tip
2700
+ });
2701
+ const maxFee = calculateGasFee({
2702
+ gasPrice,
2703
+ gas: maxGas,
2704
+ priceFactor: gasPriceFactor,
2705
+ tip
2591
2706
  });
2592
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2593
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2594
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2595
- const fee = minFee.add(feeFromGasUsed);
2596
2707
  return {
2597
- fee,
2598
2708
  minFee,
2599
2709
  maxFee,
2600
- feeFromGasUsed
2710
+ fee: maxFee
2601
2711
  };
2602
2712
  };
2603
2713
 
@@ -3164,10 +3274,12 @@ function assembleTransactionSummary(params) {
3164
3274
  gqlTransactionStatus,
3165
3275
  abiMap = {},
3166
3276
  maxInputs,
3167
- gasCosts
3277
+ gasCosts,
3278
+ maxGasPerTx,
3279
+ gasPrice
3168
3280
  } = params;
3169
3281
  const gasUsed = getGasUsedFromReceipts(receipts);
3170
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3282
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3171
3283
  const operations = getOperations({
3172
3284
  transactionType: transaction.type,
3173
3285
  inputs: transaction.inputs || [],
@@ -3178,11 +3290,14 @@ function assembleTransactionSummary(params) {
3178
3290
  maxInputs
3179
3291
  });
3180
3292
  const typeName = getTransactionTypeName(transaction.type);
3293
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3181
3294
  const { fee } = calculateTransactionFee({
3182
- gasUsed,
3295
+ gasPrice,
3183
3296
  rawPayload,
3297
+ tip,
3184
3298
  consensusParameters: {
3185
3299
  gasCosts,
3300
+ maxGasPerTx,
3186
3301
  feeParams: {
3187
3302
  gasPerByte,
3188
3303
  gasPriceFactor
@@ -3194,7 +3309,7 @@ function assembleTransactionSummary(params) {
3194
3309
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3195
3310
  let date;
3196
3311
  if (time) {
3197
- date = import_utils19.DateTime.fromTai64(time);
3312
+ date = import_utils18.DateTime.fromTai64(time);
3198
3313
  }
3199
3314
  const transactionSummary = {
3200
3315
  id,
@@ -3222,12 +3337,12 @@ function assembleTransactionSummary(params) {
3222
3337
 
3223
3338
  // src/providers/transaction-response/getDecodedLogs.ts
3224
3339
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
3225
- var import_transactions16 = require("@fuel-ts/transactions");
3340
+ var import_transactions17 = require("@fuel-ts/transactions");
3226
3341
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3227
3342
  return receipts.reduce((logs, receipt) => {
3228
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3343
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3229
3344
  const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3230
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3345
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3231
3346
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3232
3347
  logs.push(decodedLog);
3233
3348
  }
@@ -3242,7 +3357,7 @@ var TransactionResponse = class {
3242
3357
  /** Current provider */
3243
3358
  provider;
3244
3359
  /** Gas used on the transaction */
3245
- gasUsed = (0, import_math14.bn)(0);
3360
+ gasUsed = (0, import_math15.bn)(0);
3246
3361
  /** The graphql Transaction with receipts object. */
3247
3362
  gqlTransaction;
3248
3363
  abis;
@@ -3300,8 +3415,8 @@ var TransactionResponse = class {
3300
3415
  * @returns The decoded transaction.
3301
3416
  */
3302
3417
  decodeTransaction(transactionWithReceipts) {
3303
- return new import_transactions17.TransactionCoder().decode(
3304
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3418
+ return new import_transactions18.TransactionCoder().decode(
3419
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3305
3420
  0
3306
3421
  )?.[0];
3307
3422
  }
@@ -3320,20 +3435,27 @@ var TransactionResponse = class {
3320
3435
  const decodedTransaction = this.decodeTransaction(
3321
3436
  transaction
3322
3437
  );
3323
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3324
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3438
+ let txReceipts = [];
3439
+ if (transaction?.status && "receipts" in transaction.status) {
3440
+ txReceipts = transaction.status.receipts;
3441
+ }
3442
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3443
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3444
+ const gasPrice = await this.provider.getLatestGasPrice();
3325
3445
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3326
3446
  const transactionSummary = assembleTransactionSummary({
3327
3447
  id: this.id,
3328
3448
  receipts,
3329
3449
  transaction: decodedTransaction,
3330
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3450
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3331
3451
  gqlTransactionStatus: transaction.status,
3332
3452
  gasPerByte,
3333
3453
  gasPriceFactor,
3334
3454
  abiMap: contractsAbiMap,
3335
3455
  maxInputs,
3336
- gasCosts
3456
+ gasCosts,
3457
+ maxGasPerTx,
3458
+ gasPrice
3337
3459
  });
3338
3460
  return transactionSummary;
3339
3461
  }
@@ -3460,29 +3582,29 @@ var processGqlChain = (chain) => {
3460
3582
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3461
3583
  return {
3462
3584
  name,
3463
- baseChainHeight: (0, import_math15.bn)(daHeight),
3585
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3464
3586
  consensusParameters: {
3465
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3466
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3467
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3468
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3469
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3470
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3471
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3472
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3473
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3474
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3475
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3476
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3477
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3478
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3479
- chainId: (0, import_math15.bn)(consensusParameters.chainId),
3587
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3588
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3589
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3590
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3591
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3592
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3593
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3594
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3595
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3596
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3597
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3598
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3599
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3600
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3601
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3480
3602
  gasCosts
3481
3603
  },
3482
3604
  gasCosts,
3483
3605
  latestBlock: {
3484
3606
  id: latestBlock.id,
3485
- height: (0, import_math15.bn)(latestBlock.header.height),
3607
+ height: (0, import_math16.bn)(latestBlock.height),
3486
3608
  time: latestBlock.header.time,
3487
3609
  transactions: latestBlock.transactions.map((i) => ({
3488
3610
  id: i.id
@@ -3576,10 +3698,8 @@ var _Provider = class {
3576
3698
  * Returns some helpful parameters related to gas fees.
3577
3699
  */
3578
3700
  getGasConfig() {
3579
- const { minGasPrice } = this.getNode();
3580
3701
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3581
3702
  return {
3582
- minGasPrice,
3583
3703
  maxGasPerTx,
3584
3704
  maxGasPerPredicate,
3585
3705
  gasPriceFactor,
@@ -3667,7 +3787,7 @@ var _Provider = class {
3667
3787
  name,
3668
3788
  consensusParameters: { chainId }
3669
3789
  } = await this.getChain();
3670
- const network = new import_ethers.Network(name, chainId.toNumber());
3790
+ const network = new import_ethers2.Network(name, chainId.toNumber());
3671
3791
  return Promise.resolve(network);
3672
3792
  }
3673
3793
  /**
@@ -3677,7 +3797,7 @@ var _Provider = class {
3677
3797
  */
3678
3798
  async getBlockNumber() {
3679
3799
  const { chain } = await this.operations.getChain();
3680
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
3800
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3681
3801
  }
3682
3802
  /**
3683
3803
  * Returns the chain information.
@@ -3687,13 +3807,11 @@ var _Provider = class {
3687
3807
  async fetchNode() {
3688
3808
  const { nodeInfo } = await this.operations.getNodeInfo();
3689
3809
  const processedNodeInfo = {
3690
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3691
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3692
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
3810
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
3811
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3693
3812
  nodeVersion: nodeInfo.nodeVersion,
3694
3813
  utxoValidation: nodeInfo.utxoValidation,
3695
- vmBacktrace: nodeInfo.vmBacktrace,
3696
- peers: nodeInfo.peers
3814
+ vmBacktrace: nodeInfo.vmBacktrace
3697
3815
  };
3698
3816
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3699
3817
  return processedNodeInfo;
@@ -3735,9 +3853,9 @@ var _Provider = class {
3735
3853
  if (estimateTxDependencies) {
3736
3854
  await this.estimateTxDependencies(transactionRequest);
3737
3855
  }
3738
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3856
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3739
3857
  let abis;
3740
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
3858
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
3741
3859
  abis = transactionRequest.abis;
3742
3860
  }
3743
3861
  if (awaitExecution) {
@@ -3778,15 +3896,14 @@ var _Provider = class {
3778
3896
  if (estimateTxDependencies) {
3779
3897
  return this.estimateTxDependencies(transactionRequest);
3780
3898
  }
3781
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3782
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3783
- encodedTransaction,
3899
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3900
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
3901
+ encodedTransactions: encodedTransaction,
3784
3902
  utxoValidation: utxoValidation || false
3785
3903
  });
3786
- const receipts = gqlReceipts.map(processGqlReceipt);
3787
- return {
3788
- receipts
3789
- };
3904
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
3905
+ const receipts = rawReceipts.map(processGqlReceipt);
3906
+ return { receipts, dryrunStatus: status };
3790
3907
  }
3791
3908
  /**
3792
3909
  * Verifies whether enough gas is available to complete transaction.
@@ -3797,13 +3914,13 @@ var _Provider = class {
3797
3914
  async estimatePredicates(transactionRequest) {
3798
3915
  const shouldEstimatePredicates = Boolean(
3799
3916
  transactionRequest.inputs.find(
3800
- (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
3917
+ (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
3801
3918
  )
3802
3919
  );
3803
3920
  if (!shouldEstimatePredicates) {
3804
3921
  return transactionRequest;
3805
3922
  }
3806
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3923
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3807
3924
  const response = await this.operations.estimatePredicates({
3808
3925
  encodedTransaction
3809
3926
  });
@@ -3812,7 +3929,7 @@ var _Provider = class {
3812
3929
  } = response;
3813
3930
  if (inputs) {
3814
3931
  inputs.forEach((input, index) => {
3815
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
3932
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
3816
3933
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3817
3934
  }
3818
3935
  });
@@ -3825,31 +3942,31 @@ var _Provider = class {
3825
3942
  * If there are missing variable outputs,
3826
3943
  * `addVariableOutputs` is called on the transaction.
3827
3944
  *
3828
- * @privateRemarks
3829
- * TODO: Investigate support for missing contract IDs
3830
- * TODO: Add support for missing output messages
3831
3945
  *
3832
3946
  * @param transactionRequest - The transaction request object.
3833
3947
  * @returns A promise.
3834
3948
  */
3835
3949
  async estimateTxDependencies(transactionRequest) {
3836
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
3950
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
3837
3951
  return {
3838
3952
  receipts: [],
3839
3953
  outputVariables: 0,
3840
3954
  missingContractIds: []
3841
3955
  };
3842
3956
  }
3843
- await this.estimatePredicates(transactionRequest);
3844
3957
  let receipts = [];
3845
3958
  const missingContractIds = [];
3846
3959
  let outputVariables = 0;
3960
+ let dryrunStatus;
3847
3961
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3848
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3849
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
3962
+ const {
3963
+ dryRun: [{ receipts: rawReceipts, status }]
3964
+ } = await this.operations.dryRun({
3965
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
3850
3966
  utxoValidation: false
3851
3967
  });
3852
- receipts = gqlReceipts.map(processGqlReceipt);
3968
+ receipts = rawReceipts.map(processGqlReceipt);
3969
+ dryrunStatus = status;
3853
3970
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3854
3971
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3855
3972
  if (hasMissingOutputs) {
@@ -3859,6 +3976,11 @@ var _Provider = class {
3859
3976
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
3860
3977
  missingContractIds.push(contractId);
3861
3978
  });
3979
+ const { maxFee } = await this.estimateTxGasAndFee({
3980
+ transactionRequest,
3981
+ optimizeGas: false
3982
+ });
3983
+ transactionRequest.maxFee = maxFee;
3862
3984
  } else {
3863
3985
  break;
3864
3986
  }
@@ -3866,7 +3988,133 @@ var _Provider = class {
3866
3988
  return {
3867
3989
  receipts,
3868
3990
  outputVariables,
3869
- missingContractIds
3991
+ missingContractIds,
3992
+ dryrunStatus
3993
+ };
3994
+ }
3995
+ /**
3996
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
3997
+ *
3998
+ * Transactions are dry run in batches. After each dry run, transactions requiring
3999
+ * further modifications are identified. The method iteratively updates these transactions
4000
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4001
+ *
4002
+ * @param transactionRequests - Array of transaction request objects.
4003
+ * @returns A promise that resolves to an array of results for each transaction.
4004
+ */
4005
+ async estimateMultipleTxDependencies(transactionRequests) {
4006
+ const results = transactionRequests.map(() => ({
4007
+ receipts: [],
4008
+ outputVariables: 0,
4009
+ missingContractIds: [],
4010
+ dryrunStatus: void 0
4011
+ }));
4012
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4013
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4014
+ allRequests.forEach((req, index) => {
4015
+ if (req.type === import_transactions19.TransactionType.Script) {
4016
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4017
+ }
4018
+ });
4019
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4020
+ let attempt = 0;
4021
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4022
+ const encodedTransactions = transactionsToProcess.map(
4023
+ (index) => serializedTransactionsMap.get(index)
4024
+ );
4025
+ const dryRunResults = await this.operations.dryRun({
4026
+ encodedTransactions,
4027
+ utxoValidation: false
4028
+ });
4029
+ const nextRoundTransactions = [];
4030
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4031
+ const currentResultIndex = transactionsToProcess[i];
4032
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4033
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4034
+ results[currentResultIndex].dryrunStatus = status;
4035
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4036
+ results[currentResultIndex].receipts
4037
+ );
4038
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4039
+ const requestToProcess = allRequests[currentResultIndex];
4040
+ if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4041
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4042
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4043
+ missingOutputContractIds.forEach(({ contractId }) => {
4044
+ requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4045
+ results[currentResultIndex].missingContractIds.push(contractId);
4046
+ });
4047
+ const { maxFee } = await this.estimateTxGasAndFee({
4048
+ transactionRequest: requestToProcess,
4049
+ optimizeGas: false
4050
+ });
4051
+ requestToProcess.maxFee = maxFee;
4052
+ serializedTransactionsMap.set(
4053
+ currentResultIndex,
4054
+ (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4055
+ );
4056
+ nextRoundTransactions.push(currentResultIndex);
4057
+ allRequests[currentResultIndex] = requestToProcess;
4058
+ }
4059
+ }
4060
+ transactionsToProcess = nextRoundTransactions;
4061
+ attempt += 1;
4062
+ }
4063
+ return results;
4064
+ }
4065
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4066
+ if (estimateTxDependencies) {
4067
+ return this.estimateMultipleTxDependencies(transactionRequests);
4068
+ }
4069
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4070
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4071
+ encodedTransactions,
4072
+ utxoValidation: utxoValidation || false
4073
+ });
4074
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4075
+ const receipts = rawReceipts.map(processGqlReceipt);
4076
+ return { receipts, dryrunStatus: status };
4077
+ });
4078
+ return results;
4079
+ }
4080
+ async estimateTxGasAndFee(params) {
4081
+ const { transactionRequest, optimizeGas = true } = params;
4082
+ let { gasPrice } = params;
4083
+ const chainInfo = this.getChain();
4084
+ const { gasPriceFactor } = this.getGasConfig();
4085
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
4086
+ if (!gasPrice) {
4087
+ gasPrice = await this.estimateGasPrice(10);
4088
+ }
4089
+ const minFee = calculateGasFee({
4090
+ gasPrice: (0, import_math16.bn)(gasPrice),
4091
+ gas: minGas,
4092
+ priceFactor: gasPriceFactor,
4093
+ tip: transactionRequest.tip
4094
+ }).add(1);
4095
+ let gasLimit = (0, import_math16.bn)(0);
4096
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4097
+ gasLimit = transactionRequest.gasLimit;
4098
+ if (!optimizeGas) {
4099
+ transactionRequest.gasLimit = minGas;
4100
+ gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
4101
+ transactionRequest.gasLimit = gasLimit;
4102
+ }
4103
+ }
4104
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4105
+ const maxFee = calculateGasFee({
4106
+ gasPrice: (0, import_math16.bn)(gasPrice),
4107
+ gas: maxGas,
4108
+ priceFactor: gasPriceFactor,
4109
+ tip: transactionRequest.tip
4110
+ }).add(1);
4111
+ return {
4112
+ minGas,
4113
+ minFee,
4114
+ maxGas,
4115
+ maxFee,
4116
+ gasPrice,
4117
+ gasLimit
3870
4118
  };
3871
4119
  }
3872
4120
  /**
@@ -3884,15 +4132,17 @@ var _Provider = class {
3884
4132
  if (estimateTxDependencies) {
3885
4133
  return this.estimateTxDependencies(transactionRequest);
3886
4134
  }
3887
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3888
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3889
- encodedTransaction,
4135
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4136
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4137
+ encodedTransactions,
3890
4138
  utxoValidation: true
3891
4139
  });
3892
- const receipts = gqlReceipts.map(processGqlReceipt);
3893
- return {
3894
- receipts
3895
- };
4140
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4141
+ const { id, receipts, status } = dryRunStatus;
4142
+ const processedReceipts = receipts.map(processGqlReceipt);
4143
+ return { id, receipts: processedReceipts, status };
4144
+ });
4145
+ return { receipts: callResult[0].receipts };
3896
4146
  }
3897
4147
  /**
3898
4148
  * Returns a transaction cost to enable user
@@ -3909,80 +4159,80 @@ var _Provider = class {
3909
4159
  * @param tolerance - The tolerance to add on top of the gasUsed.
3910
4160
  * @returns A promise that resolves to the transaction cost object.
3911
4161
  */
3912
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3913
- estimateTxDependencies = true,
3914
- estimatePredicates = true,
3915
- resourcesOwner,
3916
- signatureCallback
3917
- } = {}) {
4162
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3918
4163
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
3919
- const chainInfo = this.getChain();
3920
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3921
- const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
3922
- const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4164
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
3923
4165
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3924
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4166
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
3925
4167
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3926
- if (estimatePredicates) {
3927
- if (isScriptTransaction) {
3928
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
3929
- }
3930
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3931
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
3932
- }
3933
- await this.estimatePredicates(txRequestClone);
4168
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
4169
+ if (isScriptTransaction) {
4170
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
3934
4171
  }
3935
- if (signatureCallback && isScriptTransaction) {
3936
- await signatureCallback(txRequestClone);
4172
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4173
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
3937
4174
  }
3938
- const minGas = txRequestClone.calculateMinGas(chainInfo);
3939
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4175
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4176
+ let addedSignatures = 0;
4177
+ if (signatureCallback && isScriptTransaction) {
4178
+ const lengthBefore = signedRequest.witnesses.length;
4179
+ await signatureCallback(signedRequest);
4180
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4181
+ }
4182
+ await this.estimatePredicates(signedRequest);
4183
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4184
+ transactionRequest: signedRequest,
4185
+ optimizeGas: false
4186
+ });
4187
+ txRequestClone.maxFee = maxFee;
3940
4188
  let receipts = [];
3941
4189
  let missingContractIds = [];
3942
4190
  let outputVariables = 0;
3943
- if (isScriptTransaction && estimateTxDependencies) {
3944
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
3945
- txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4191
+ let gasUsed = (0, import_math16.bn)(0);
4192
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4193
+ if (isScriptTransaction) {
4194
+ if (signatureCallback) {
4195
+ await signatureCallback(txRequestClone);
4196
+ }
4197
+ txRequestClone.gasLimit = gasLimit;
3946
4198
  const result = await this.estimateTxDependencies(txRequestClone);
3947
4199
  receipts = result.receipts;
3948
4200
  outputVariables = result.outputVariables;
3949
4201
  missingContractIds = result.missingContractIds;
4202
+ gasUsed = getGasUsedFromReceipts(receipts);
4203
+ txRequestClone.gasLimit = gasUsed;
4204
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4205
+ transactionRequest: txRequestClone,
4206
+ gasPrice
4207
+ }));
3950
4208
  }
3951
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3952
- const usedFee = calculatePriceWithFactor(
3953
- gasUsed,
3954
- gasPrice,
3955
- gasPriceFactor
3956
- ).normalizeZeroToOne();
3957
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3958
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3959
4209
  return {
3960
4210
  requiredQuantities: allQuantities,
3961
4211
  receipts,
3962
4212
  gasUsed,
3963
- minGasPrice,
3964
4213
  gasPrice,
3965
4214
  minGas,
3966
4215
  maxGas,
3967
- usedFee,
3968
4216
  minFee,
3969
4217
  maxFee,
3970
- estimatedInputs: txRequestClone.inputs,
3971
4218
  outputVariables,
3972
- missingContractIds
4219
+ missingContractIds,
4220
+ addedSignatures,
4221
+ estimatedPredicates: txRequestClone.inputs
3973
4222
  };
3974
4223
  }
3975
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4224
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
3976
4225
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
3977
4226
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
3978
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4227
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4228
+ quantitiesToContract
4229
+ });
3979
4230
  transactionRequest.addResources(
3980
4231
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
3981
4232
  );
3982
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
3983
- transactionRequest,
3984
- forwardingQuantities
3985
- );
4233
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4234
+ quantitiesToContract
4235
+ });
3986
4236
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
3987
4237
  return {
3988
4238
  resources,
@@ -3998,17 +4248,16 @@ var _Provider = class {
3998
4248
  const result = await this.operations.getCoins({
3999
4249
  first: 10,
4000
4250
  ...paginationArgs,
4001
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4251
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4002
4252
  });
4003
4253
  const coins = result.coins.edges.map((edge) => edge.node);
4004
4254
  return coins.map((coin) => ({
4005
4255
  id: coin.utxoId,
4006
4256
  assetId: coin.assetId,
4007
- amount: (0, import_math15.bn)(coin.amount),
4257
+ amount: (0, import_math16.bn)(coin.amount),
4008
4258
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4009
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4010
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4011
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4259
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4260
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4012
4261
  }));
4013
4262
  }
4014
4263
  /**
@@ -4022,19 +4271,19 @@ var _Provider = class {
4022
4271
  async getResourcesToSpend(owner, quantities, excludedIds) {
4023
4272
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4024
4273
  const excludeInput = {
4025
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4026
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4274
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4275
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4027
4276
  };
4028
4277
  if (this.cache) {
4029
4278
  const uniqueUtxos = new Set(
4030
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4279
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4031
4280
  );
4032
4281
  excludeInput.utxos = Array.from(uniqueUtxos);
4033
4282
  }
4034
4283
  const coinsQuery = {
4035
4284
  owner: ownerAddress.toB256(),
4036
4285
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4037
- assetId: (0, import_utils23.hexlify)(assetId),
4286
+ assetId: (0, import_utils22.hexlify)(assetId),
4038
4287
  amount: amount.toString(10),
4039
4288
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4040
4289
  })),
@@ -4045,9 +4294,9 @@ var _Provider = class {
4045
4294
  switch (coin.__typename) {
4046
4295
  case "MessageCoin":
4047
4296
  return {
4048
- amount: (0, import_math15.bn)(coin.amount),
4297
+ amount: (0, import_math16.bn)(coin.amount),
4049
4298
  assetId: coin.assetId,
4050
- daHeight: (0, import_math15.bn)(coin.daHeight),
4299
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4051
4300
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4052
4301
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4053
4302
  nonce: coin.nonce
@@ -4055,12 +4304,11 @@ var _Provider = class {
4055
4304
  case "Coin":
4056
4305
  return {
4057
4306
  id: coin.utxoId,
4058
- amount: (0, import_math15.bn)(coin.amount),
4307
+ amount: (0, import_math16.bn)(coin.amount),
4059
4308
  assetId: coin.assetId,
4060
4309
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4061
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4062
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4063
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4310
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4311
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4064
4312
  };
4065
4313
  default:
4066
4314
  return null;
@@ -4077,13 +4325,13 @@ var _Provider = class {
4077
4325
  async getBlock(idOrHeight) {
4078
4326
  let variables;
4079
4327
  if (typeof idOrHeight === "number") {
4080
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4328
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4081
4329
  } else if (idOrHeight === "latest") {
4082
4330
  variables = { height: (await this.getBlockNumber()).toString(10) };
4083
4331
  } else if (idOrHeight.length === 66) {
4084
4332
  variables = { blockId: idOrHeight };
4085
4333
  } else {
4086
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4334
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4087
4335
  }
4088
4336
  const { block } = await this.operations.getBlock(variables);
4089
4337
  if (!block) {
@@ -4091,7 +4339,7 @@ var _Provider = class {
4091
4339
  }
4092
4340
  return {
4093
4341
  id: block.id,
4094
- height: (0, import_math15.bn)(block.header.height),
4342
+ height: (0, import_math16.bn)(block.height),
4095
4343
  time: block.header.time,
4096
4344
  transactionIds: block.transactions.map((tx) => tx.id)
4097
4345
  };
@@ -4106,7 +4354,7 @@ var _Provider = class {
4106
4354
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4107
4355
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4108
4356
  id: block.id,
4109
- height: (0, import_math15.bn)(block.header.height),
4357
+ height: (0, import_math16.bn)(block.height),
4110
4358
  time: block.header.time,
4111
4359
  transactionIds: block.transactions.map((tx) => tx.id)
4112
4360
  }));
@@ -4121,7 +4369,7 @@ var _Provider = class {
4121
4369
  async getBlockWithTransactions(idOrHeight) {
4122
4370
  let variables;
4123
4371
  if (typeof idOrHeight === "number") {
4124
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4372
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4125
4373
  } else if (idOrHeight === "latest") {
4126
4374
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4127
4375
  } else {
@@ -4133,11 +4381,11 @@ var _Provider = class {
4133
4381
  }
4134
4382
  return {
4135
4383
  id: block.id,
4136
- height: (0, import_math15.bn)(block.header.height, 10),
4384
+ height: (0, import_math16.bn)(block.height, 10),
4137
4385
  time: block.header.time,
4138
4386
  transactionIds: block.transactions.map((tx) => tx.id),
4139
4387
  transactions: block.transactions.map(
4140
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4388
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4141
4389
  )
4142
4390
  };
4143
4391
  }
@@ -4152,8 +4400,8 @@ var _Provider = class {
4152
4400
  if (!transaction) {
4153
4401
  return null;
4154
4402
  }
4155
- return new import_transactions18.TransactionCoder().decode(
4156
- (0, import_utils23.arrayify)(transaction.rawPayload),
4403
+ return new import_transactions19.TransactionCoder().decode(
4404
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4157
4405
  0
4158
4406
  )?.[0];
4159
4407
  }
@@ -4180,9 +4428,9 @@ var _Provider = class {
4180
4428
  async getContractBalance(contractId, assetId) {
4181
4429
  const { contractBalance } = await this.operations.getContractBalance({
4182
4430
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4183
- asset: (0, import_utils23.hexlify)(assetId)
4431
+ asset: (0, import_utils22.hexlify)(assetId)
4184
4432
  });
4185
- return (0, import_math15.bn)(contractBalance.amount, 10);
4433
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4186
4434
  }
4187
4435
  /**
4188
4436
  * Returns the balance for the given owner for the given asset ID.
@@ -4194,9 +4442,9 @@ var _Provider = class {
4194
4442
  async getBalance(owner, assetId) {
4195
4443
  const { balance } = await this.operations.getBalance({
4196
4444
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4197
- assetId: (0, import_utils23.hexlify)(assetId)
4445
+ assetId: (0, import_utils22.hexlify)(assetId)
4198
4446
  });
4199
- return (0, import_math15.bn)(balance.amount, 10);
4447
+ return (0, import_math16.bn)(balance.amount, 10);
4200
4448
  }
4201
4449
  /**
4202
4450
  * Returns balances for the given owner.
@@ -4214,7 +4462,7 @@ var _Provider = class {
4214
4462
  const balances = result.balances.edges.map((edge) => edge.node);
4215
4463
  return balances.map((balance) => ({
4216
4464
  assetId: balance.assetId,
4217
- amount: (0, import_math15.bn)(balance.amount)
4465
+ amount: (0, import_math16.bn)(balance.amount)
4218
4466
  }));
4219
4467
  }
4220
4468
  /**
@@ -4232,19 +4480,19 @@ var _Provider = class {
4232
4480
  });
4233
4481
  const messages = result.messages.edges.map((edge) => edge.node);
4234
4482
  return messages.map((message) => ({
4235
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4483
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4236
4484
  sender: message.sender,
4237
4485
  recipient: message.recipient,
4238
4486
  nonce: message.nonce,
4239
- amount: (0, import_math15.bn)(message.amount),
4487
+ amount: (0, import_math16.bn)(message.amount),
4240
4488
  data: message.data
4241
4489
  }),
4242
4490
  sender: import_address3.Address.fromAddressOrString(message.sender),
4243
4491
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4244
4492
  nonce: message.nonce,
4245
- amount: (0, import_math15.bn)(message.amount),
4246
- data: import_transactions18.InputMessageCoder.decodeData(message.data),
4247
- daHeight: (0, import_math15.bn)(message.daHeight)
4493
+ amount: (0, import_math16.bn)(message.amount),
4494
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4495
+ daHeight: (0, import_math16.bn)(message.daHeight)
4248
4496
  }));
4249
4497
  }
4250
4498
  /**
@@ -4297,44 +4545,52 @@ var _Provider = class {
4297
4545
  } = result.messageProof;
4298
4546
  return {
4299
4547
  messageProof: {
4300
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4548
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4301
4549
  proofSet: messageProof.proofSet
4302
4550
  },
4303
4551
  blockProof: {
4304
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4552
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4305
4553
  proofSet: blockProof.proofSet
4306
4554
  },
4307
4555
  messageBlockHeader: {
4308
4556
  id: messageBlockHeader.id,
4309
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4310
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4557
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4558
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4311
4559
  transactionsRoot: messageBlockHeader.transactionsRoot,
4312
- height: (0, import_math15.bn)(messageBlockHeader.height),
4560
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4313
4561
  prevRoot: messageBlockHeader.prevRoot,
4314
4562
  time: messageBlockHeader.time,
4315
4563
  applicationHash: messageBlockHeader.applicationHash,
4316
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4317
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4564
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount)
4318
4565
  },
4319
4566
  commitBlockHeader: {
4320
4567
  id: commitBlockHeader.id,
4321
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4322
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4568
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4569
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4323
4570
  transactionsRoot: commitBlockHeader.transactionsRoot,
4324
- height: (0, import_math15.bn)(commitBlockHeader.height),
4571
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4325
4572
  prevRoot: commitBlockHeader.prevRoot,
4326
4573
  time: commitBlockHeader.time,
4327
4574
  applicationHash: commitBlockHeader.applicationHash,
4328
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4329
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4575
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount)
4330
4576
  },
4331
4577
  sender: import_address3.Address.fromAddressOrString(sender),
4332
4578
  recipient: import_address3.Address.fromAddressOrString(recipient),
4333
4579
  nonce,
4334
- amount: (0, import_math15.bn)(amount),
4580
+ amount: (0, import_math16.bn)(amount),
4335
4581
  data
4336
4582
  };
4337
4583
  }
4584
+ async getLatestGasPrice() {
4585
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4586
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4587
+ }
4588
+ async estimateGasPrice(blockHorizon) {
4589
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4590
+ blockHorizon: String(blockHorizon)
4591
+ });
4592
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4593
+ }
4338
4594
  /**
4339
4595
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4340
4596
  *
@@ -4354,10 +4610,10 @@ var _Provider = class {
4354
4610
  */
4355
4611
  async produceBlocks(amount, startTime) {
4356
4612
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4357
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4358
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4613
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4614
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4359
4615
  });
4360
- return (0, import_math15.bn)(latestBlockHeight);
4616
+ return (0, import_math16.bn)(latestBlockHeight);
4361
4617
  }
4362
4618
  // eslint-disable-next-line @typescript-eslint/require-await
4363
4619
  async getTransactionResponse(transactionId) {
@@ -4371,7 +4627,7 @@ cacheInputs_fn = function(inputs) {
4371
4627
  return;
4372
4628
  }
4373
4629
  inputs.forEach((input) => {
4374
- if (input.type === import_transactions18.InputType.Coin) {
4630
+ if (input.type === import_transactions19.InputType.Coin) {
4375
4631
  this.cache?.set(input.id);
4376
4632
  }
4377
4633
  });
@@ -4381,9 +4637,9 @@ __publicField(Provider, "nodeInfoCache", {});
4381
4637
 
4382
4638
  // src/providers/transaction-summary/get-transaction-summary.ts
4383
4639
  var import_errors15 = require("@fuel-ts/errors");
4384
- var import_math16 = require("@fuel-ts/math");
4385
- var import_transactions19 = require("@fuel-ts/transactions");
4386
- var import_utils26 = require("@fuel-ts/utils");
4640
+ var import_math17 = require("@fuel-ts/math");
4641
+ var import_transactions20 = require("@fuel-ts/transactions");
4642
+ var import_utils25 = require("@fuel-ts/utils");
4387
4643
 
4388
4644
  // src/providers/chains.ts
4389
4645
  var CHAIN_IDS = {
@@ -4432,17 +4688,17 @@ var assets = [
4432
4688
 
4433
4689
  // src/utils/formatTransferToContractScriptData.ts
4434
4690
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
4435
- var import_math17 = require("@fuel-ts/math");
4436
- var import_utils27 = require("@fuel-ts/utils");
4691
+ var import_math18 = require("@fuel-ts/math");
4692
+ var import_utils26 = require("@fuel-ts/utils");
4437
4693
  var asm = __toESM(require("@fuels/vm-asm"));
4438
4694
  var formatTransferToContractScriptData = (params) => {
4439
4695
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4440
4696
  const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4441
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4697
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4442
4698
  const scriptData = Uint8Array.from([
4443
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
4699
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4444
4700
  ...encoded,
4445
- ...(0, import_utils27.arrayify)(assetId)
4701
+ ...(0, import_utils26.arrayify)(assetId)
4446
4702
  ]);
4447
4703
  return scriptData;
4448
4704
  };
@@ -4627,36 +4883,33 @@ var Account = class extends import_interfaces.AbstractAccount {
4627
4883
  * @param fee - The estimated transaction fee.
4628
4884
  * @returns A promise that resolves when the resources are added to the transaction.
4629
4885
  */
4630
- async fund(request, coinQuantities, fee) {
4631
- const updatedQuantities = addAmountToAsset({
4632
- amount: (0, import_math18.bn)(fee),
4886
+ async fund(request, params) {
4887
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4888
+ const txRequest = request;
4889
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4890
+ amount: (0, import_math19.bn)(fee),
4633
4891
  assetId: import_configs12.BaseAssetId,
4634
- coinQuantities
4892
+ coinQuantities: requiredQuantities
4635
4893
  });
4636
4894
  const quantitiesDict = {};
4637
- updatedQuantities.forEach(({ amount, assetId }) => {
4895
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4638
4896
  quantitiesDict[assetId] = {
4639
4897
  required: amount,
4640
- owned: (0, import_math18.bn)(0)
4898
+ owned: (0, import_math19.bn)(0)
4641
4899
  };
4642
4900
  });
4643
- const cachedUtxos = [];
4644
- const cachedMessages = [];
4645
- const owner = this.address.toB256();
4646
- request.inputs.forEach((input) => {
4901
+ txRequest.inputs.forEach((input) => {
4647
4902
  const isResource = "amount" in input;
4648
4903
  if (isResource) {
4649
4904
  const isCoin2 = "owner" in input;
4650
4905
  if (isCoin2) {
4651
4906
  const assetId = String(input.assetId);
4652
- if (input.owner === owner && quantitiesDict[assetId]) {
4653
- const amount = (0, import_math18.bn)(input.amount);
4907
+ if (quantitiesDict[assetId]) {
4908
+ const amount = (0, import_math19.bn)(input.amount);
4654
4909
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4655
- cachedUtxos.push(input.id);
4656
4910
  }
4657
- } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
4911
+ } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
4658
4912
  quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
4659
- cachedMessages.push(input.nonce);
4660
4913
  }
4661
4914
  }
4662
4915
  });
@@ -4671,12 +4924,23 @@ var Account = class extends import_interfaces.AbstractAccount {
4671
4924
  });
4672
4925
  const needsToBeFunded = missingQuantities.length;
4673
4926
  if (needsToBeFunded) {
4674
- const resources = await this.getResourcesToSpend(missingQuantities, {
4675
- messages: cachedMessages,
4676
- utxos: cachedUtxos
4677
- });
4678
- request.addResources(resources);
4927
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
4928
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4929
+ txRequest.addResources(resources);
4930
+ }
4931
+ txRequest.shiftPredicateData();
4932
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
4933
+ const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
4934
+ if (addedSignatures) {
4935
+ Array.from({ length: addedSignatures }).forEach(
4936
+ () => requestToBeReEstimate.addEmptyWitness()
4937
+ );
4679
4938
  }
4939
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
4940
+ transactionRequest: requestToBeReEstimate
4941
+ });
4942
+ txRequest.maxFee = maxFee;
4943
+ return txRequest;
4680
4944
  }
4681
4945
  /**
4682
4946
  * A helper that creates a transfer transaction request and returns it.
@@ -4684,28 +4948,25 @@ var Account = class extends import_interfaces.AbstractAccount {
4684
4948
  * @param destination - The address of the destination.
4685
4949
  * @param amount - The amount of coins to transfer.
4686
4950
  * @param assetId - The asset ID of the coins to transfer.
4687
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4951
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4688
4952
  * @returns A promise that resolves to the prepared transaction request.
4689
4953
  */
4690
4954
  async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4691
- const { minGasPrice } = this.provider.getGasConfig();
4692
- const params = { gasPrice: minGasPrice, ...txParams };
4693
- const request = new ScriptTransactionRequest(params);
4955
+ const request = new ScriptTransactionRequest(txParams);
4694
4956
  request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
4695
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4957
+ const txCost = await this.provider.getTransactionCost(request, {
4696
4958
  estimateTxDependencies: true,
4697
4959
  resourcesOwner: this
4698
4960
  });
4699
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
4700
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
4701
- this.validateGas({
4702
- gasUsed,
4703
- gasPrice: request.gasPrice,
4704
- gasLimit: request.gasLimit,
4705
- minGasPrice
4706
- });
4707
- await this.fund(request, requiredQuantities, maxFee);
4708
- request.updatePredicateInputs(estimatedInputs);
4961
+ if ("gasLimit" in txParams) {
4962
+ this.validateGas({
4963
+ gasUsed: txCost.gasUsed,
4964
+ gasLimit: request.gasLimit
4965
+ });
4966
+ }
4967
+ request.gasLimit = txCost.gasUsed;
4968
+ request.maxFee = txCost.maxFee;
4969
+ await this.fund(request, txCost);
4709
4970
  return request;
4710
4971
  }
4711
4972
  /**
@@ -4718,7 +4979,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4718
4979
  * @returns A promise that resolves to the transaction response.
4719
4980
  */
4720
4981
  async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4721
- if ((0, import_math18.bn)(amount).lte(0)) {
4982
+ if ((0, import_math19.bn)(amount).lte(0)) {
4722
4983
  throw new import_errors16.FuelError(
4723
4984
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4724
4985
  "Transfer amount must be a positive number."
@@ -4737,38 +4998,37 @@ var Account = class extends import_interfaces.AbstractAccount {
4737
4998
  * @returns A promise that resolves to the transaction response.
4738
4999
  */
4739
5000
  async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4740
- if ((0, import_math18.bn)(amount).lte(0)) {
5001
+ if ((0, import_math19.bn)(amount).lte(0)) {
4741
5002
  throw new import_errors16.FuelError(
4742
5003
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4743
5004
  "Transfer amount must be a positive number."
4744
5005
  );
4745
5006
  }
4746
5007
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4747
- const { minGasPrice } = this.provider.getGasConfig();
4748
- const params = { gasPrice: minGasPrice, ...txParams };
4749
5008
  const { script, scriptData } = await assembleTransferToContractScript({
4750
5009
  hexlifiedContractId: contractAddress.toB256(),
4751
- amountToTransfer: (0, import_math18.bn)(amount),
5010
+ amountToTransfer: (0, import_math19.bn)(amount),
4752
5011
  assetId
4753
5012
  });
4754
5013
  const request = new ScriptTransactionRequest({
4755
- ...params,
5014
+ ...txParams,
4756
5015
  script,
4757
5016
  scriptData
4758
5017
  });
4759
5018
  request.addContractInputAndOutput(contractAddress);
4760
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4761
- request,
4762
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
4763
- );
4764
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4765
- this.validateGas({
4766
- gasUsed,
4767
- gasPrice: request.gasPrice,
4768
- gasLimit: request.gasLimit,
4769
- minGasPrice
5019
+ const txCost = await this.provider.getTransactionCost(request, {
5020
+ resourcesOwner: this,
5021
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
4770
5022
  });
4771
- await this.fund(request, requiredQuantities, maxFee);
5023
+ if (txParams.gasLimit) {
5024
+ this.validateGas({
5025
+ gasUsed: txCost.gasUsed,
5026
+ gasLimit: request.gasLimit
5027
+ });
5028
+ }
5029
+ request.gasLimit = txCost.gasUsed;
5030
+ request.maxFee = txCost.maxFee;
5031
+ await this.fund(request, txCost);
4772
5032
  return this.sendTransaction(request);
4773
5033
  }
4774
5034
  /**
@@ -4780,34 +5040,31 @@ var Account = class extends import_interfaces.AbstractAccount {
4780
5040
  * @returns A promise that resolves to the transaction response.
4781
5041
  */
4782
5042
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4783
- const { minGasPrice } = this.provider.getGasConfig();
4784
5043
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
4785
- const recipientDataArray = (0, import_utils28.arrayify)(
5044
+ const recipientDataArray = (0, import_utils27.arrayify)(
4786
5045
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4787
5046
  );
4788
- const amountDataArray = (0, import_utils28.arrayify)(
4789
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5047
+ const amountDataArray = (0, import_utils27.arrayify)(
5048
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
4790
5049
  );
4791
5050
  const script = new Uint8Array([
4792
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5051
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
4793
5052
  ...recipientDataArray,
4794
5053
  ...amountDataArray
4795
5054
  ]);
4796
- const params = { script, gasPrice: minGasPrice, ...txParams };
5055
+ const params = { script, ...txParams };
4797
5056
  const request = new ScriptTransactionRequest(params);
4798
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
4799
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4800
- request,
4801
- forwardingQuantities
4802
- );
4803
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4804
- this.validateGas({
4805
- gasUsed,
4806
- gasPrice: request.gasPrice,
4807
- gasLimit: request.gasLimit,
4808
- minGasPrice
4809
- });
4810
- await this.fund(request, requiredQuantities, maxFee);
5057
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5058
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5059
+ if (txParams.gasLimit) {
5060
+ this.validateGas({
5061
+ gasUsed: txCost.gasUsed,
5062
+ gasLimit: request.gasLimit
5063
+ });
5064
+ }
5065
+ request.maxFee = txCost.maxFee;
5066
+ request.gasLimit = txCost.gasUsed;
5067
+ await this.fund(request, txCost);
4811
5068
  return this.sendTransaction(request);
4812
5069
  }
4813
5070
  async signMessage(message) {
@@ -4865,18 +5122,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4865
5122
  }
4866
5123
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
4867
5124
  }
4868
- validateGas({
4869
- gasUsed,
4870
- gasPrice,
4871
- gasLimit,
4872
- minGasPrice
4873
- }) {
4874
- if (minGasPrice.gt(gasPrice)) {
4875
- throw new import_errors16.FuelError(
4876
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
4877
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
4878
- );
4879
- }
5125
+ validateGas({ gasUsed, gasLimit }) {
4880
5126
  if (gasUsed.gt(gasLimit)) {
4881
5127
  throw new import_errors16.FuelError(
4882
5128
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -4890,8 +5136,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4890
5136
  var import_address5 = require("@fuel-ts/address");
4891
5137
  var import_crypto = require("@fuel-ts/crypto");
4892
5138
  var import_hasher2 = require("@fuel-ts/hasher");
4893
- var import_math19 = require("@fuel-ts/math");
4894
- var import_utils29 = require("@fuel-ts/utils");
5139
+ var import_math20 = require("@fuel-ts/math");
5140
+ var import_utils28 = require("@fuel-ts/utils");
4895
5141
  var import_secp256k1 = require("@noble/curves/secp256k1");
4896
5142
  var Signer = class {
4897
5143
  address;
@@ -4910,10 +5156,10 @@ var Signer = class {
4910
5156
  privateKey = `0x${privateKey}`;
4911
5157
  }
4912
5158
  }
4913
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
4914
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
4915
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
4916
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5159
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5160
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5161
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5162
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
4917
5163
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
4918
5164
  }
4919
5165
  /**
@@ -4927,11 +5173,11 @@ var Signer = class {
4927
5173
  * @returns hashed signature
4928
5174
  */
4929
5175
  sign(data) {
4930
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
4931
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
4932
- const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5176
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5177
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5178
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
4933
5179
  s[0] |= (signature.recovery || 0) << 7;
4934
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5180
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
4935
5181
  }
4936
5182
  /**
4937
5183
  * Add point on the current elliptic curve
@@ -4940,8 +5186,8 @@ var Signer = class {
4940
5186
  * @returns compressed point on the curve
4941
5187
  */
4942
5188
  addPoint(point) {
4943
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
4944
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5189
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5190
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
4945
5191
  const result = p0.add(p1);
4946
5192
  return `0x${result.toHex(true)}`;
4947
5193
  }
@@ -4953,16 +5199,16 @@ var Signer = class {
4953
5199
  * @returns public key from signature from the
4954
5200
  */
4955
5201
  static recoverPublicKey(data, signature) {
4956
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5202
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
4957
5203
  const r = signedMessageBytes.slice(0, 32);
4958
5204
  const s = signedMessageBytes.slice(32, 64);
4959
5205
  const recoveryParam = (s[0] & 128) >> 7;
4960
5206
  s[0] &= 127;
4961
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5207
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
4962
5208
  recoveryParam
4963
5209
  );
4964
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
4965
- return (0, import_utils29.hexlify)(publicKey);
5210
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5211
+ return (0, import_utils28.hexlify)(publicKey);
4966
5212
  }
4967
5213
  /**
4968
5214
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -4981,7 +5227,7 @@ var Signer = class {
4981
5227
  * @returns random 32-byte hashed
4982
5228
  */
4983
5229
  static generatePrivateKey(entropy) {
4984
- return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
5230
+ return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
4985
5231
  }
4986
5232
  /**
4987
5233
  * Extended publicKey from a compact publicKey
@@ -4990,8 +5236,8 @@ var Signer = class {
4990
5236
  * @returns extended publicKey
4991
5237
  */
4992
5238
  static extendPublicKey(publicKey) {
4993
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
4994
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5239
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5240
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
4995
5241
  }
4996
5242
  };
4997
5243
 
@@ -4999,7 +5245,7 @@ var Signer = class {
4999
5245
  var import_address6 = require("@fuel-ts/address");
5000
5246
  var import_crypto2 = require("@fuel-ts/crypto");
5001
5247
  var import_errors17 = require("@fuel-ts/errors");
5002
- var import_utils30 = require("@fuel-ts/utils");
5248
+ var import_utils29 = require("@fuel-ts/utils");
5003
5249
  var import_uuid = require("uuid");
5004
5250
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5005
5251
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5082,7 +5328,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5082
5328
  );
5083
5329
  }
5084
5330
  const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5085
- const privateKey = (0, import_utils30.hexlify)(buffer);
5331
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5086
5332
  return privateKey;
5087
5333
  }
5088
5334
 
@@ -5127,7 +5373,7 @@ var BaseWalletUnlocked = class extends Account {
5127
5373
  */
5128
5374
  async signMessage(message) {
5129
5375
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5130
- return (0, import_utils31.hexlify)(signedMessage);
5376
+ return (0, import_utils30.hexlify)(signedMessage);
5131
5377
  }
5132
5378
  /**
5133
5379
  * Signs a transaction with the wallet's private key.
@@ -5140,7 +5386,7 @@ var BaseWalletUnlocked = class extends Account {
5140
5386
  const chainId = this.provider.getChainId();
5141
5387
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5142
5388
  const signature = await this.signer().sign(hashedTransaction);
5143
- return (0, import_utils31.hexlify)(signature);
5389
+ return (0, import_utils30.hexlify)(signature);
5144
5390
  }
5145
5391
  /**
5146
5392
  * Populates a transaction with the witnesses signature.
@@ -5160,7 +5406,7 @@ var BaseWalletUnlocked = class extends Account {
5160
5406
  * @param transactionRequestLike - The transaction request to send.
5161
5407
  * @returns A promise that resolves to the TransactionResponse object.
5162
5408
  */
5163
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5409
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5164
5410
  const transactionRequest = transactionRequestify(transactionRequestLike);
5165
5411
  if (estimateTxDependencies) {
5166
5412
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5201,16 +5447,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5201
5447
  // src/hdwallet/hdwallet.ts
5202
5448
  var import_errors20 = require("@fuel-ts/errors");
5203
5449
  var import_hasher6 = require("@fuel-ts/hasher");
5204
- var import_math20 = require("@fuel-ts/math");
5205
- var import_utils35 = require("@fuel-ts/utils");
5206
- var import_ethers3 = require("ethers");
5450
+ var import_math21 = require("@fuel-ts/math");
5451
+ var import_utils34 = require("@fuel-ts/utils");
5452
+ var import_ethers4 = require("ethers");
5207
5453
 
5208
5454
  // src/mnemonic/mnemonic.ts
5209
5455
  var import_crypto3 = require("@fuel-ts/crypto");
5210
5456
  var import_errors19 = require("@fuel-ts/errors");
5211
5457
  var import_hasher5 = require("@fuel-ts/hasher");
5212
- var import_utils33 = require("@fuel-ts/utils");
5213
- var import_ethers2 = require("ethers");
5458
+ var import_utils32 = require("@fuel-ts/utils");
5459
+ var import_ethers3 = require("ethers");
5214
5460
 
5215
5461
  // src/wordlists/words/english.ts
5216
5462
  var english = [
@@ -7267,7 +7513,7 @@ var english = [
7267
7513
  // src/mnemonic/utils.ts
7268
7514
  var import_errors18 = require("@fuel-ts/errors");
7269
7515
  var import_hasher4 = require("@fuel-ts/hasher");
7270
- var import_utils32 = require("@fuel-ts/utils");
7516
+ var import_utils31 = require("@fuel-ts/utils");
7271
7517
  function toUtf8Bytes(stri) {
7272
7518
  const str = stri.normalize("NFKD");
7273
7519
  const result = [];
@@ -7334,14 +7580,14 @@ function entropyToMnemonicIndices(entropy) {
7334
7580
  }
7335
7581
  }
7336
7582
  const checksumBits = entropy.length / 4;
7337
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7583
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7338
7584
  indices[indices.length - 1] <<= checksumBits;
7339
7585
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7340
7586
  return indices;
7341
7587
  }
7342
7588
  function mnemonicWordsToEntropy(words, wordlist) {
7343
7589
  const size = Math.ceil(11 * words.length / 8);
7344
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7590
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7345
7591
  let offset = 0;
7346
7592
  for (let i = 0; i < words.length; i += 1) {
7347
7593
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7361,7 +7607,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7361
7607
  const entropyBits = 32 * words.length / 3;
7362
7608
  const checksumBits = words.length / 3;
7363
7609
  const checksumMask = getUpperMask(checksumBits);
7364
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7610
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7365
7611
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7366
7612
  throw new import_errors18.FuelError(
7367
7613
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7436,7 +7682,7 @@ var Mnemonic = class {
7436
7682
  static mnemonicToEntropy(phrase, wordlist = english) {
7437
7683
  const words = getWords(phrase);
7438
7684
  assertMnemonic(words);
7439
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7685
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7440
7686
  }
7441
7687
  /**
7442
7688
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7444,7 +7690,7 @@ var Mnemonic = class {
7444
7690
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7445
7691
  */
7446
7692
  static entropyToMnemonic(entropy, wordlist = english) {
7447
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
7693
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7448
7694
  assertWordList(wordlist);
7449
7695
  assertEntropy(entropyBytes);
7450
7696
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7458,7 +7704,7 @@ var Mnemonic = class {
7458
7704
  assertMnemonic(getWords(phrase));
7459
7705
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7460
7706
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7461
- return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7707
+ return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7462
7708
  }
7463
7709
  /**
7464
7710
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7513,14 +7759,14 @@ var Mnemonic = class {
7513
7759
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7514
7760
  */
7515
7761
  static masterKeysFromSeed(seed) {
7516
- const seedArray = (0, import_utils33.arrayify)(seed);
7762
+ const seedArray = (0, import_utils32.arrayify)(seed);
7517
7763
  if (seedArray.length < 16 || seedArray.length > 64) {
7518
7764
  throw new import_errors19.FuelError(
7519
7765
  import_errors19.ErrorCode.INVALID_SEED,
7520
7766
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7521
7767
  );
7522
7768
  }
7523
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7769
+ return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
7524
7770
  }
7525
7771
  /**
7526
7772
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7531,22 +7777,22 @@ var Mnemonic = class {
7531
7777
  */
7532
7778
  static seedToExtendedKey(seed, testnet = false) {
7533
7779
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7534
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7780
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7535
7781
  const depth = "0x00";
7536
7782
  const fingerprint = "0x00000000";
7537
7783
  const index = "0x00000000";
7538
7784
  const chainCode = masterKey.slice(32);
7539
7785
  const privateKey = masterKey.slice(0, 32);
7540
- const extendedKey = (0, import_utils33.concat)([
7786
+ const extendedKey = (0, import_utils32.concat)([
7541
7787
  prefix,
7542
7788
  depth,
7543
7789
  fingerprint,
7544
7790
  index,
7545
7791
  chainCode,
7546
- (0, import_utils33.concat)(["0x00", privateKey])
7792
+ (0, import_utils32.concat)(["0x00", privateKey])
7547
7793
  ]);
7548
- const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7549
- return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
7794
+ const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7795
+ return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7550
7796
  }
7551
7797
  /**
7552
7798
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7561,7 +7807,7 @@ var Mnemonic = class {
7561
7807
  * @returns A randomly generated mnemonic
7562
7808
  */
7563
7809
  static generate(size = 32, extraEntropy = "") {
7564
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7810
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7565
7811
  return Mnemonic.entropyToMnemonic(entropy);
7566
7812
  }
7567
7813
  };
@@ -7569,12 +7815,12 @@ var mnemonic_default = Mnemonic;
7569
7815
 
7570
7816
  // src/hdwallet/hdwallet.ts
7571
7817
  var HARDENED_INDEX = 2147483648;
7572
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
7573
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
7574
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
7575
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
7818
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
7819
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7820
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7821
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7576
7822
  function base58check(data) {
7577
- return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7823
+ return (0, import_ethers4.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7578
7824
  }
7579
7825
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7580
7826
  if (isPublic) {
@@ -7583,11 +7829,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7583
7829
  return testnet ? TestnetPRV2 : MainnetPRV2;
7584
7830
  }
7585
7831
  function isPublicExtendedKey(extendedKey) {
7586
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
7832
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
7587
7833
  }
7588
7834
  function isValidExtendedKey(extendedKey) {
7589
7835
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
7590
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
7836
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
7591
7837
  );
7592
7838
  }
7593
7839
  function parsePath(path2, depth = 0) {
@@ -7605,8 +7851,8 @@ function parsePath(path2, depth = 0) {
7605
7851
  var HDWallet = class {
7606
7852
  depth = 0;
7607
7853
  index = 0;
7608
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
7609
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
7854
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
7855
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
7610
7856
  privateKey;
7611
7857
  publicKey;
7612
7858
  chainCode;
@@ -7618,8 +7864,8 @@ var HDWallet = class {
7618
7864
  constructor(config) {
7619
7865
  if (config.privateKey) {
7620
7866
  const signer = new Signer(config.privateKey);
7621
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
7622
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
7867
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
7868
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
7623
7869
  } else {
7624
7870
  if (!config.publicKey) {
7625
7871
  throw new import_errors20.FuelError(
@@ -7627,10 +7873,10 @@ var HDWallet = class {
7627
7873
  "Both public and private Key cannot be missing. At least one should be provided."
7628
7874
  );
7629
7875
  }
7630
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
7876
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7631
7877
  }
7632
7878
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7633
- this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7879
+ this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7634
7880
  this.depth = config.depth || this.depth;
7635
7881
  this.index = config.index || this.index;
7636
7882
  this.chainCode = config.chainCode;
@@ -7646,9 +7892,9 @@ var HDWallet = class {
7646
7892
  * @returns A new instance of HDWallet on the derived index
7647
7893
  */
7648
7894
  deriveIndex(index) {
7649
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
7650
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
7651
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
7895
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
7896
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
7897
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
7652
7898
  const data = new Uint8Array(37);
7653
7899
  if (index & HARDENED_INDEX) {
7654
7900
  if (!privateKey) {
@@ -7659,15 +7905,15 @@ var HDWallet = class {
7659
7905
  }
7660
7906
  data.set(privateKey, 1);
7661
7907
  } else {
7662
- data.set((0, import_utils35.arrayify)(this.publicKey));
7908
+ data.set((0, import_utils34.arrayify)(this.publicKey));
7663
7909
  }
7664
- data.set((0, import_math20.toBytes)(index, 4), 33);
7665
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7910
+ data.set((0, import_math21.toBytes)(index, 4), 33);
7911
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
7666
7912
  const IL = bytes.slice(0, 32);
7667
7913
  const IR = bytes.slice(32);
7668
7914
  if (privateKey) {
7669
7915
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7670
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
7916
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
7671
7917
  return new HDWallet({
7672
7918
  privateKey: ki,
7673
7919
  chainCode: IR,
@@ -7676,7 +7922,7 @@ var HDWallet = class {
7676
7922
  parentFingerprint: this.fingerprint
7677
7923
  });
7678
7924
  }
7679
- const signer = new Signer((0, import_utils35.hexlify)(IL));
7925
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
7680
7926
  const Ki = signer.addPoint(publicKey);
7681
7927
  return new HDWallet({
7682
7928
  publicKey: Ki,
@@ -7711,12 +7957,12 @@ var HDWallet = class {
7711
7957
  );
7712
7958
  }
7713
7959
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
7714
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
7960
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
7715
7961
  const parentFingerprint = this.parentFingerprint;
7716
- const index = (0, import_math20.toHex)(this.index, 4);
7962
+ const index = (0, import_math21.toHex)(this.index, 4);
7717
7963
  const chainCode = this.chainCode;
7718
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
7719
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7964
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
7965
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7720
7966
  return base58check(extendedKey);
7721
7967
  }
7722
7968
  /**
@@ -7728,13 +7974,13 @@ var HDWallet = class {
7728
7974
  static fromSeed(seed) {
7729
7975
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
7730
7976
  return new HDWallet({
7731
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
7732
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
7977
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
7978
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
7733
7979
  });
7734
7980
  }
7735
7981
  static fromExtendedKey(extendedKey) {
7736
- const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7737
- const bytes = (0, import_utils35.arrayify)(decoded);
7982
+ const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
7983
+ const bytes = (0, import_utils34.arrayify)(decoded);
7738
7984
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7739
7985
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7740
7986
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -7743,9 +7989,9 @@ var HDWallet = class {
7743
7989
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7744
7990
  }
7745
7991
  const depth = bytes[4];
7746
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
7747
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7748
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
7992
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
7993
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7994
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
7749
7995
  const key = bytes.slice(45, 78);
7750
7996
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7751
7997
  throw new import_errors20.FuelError(
@@ -7938,14 +8184,15 @@ var seedTestWallet = async (wallet, quantities) => {
7938
8184
  process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
7939
8185
  wallet.provider
7940
8186
  );
7941
- const resources = await genesisWallet.getResourcesToSpend(quantities);
7942
- const { minGasPrice } = genesisWallet.provider.getGasConfig();
7943
- const request = new ScriptTransactionRequest({
7944
- gasLimit: 1e4,
7945
- gasPrice: minGasPrice
8187
+ const request = new ScriptTransactionRequest();
8188
+ quantities.forEach((quantity) => {
8189
+ const { amount, assetId } = coinQuantityfy(quantity);
8190
+ request.addCoinOutput(wallet.address, amount, assetId);
7946
8191
  });
7947
- request.addResources(resources);
7948
- quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
8192
+ const txCost = await genesisWallet.provider.getTransactionCost(request);
8193
+ request.gasLimit = txCost.gasUsed;
8194
+ request.maxFee = txCost.maxFee;
8195
+ await genesisWallet.fund(request, txCost);
7949
8196
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
7950
8197
  };
7951
8198
 
@@ -7960,11 +8207,11 @@ var generateTestWallet = async (provider, quantities) => {
7960
8207
 
7961
8208
  // src/test-utils/launchNode.ts
7962
8209
  var import_configs13 = require("@fuel-ts/address/configs");
7963
- var import_math21 = require("@fuel-ts/math");
7964
- var import_utils36 = require("@fuel-ts/utils");
8210
+ var import_utils35 = require("@fuel-ts/utils");
7965
8211
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
7966
8212
  var import_child_process = require("child_process");
7967
8213
  var import_crypto5 = require("crypto");
8214
+ var import_ethers5 = require("ethers");
7968
8215
  var import_fs = require("fs");
7969
8216
  var import_os = __toESM(require("os"));
7970
8217
  var import_path = __toESM(require("path"));
@@ -8013,13 +8260,13 @@ var launchNode = async ({
8013
8260
  // eslint-disable-next-line no-async-promise-executor
8014
8261
  new Promise(async (resolve, reject) => {
8015
8262
  const remainingArgs = extractRemainingArgs(args, [
8016
- "--chain",
8263
+ "--snapshot",
8017
8264
  "--consensus-key",
8018
8265
  "--db-type",
8019
8266
  "--poa-instant"
8020
8267
  ]);
8021
- const chainConfigPath = getFlagValueFromArgs(args, "--chain");
8022
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8268
+ const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
8269
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
8023
8270
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8024
8271
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8025
8272
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
@@ -8037,36 +8284,54 @@ var launchNode = async ({
8037
8284
  let chainConfigPathToUse;
8038
8285
  const prefix = basePath || import_os.default.tmpdir();
8039
8286
  const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
8040
- const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
8287
+ const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "chainConfigs");
8041
8288
  if (chainConfigPath) {
8042
8289
  chainConfigPathToUse = chainConfigPath;
8043
8290
  } else {
8044
8291
  if (!(0, import_fs.existsSync)(tempDirPath)) {
8045
8292
  (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8046
8293
  }
8047
- const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
8048
- let chainConfig = import_utils36.defaultChainConfig;
8294
+ let { stateConfigJson } = import_utils35.defaultChainConfigs;
8295
+ const { chainConfigJson, metadataJson } = import_utils35.defaultChainConfigs;
8296
+ stateConfigJson = {
8297
+ ...stateConfigJson,
8298
+ coins: [
8299
+ ...stateConfigJson.coins.map((coin) => ({
8300
+ ...coin,
8301
+ amount: "18446744073709551615"
8302
+ }))
8303
+ ],
8304
+ messages: stateConfigJson.messages.map((message) => ({
8305
+ ...message,
8306
+ amount: "18446744073709551615"
8307
+ }))
8308
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8309
+ };
8049
8310
  if (!process.env.GENESIS_SECRET) {
8050
8311
  const pk = Signer.generatePrivateKey();
8051
8312
  const signer = new Signer(pk);
8052
- process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8053
- chainConfig = {
8054
- ...import_utils36.defaultChainConfig,
8055
- initial_state: {
8056
- ...import_utils36.defaultChainConfig.initial_state,
8057
- coins: [
8058
- ...import_utils36.defaultChainConfig.initial_state.coins,
8059
- {
8060
- owner: signer.address.toHexString(),
8061
- amount: (0, import_math21.toHex)(1e9),
8062
- asset_id: import_configs13.BaseAssetId
8063
- }
8064
- ]
8065
- }
8066
- };
8313
+ process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
8314
+ stateConfigJson.coins.push({
8315
+ tx_id: (0, import_utils35.hexlify)((0, import_ethers5.randomBytes)(34)),
8316
+ owner: signer.address.toHexString(),
8317
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8318
+ amount: "18446744073709551615",
8319
+ asset_id: import_configs13.BaseAssetId,
8320
+ output_index: 0,
8321
+ tx_pointer_block_height: 0,
8322
+ tx_pointer_tx_idx: 0
8323
+ });
8067
8324
  }
8068
- (0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
8069
- chainConfigPathToUse = tempChainConfigFilePath;
8325
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8326
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8327
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8328
+ const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8329
+ const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8330
+ const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8331
+ (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8332
+ (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8333
+ (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8334
+ chainConfigPathToUse = tempDirPath;
8070
8335
  }
8071
8336
  const child = (0, import_child_process.spawn)(
8072
8337
  command,
@@ -8075,10 +8340,10 @@ var launchNode = async ({
8075
8340
  ["--ip", ipToUse],
8076
8341
  ["--port", portToUse],
8077
8342
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8078
- ["--min-gas-price", "0"],
8343
+ ["--min-gas-price", "1"],
8079
8344
  poaInstant ? ["--poa-instant", "true"] : [],
8080
8345
  ["--consensus-key", consensusKey],
8081
- ["--chain", chainConfigPathToUse],
8346
+ ["--snapshot", chainConfigPathToUse],
8082
8347
  "--vm-backtrace",
8083
8348
  "--utxo-validation",
8084
8349
  "--debug",
@@ -8137,7 +8402,7 @@ var launchNodeAndGetWallets = async ({
8137
8402
  walletCount = 10
8138
8403
  } = {}) => {
8139
8404
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8140
- const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8405
+ const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8141
8406
  const wallets = await generateWallets(walletCount, provider);
8142
8407
  const cleanup = () => {
8143
8408
  closeNode();