@fuel-ts/account 0.0.0-rc-1976-20240419101644 → 0.0.0-rc-2021-20240419145341

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 (56) 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 +830 -604
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +833 -601
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +675 -444
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +10 -2
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +906 -324
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +3 -3
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +7 -1
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +37 -34
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  30. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/input.d.ts +2 -2
  32. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
  34. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
  36. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  37. package/dist/providers/transaction-request/utils.d.ts +3 -0
  38. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  39. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  40. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  41. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  43. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  44. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  45. package/dist/providers/utils/gas.d.ts +8 -2
  46. package/dist/providers/utils/gas.d.ts.map +1 -1
  47. package/dist/test-utils/launchNode.d.ts.map +1 -1
  48. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  49. package/dist/test-utils.global.js +1579 -1118
  50. package/dist/test-utils.global.js.map +1 -1
  51. package/dist/test-utils.js +811 -600
  52. package/dist/test-utils.js.map +1 -1
  53. package/dist/test-utils.mjs +667 -456
  54. package/dist/test-utils.mjs.map +1 -1
  55. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  56. package/package.json +16 -16
@@ -58,39 +58,42 @@ module.exports = __toCommonJS(test_utils_exports);
58
58
 
59
59
  // src/wallet/base-wallet-unlocked.ts
60
60
  var import_hasher3 = require("@fuel-ts/hasher");
61
- var import_utils31 = require("@fuel-ts/utils");
61
+ var import_utils30 = require("@fuel-ts/utils");
62
62
 
63
63
  // src/account.ts
64
64
  var import_address4 = require("@fuel-ts/address");
65
+ var import_configs12 = require("@fuel-ts/address/configs");
65
66
  var import_errors16 = require("@fuel-ts/errors");
66
67
  var import_interfaces = require("@fuel-ts/interfaces");
67
- var import_math18 = require("@fuel-ts/math");
68
- var import_utils28 = require("@fuel-ts/utils");
68
+ var import_math19 = require("@fuel-ts/math");
69
+ var import_utils27 = require("@fuel-ts/utils");
70
+ var import_ramda4 = require("ramda");
69
71
 
70
72
  // src/providers/coin-quantity.ts
73
+ var import_configs = require("@fuel-ts/address/configs");
71
74
  var import_math = require("@fuel-ts/math");
72
75
  var import_utils = require("@fuel-ts/utils");
73
76
  var coinQuantityfy = (coinQuantityLike) => {
74
77
  let assetId;
75
78
  let amount;
76
- let max2;
79
+ let max;
77
80
  if (Array.isArray(coinQuantityLike)) {
78
81
  amount = coinQuantityLike[0];
79
- assetId = coinQuantityLike[1];
80
- max2 = coinQuantityLike[2];
82
+ assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
83
+ max = coinQuantityLike[2] ?? void 0;
81
84
  } else {
82
85
  amount = coinQuantityLike.amount;
83
- assetId = coinQuantityLike.assetId;
84
- max2 = coinQuantityLike.max ?? void 0;
86
+ assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
87
+ max = coinQuantityLike.max ?? void 0;
85
88
  }
86
89
  const bnAmount = (0, import_math.bn)(amount);
87
90
  return {
88
91
  assetId: (0, import_utils.hexlify)(assetId),
89
92
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
90
- max: max2 ? (0, import_math.bn)(max2) : void 0
93
+ max: max ? (0, import_math.bn)(max) : void 0
91
94
  };
92
95
  };
93
- var addAmountToAsset = (params) => {
96
+ var addAmountToCoinQuantities = (params) => {
94
97
  const { amount, assetId } = params;
95
98
  const coinQuantities = [...params.coinQuantities];
96
99
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -105,11 +108,11 @@ var addAmountToAsset = (params) => {
105
108
  // src/providers/provider.ts
106
109
  var import_address3 = require("@fuel-ts/address");
107
110
  var import_errors14 = require("@fuel-ts/errors");
108
- var import_math15 = require("@fuel-ts/math");
109
- var import_transactions18 = require("@fuel-ts/transactions");
110
- var import_utils23 = require("@fuel-ts/utils");
111
+ var import_math16 = require("@fuel-ts/math");
112
+ var import_transactions19 = require("@fuel-ts/transactions");
113
+ var import_utils22 = require("@fuel-ts/utils");
111
114
  var import_versions = require("@fuel-ts/versions");
112
- var import_utils24 = require("@noble/curves/abstract/utils");
115
+ var import_utils23 = require("@noble/curves/abstract/utils");
113
116
  var import_ethers = require("ethers");
114
117
  var import_graphql_request = require("graphql-request");
115
118
  var import_ramda3 = require("ramda");
@@ -118,14 +121,10 @@ var import_ramda3 = require("ramda");
118
121
  var import_graphql_tag = __toESM(require("graphql-tag"));
119
122
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
120
123
  fragment receiptFragment on Receipt {
121
- contract {
122
- id
123
- }
124
+ id
124
125
  pc
125
126
  is
126
- to {
127
- id
128
- }
127
+ to
129
128
  toAddress
130
129
  amount
131
130
  assetId
@@ -163,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
163
162
  id
164
163
  }
165
164
  time
165
+ receipts {
166
+ ...receiptFragment
167
+ }
166
168
  programState {
167
169
  returnType
168
170
  data
169
171
  }
172
+ receipts {
173
+ ...receiptFragment
174
+ }
170
175
  }
171
176
  ... on FailureStatus {
172
177
  block {
@@ -174,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
174
179
  }
175
180
  time
176
181
  reason
182
+ receipts {
183
+ ...receiptFragment
184
+ }
177
185
  }
178
186
  ... on SqueezedOutStatus {
179
187
  reason
180
188
  }
181
189
  }
182
- `;
190
+ ${ReceiptFragmentFragmentDoc}`;
183
191
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
184
192
  fragment transactionFragment on Transaction {
185
193
  id
186
194
  rawPayload
187
- gasPrice
188
- receipts {
189
- ...receiptFragment
190
- }
191
195
  status {
192
196
  ...transactionStatusFragment
193
197
  }
194
198
  }
195
- ${ReceiptFragmentFragmentDoc}
196
- ${TransactionStatusFragmentFragmentDoc}`;
199
+ ${TransactionStatusFragmentFragmentDoc}`;
197
200
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
198
201
  fragment inputEstimatePredicatesFragment on Input {
199
202
  ... on InputCoin {
@@ -211,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
211
214
  }
212
215
  }
213
216
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
217
+ var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
218
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
219
+ reason
220
+ programState {
221
+ returnType
222
+ data
223
+ }
224
+ }
225
+ `;
226
+ var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
227
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
228
+ programState {
229
+ returnType
230
+ data
231
+ }
232
+ }
233
+ `;
234
+ var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
235
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
236
+ ... on DryRunFailureStatus {
237
+ ...dryRunFailureStatusFragment
238
+ }
239
+ ... on DryRunSuccessStatus {
240
+ ...dryRunSuccessStatusFragment
241
+ }
242
+ }
243
+ ${DryRunFailureStatusFragmentFragmentDoc}
244
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
245
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
246
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
247
+ id
248
+ status {
249
+ ...dryRunTransactionStatusFragment
250
+ }
251
+ receipts {
252
+ ...receiptFragment
253
+ }
254
+ }
255
+ ${DryRunTransactionStatusFragmentFragmentDoc}
256
+ ${ReceiptFragmentFragmentDoc}`;
214
257
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
215
258
  fragment coinFragment on Coin {
216
259
  __typename
@@ -218,7 +261,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
218
261
  owner
219
262
  amount
220
263
  assetId
221
- maturity
222
264
  blockCreated
223
265
  txCreatedIdx
224
266
  }
@@ -257,26 +299,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
257
299
  messageBlockHeader {
258
300
  id
259
301
  daHeight
302
+ consensusParametersVersion
303
+ stateTransitionBytecodeVersion
260
304
  transactionsCount
305
+ messageReceiptCount
261
306
  transactionsRoot
307
+ messageOutboxRoot
308
+ eventInboxRoot
262
309
  height
263
310
  prevRoot
264
311
  time
265
312
  applicationHash
266
- messageReceiptRoot
267
- messageReceiptCount
268
313
  }
269
314
  commitBlockHeader {
270
315
  id
271
316
  daHeight
317
+ consensusParametersVersion
318
+ stateTransitionBytecodeVersion
272
319
  transactionsCount
320
+ messageReceiptCount
273
321
  transactionsRoot
322
+ messageOutboxRoot
323
+ eventInboxRoot
274
324
  height
275
325
  prevRoot
276
326
  time
277
327
  applicationHash
278
- messageReceiptRoot
279
- messageReceiptCount
280
328
  }
281
329
  sender
282
330
  recipient
@@ -295,8 +343,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
295
343
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
296
344
  fragment blockFragment on Block {
297
345
  id
346
+ height
298
347
  header {
299
- height
300
348
  time
301
349
  }
302
350
  transactions {
@@ -354,6 +402,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
354
402
  `;
355
403
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
356
404
  fragment GasCostsFragment on GasCosts {
405
+ version {
406
+ ... on Version {
407
+ value
408
+ }
409
+ }
357
410
  add
358
411
  addi
359
412
  aloc
@@ -366,7 +419,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
366
419
  cb
367
420
  cfei
368
421
  cfsi
369
- croo
370
422
  div
371
423
  divi
372
424
  ecr1
@@ -449,6 +501,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
449
501
  ccp {
450
502
  ...DependentCostFragment
451
503
  }
504
+ croo {
505
+ ...DependentCostFragment
506
+ }
452
507
  csiz {
453
508
  ...DependentCostFragment
454
509
  }
@@ -508,6 +563,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
508
563
  ${DependentCostFragmentFragmentDoc}`;
509
564
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
510
565
  fragment consensusParametersFragment on ConsensusParameters {
566
+ version {
567
+ ... on Version {
568
+ value
569
+ }
570
+ }
511
571
  txParams {
512
572
  ...TxParametersFragment
513
573
  }
@@ -567,18 +627,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
567
627
  fragment nodeInfoFragment on NodeInfo {
568
628
  utxoValidation
569
629
  vmBacktrace
570
- minGasPrice
571
630
  maxTx
572
631
  maxDepth
573
632
  nodeVersion
574
- peers {
575
- id
576
- addresses
577
- clientVersion
578
- blockHeight
579
- lastHeartbeatMs
580
- appScore
581
- }
582
633
  }
583
634
  `;
584
635
  var GetVersionDocument = import_graphql_tag.default`
@@ -613,13 +664,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
613
664
  query getTransactionWithReceipts($transactionId: TransactionId!) {
614
665
  transaction(id: $transactionId) {
615
666
  ...transactionFragment
616
- receipts {
617
- ...receiptFragment
618
- }
619
667
  }
620
668
  }
621
- ${TransactionFragmentFragmentDoc}
622
- ${ReceiptFragmentFragmentDoc}`;
669
+ ${TransactionFragmentFragmentDoc}`;
623
670
  var GetTransactionsDocument = import_graphql_tag.default`
624
671
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
625
672
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -747,6 +794,20 @@ var GetBalanceDocument = import_graphql_tag.default`
747
794
  }
748
795
  }
749
796
  ${BalanceFragmentFragmentDoc}`;
797
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
798
+ query getLatestGasPrice {
799
+ latestGasPrice {
800
+ gasPrice
801
+ }
802
+ }
803
+ `;
804
+ var EstimateGasPriceDocument = import_graphql_tag.default`
805
+ query estimateGasPrice($blockHorizon: U32!) {
806
+ estimateGasPrice(blockHorizon: $blockHorizon) {
807
+ gasPrice
808
+ }
809
+ }
810
+ `;
750
811
  var GetBalancesDocument = import_graphql_tag.default`
751
812
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
752
813
  balances(
@@ -801,12 +862,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
801
862
  }
802
863
  `;
803
864
  var DryRunDocument = import_graphql_tag.default`
804
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
805
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
806
- ...receiptFragment
865
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
866
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
867
+ ...dryRunTransactionExecutionStatusFragment
807
868
  }
808
869
  }
809
- ${ReceiptFragmentFragmentDoc}`;
870
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
810
871
  var SubmitDocument = import_graphql_tag.default`
811
872
  mutation submit($encodedTransaction: HexString!) {
812
873
  submit(tx: $encodedTransaction) {
@@ -889,6 +950,12 @@ function getSdk(requester) {
889
950
  getBalance(variables, options) {
890
951
  return requester(GetBalanceDocument, variables, options);
891
952
  },
953
+ getLatestGasPrice(variables, options) {
954
+ return requester(GetLatestGasPriceDocument, variables, options);
955
+ },
956
+ estimateGasPrice(variables, options) {
957
+ return requester(EstimateGasPriceDocument, variables, options);
958
+ },
892
959
  getBalances(variables, options) {
893
960
  return requester(GetBalancesDocument, variables, options);
894
961
  },
@@ -1059,7 +1126,7 @@ var MemoryCache = class {
1059
1126
 
1060
1127
  // src/providers/transaction-request/input.ts
1061
1128
  var import_abi_coder = require("@fuel-ts/abi-coder");
1062
- var import_configs = require("@fuel-ts/address/configs");
1129
+ var import_configs2 = require("@fuel-ts/address/configs");
1063
1130
  var import_errors3 = require("@fuel-ts/errors");
1064
1131
  var import_math2 = require("@fuel-ts/math");
1065
1132
  var import_transactions = require("@fuel-ts/transactions");
@@ -1082,10 +1149,9 @@ var inputify = (value) => {
1082
1149
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1083
1150
  },
1084
1151
  witnessIndex: value.witnessIndex,
1085
- maturity: value.maturity ?? 0,
1086
1152
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1087
- predicateLength: predicate.length,
1088
- predicateDataLength: predicateData.length,
1153
+ predicateLength: (0, import_math2.bn)(predicate.length),
1154
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1089
1155
  predicate: (0, import_utils3.hexlify)(predicate),
1090
1156
  predicateData: (0, import_utils3.hexlify)(predicateData)
1091
1157
  };
@@ -1093,10 +1159,10 @@ var inputify = (value) => {
1093
1159
  case import_transactions.InputType.Contract: {
1094
1160
  return {
1095
1161
  type: import_transactions.InputType.Contract,
1096
- txID: import_configs.ZeroBytes32,
1162
+ txID: import_configs2.ZeroBytes32,
1097
1163
  outputIndex: 0,
1098
- balanceRoot: import_configs.ZeroBytes32,
1099
- stateRoot: import_configs.ZeroBytes32,
1164
+ balanceRoot: import_configs2.ZeroBytes32,
1165
+ stateRoot: import_configs2.ZeroBytes32,
1100
1166
  txPointer: {
1101
1167
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1102
1168
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1116,8 +1182,8 @@ var inputify = (value) => {
1116
1182
  nonce: (0, import_utils3.hexlify)(value.nonce),
1117
1183
  witnessIndex: value.witnessIndex,
1118
1184
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1119
- predicateLength: predicate.length,
1120
- predicateDataLength: predicateData.length,
1185
+ predicateLength: (0, import_math2.bn)(predicate.length),
1186
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1121
1187
  predicate: (0, import_utils3.hexlify)(predicate),
1122
1188
  predicateData: (0, import_utils3.hexlify)(predicateData),
1123
1189
  data: (0, import_utils3.hexlify)(data),
@@ -1134,7 +1200,7 @@ var inputify = (value) => {
1134
1200
  };
1135
1201
 
1136
1202
  // src/providers/transaction-request/output.ts
1137
- var import_configs2 = require("@fuel-ts/address/configs");
1203
+ var import_configs3 = require("@fuel-ts/address/configs");
1138
1204
  var import_errors4 = require("@fuel-ts/errors");
1139
1205
  var import_math3 = require("@fuel-ts/math");
1140
1206
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1154,8 +1220,8 @@ var outputify = (value) => {
1154
1220
  return {
1155
1221
  type: import_transactions2.OutputType.Contract,
1156
1222
  inputIndex: value.inputIndex,
1157
- balanceRoot: import_configs2.ZeroBytes32,
1158
- stateRoot: import_configs2.ZeroBytes32
1223
+ balanceRoot: import_configs3.ZeroBytes32,
1224
+ stateRoot: import_configs3.ZeroBytes32
1159
1225
  };
1160
1226
  }
1161
1227
  case import_transactions2.OutputType.Change: {
@@ -1169,9 +1235,9 @@ var outputify = (value) => {
1169
1235
  case import_transactions2.OutputType.Variable: {
1170
1236
  return {
1171
1237
  type: import_transactions2.OutputType.Variable,
1172
- to: import_configs2.ZeroBytes32,
1238
+ to: import_configs3.ZeroBytes32,
1173
1239
  amount: (0, import_math3.bn)(0),
1174
- assetId: import_configs2.ZeroBytes32
1240
+ assetId: import_configs3.ZeroBytes32
1175
1241
  };
1176
1242
  }
1177
1243
  case import_transactions2.OutputType.ContractCreated: {
@@ -1193,7 +1259,7 @@ var outputify = (value) => {
1193
1259
  // src/providers/transaction-request/transaction-request.ts
1194
1260
  var import_abi_coder2 = require("@fuel-ts/abi-coder");
1195
1261
  var import_address = require("@fuel-ts/address");
1196
- var import_configs6 = require("@fuel-ts/address/configs");
1262
+ var import_configs7 = require("@fuel-ts/address/configs");
1197
1263
  var import_crypto = require("@fuel-ts/crypto");
1198
1264
  var import_math7 = require("@fuel-ts/math");
1199
1265
  var import_transactions6 = require("@fuel-ts/transactions");
@@ -1203,13 +1269,13 @@ var import_utils9 = require("@fuel-ts/utils");
1203
1269
  var isCoin = (resource) => "id" in resource;
1204
1270
 
1205
1271
  // src/providers/utils/receipts.ts
1206
- var import_configs3 = require("@fuel-ts/address/configs");
1272
+ var import_configs4 = require("@fuel-ts/address/configs");
1207
1273
  var import_errors5 = require("@fuel-ts/errors");
1208
1274
  var import_math4 = require("@fuel-ts/math");
1209
1275
  var import_transactions3 = require("@fuel-ts/transactions");
1210
- var import_configs4 = require("@fuel-ts/transactions/configs");
1276
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1211
1277
  var import_utils5 = require("@fuel-ts/utils");
1212
- var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1278
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1213
1279
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1214
1280
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1215
1281
  (memo, receipt) => {
@@ -1226,15 +1292,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1226
1292
  missingOutputContractIds: []
1227
1293
  }
1228
1294
  );
1229
- var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1295
+ var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1230
1296
  function assembleReceiptByType(receipt) {
1231
1297
  const { receiptType } = receipt;
1232
1298
  switch (receiptType) {
1233
1299
  case "CALL" /* Call */: {
1234
1300
  const callReceipt = {
1235
1301
  type: import_transactions3.ReceiptType.Call,
1236
- from: hexOrZero(receipt.contract?.id),
1237
- to: hexOrZero(receipt?.to?.id),
1302
+ from: hexOrZero(receipt.id || receipt.contractId),
1303
+ to: hexOrZero(receipt?.to),
1238
1304
  amount: (0, import_math4.bn)(receipt.amount),
1239
1305
  assetId: hexOrZero(receipt.assetId),
1240
1306
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1248,7 +1314,7 @@ function assembleReceiptByType(receipt) {
1248
1314
  case "RETURN" /* Return */: {
1249
1315
  const returnReceipt = {
1250
1316
  type: import_transactions3.ReceiptType.Return,
1251
- id: hexOrZero(receipt.contract?.id),
1317
+ id: hexOrZero(receipt.id || receipt.contractId),
1252
1318
  val: (0, import_math4.bn)(receipt.val),
1253
1319
  pc: (0, import_math4.bn)(receipt.pc),
1254
1320
  is: (0, import_math4.bn)(receipt.is)
@@ -1258,7 +1324,7 @@ function assembleReceiptByType(receipt) {
1258
1324
  case "RETURN_DATA" /* ReturnData */: {
1259
1325
  const returnDataReceipt = {
1260
1326
  type: import_transactions3.ReceiptType.ReturnData,
1261
- id: hexOrZero(receipt.contract?.id),
1327
+ id: hexOrZero(receipt.id || receipt.contractId),
1262
1328
  ptr: (0, import_math4.bn)(receipt.ptr),
1263
1329
  len: (0, import_math4.bn)(receipt.len),
1264
1330
  digest: hexOrZero(receipt.digest),
@@ -1270,7 +1336,7 @@ function assembleReceiptByType(receipt) {
1270
1336
  case "PANIC" /* Panic */: {
1271
1337
  const panicReceipt = {
1272
1338
  type: import_transactions3.ReceiptType.Panic,
1273
- id: hexOrZero(receipt.contract?.id),
1339
+ id: hexOrZero(receipt.id),
1274
1340
  reason: (0, import_math4.bn)(receipt.reason),
1275
1341
  pc: (0, import_math4.bn)(receipt.pc),
1276
1342
  is: (0, import_math4.bn)(receipt.is),
@@ -1281,7 +1347,7 @@ function assembleReceiptByType(receipt) {
1281
1347
  case "REVERT" /* Revert */: {
1282
1348
  const revertReceipt = {
1283
1349
  type: import_transactions3.ReceiptType.Revert,
1284
- id: hexOrZero(receipt.contract?.id),
1350
+ id: hexOrZero(receipt.id || receipt.contractId),
1285
1351
  val: (0, import_math4.bn)(receipt.ra),
1286
1352
  pc: (0, import_math4.bn)(receipt.pc),
1287
1353
  is: (0, import_math4.bn)(receipt.is)
@@ -1291,7 +1357,7 @@ function assembleReceiptByType(receipt) {
1291
1357
  case "LOG" /* Log */: {
1292
1358
  const logReceipt = {
1293
1359
  type: import_transactions3.ReceiptType.Log,
1294
- id: hexOrZero(receipt.contract?.id),
1360
+ id: hexOrZero(receipt.id || receipt.contractId),
1295
1361
  val0: (0, import_math4.bn)(receipt.ra),
1296
1362
  val1: (0, import_math4.bn)(receipt.rb),
1297
1363
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1304,7 +1370,7 @@ function assembleReceiptByType(receipt) {
1304
1370
  case "LOG_DATA" /* LogData */: {
1305
1371
  const logDataReceipt = {
1306
1372
  type: import_transactions3.ReceiptType.LogData,
1307
- id: hexOrZero(receipt.contract?.id),
1373
+ id: hexOrZero(receipt.id || receipt.contractId),
1308
1374
  val0: (0, import_math4.bn)(receipt.ra),
1309
1375
  val1: (0, import_math4.bn)(receipt.rb),
1310
1376
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1318,8 +1384,8 @@ function assembleReceiptByType(receipt) {
1318
1384
  case "TRANSFER" /* Transfer */: {
1319
1385
  const transferReceipt = {
1320
1386
  type: import_transactions3.ReceiptType.Transfer,
1321
- from: hexOrZero(receipt.contract?.id),
1322
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1387
+ from: hexOrZero(receipt.id || receipt.contractId),
1388
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1323
1389
  amount: (0, import_math4.bn)(receipt.amount),
1324
1390
  assetId: hexOrZero(receipt.assetId),
1325
1391
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1330,8 +1396,8 @@ function assembleReceiptByType(receipt) {
1330
1396
  case "TRANSFER_OUT" /* TransferOut */: {
1331
1397
  const transferOutReceipt = {
1332
1398
  type: import_transactions3.ReceiptType.TransferOut,
1333
- from: hexOrZero(receipt.contract?.id),
1334
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1399
+ from: hexOrZero(receipt.id || receipt.contractId),
1400
+ to: hexOrZero(receipt.toAddress || receipt.to),
1335
1401
  amount: (0, import_math4.bn)(receipt.amount),
1336
1402
  assetId: hexOrZero(receipt.assetId),
1337
1403
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1374,7 +1440,7 @@ function assembleReceiptByType(receipt) {
1374
1440
  return receiptMessageOut;
1375
1441
  }
1376
1442
  case "MINT" /* Mint */: {
1377
- const contractId = hexOrZero(receipt.contract?.id);
1443
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1378
1444
  const subId = hexOrZero(receipt.subId);
1379
1445
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1380
1446
  const mintReceipt = {
@@ -1389,7 +1455,7 @@ function assembleReceiptByType(receipt) {
1389
1455
  return mintReceipt;
1390
1456
  }
1391
1457
  case "BURN" /* Burn */: {
1392
- const contractId = hexOrZero(receipt.contract?.id);
1458
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1393
1459
  const subId = hexOrZero(receipt.subId);
1394
1460
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1395
1461
  const burnReceipt = {
@@ -1415,7 +1481,6 @@ var import_errors6 = require("@fuel-ts/errors");
1415
1481
  var import_math5 = require("@fuel-ts/math");
1416
1482
  var import_transactions4 = require("@fuel-ts/transactions");
1417
1483
  var import_utils6 = require("@fuel-ts/utils");
1418
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1419
1484
  var getGasUsedFromReceipts = (receipts) => {
1420
1485
  const scriptResult = receipts.filter(
1421
1486
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1436,18 +1501,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1436
1501
  }
1437
1502
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1438
1503
  const witnessCache = [];
1439
- const totalGas = inputs.reduce((total, input) => {
1504
+ const chargeableInputs = inputs.filter((input) => {
1505
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1506
+ if (isCoinOrMessage) {
1507
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1508
+ return true;
1509
+ }
1510
+ if (!witnessCache.includes(input.witnessIndex)) {
1511
+ witnessCache.push(input.witnessIndex);
1512
+ return true;
1513
+ }
1514
+ }
1515
+ return false;
1516
+ });
1517
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1518
+ const totalGas = chargeableInputs.reduce((total, input) => {
1440
1519
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1441
1520
  return total.add(
1442
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1521
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1443
1522
  );
1444
1523
  }
1445
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1446
- witnessCache.push(input.witnessIndex);
1447
- return total.add(gasCosts.ecr1);
1448
- }
1449
- return total;
1450
- }, (0, import_math5.bn)());
1524
+ return total.add(gasCosts.ecr1);
1525
+ }, (0, import_math5.bn)(0));
1451
1526
  return totalGas;
1452
1527
  }
1453
1528
  function getMinGas(params) {
@@ -1459,12 +1534,20 @@ function getMinGas(params) {
1459
1534
  return minGas;
1460
1535
  }
1461
1536
  function getMaxGas(params) {
1462
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1537
+ const {
1538
+ gasPerByte,
1539
+ witnessesLength,
1540
+ witnessLimit,
1541
+ minGas,
1542
+ gasLimit = (0, import_math5.bn)(0),
1543
+ maxGasPerTx
1544
+ } = params;
1463
1545
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1464
1546
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1465
1547
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1466
1548
  }
1467
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1549
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1550
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1468
1551
  }
1469
1552
  function calculateMetadataGasForTxCreate({
1470
1553
  gasCosts,
@@ -1486,6 +1569,10 @@ function calculateMetadataGasForTxScript({
1486
1569
  }) {
1487
1570
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1488
1571
  }
1572
+ var calculateGasFee = (params) => {
1573
+ const { gas, gasPrice, priceFactor, tip } = params;
1574
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1575
+ };
1489
1576
 
1490
1577
  // src/providers/utils/json.ts
1491
1578
  var import_utils7 = require("@fuel-ts/utils");
@@ -1531,16 +1618,16 @@ function sleep(time) {
1531
1618
  var import_errors7 = require("@fuel-ts/errors");
1532
1619
  var import_math6 = require("@fuel-ts/math");
1533
1620
  var import_transactions5 = require("@fuel-ts/transactions");
1534
- var import_configs5 = require("@fuel-ts/transactions/configs");
1621
+ var import_configs6 = require("@fuel-ts/transactions/configs");
1535
1622
  var assemblePanicError = (status) => {
1536
1623
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1537
1624
  const reason = status.reason;
1538
- if (import_configs5.PANIC_REASONS.includes(status.reason)) {
1625
+ if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1539
1626
  errorMessage = `${errorMessage}
1540
1627
 
1541
1628
  You can read more about this error at:
1542
1629
 
1543
- ${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
1630
+ ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1544
1631
  }
1545
1632
  return { errorMessage, reason };
1546
1633
  };
@@ -1552,28 +1639,28 @@ var assembleRevertError = (receipts, logs) => {
1552
1639
  if (revertReceipt) {
1553
1640
  const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1554
1641
  switch (reasonHex) {
1555
- case import_configs5.FAILED_REQUIRE_SIGNAL: {
1642
+ case import_configs6.FAILED_REQUIRE_SIGNAL: {
1556
1643
  reason = "require";
1557
1644
  errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1558
1645
  break;
1559
1646
  }
1560
- case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
1647
+ case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1561
1648
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1562
1649
  reason = "assert_eq";
1563
1650
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1564
1651
  break;
1565
1652
  }
1566
- case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
1653
+ case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1567
1654
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1568
1655
  reason = "assert_ne";
1569
1656
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1570
1657
  break;
1571
1658
  }
1572
- case import_configs5.FAILED_ASSERT_SIGNAL:
1659
+ case import_configs6.FAILED_ASSERT_SIGNAL:
1573
1660
  reason = "assert";
1574
1661
  errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1575
1662
  break;
1576
- case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1663
+ case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1577
1664
  reason = "MissingOutputChange";
1578
1665
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1579
1666
  break;
@@ -1622,7 +1709,7 @@ var witnessify = (value) => {
1622
1709
  // src/providers/transaction-request/transaction-request.ts
1623
1710
  var BaseTransactionRequest = class {
1624
1711
  /** Gas price for transaction */
1625
- gasPrice;
1712
+ tip;
1626
1713
  /** Block until which tx cannot be included */
1627
1714
  maturity;
1628
1715
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1635,38 +1722,34 @@ var BaseTransactionRequest = class {
1635
1722
  outputs = [];
1636
1723
  /** List of witnesses */
1637
1724
  witnesses = [];
1638
- /** Base asset ID - should be fetched from the chain */
1639
- baseAssetId;
1640
1725
  /**
1641
1726
  * Constructor for initializing a base transaction request.
1642
1727
  *
1643
1728
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1644
1729
  */
1645
1730
  constructor({
1646
- gasPrice,
1731
+ tip,
1647
1732
  maturity,
1648
1733
  maxFee,
1649
1734
  witnessLimit,
1650
1735
  inputs,
1651
1736
  outputs,
1652
- witnesses,
1653
- baseAssetId
1654
- }) {
1655
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1737
+ witnesses
1738
+ } = {}) {
1739
+ this.tip = (0, import_math7.bn)(tip);
1656
1740
  this.maturity = maturity ?? 0;
1657
1741
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1658
1742
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
1659
1743
  this.inputs = inputs ?? [];
1660
1744
  this.outputs = outputs ?? [];
1661
1745
  this.witnesses = witnesses ?? [];
1662
- this.baseAssetId = baseAssetId;
1663
1746
  }
1664
1747
  static getPolicyMeta(req) {
1665
1748
  let policyTypes = 0;
1666
1749
  const policies = [];
1667
- if (req.gasPrice) {
1668
- policyTypes += import_transactions6.PolicyType.GasPrice;
1669
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1750
+ if (req.tip) {
1751
+ policyTypes += import_transactions6.PolicyType.Tip;
1752
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1670
1753
  }
1671
1754
  if (req.witnessLimit) {
1672
1755
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -1752,7 +1835,7 @@ var BaseTransactionRequest = class {
1752
1835
  * @returns The index of the created witness.
1753
1836
  */
1754
1837
  addEmptyWitness() {
1755
- this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1838
+ this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
1756
1839
  return this.witnesses.length - 1;
1757
1840
  }
1758
1841
  /**
@@ -1853,10 +1936,10 @@ var BaseTransactionRequest = class {
1853
1936
  * @param predicate - Predicate bytes.
1854
1937
  * @param predicateData - Predicate data bytes.
1855
1938
  */
1856
- addCoinInput(coin, predicate) {
1939
+ addCoinInput(coin) {
1857
1940
  const { assetId, owner, amount } = coin;
1858
1941
  let witnessIndex;
1859
- if (predicate) {
1942
+ if (coin.predicate) {
1860
1943
  witnessIndex = 0;
1861
1944
  } else {
1862
1945
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1871,8 +1954,7 @@ var BaseTransactionRequest = class {
1871
1954
  amount,
1872
1955
  assetId,
1873
1956
  txPointer: "0x00000000000000000000000000000000",
1874
- witnessIndex,
1875
- predicate: predicate?.bytes
1957
+ witnessIndex
1876
1958
  };
1877
1959
  this.pushInput(input);
1878
1960
  this.addChangeOutput(owner, assetId);
@@ -1883,11 +1965,13 @@ var BaseTransactionRequest = class {
1883
1965
  *
1884
1966
  * @param message - Message resource.
1885
1967
  * @param predicate - Predicate bytes.
1968
+ * @param predicateData - Predicate data bytes.
1886
1969
  */
1887
- addMessageInput(message, predicate) {
1970
+ addMessageInput(message) {
1888
1971
  const { recipient, sender, amount } = message;
1972
+ const assetId = import_configs7.BaseAssetId;
1889
1973
  let witnessIndex;
1890
- if (predicate) {
1974
+ if (message.predicate) {
1891
1975
  witnessIndex = 0;
1892
1976
  } else {
1893
1977
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1901,11 +1985,10 @@ var BaseTransactionRequest = class {
1901
1985
  sender: sender.toB256(),
1902
1986
  recipient: recipient.toB256(),
1903
1987
  amount,
1904
- witnessIndex,
1905
- predicate: predicate?.bytes
1988
+ witnessIndex
1906
1989
  };
1907
1990
  this.pushInput(input);
1908
- this.addChangeOutput(recipient, this.baseAssetId);
1991
+ this.addChangeOutput(recipient, assetId);
1909
1992
  }
1910
1993
  /**
1911
1994
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1933,32 +2016,6 @@ var BaseTransactionRequest = class {
1933
2016
  resources.forEach((resource) => this.addResource(resource));
1934
2017
  return this;
1935
2018
  }
1936
- /**
1937
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1938
- * outputs from the related assetIds.
1939
- *
1940
- * @param resources - The resources to add.
1941
- * @returns This transaction.
1942
- */
1943
- addPredicateResource(resource, predicate) {
1944
- if (isCoin(resource)) {
1945
- this.addCoinInput(resource, predicate);
1946
- } else {
1947
- this.addMessageInput(resource, predicate);
1948
- }
1949
- return this;
1950
- }
1951
- /**
1952
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
1953
- * from the related assetIds.
1954
- *
1955
- * @param resources - The resources to add.
1956
- * @returns This transaction.
1957
- */
1958
- addPredicateResources(resources, predicate) {
1959
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1960
- return this;
1961
- }
1962
2019
  /**
1963
2020
  * Adds a coin output to the transaction.
1964
2021
  *
@@ -1966,12 +2023,12 @@ var BaseTransactionRequest = class {
1966
2023
  * @param amount - Amount of coin.
1967
2024
  * @param assetId - Asset ID of coin.
1968
2025
  */
1969
- addCoinOutput(to, amount, assetId) {
2026
+ addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
1970
2027
  this.pushOutput({
1971
2028
  type: import_transactions6.OutputType.Coin,
1972
2029
  to: (0, import_address.addressify)(to).toB256(),
1973
2030
  amount,
1974
- assetId: assetId ?? this.baseAssetId
2031
+ assetId
1975
2032
  });
1976
2033
  return this;
1977
2034
  }
@@ -1998,7 +2055,7 @@ var BaseTransactionRequest = class {
1998
2055
  * @param to - Address of the owner.
1999
2056
  * @param assetId - Asset ID of coin.
2000
2057
  */
2001
- addChangeOutput(to, assetId) {
2058
+ addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2002
2059
  const changeOutput = this.getChangeOutputs().find(
2003
2060
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2004
2061
  );
@@ -2006,7 +2063,7 @@ var BaseTransactionRequest = class {
2006
2063
  this.pushOutput({
2007
2064
  type: import_transactions6.OutputType.Change,
2008
2065
  to: (0, import_address.addressify)(to).toB256(),
2009
- assetId: assetId ?? this.baseAssetId
2066
+ assetId
2010
2067
  });
2011
2068
  }
2012
2069
  }
@@ -2038,7 +2095,7 @@ var BaseTransactionRequest = class {
2038
2095
  }
2039
2096
  calculateMaxGas(chainInfo, minGas) {
2040
2097
  const { consensusParameters } = chainInfo;
2041
- const { gasPerByte } = consensusParameters;
2098
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2042
2099
  const witnessesLength = this.toTransaction().witnesses.reduce(
2043
2100
  (acc, wit) => acc + wit.dataLength,
2044
2101
  0
@@ -2047,7 +2104,8 @@ var BaseTransactionRequest = class {
2047
2104
  gasPerByte,
2048
2105
  minGas,
2049
2106
  witnessesLength,
2050
- witnessLimit: this.witnessLimit
2107
+ witnessLimit: this.witnessLimit,
2108
+ maxGasPerTx
2051
2109
  });
2052
2110
  }
2053
2111
  /**
@@ -2065,24 +2123,27 @@ var BaseTransactionRequest = class {
2065
2123
  });
2066
2124
  const updateAssetInput = (assetId, quantity) => {
2067
2125
  const assetInput = findAssetInput(assetId);
2126
+ let usedQuantity = quantity;
2127
+ if (assetId === import_configs7.BaseAssetId) {
2128
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2129
+ }
2068
2130
  if (assetInput && "assetId" in assetInput) {
2069
2131
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2070
- assetInput.amount = quantity;
2132
+ assetInput.amount = usedQuantity;
2071
2133
  } else {
2072
2134
  this.addResources([
2073
2135
  {
2074
2136
  id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2075
- amount: quantity,
2137
+ amount: usedQuantity,
2076
2138
  assetId,
2077
2139
  owner: resourcesOwner || import_address.Address.fromRandom(),
2078
- maturity: 0,
2079
2140
  blockCreated: (0, import_math7.bn)(1),
2080
2141
  txCreatedIdx: (0, import_math7.bn)(1)
2081
2142
  }
2082
2143
  ]);
2083
2144
  }
2084
2145
  };
2085
- updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
2146
+ updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2086
2147
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2087
2148
  }
2088
2149
  /**
@@ -2107,7 +2168,7 @@ var BaseTransactionRequest = class {
2107
2168
  toJSON() {
2108
2169
  return normalizeJSON(this);
2109
2170
  }
2110
- updatePredicateInputs(inputs) {
2171
+ updatePredicateGasUsed(inputs) {
2111
2172
  this.inputs.forEach((i) => {
2112
2173
  let correspondingInput;
2113
2174
  switch (i.type) {
@@ -2129,16 +2190,25 @@ var BaseTransactionRequest = class {
2129
2190
  }
2130
2191
  });
2131
2192
  }
2193
+ shiftPredicateData() {
2194
+ this.inputs.forEach((input) => {
2195
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2196
+ input.predicateData = input.paddPredicateData(
2197
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2198
+ );
2199
+ }
2200
+ });
2201
+ }
2132
2202
  };
2133
2203
 
2134
2204
  // src/providers/transaction-request/create-transaction-request.ts
2135
- var import_configs8 = require("@fuel-ts/address/configs");
2205
+ var import_configs9 = require("@fuel-ts/address/configs");
2136
2206
  var import_math9 = require("@fuel-ts/math");
2137
2207
  var import_transactions8 = require("@fuel-ts/transactions");
2138
2208
  var import_utils13 = require("@fuel-ts/utils");
2139
2209
 
2140
2210
  // src/providers/transaction-request/hash-transaction.ts
2141
- var import_configs7 = require("@fuel-ts/address/configs");
2211
+ var import_configs8 = require("@fuel-ts/address/configs");
2142
2212
  var import_hasher = require("@fuel-ts/hasher");
2143
2213
  var import_math8 = require("@fuel-ts/math");
2144
2214
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2147,7 +2217,7 @@ var import_ramda2 = require("ramda");
2147
2217
  function hashTransaction(transactionRequest, chainId) {
2148
2218
  const transaction = transactionRequest.toTransaction();
2149
2219
  if (transaction.type === import_transactions7.TransactionType.Script) {
2150
- transaction.receiptsRoot = import_configs7.ZeroBytes32;
2220
+ transaction.receiptsRoot = import_configs8.ZeroBytes32;
2151
2221
  }
2152
2222
  transaction.inputs = transaction.inputs.map((input) => {
2153
2223
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2169,10 +2239,10 @@ function hashTransaction(transactionRequest, chainId) {
2169
2239
  blockHeight: 0,
2170
2240
  txIndex: 0
2171
2241
  };
2172
- inputClone.txID = import_configs7.ZeroBytes32;
2242
+ inputClone.txID = import_configs8.ZeroBytes32;
2173
2243
  inputClone.outputIndex = 0;
2174
- inputClone.balanceRoot = import_configs7.ZeroBytes32;
2175
- inputClone.stateRoot = import_configs7.ZeroBytes32;
2244
+ inputClone.balanceRoot = import_configs8.ZeroBytes32;
2245
+ inputClone.stateRoot = import_configs8.ZeroBytes32;
2176
2246
  return inputClone;
2177
2247
  }
2178
2248
  default:
@@ -2183,8 +2253,8 @@ function hashTransaction(transactionRequest, chainId) {
2183
2253
  const outputClone = (0, import_ramda2.clone)(output);
2184
2254
  switch (outputClone.type) {
2185
2255
  case import_transactions7.OutputType.Contract: {
2186
- outputClone.balanceRoot = import_configs7.ZeroBytes32;
2187
- outputClone.stateRoot = import_configs7.ZeroBytes32;
2256
+ outputClone.balanceRoot = import_configs8.ZeroBytes32;
2257
+ outputClone.stateRoot = import_configs8.ZeroBytes32;
2188
2258
  return outputClone;
2189
2259
  }
2190
2260
  case import_transactions7.OutputType.Change: {
@@ -2192,9 +2262,9 @@ function hashTransaction(transactionRequest, chainId) {
2192
2262
  return outputClone;
2193
2263
  }
2194
2264
  case import_transactions7.OutputType.Variable: {
2195
- outputClone.to = import_configs7.ZeroBytes32;
2265
+ outputClone.to = import_configs8.ZeroBytes32;
2196
2266
  outputClone.amount = (0, import_math8.bn)(0);
2197
- outputClone.assetId = import_configs7.ZeroBytes32;
2267
+ outputClone.assetId = import_configs8.ZeroBytes32;
2198
2268
  return outputClone;
2199
2269
  }
2200
2270
  default:
@@ -2252,10 +2322,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2252
2322
  *
2253
2323
  * @param createTransactionRequestLike - The initial values for the instance
2254
2324
  */
2255
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2325
+ constructor({
2326
+ bytecodeWitnessIndex,
2327
+ salt,
2328
+ storageSlots,
2329
+ ...rest
2330
+ } = {}) {
2256
2331
  super(rest);
2257
2332
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2258
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2333
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2259
2334
  this.storageSlots = [...storageSlots ?? []];
2260
2335
  }
2261
2336
  /**
@@ -2270,10 +2345,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2270
2345
  return {
2271
2346
  type: import_transactions8.TransactionType.Create,
2272
2347
  ...baseTransaction,
2273
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2274
2348
  bytecodeWitnessIndex,
2275
- storageSlotsCount: storageSlots.length,
2276
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2349
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2350
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2277
2351
  storageSlots
2278
2352
  };
2279
2353
  }
@@ -2323,7 +2397,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2323
2397
  // src/providers/transaction-request/script-transaction-request.ts
2324
2398
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
2325
2399
  var import_address2 = require("@fuel-ts/address");
2326
- var import_configs9 = require("@fuel-ts/address/configs");
2400
+ var import_configs10 = require("@fuel-ts/address/configs");
2327
2401
  var import_math10 = require("@fuel-ts/math");
2328
2402
  var import_transactions9 = require("@fuel-ts/transactions");
2329
2403
  var import_utils15 = require("@fuel-ts/utils");
@@ -2376,7 +2450,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2376
2450
  *
2377
2451
  * @param scriptTransactionRequestLike - The initial values for the instance.
2378
2452
  */
2379
- constructor({ script, scriptData, gasLimit, ...rest }) {
2453
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2380
2454
  super(rest);
2381
2455
  this.gasLimit = (0, import_math10.bn)(gasLimit);
2382
2456
  this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
@@ -2395,9 +2469,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2395
2469
  type: import_transactions9.TransactionType.Script,
2396
2470
  scriptGasLimit: this.gasLimit,
2397
2471
  ...super.getBaseTransaction(),
2398
- scriptLength: script.length,
2399
- scriptDataLength: scriptData.length,
2400
- receiptsRoot: import_configs9.ZeroBytes32,
2472
+ scriptLength: (0, import_math10.bn)(script.length),
2473
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2474
+ receiptsRoot: import_configs10.ZeroBytes32,
2401
2475
  script: (0, import_utils15.hexlify)(script),
2402
2476
  scriptData: (0, import_utils15.hexlify)(scriptData)
2403
2477
  };
@@ -2460,7 +2534,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2460
2534
  }
2461
2535
  calculateMaxGas(chainInfo, minGas) {
2462
2536
  const { consensusParameters } = chainInfo;
2463
- const { gasPerByte } = consensusParameters;
2537
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2464
2538
  const witnessesLength = this.toTransaction().witnesses.reduce(
2465
2539
  (acc, wit) => acc + wit.dataLength,
2466
2540
  0
@@ -2470,7 +2544,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2470
2544
  minGas,
2471
2545
  witnessesLength,
2472
2546
  witnessLimit: this.witnessLimit,
2473
- gasLimit: this.gasLimit
2547
+ gasLimit: this.gasLimit,
2548
+ maxGasPerTx
2474
2549
  });
2475
2550
  }
2476
2551
  /**
@@ -2545,15 +2620,32 @@ var transactionRequestify = (obj) => {
2545
2620
  }
2546
2621
  }
2547
2622
  };
2623
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2624
+ (acc, input) => {
2625
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2626
+ acc.utxos.push(input.id);
2627
+ }
2628
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2629
+ acc.messages.push(input.nonce);
2630
+ }
2631
+ return acc;
2632
+ },
2633
+ {
2634
+ utxos: [],
2635
+ messages: []
2636
+ }
2637
+ );
2548
2638
 
2549
2639
  // src/providers/transaction-response/transaction-response.ts
2550
2640
  var import_errors13 = require("@fuel-ts/errors");
2551
- var import_math14 = require("@fuel-ts/math");
2552
- var import_transactions17 = require("@fuel-ts/transactions");
2553
- var import_utils21 = require("@fuel-ts/utils");
2641
+ var import_math15 = require("@fuel-ts/math");
2642
+ var import_transactions18 = require("@fuel-ts/transactions");
2643
+ var import_utils20 = require("@fuel-ts/utils");
2554
2644
 
2555
2645
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2556
- var import_utils19 = require("@fuel-ts/utils");
2646
+ var import_math14 = require("@fuel-ts/math");
2647
+ var import_transactions16 = require("@fuel-ts/transactions");
2648
+ var import_utils18 = require("@fuel-ts/utils");
2557
2649
 
2558
2650
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2559
2651
  var import_math11 = require("@fuel-ts/math");
@@ -2561,9 +2653,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
2561
2653
  var import_utils16 = require("@fuel-ts/utils");
2562
2654
  var calculateTransactionFee = (params) => {
2563
2655
  const {
2564
- gasUsed,
2656
+ gasPrice,
2565
2657
  rawPayload,
2566
- consensusParameters: { gasCosts, feeParams }
2658
+ tip,
2659
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2567
2660
  } = params;
2568
2661
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2569
2662
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2573,8 +2666,7 @@ var calculateTransactionFee = (params) => {
2573
2666
  return {
2574
2667
  fee: (0, import_math11.bn)(0),
2575
2668
  minFee: (0, import_math11.bn)(0),
2576
- maxFee: (0, import_math11.bn)(0),
2577
- feeFromGasUsed: (0, import_math11.bn)(0)
2669
+ maxFee: (0, import_math11.bn)(0)
2578
2670
  };
2579
2671
  }
2580
2672
  const { type, witnesses, inputs, policies } = transaction;
@@ -2606,7 +2698,6 @@ var calculateTransactionFee = (params) => {
2606
2698
  metadataGas,
2607
2699
  txBytesSize: transactionBytes.length
2608
2700
  });
2609
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2610
2701
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2611
2702
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2612
2703
  const maxGas = getMaxGas({
@@ -2614,22 +2705,30 @@ var calculateTransactionFee = (params) => {
2614
2705
  minGas,
2615
2706
  witnessesLength,
2616
2707
  gasLimit,
2617
- witnessLimit
2708
+ witnessLimit,
2709
+ maxGasPerTx
2710
+ });
2711
+ const minFee = calculateGasFee({
2712
+ gasPrice,
2713
+ gas: minGas,
2714
+ priceFactor: gasPriceFactor,
2715
+ tip
2716
+ });
2717
+ const maxFee = calculateGasFee({
2718
+ gasPrice,
2719
+ gas: maxGas,
2720
+ priceFactor: gasPriceFactor,
2721
+ tip
2618
2722
  });
2619
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2620
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2621
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2622
- const fee = minFee.add(feeFromGasUsed);
2623
2723
  return {
2624
- fee,
2625
2724
  minFee,
2626
2725
  maxFee,
2627
- feeFromGasUsed
2726
+ fee: maxFee
2628
2727
  };
2629
2728
  };
2630
2729
 
2631
2730
  // src/providers/transaction-summary/operations.ts
2632
- var import_configs10 = require("@fuel-ts/address/configs");
2731
+ var import_configs11 = require("@fuel-ts/address/configs");
2633
2732
  var import_errors11 = require("@fuel-ts/errors");
2634
2733
  var import_math13 = require("@fuel-ts/math");
2635
2734
  var import_transactions14 = require("@fuel-ts/transactions");
@@ -2927,7 +3026,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
2927
3026
  const { to: toAddress, assetId, amount } = receipt;
2928
3027
  let { from: fromAddress } = receipt;
2929
3028
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
2930
- if (import_configs10.ZeroBytes32 === fromAddress) {
3029
+ if (import_configs11.ZeroBytes32 === fromAddress) {
2931
3030
  const change = changeOutputs.find((output) => output.assetId === assetId);
2932
3031
  fromAddress = change?.to || fromAddress;
2933
3032
  }
@@ -3191,10 +3290,12 @@ function assembleTransactionSummary(params) {
3191
3290
  gqlTransactionStatus,
3192
3291
  abiMap = {},
3193
3292
  maxInputs,
3194
- gasCosts
3293
+ gasCosts,
3294
+ maxGasPerTx,
3295
+ gasPrice
3195
3296
  } = params;
3196
3297
  const gasUsed = getGasUsedFromReceipts(receipts);
3197
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3298
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3198
3299
  const operations = getOperations({
3199
3300
  transactionType: transaction.type,
3200
3301
  inputs: transaction.inputs || [],
@@ -3205,11 +3306,14 @@ function assembleTransactionSummary(params) {
3205
3306
  maxInputs
3206
3307
  });
3207
3308
  const typeName = getTransactionTypeName(transaction.type);
3309
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3208
3310
  const { fee } = calculateTransactionFee({
3209
- gasUsed,
3311
+ gasPrice,
3210
3312
  rawPayload,
3313
+ tip,
3211
3314
  consensusParameters: {
3212
3315
  gasCosts,
3316
+ maxGasPerTx,
3213
3317
  feeParams: {
3214
3318
  gasPerByte,
3215
3319
  gasPriceFactor
@@ -3221,7 +3325,7 @@ function assembleTransactionSummary(params) {
3221
3325
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3222
3326
  let date;
3223
3327
  if (time) {
3224
- date = import_utils19.DateTime.fromTai64(time);
3328
+ date = import_utils18.DateTime.fromTai64(time);
3225
3329
  }
3226
3330
  const transactionSummary = {
3227
3331
  id,
@@ -3249,12 +3353,12 @@ function assembleTransactionSummary(params) {
3249
3353
 
3250
3354
  // src/providers/transaction-response/getDecodedLogs.ts
3251
3355
  var import_abi_coder5 = require("@fuel-ts/abi-coder");
3252
- var import_transactions16 = require("@fuel-ts/transactions");
3356
+ var import_transactions17 = require("@fuel-ts/transactions");
3253
3357
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3254
3358
  return receipts.reduce((logs, receipt) => {
3255
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3359
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3256
3360
  const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3257
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3361
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3258
3362
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3259
3363
  logs.push(decodedLog);
3260
3364
  }
@@ -3269,7 +3373,7 @@ var TransactionResponse = class {
3269
3373
  /** Current provider */
3270
3374
  provider;
3271
3375
  /** Gas used on the transaction */
3272
- gasUsed = (0, import_math14.bn)(0);
3376
+ gasUsed = (0, import_math15.bn)(0);
3273
3377
  /** The graphql Transaction with receipts object. */
3274
3378
  gqlTransaction;
3275
3379
  abis;
@@ -3327,8 +3431,8 @@ var TransactionResponse = class {
3327
3431
  * @returns The decoded transaction.
3328
3432
  */
3329
3433
  decodeTransaction(transactionWithReceipts) {
3330
- return new import_transactions17.TransactionCoder().decode(
3331
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3434
+ return new import_transactions18.TransactionCoder().decode(
3435
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3332
3436
  0
3333
3437
  )?.[0];
3334
3438
  }
@@ -3347,20 +3451,27 @@ var TransactionResponse = class {
3347
3451
  const decodedTransaction = this.decodeTransaction(
3348
3452
  transaction
3349
3453
  );
3350
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3351
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3454
+ let txReceipts = [];
3455
+ if (transaction?.status && "receipts" in transaction.status) {
3456
+ txReceipts = transaction.status.receipts;
3457
+ }
3458
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3459
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3460
+ const gasPrice = await this.provider.getLatestGasPrice();
3352
3461
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3353
3462
  const transactionSummary = assembleTransactionSummary({
3354
3463
  id: this.id,
3355
3464
  receipts,
3356
3465
  transaction: decodedTransaction,
3357
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3466
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3358
3467
  gqlTransactionStatus: transaction.status,
3359
3468
  gasPerByte,
3360
3469
  gasPriceFactor,
3361
3470
  abiMap: contractsAbiMap,
3362
3471
  maxInputs,
3363
- gasCosts
3472
+ gasCosts,
3473
+ maxGasPerTx,
3474
+ gasPrice
3364
3475
  });
3365
3476
  return transactionSummary;
3366
3477
  }
@@ -3487,30 +3598,29 @@ var processGqlChain = (chain) => {
3487
3598
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3488
3599
  return {
3489
3600
  name,
3490
- baseChainHeight: (0, import_math15.bn)(daHeight),
3601
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3491
3602
  consensusParameters: {
3492
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3493
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3494
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3495
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3496
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3497
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3498
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3499
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3500
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3501
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3502
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3503
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3504
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3505
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3506
- chainId: (0, import_math15.bn)(consensusParameters.chainId),
3507
- baseAssetId: consensusParameters.baseAssetId,
3603
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3604
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3605
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3606
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3607
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3608
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3609
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3610
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3611
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3612
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3613
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3614
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3615
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3616
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3617
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3508
3618
  gasCosts
3509
3619
  },
3510
3620
  gasCosts,
3511
3621
  latestBlock: {
3512
3622
  id: latestBlock.id,
3513
- height: (0, import_math15.bn)(latestBlock.header.height),
3623
+ height: (0, import_math16.bn)(latestBlock.height),
3514
3624
  time: latestBlock.header.time,
3515
3625
  transactions: latestBlock.transactions.map((i) => ({
3516
3626
  id: i.id
@@ -3604,10 +3714,8 @@ var _Provider = class {
3604
3714
  * Returns some helpful parameters related to gas fees.
3605
3715
  */
3606
3716
  getGasConfig() {
3607
- const { minGasPrice } = this.getNode();
3608
3717
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3609
3718
  return {
3610
- minGasPrice,
3611
3719
  maxGasPerTx,
3612
3720
  maxGasPerPredicate,
3613
3721
  gasPriceFactor,
@@ -3705,7 +3813,7 @@ var _Provider = class {
3705
3813
  */
3706
3814
  async getBlockNumber() {
3707
3815
  const { chain } = await this.operations.getChain();
3708
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
3816
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3709
3817
  }
3710
3818
  /**
3711
3819
  * Returns the chain information.
@@ -3715,13 +3823,11 @@ var _Provider = class {
3715
3823
  async fetchNode() {
3716
3824
  const { nodeInfo } = await this.operations.getNodeInfo();
3717
3825
  const processedNodeInfo = {
3718
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3719
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3720
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
3826
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
3827
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3721
3828
  nodeVersion: nodeInfo.nodeVersion,
3722
3829
  utxoValidation: nodeInfo.utxoValidation,
3723
- vmBacktrace: nodeInfo.vmBacktrace,
3724
- peers: nodeInfo.peers
3830
+ vmBacktrace: nodeInfo.vmBacktrace
3725
3831
  };
3726
3832
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3727
3833
  return processedNodeInfo;
@@ -3747,17 +3853,6 @@ var _Provider = class {
3747
3853
  } = this.getChain();
3748
3854
  return chainId.toNumber();
3749
3855
  }
3750
- /**
3751
- * Returns the base asset ID
3752
- *
3753
- * @returns A promise that resolves to the base asset ID
3754
- */
3755
- getBaseAssetId() {
3756
- const {
3757
- consensusParameters: { baseAssetId }
3758
- } = this.getChain();
3759
- return baseAssetId;
3760
- }
3761
3856
  /**
3762
3857
  * Submits a transaction to the chain to be executed.
3763
3858
  *
@@ -3774,9 +3869,9 @@ var _Provider = class {
3774
3869
  if (estimateTxDependencies) {
3775
3870
  await this.estimateTxDependencies(transactionRequest);
3776
3871
  }
3777
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3872
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3778
3873
  let abis;
3779
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
3874
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
3780
3875
  abis = transactionRequest.abis;
3781
3876
  }
3782
3877
  if (awaitExecution) {
@@ -3817,15 +3912,14 @@ var _Provider = class {
3817
3912
  if (estimateTxDependencies) {
3818
3913
  return this.estimateTxDependencies(transactionRequest);
3819
3914
  }
3820
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3821
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3822
- encodedTransaction,
3915
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3916
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
3917
+ encodedTransactions: encodedTransaction,
3823
3918
  utxoValidation: utxoValidation || false
3824
3919
  });
3825
- const receipts = gqlReceipts.map(processGqlReceipt);
3826
- return {
3827
- receipts
3828
- };
3920
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
3921
+ const receipts = rawReceipts.map(processGqlReceipt);
3922
+ return { receipts, dryrunStatus: status };
3829
3923
  }
3830
3924
  /**
3831
3925
  * Verifies whether enough gas is available to complete transaction.
@@ -3836,13 +3930,13 @@ var _Provider = class {
3836
3930
  async estimatePredicates(transactionRequest) {
3837
3931
  const shouldEstimatePredicates = Boolean(
3838
3932
  transactionRequest.inputs.find(
3839
- (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()
3933
+ (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()
3840
3934
  )
3841
3935
  );
3842
3936
  if (!shouldEstimatePredicates) {
3843
3937
  return transactionRequest;
3844
3938
  }
3845
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3939
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3846
3940
  const response = await this.operations.estimatePredicates({
3847
3941
  encodedTransaction
3848
3942
  });
@@ -3851,7 +3945,7 @@ var _Provider = class {
3851
3945
  } = response;
3852
3946
  if (inputs) {
3853
3947
  inputs.forEach((input, index) => {
3854
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
3948
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
3855
3949
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3856
3950
  }
3857
3951
  });
@@ -3864,31 +3958,31 @@ var _Provider = class {
3864
3958
  * If there are missing variable outputs,
3865
3959
  * `addVariableOutputs` is called on the transaction.
3866
3960
  *
3867
- * @privateRemarks
3868
- * TODO: Investigate support for missing contract IDs
3869
- * TODO: Add support for missing output messages
3870
3961
  *
3871
3962
  * @param transactionRequest - The transaction request object.
3872
3963
  * @returns A promise.
3873
3964
  */
3874
3965
  async estimateTxDependencies(transactionRequest) {
3875
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
3966
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
3876
3967
  return {
3877
3968
  receipts: [],
3878
3969
  outputVariables: 0,
3879
3970
  missingContractIds: []
3880
3971
  };
3881
3972
  }
3882
- await this.estimatePredicates(transactionRequest);
3883
3973
  let receipts = [];
3884
3974
  const missingContractIds = [];
3885
3975
  let outputVariables = 0;
3976
+ let dryrunStatus;
3886
3977
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3887
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3888
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
3978
+ const {
3979
+ dryRun: [{ receipts: rawReceipts, status }]
3980
+ } = await this.operations.dryRun({
3981
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
3889
3982
  utxoValidation: false
3890
3983
  });
3891
- receipts = gqlReceipts.map(processGqlReceipt);
3984
+ receipts = rawReceipts.map(processGqlReceipt);
3985
+ dryrunStatus = status;
3892
3986
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3893
3987
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3894
3988
  if (hasMissingOutputs) {
@@ -3898,6 +3992,10 @@ var _Provider = class {
3898
3992
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
3899
3993
  missingContractIds.push(contractId);
3900
3994
  });
3995
+ const { maxFee } = await this.estimateTxGasAndFee({
3996
+ transactionRequest
3997
+ });
3998
+ transactionRequest.maxFee = maxFee;
3901
3999
  } else {
3902
4000
  break;
3903
4001
  }
@@ -3905,37 +4003,139 @@ var _Provider = class {
3905
4003
  return {
3906
4004
  receipts,
3907
4005
  outputVariables,
3908
- missingContractIds
4006
+ missingContractIds,
4007
+ dryrunStatus
3909
4008
  };
3910
4009
  }
4010
+ /**
4011
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4012
+ *
4013
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4014
+ * further modifications are identified. The method iteratively updates these transactions
4015
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4016
+ *
4017
+ * @param transactionRequests - Array of transaction request objects.
4018
+ * @returns A promise that resolves to an array of results for each transaction.
4019
+ */
4020
+ async estimateMultipleTxDependencies(transactionRequests) {
4021
+ const results = transactionRequests.map(() => ({
4022
+ receipts: [],
4023
+ outputVariables: 0,
4024
+ missingContractIds: [],
4025
+ dryrunStatus: void 0
4026
+ }));
4027
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4028
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4029
+ allRequests.forEach((req, index) => {
4030
+ if (req.type === import_transactions19.TransactionType.Script) {
4031
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4032
+ }
4033
+ });
4034
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4035
+ let attempt = 0;
4036
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4037
+ const encodedTransactions = transactionsToProcess.map(
4038
+ (index) => serializedTransactionsMap.get(index)
4039
+ );
4040
+ const dryRunResults = await this.operations.dryRun({
4041
+ encodedTransactions,
4042
+ utxoValidation: false
4043
+ });
4044
+ const nextRoundTransactions = [];
4045
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4046
+ const currentResultIndex = transactionsToProcess[i];
4047
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4048
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4049
+ results[currentResultIndex].dryrunStatus = status;
4050
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4051
+ results[currentResultIndex].receipts
4052
+ );
4053
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4054
+ const requestToProcess = allRequests[currentResultIndex];
4055
+ if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4056
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4057
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4058
+ missingOutputContractIds.forEach(({ contractId }) => {
4059
+ requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4060
+ results[currentResultIndex].missingContractIds.push(contractId);
4061
+ });
4062
+ const { maxFee } = await this.estimateTxGasAndFee({
4063
+ transactionRequest: requestToProcess
4064
+ });
4065
+ requestToProcess.maxFee = maxFee;
4066
+ serializedTransactionsMap.set(
4067
+ currentResultIndex,
4068
+ (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4069
+ );
4070
+ nextRoundTransactions.push(currentResultIndex);
4071
+ allRequests[currentResultIndex] = requestToProcess;
4072
+ }
4073
+ }
4074
+ transactionsToProcess = nextRoundTransactions;
4075
+ attempt += 1;
4076
+ }
4077
+ return results;
4078
+ }
4079
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4080
+ if (estimateTxDependencies) {
4081
+ return this.estimateMultipleTxDependencies(transactionRequests);
4082
+ }
4083
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4084
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4085
+ encodedTransactions,
4086
+ utxoValidation: utxoValidation || false
4087
+ });
4088
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4089
+ const receipts = rawReceipts.map(processGqlReceipt);
4090
+ return { receipts, dryrunStatus: status };
4091
+ });
4092
+ return results;
4093
+ }
3911
4094
  /**
3912
4095
  * Estimates the transaction gas and fee based on the provided transaction request.
3913
4096
  * @param transactionRequest - The transaction request object.
3914
4097
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3915
4098
  */
3916
- estimateTxGasAndFee(params) {
4099
+ async estimateTxGasAndFee(params) {
3917
4100
  const { transactionRequest } = params;
3918
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4101
+ let { gasPrice } = params;
3919
4102
  const chainInfo = this.getChain();
3920
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3921
- transactionRequest.gasPrice = gasPrice;
4103
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
3922
4104
  const minGas = transactionRequest.calculateMinGas(chainInfo);
3923
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3924
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4105
+ if (!gasPrice) {
4106
+ gasPrice = await this.estimateGasPrice(10);
4107
+ }
4108
+ const minFee = calculateGasFee({
4109
+ gasPrice: (0, import_math16.bn)(gasPrice),
4110
+ gas: minGas,
4111
+ priceFactor: gasPriceFactor,
4112
+ tip: transactionRequest.tip
4113
+ }).add(1);
4114
+ let gasLimit = (0, import_math16.bn)(0);
4115
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4116
+ gasLimit = transactionRequest.gasLimit;
3925
4117
  if (transactionRequest.gasLimit.eq(0)) {
3926
4118
  transactionRequest.gasLimit = minGas;
3927
4119
  transactionRequest.gasLimit = maxGasPerTx.sub(
3928
4120
  transactionRequest.calculateMaxGas(chainInfo, minGas)
3929
4121
  );
4122
+ gasLimit = transactionRequest.gasLimit;
3930
4123
  }
3931
4124
  }
3932
4125
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3933
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4126
+ const maxFee = calculateGasFee({
4127
+ gasPrice: (0, import_math16.bn)(gasPrice),
4128
+ gas: maxGas,
4129
+ priceFactor: gasPriceFactor,
4130
+ tip: transactionRequest.tip
4131
+ }).add(1);
3934
4132
  return {
3935
4133
  minGas,
3936
4134
  minFee,
3937
4135
  maxGas,
3938
- maxFee
4136
+ maxFee,
4137
+ gasPrice,
4138
+ gasLimit
3939
4139
  };
3940
4140
  }
3941
4141
  /**
@@ -3953,15 +4153,17 @@ var _Provider = class {
3953
4153
  if (estimateTxDependencies) {
3954
4154
  return this.estimateTxDependencies(transactionRequest);
3955
4155
  }
3956
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3957
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3958
- encodedTransaction,
4156
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4157
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4158
+ encodedTransactions,
3959
4159
  utxoValidation: true
3960
4160
  });
3961
- const receipts = gqlReceipts.map(processGqlReceipt);
3962
- return {
3963
- receipts
3964
- };
4161
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4162
+ const { id, receipts, status } = dryRunStatus;
4163
+ const processedReceipts = receipts.map(processGqlReceipt);
4164
+ return { id, receipts: processedReceipts, status };
4165
+ });
4166
+ return { receipts: callResult[0].receipts };
3965
4167
  }
3966
4168
  /**
3967
4169
  * Returns a transaction cost to enable user
@@ -3978,77 +4180,79 @@ var _Provider = class {
3978
4180
  * @param tolerance - The tolerance to add on top of the gasUsed.
3979
4181
  * @returns A promise that resolves to the transaction cost object.
3980
4182
  */
3981
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3982
- estimateTxDependencies = true,
3983
- estimatePredicates = true,
3984
- resourcesOwner,
3985
- signatureCallback
3986
- } = {}) {
4183
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3987
4184
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
3988
- const { minGasPrice } = this.getGasConfig();
3989
- const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
3990
- const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4185
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
3991
4186
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3992
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4187
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
3993
4188
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4189
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
3994
4190
  if (isScriptTransaction) {
3995
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4191
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
3996
4192
  }
3997
- if (estimatePredicates) {
3998
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3999
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4000
- }
4001
- await this.estimatePredicates(txRequestClone);
4193
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4194
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4002
4195
  }
4196
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4197
+ let addedSignatures = 0;
4003
4198
  if (signatureCallback && isScriptTransaction) {
4004
- await signatureCallback(txRequestClone);
4199
+ const lengthBefore = signedRequest.witnesses.length;
4200
+ await signatureCallback(signedRequest);
4201
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4005
4202
  }
4006
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4007
- transactionRequest: txRequestClone
4203
+ await this.estimatePredicates(signedRequest);
4204
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4205
+ transactionRequest: signedRequest
4008
4206
  });
4009
4207
  let receipts = [];
4010
4208
  let missingContractIds = [];
4011
4209
  let outputVariables = 0;
4012
- let gasUsed = (0, import_math15.bn)(0);
4013
- if (isScriptTransaction && estimateTxDependencies) {
4014
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
4210
+ let gasUsed = (0, import_math16.bn)(0);
4211
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4212
+ txRequestClone.maxFee = maxFee;
4213
+ if (isScriptTransaction) {
4214
+ txRequestClone.gasLimit = gasLimit;
4215
+ if (signatureCallback) {
4216
+ await signatureCallback(txRequestClone);
4217
+ }
4015
4218
  const result = await this.estimateTxDependencies(txRequestClone);
4016
4219
  receipts = result.receipts;
4017
4220
  outputVariables = result.outputVariables;
4018
4221
  missingContractIds = result.missingContractIds;
4019
4222
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4020
4223
  txRequestClone.gasLimit = gasUsed;
4021
- txRequestClone.gasPrice = setGasPrice;
4022
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4023
- transactionRequest: txRequestClone
4224
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4225
+ transactionRequest: txRequestClone,
4226
+ gasPrice
4024
4227
  }));
4025
4228
  }
4026
4229
  return {
4027
4230
  requiredQuantities: allQuantities,
4028
4231
  receipts,
4029
4232
  gasUsed,
4030
- minGasPrice,
4031
- gasPrice: setGasPrice,
4233
+ gasPrice,
4032
4234
  minGas,
4033
4235
  maxGas,
4034
4236
  minFee,
4035
4237
  maxFee,
4036
- estimatedInputs: txRequestClone.inputs,
4037
4238
  outputVariables,
4038
- missingContractIds
4239
+ missingContractIds,
4240
+ addedSignatures,
4241
+ estimatedPredicates: txRequestClone.inputs
4039
4242
  };
4040
4243
  }
4041
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4244
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4042
4245
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4043
4246
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4044
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4247
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4248
+ quantitiesToContract
4249
+ });
4045
4250
  transactionRequest.addResources(
4046
4251
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4047
4252
  );
4048
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4049
- transactionRequest,
4050
- forwardingQuantities
4051
- );
4253
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4254
+ quantitiesToContract
4255
+ });
4052
4256
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4053
4257
  return {
4054
4258
  resources,
@@ -4064,17 +4268,16 @@ var _Provider = class {
4064
4268
  const result = await this.operations.getCoins({
4065
4269
  first: 10,
4066
4270
  ...paginationArgs,
4067
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4271
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4068
4272
  });
4069
4273
  const coins = result.coins.edges.map((edge) => edge.node);
4070
4274
  return coins.map((coin) => ({
4071
4275
  id: coin.utxoId,
4072
4276
  assetId: coin.assetId,
4073
- amount: (0, import_math15.bn)(coin.amount),
4277
+ amount: (0, import_math16.bn)(coin.amount),
4074
4278
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4075
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4076
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4077
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4279
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4280
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4078
4281
  }));
4079
4282
  }
4080
4283
  /**
@@ -4088,19 +4291,19 @@ var _Provider = class {
4088
4291
  async getResourcesToSpend(owner, quantities, excludedIds) {
4089
4292
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4090
4293
  const excludeInput = {
4091
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4092
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4294
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4295
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4093
4296
  };
4094
4297
  if (this.cache) {
4095
4298
  const uniqueUtxos = new Set(
4096
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4299
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4097
4300
  );
4098
4301
  excludeInput.utxos = Array.from(uniqueUtxos);
4099
4302
  }
4100
4303
  const coinsQuery = {
4101
4304
  owner: ownerAddress.toB256(),
4102
4305
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4103
- assetId: (0, import_utils23.hexlify)(assetId),
4306
+ assetId: (0, import_utils22.hexlify)(assetId),
4104
4307
  amount: amount.toString(10),
4105
4308
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4106
4309
  })),
@@ -4111,9 +4314,9 @@ var _Provider = class {
4111
4314
  switch (coin.__typename) {
4112
4315
  case "MessageCoin":
4113
4316
  return {
4114
- amount: (0, import_math15.bn)(coin.amount),
4317
+ amount: (0, import_math16.bn)(coin.amount),
4115
4318
  assetId: coin.assetId,
4116
- daHeight: (0, import_math15.bn)(coin.daHeight),
4319
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4117
4320
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4118
4321
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4119
4322
  nonce: coin.nonce
@@ -4121,12 +4324,11 @@ var _Provider = class {
4121
4324
  case "Coin":
4122
4325
  return {
4123
4326
  id: coin.utxoId,
4124
- amount: (0, import_math15.bn)(coin.amount),
4327
+ amount: (0, import_math16.bn)(coin.amount),
4125
4328
  assetId: coin.assetId,
4126
4329
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4127
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4128
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4129
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4330
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4331
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4130
4332
  };
4131
4333
  default:
4132
4334
  return null;
@@ -4143,13 +4345,13 @@ var _Provider = class {
4143
4345
  async getBlock(idOrHeight) {
4144
4346
  let variables;
4145
4347
  if (typeof idOrHeight === "number") {
4146
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4348
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4147
4349
  } else if (idOrHeight === "latest") {
4148
4350
  variables = { height: (await this.getBlockNumber()).toString(10) };
4149
4351
  } else if (idOrHeight.length === 66) {
4150
4352
  variables = { blockId: idOrHeight };
4151
4353
  } else {
4152
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4354
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4153
4355
  }
4154
4356
  const { block } = await this.operations.getBlock(variables);
4155
4357
  if (!block) {
@@ -4157,7 +4359,7 @@ var _Provider = class {
4157
4359
  }
4158
4360
  return {
4159
4361
  id: block.id,
4160
- height: (0, import_math15.bn)(block.header.height),
4362
+ height: (0, import_math16.bn)(block.height),
4161
4363
  time: block.header.time,
4162
4364
  transactionIds: block.transactions.map((tx) => tx.id)
4163
4365
  };
@@ -4172,7 +4374,7 @@ var _Provider = class {
4172
4374
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4173
4375
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4174
4376
  id: block.id,
4175
- height: (0, import_math15.bn)(block.header.height),
4377
+ height: (0, import_math16.bn)(block.height),
4176
4378
  time: block.header.time,
4177
4379
  transactionIds: block.transactions.map((tx) => tx.id)
4178
4380
  }));
@@ -4187,7 +4389,7 @@ var _Provider = class {
4187
4389
  async getBlockWithTransactions(idOrHeight) {
4188
4390
  let variables;
4189
4391
  if (typeof idOrHeight === "number") {
4190
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4392
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4191
4393
  } else if (idOrHeight === "latest") {
4192
4394
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4193
4395
  } else {
@@ -4199,11 +4401,11 @@ var _Provider = class {
4199
4401
  }
4200
4402
  return {
4201
4403
  id: block.id,
4202
- height: (0, import_math15.bn)(block.header.height, 10),
4404
+ height: (0, import_math16.bn)(block.height, 10),
4203
4405
  time: block.header.time,
4204
4406
  transactionIds: block.transactions.map((tx) => tx.id),
4205
4407
  transactions: block.transactions.map(
4206
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4408
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4207
4409
  )
4208
4410
  };
4209
4411
  }
@@ -4218,8 +4420,8 @@ var _Provider = class {
4218
4420
  if (!transaction) {
4219
4421
  return null;
4220
4422
  }
4221
- return new import_transactions18.TransactionCoder().decode(
4222
- (0, import_utils23.arrayify)(transaction.rawPayload),
4423
+ return new import_transactions19.TransactionCoder().decode(
4424
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4223
4425
  0
4224
4426
  )?.[0];
4225
4427
  }
@@ -4246,9 +4448,9 @@ var _Provider = class {
4246
4448
  async getContractBalance(contractId, assetId) {
4247
4449
  const { contractBalance } = await this.operations.getContractBalance({
4248
4450
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4249
- asset: (0, import_utils23.hexlify)(assetId)
4451
+ asset: (0, import_utils22.hexlify)(assetId)
4250
4452
  });
4251
- return (0, import_math15.bn)(contractBalance.amount, 10);
4453
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4252
4454
  }
4253
4455
  /**
4254
4456
  * Returns the balance for the given owner for the given asset ID.
@@ -4260,9 +4462,9 @@ var _Provider = class {
4260
4462
  async getBalance(owner, assetId) {
4261
4463
  const { balance } = await this.operations.getBalance({
4262
4464
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4263
- assetId: (0, import_utils23.hexlify)(assetId)
4465
+ assetId: (0, import_utils22.hexlify)(assetId)
4264
4466
  });
4265
- return (0, import_math15.bn)(balance.amount, 10);
4467
+ return (0, import_math16.bn)(balance.amount, 10);
4266
4468
  }
4267
4469
  /**
4268
4470
  * Returns balances for the given owner.
@@ -4280,7 +4482,7 @@ var _Provider = class {
4280
4482
  const balances = result.balances.edges.map((edge) => edge.node);
4281
4483
  return balances.map((balance) => ({
4282
4484
  assetId: balance.assetId,
4283
- amount: (0, import_math15.bn)(balance.amount)
4485
+ amount: (0, import_math16.bn)(balance.amount)
4284
4486
  }));
4285
4487
  }
4286
4488
  /**
@@ -4298,19 +4500,19 @@ var _Provider = class {
4298
4500
  });
4299
4501
  const messages = result.messages.edges.map((edge) => edge.node);
4300
4502
  return messages.map((message) => ({
4301
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4503
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4302
4504
  sender: message.sender,
4303
4505
  recipient: message.recipient,
4304
4506
  nonce: message.nonce,
4305
- amount: (0, import_math15.bn)(message.amount),
4507
+ amount: (0, import_math16.bn)(message.amount),
4306
4508
  data: message.data
4307
4509
  }),
4308
4510
  sender: import_address3.Address.fromAddressOrString(message.sender),
4309
4511
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4310
4512
  nonce: message.nonce,
4311
- amount: (0, import_math15.bn)(message.amount),
4312
- data: import_transactions18.InputMessageCoder.decodeData(message.data),
4313
- daHeight: (0, import_math15.bn)(message.daHeight)
4513
+ amount: (0, import_math16.bn)(message.amount),
4514
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4515
+ daHeight: (0, import_math16.bn)(message.daHeight)
4314
4516
  }));
4315
4517
  }
4316
4518
  /**
@@ -4363,44 +4565,60 @@ var _Provider = class {
4363
4565
  } = result.messageProof;
4364
4566
  return {
4365
4567
  messageProof: {
4366
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4568
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4367
4569
  proofSet: messageProof.proofSet
4368
4570
  },
4369
4571
  blockProof: {
4370
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4572
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4371
4573
  proofSet: blockProof.proofSet
4372
4574
  },
4373
4575
  messageBlockHeader: {
4374
4576
  id: messageBlockHeader.id,
4375
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4376
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4577
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4578
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4377
4579
  transactionsRoot: messageBlockHeader.transactionsRoot,
4378
- height: (0, import_math15.bn)(messageBlockHeader.height),
4580
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4379
4581
  prevRoot: messageBlockHeader.prevRoot,
4380
4582
  time: messageBlockHeader.time,
4381
4583
  applicationHash: messageBlockHeader.applicationHash,
4382
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4383
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4584
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
4585
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4586
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4587
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4588
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4384
4589
  },
4385
4590
  commitBlockHeader: {
4386
4591
  id: commitBlockHeader.id,
4387
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4388
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4592
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4593
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4389
4594
  transactionsRoot: commitBlockHeader.transactionsRoot,
4390
- height: (0, import_math15.bn)(commitBlockHeader.height),
4595
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4391
4596
  prevRoot: commitBlockHeader.prevRoot,
4392
4597
  time: commitBlockHeader.time,
4393
4598
  applicationHash: commitBlockHeader.applicationHash,
4394
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4395
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4599
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
4600
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4601
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4602
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4603
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4396
4604
  },
4397
4605
  sender: import_address3.Address.fromAddressOrString(sender),
4398
4606
  recipient: import_address3.Address.fromAddressOrString(recipient),
4399
4607
  nonce,
4400
- amount: (0, import_math15.bn)(amount),
4608
+ amount: (0, import_math16.bn)(amount),
4401
4609
  data
4402
4610
  };
4403
4611
  }
4612
+ async getLatestGasPrice() {
4613
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4614
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4615
+ }
4616
+ async estimateGasPrice(blockHorizon) {
4617
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4618
+ blockHorizon: String(blockHorizon)
4619
+ });
4620
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4621
+ }
4404
4622
  /**
4405
4623
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4406
4624
  *
@@ -4420,10 +4638,10 @@ var _Provider = class {
4420
4638
  */
4421
4639
  async produceBlocks(amount, startTime) {
4422
4640
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4423
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4424
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4641
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4642
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4425
4643
  });
4426
- return (0, import_math15.bn)(latestBlockHeight);
4644
+ return (0, import_math16.bn)(latestBlockHeight);
4427
4645
  }
4428
4646
  // eslint-disable-next-line @typescript-eslint/require-await
4429
4647
  async getTransactionResponse(transactionId) {
@@ -4437,7 +4655,7 @@ cacheInputs_fn = function(inputs) {
4437
4655
  return;
4438
4656
  }
4439
4657
  inputs.forEach((input) => {
4440
- if (input.type === import_transactions18.InputType.Coin) {
4658
+ if (input.type === import_transactions19.InputType.Coin) {
4441
4659
  this.cache?.set(input.id);
4442
4660
  }
4443
4661
  });
@@ -4447,9 +4665,9 @@ __publicField(Provider, "nodeInfoCache", {});
4447
4665
 
4448
4666
  // src/providers/transaction-summary/get-transaction-summary.ts
4449
4667
  var import_errors15 = require("@fuel-ts/errors");
4450
- var import_math16 = require("@fuel-ts/math");
4451
- var import_transactions19 = require("@fuel-ts/transactions");
4452
- var import_utils26 = require("@fuel-ts/utils");
4668
+ var import_math17 = require("@fuel-ts/math");
4669
+ var import_transactions20 = require("@fuel-ts/transactions");
4670
+ var import_utils25 = require("@fuel-ts/utils");
4453
4671
 
4454
4672
  // src/providers/chains.ts
4455
4673
  var CHAIN_IDS = {
@@ -4498,17 +4716,17 @@ var assets = [
4498
4716
 
4499
4717
  // src/utils/formatTransferToContractScriptData.ts
4500
4718
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4501
- var import_math17 = require("@fuel-ts/math");
4502
- var import_utils27 = require("@fuel-ts/utils");
4719
+ var import_math18 = require("@fuel-ts/math");
4720
+ var import_utils26 = require("@fuel-ts/utils");
4503
4721
  var asm = __toESM(require("@fuels/vm-asm"));
4504
4722
  var formatTransferToContractScriptData = (params) => {
4505
4723
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4506
4724
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4507
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4725
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4508
4726
  const scriptData = Uint8Array.from([
4509
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
4727
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4510
4728
  ...encoded,
4511
- ...(0, import_utils27.arrayify)(assetId)
4729
+ ...(0, import_utils26.arrayify)(assetId)
4512
4730
  ]);
4513
4731
  return scriptData;
4514
4732
  };
@@ -4655,9 +4873,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4655
4873
  * @param assetId - The asset ID to check the balance for.
4656
4874
  * @returns A promise that resolves to the balance amount.
4657
4875
  */
4658
- async getBalance(assetId) {
4659
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4660
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4876
+ async getBalance(assetId = import_configs12.BaseAssetId) {
4877
+ const amount = await this.provider.getBalance(this.address, assetId);
4661
4878
  return amount;
4662
4879
  }
4663
4880
  /**
@@ -4694,37 +4911,33 @@ var Account = class extends import_interfaces.AbstractAccount {
4694
4911
  * @param fee - The estimated transaction fee.
4695
4912
  * @returns A promise that resolves when the resources are added to the transaction.
4696
4913
  */
4697
- async fund(request, coinQuantities, fee) {
4698
- const baseAssetId = this.provider.getBaseAssetId();
4699
- const updatedQuantities = addAmountToAsset({
4700
- amount: (0, import_math18.bn)(fee),
4701
- assetId: baseAssetId,
4702
- coinQuantities
4914
+ async fund(request, params) {
4915
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4916
+ const txRequest = request;
4917
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4918
+ amount: (0, import_math19.bn)(fee),
4919
+ assetId: import_configs12.BaseAssetId,
4920
+ coinQuantities: requiredQuantities
4703
4921
  });
4704
4922
  const quantitiesDict = {};
4705
- updatedQuantities.forEach(({ amount, assetId }) => {
4923
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4706
4924
  quantitiesDict[assetId] = {
4707
4925
  required: amount,
4708
- owned: (0, import_math18.bn)(0)
4926
+ owned: (0, import_math19.bn)(0)
4709
4927
  };
4710
4928
  });
4711
- const cachedUtxos = [];
4712
- const cachedMessages = [];
4713
- const owner = this.address.toB256();
4714
- request.inputs.forEach((input) => {
4929
+ txRequest.inputs.forEach((input) => {
4715
4930
  const isResource = "amount" in input;
4716
4931
  if (isResource) {
4717
4932
  const isCoin2 = "owner" in input;
4718
4933
  if (isCoin2) {
4719
4934
  const assetId = String(input.assetId);
4720
- if (input.owner === owner && quantitiesDict[assetId]) {
4721
- const amount = (0, import_math18.bn)(input.amount);
4935
+ if (quantitiesDict[assetId]) {
4936
+ const amount = (0, import_math19.bn)(input.amount);
4722
4937
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4723
- cachedUtxos.push(input.id);
4724
4938
  }
4725
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4726
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4727
- cachedMessages.push(input.nonce);
4939
+ } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
4940
+ quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
4728
4941
  }
4729
4942
  }
4730
4943
  });
@@ -4739,12 +4952,23 @@ var Account = class extends import_interfaces.AbstractAccount {
4739
4952
  });
4740
4953
  const needsToBeFunded = missingQuantities.length;
4741
4954
  if (needsToBeFunded) {
4742
- const resources = await this.getResourcesToSpend(missingQuantities, {
4743
- messages: cachedMessages,
4744
- utxos: cachedUtxos
4745
- });
4746
- request.addResources(resources);
4955
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
4956
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4957
+ txRequest.addResources(resources);
4958
+ }
4959
+ txRequest.shiftPredicateData();
4960
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
4961
+ const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
4962
+ if (addedSignatures) {
4963
+ Array.from({ length: addedSignatures }).forEach(
4964
+ () => requestToBeReEstimate.addEmptyWitness()
4965
+ );
4747
4966
  }
4967
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
4968
+ transactionRequest: requestToBeReEstimate
4969
+ });
4970
+ txRequest.maxFee = maxFee;
4971
+ return txRequest;
4748
4972
  }
4749
4973
  /**
4750
4974
  * A helper that creates a transfer transaction request and returns it.
@@ -4752,30 +4976,25 @@ var Account = class extends import_interfaces.AbstractAccount {
4752
4976
  * @param destination - The address of the destination.
4753
4977
  * @param amount - The amount of coins to transfer.
4754
4978
  * @param assetId - The asset ID of the coins to transfer.
4755
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4979
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4756
4980
  * @returns A promise that resolves to the prepared transaction request.
4757
4981
  */
4758
- async createTransfer(destination, amount, assetId, txParams = {}) {
4759
- const { minGasPrice } = this.provider.getGasConfig();
4760
- const baseAssetId = this.provider.getBaseAssetId();
4761
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4762
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4763
- const request = new ScriptTransactionRequest(params);
4764
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
4765
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4982
+ async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4983
+ const request = new ScriptTransactionRequest(txParams);
4984
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
4985
+ const txCost = await this.provider.getTransactionCost(request, {
4766
4986
  estimateTxDependencies: true,
4767
4987
  resourcesOwner: this
4768
4988
  });
4769
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
4770
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
4771
- this.validateGas({
4772
- gasUsed,
4773
- gasPrice: request.gasPrice,
4774
- gasLimit: request.gasLimit,
4775
- minGasPrice
4776
- });
4777
- await this.fund(request, requiredQuantities, maxFee);
4778
- request.updatePredicateInputs(estimatedInputs);
4989
+ if ("gasLimit" in txParams) {
4990
+ this.validateGas({
4991
+ gasUsed: txCost.gasUsed,
4992
+ gasLimit: request.gasLimit
4993
+ });
4994
+ }
4995
+ request.gasLimit = txCost.gasUsed;
4996
+ request.maxFee = txCost.maxFee;
4997
+ await this.fund(request, txCost);
4779
4998
  return request;
4780
4999
  }
4781
5000
  /**
@@ -4787,15 +5006,14 @@ var Account = class extends import_interfaces.AbstractAccount {
4787
5006
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4788
5007
  * @returns A promise that resolves to the transaction response.
4789
5008
  */
4790
- async transfer(destination, amount, assetId, txParams = {}) {
4791
- if ((0, import_math18.bn)(amount).lte(0)) {
5009
+ async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5010
+ if ((0, import_math19.bn)(amount).lte(0)) {
4792
5011
  throw new import_errors16.FuelError(
4793
5012
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4794
5013
  "Transfer amount must be a positive number."
4795
5014
  );
4796
5015
  }
4797
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4798
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5016
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4799
5017
  return this.sendTransaction(request, { estimateTxDependencies: false });
4800
5018
  }
4801
5019
  /**
@@ -4807,41 +5025,38 @@ var Account = class extends import_interfaces.AbstractAccount {
4807
5025
  * @param txParams - The optional transaction parameters.
4808
5026
  * @returns A promise that resolves to the transaction response.
4809
5027
  */
4810
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4811
- if ((0, import_math18.bn)(amount).lte(0)) {
5028
+ async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5029
+ if ((0, import_math19.bn)(amount).lte(0)) {
4812
5030
  throw new import_errors16.FuelError(
4813
5031
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4814
5032
  "Transfer amount must be a positive number."
4815
5033
  );
4816
5034
  }
4817
5035
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4818
- const { minGasPrice } = this.provider.getGasConfig();
4819
- const baseAssetId = this.provider.getBaseAssetId();
4820
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4821
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4822
5036
  const { script, scriptData } = await assembleTransferToContractScript({
4823
5037
  hexlifiedContractId: contractAddress.toB256(),
4824
- amountToTransfer: (0, import_math18.bn)(amount),
4825
- assetId: assetIdToTransfer
5038
+ amountToTransfer: (0, import_math19.bn)(amount),
5039
+ assetId
4826
5040
  });
4827
5041
  const request = new ScriptTransactionRequest({
4828
- ...params,
5042
+ ...txParams,
4829
5043
  script,
4830
5044
  scriptData
4831
5045
  });
4832
5046
  request.addContractInputAndOutput(contractAddress);
4833
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4834
- request,
4835
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
4836
- );
4837
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4838
- this.validateGas({
4839
- gasUsed,
4840
- gasPrice: request.gasPrice,
4841
- gasLimit: request.gasLimit,
4842
- minGasPrice
5047
+ const txCost = await this.provider.getTransactionCost(request, {
5048
+ resourcesOwner: this,
5049
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
4843
5050
  });
4844
- await this.fund(request, requiredQuantities, maxFee);
5051
+ if (txParams.gasLimit) {
5052
+ this.validateGas({
5053
+ gasUsed: txCost.gasUsed,
5054
+ gasLimit: request.gasLimit
5055
+ });
5056
+ }
5057
+ request.gasLimit = txCost.gasUsed;
5058
+ request.maxFee = txCost.maxFee;
5059
+ await this.fund(request, txCost);
4845
5060
  return this.sendTransaction(request);
4846
5061
  }
4847
5062
  /**
@@ -4853,40 +5068,31 @@ var Account = class extends import_interfaces.AbstractAccount {
4853
5068
  * @returns A promise that resolves to the transaction response.
4854
5069
  */
4855
5070
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4856
- const { minGasPrice } = this.provider.getGasConfig();
4857
- const baseAssetId = this.provider.getBaseAssetId();
4858
5071
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
4859
- const recipientDataArray = (0, import_utils28.arrayify)(
5072
+ const recipientDataArray = (0, import_utils27.arrayify)(
4860
5073
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4861
5074
  );
4862
- const amountDataArray = (0, import_utils28.arrayify)(
4863
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5075
+ const amountDataArray = (0, import_utils27.arrayify)(
5076
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
4864
5077
  );
4865
5078
  const script = new Uint8Array([
4866
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5079
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
4867
5080
  ...recipientDataArray,
4868
5081
  ...amountDataArray
4869
5082
  ]);
4870
- const params = {
4871
- script,
4872
- gasPrice: minGasPrice,
4873
- baseAssetId,
4874
- ...txParams
4875
- };
5083
+ const params = { script, ...txParams };
4876
5084
  const request = new ScriptTransactionRequest(params);
4877
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
4878
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4879
- request,
4880
- forwardingQuantities
4881
- );
4882
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4883
- this.validateGas({
4884
- gasUsed,
4885
- gasPrice: request.gasPrice,
4886
- gasLimit: request.gasLimit,
4887
- minGasPrice
4888
- });
4889
- await this.fund(request, requiredQuantities, maxFee);
5085
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5086
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5087
+ if (txParams.gasLimit) {
5088
+ this.validateGas({
5089
+ gasUsed: txCost.gasUsed,
5090
+ gasLimit: request.gasLimit
5091
+ });
5092
+ }
5093
+ request.maxFee = txCost.maxFee;
5094
+ request.gasLimit = txCost.gasUsed;
5095
+ await this.fund(request, txCost);
4890
5096
  return this.sendTransaction(request);
4891
5097
  }
4892
5098
  async signMessage(message) {
@@ -4944,18 +5150,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4944
5150
  }
4945
5151
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
4946
5152
  }
4947
- validateGas({
4948
- gasUsed,
4949
- gasPrice,
4950
- gasLimit,
4951
- minGasPrice
4952
- }) {
4953
- if (minGasPrice.gt(gasPrice)) {
4954
- throw new import_errors16.FuelError(
4955
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
4956
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
4957
- );
4958
- }
5153
+ validateGas({ gasUsed, gasLimit }) {
4959
5154
  if (gasUsed.gt(gasLimit)) {
4960
5155
  throw new import_errors16.FuelError(
4961
5156
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -4969,8 +5164,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4969
5164
  var import_address5 = require("@fuel-ts/address");
4970
5165
  var import_crypto2 = require("@fuel-ts/crypto");
4971
5166
  var import_hasher2 = require("@fuel-ts/hasher");
4972
- var import_math19 = require("@fuel-ts/math");
4973
- var import_utils29 = require("@fuel-ts/utils");
5167
+ var import_math20 = require("@fuel-ts/math");
5168
+ var import_utils28 = require("@fuel-ts/utils");
4974
5169
  var import_secp256k1 = require("@noble/curves/secp256k1");
4975
5170
  var Signer = class {
4976
5171
  address;
@@ -4989,10 +5184,10 @@ var Signer = class {
4989
5184
  privateKey = `0x${privateKey}`;
4990
5185
  }
4991
5186
  }
4992
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
4993
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
4994
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
4995
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5187
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5188
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5189
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5190
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
4996
5191
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
4997
5192
  }
4998
5193
  /**
@@ -5006,11 +5201,11 @@ var Signer = class {
5006
5201
  * @returns hashed signature
5007
5202
  */
5008
5203
  sign(data) {
5009
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5010
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
5011
- const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5204
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5205
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5206
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
5012
5207
  s[0] |= (signature.recovery || 0) << 7;
5013
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5208
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5014
5209
  }
5015
5210
  /**
5016
5211
  * Add point on the current elliptic curve
@@ -5019,8 +5214,8 @@ var Signer = class {
5019
5214
  * @returns compressed point on the curve
5020
5215
  */
5021
5216
  addPoint(point) {
5022
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5023
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5217
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5218
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
5024
5219
  const result = p0.add(p1);
5025
5220
  return `0x${result.toHex(true)}`;
5026
5221
  }
@@ -5032,16 +5227,16 @@ var Signer = class {
5032
5227
  * @returns public key from signature from the
5033
5228
  */
5034
5229
  static recoverPublicKey(data, signature) {
5035
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5230
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5036
5231
  const r = signedMessageBytes.slice(0, 32);
5037
5232
  const s = signedMessageBytes.slice(32, 64);
5038
5233
  const recoveryParam = (s[0] & 128) >> 7;
5039
5234
  s[0] &= 127;
5040
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5235
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5041
5236
  recoveryParam
5042
5237
  );
5043
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5044
- return (0, import_utils29.hexlify)(publicKey);
5238
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5239
+ return (0, import_utils28.hexlify)(publicKey);
5045
5240
  }
5046
5241
  /**
5047
5242
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5060,7 +5255,7 @@ var Signer = class {
5060
5255
  * @returns random 32-byte hashed
5061
5256
  */
5062
5257
  static generatePrivateKey(entropy) {
5063
- return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
5258
+ return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
5064
5259
  }
5065
5260
  /**
5066
5261
  * Extended publicKey from a compact publicKey
@@ -5069,8 +5264,8 @@ var Signer = class {
5069
5264
  * @returns extended publicKey
5070
5265
  */
5071
5266
  static extendPublicKey(publicKey) {
5072
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5073
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5267
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5268
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5074
5269
  }
5075
5270
  };
5076
5271
 
@@ -5078,7 +5273,7 @@ var Signer = class {
5078
5273
  var import_address6 = require("@fuel-ts/address");
5079
5274
  var import_crypto3 = require("@fuel-ts/crypto");
5080
5275
  var import_errors17 = require("@fuel-ts/errors");
5081
- var import_utils30 = require("@fuel-ts/utils");
5276
+ var import_utils29 = require("@fuel-ts/utils");
5082
5277
  var import_uuid = require("uuid");
5083
5278
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5084
5279
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5161,7 +5356,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5161
5356
  );
5162
5357
  }
5163
5358
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5164
- const privateKey = (0, import_utils30.hexlify)(buffer);
5359
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5165
5360
  return privateKey;
5166
5361
  }
5167
5362
 
@@ -5206,7 +5401,7 @@ var BaseWalletUnlocked = class extends Account {
5206
5401
  */
5207
5402
  async signMessage(message) {
5208
5403
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5209
- return (0, import_utils31.hexlify)(signedMessage);
5404
+ return (0, import_utils30.hexlify)(signedMessage);
5210
5405
  }
5211
5406
  /**
5212
5407
  * Signs a transaction with the wallet's private key.
@@ -5219,7 +5414,7 @@ var BaseWalletUnlocked = class extends Account {
5219
5414
  const chainId = this.provider.getChainId();
5220
5415
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5221
5416
  const signature = await this.signer().sign(hashedTransaction);
5222
- return (0, import_utils31.hexlify)(signature);
5417
+ return (0, import_utils30.hexlify)(signature);
5223
5418
  }
5224
5419
  /**
5225
5420
  * Populates a transaction with the witnesses signature.
@@ -5239,7 +5434,7 @@ var BaseWalletUnlocked = class extends Account {
5239
5434
  * @param transactionRequestLike - The transaction request to send.
5240
5435
  * @returns A promise that resolves to the TransactionResponse object.
5241
5436
  */
5242
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5437
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5243
5438
  const transactionRequest = transactionRequestify(transactionRequestLike);
5244
5439
  if (estimateTxDependencies) {
5245
5440
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5280,15 +5475,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5280
5475
  // src/hdwallet/hdwallet.ts
5281
5476
  var import_errors20 = require("@fuel-ts/errors");
5282
5477
  var import_hasher6 = require("@fuel-ts/hasher");
5283
- var import_math20 = require("@fuel-ts/math");
5284
- var import_utils35 = require("@fuel-ts/utils");
5478
+ var import_math21 = require("@fuel-ts/math");
5479
+ var import_utils34 = require("@fuel-ts/utils");
5285
5480
  var import_ethers3 = require("ethers");
5286
5481
 
5287
5482
  // src/mnemonic/mnemonic.ts
5288
5483
  var import_crypto4 = require("@fuel-ts/crypto");
5289
5484
  var import_errors19 = require("@fuel-ts/errors");
5290
5485
  var import_hasher5 = require("@fuel-ts/hasher");
5291
- var import_utils33 = require("@fuel-ts/utils");
5486
+ var import_utils32 = require("@fuel-ts/utils");
5292
5487
  var import_ethers2 = require("ethers");
5293
5488
 
5294
5489
  // src/wordlists/words/english.ts
@@ -7346,7 +7541,7 @@ var english = [
7346
7541
  // src/mnemonic/utils.ts
7347
7542
  var import_errors18 = require("@fuel-ts/errors");
7348
7543
  var import_hasher4 = require("@fuel-ts/hasher");
7349
- var import_utils32 = require("@fuel-ts/utils");
7544
+ var import_utils31 = require("@fuel-ts/utils");
7350
7545
  function toUtf8Bytes(stri) {
7351
7546
  const str = stri.normalize("NFKD");
7352
7547
  const result = [];
@@ -7413,14 +7608,14 @@ function entropyToMnemonicIndices(entropy) {
7413
7608
  }
7414
7609
  }
7415
7610
  const checksumBits = entropy.length / 4;
7416
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7611
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7417
7612
  indices[indices.length - 1] <<= checksumBits;
7418
7613
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7419
7614
  return indices;
7420
7615
  }
7421
7616
  function mnemonicWordsToEntropy(words, wordlist) {
7422
7617
  const size = Math.ceil(11 * words.length / 8);
7423
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7618
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7424
7619
  let offset = 0;
7425
7620
  for (let i = 0; i < words.length; i += 1) {
7426
7621
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7440,7 +7635,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7440
7635
  const entropyBits = 32 * words.length / 3;
7441
7636
  const checksumBits = words.length / 3;
7442
7637
  const checksumMask = getUpperMask(checksumBits);
7443
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7638
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7444
7639
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7445
7640
  throw new import_errors18.FuelError(
7446
7641
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7515,7 +7710,7 @@ var Mnemonic = class {
7515
7710
  static mnemonicToEntropy(phrase, wordlist = english) {
7516
7711
  const words = getWords(phrase);
7517
7712
  assertMnemonic(words);
7518
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7713
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7519
7714
  }
7520
7715
  /**
7521
7716
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7523,7 +7718,7 @@ var Mnemonic = class {
7523
7718
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7524
7719
  */
7525
7720
  static entropyToMnemonic(entropy, wordlist = english) {
7526
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
7721
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7527
7722
  assertWordList(wordlist);
7528
7723
  assertEntropy(entropyBytes);
7529
7724
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7592,14 +7787,14 @@ var Mnemonic = class {
7592
7787
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7593
7788
  */
7594
7789
  static masterKeysFromSeed(seed) {
7595
- const seedArray = (0, import_utils33.arrayify)(seed);
7790
+ const seedArray = (0, import_utils32.arrayify)(seed);
7596
7791
  if (seedArray.length < 16 || seedArray.length > 64) {
7597
7792
  throw new import_errors19.FuelError(
7598
7793
  import_errors19.ErrorCode.INVALID_SEED,
7599
7794
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7600
7795
  );
7601
7796
  }
7602
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7797
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7603
7798
  }
7604
7799
  /**
7605
7800
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7610,22 +7805,22 @@ var Mnemonic = class {
7610
7805
  */
7611
7806
  static seedToExtendedKey(seed, testnet = false) {
7612
7807
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7613
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7808
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7614
7809
  const depth = "0x00";
7615
7810
  const fingerprint = "0x00000000";
7616
7811
  const index = "0x00000000";
7617
7812
  const chainCode = masterKey.slice(32);
7618
7813
  const privateKey = masterKey.slice(0, 32);
7619
- const extendedKey = (0, import_utils33.concat)([
7814
+ const extendedKey = (0, import_utils32.concat)([
7620
7815
  prefix,
7621
7816
  depth,
7622
7817
  fingerprint,
7623
7818
  index,
7624
7819
  chainCode,
7625
- (0, import_utils33.concat)(["0x00", privateKey])
7820
+ (0, import_utils32.concat)(["0x00", privateKey])
7626
7821
  ]);
7627
7822
  const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7628
- return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
7823
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7629
7824
  }
7630
7825
  /**
7631
7826
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7640,7 +7835,7 @@ var Mnemonic = class {
7640
7835
  * @returns A randomly generated mnemonic
7641
7836
  */
7642
7837
  static generate(size = 32, extraEntropy = "") {
7643
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
7838
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
7644
7839
  return Mnemonic.entropyToMnemonic(entropy);
7645
7840
  }
7646
7841
  };
@@ -7648,12 +7843,12 @@ var mnemonic_default = Mnemonic;
7648
7843
 
7649
7844
  // src/hdwallet/hdwallet.ts
7650
7845
  var HARDENED_INDEX = 2147483648;
7651
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
7652
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
7653
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
7654
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
7846
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
7847
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7848
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7849
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7655
7850
  function base58check(data) {
7656
- 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)]));
7851
+ return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7657
7852
  }
7658
7853
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7659
7854
  if (isPublic) {
@@ -7662,11 +7857,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7662
7857
  return testnet ? TestnetPRV2 : MainnetPRV2;
7663
7858
  }
7664
7859
  function isPublicExtendedKey(extendedKey) {
7665
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
7860
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
7666
7861
  }
7667
7862
  function isValidExtendedKey(extendedKey) {
7668
7863
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
7669
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
7864
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
7670
7865
  );
7671
7866
  }
7672
7867
  function parsePath(path2, depth = 0) {
@@ -7684,8 +7879,8 @@ function parsePath(path2, depth = 0) {
7684
7879
  var HDWallet = class {
7685
7880
  depth = 0;
7686
7881
  index = 0;
7687
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
7688
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
7882
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
7883
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
7689
7884
  privateKey;
7690
7885
  publicKey;
7691
7886
  chainCode;
@@ -7697,8 +7892,8 @@ var HDWallet = class {
7697
7892
  constructor(config) {
7698
7893
  if (config.privateKey) {
7699
7894
  const signer = new Signer(config.privateKey);
7700
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
7701
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
7895
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
7896
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
7702
7897
  } else {
7703
7898
  if (!config.publicKey) {
7704
7899
  throw new import_errors20.FuelError(
@@ -7706,7 +7901,7 @@ var HDWallet = class {
7706
7901
  "Both public and private Key cannot be missing. At least one should be provided."
7707
7902
  );
7708
7903
  }
7709
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
7904
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7710
7905
  }
7711
7906
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7712
7907
  this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
@@ -7725,9 +7920,9 @@ var HDWallet = class {
7725
7920
  * @returns A new instance of HDWallet on the derived index
7726
7921
  */
7727
7922
  deriveIndex(index) {
7728
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
7729
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
7730
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
7923
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
7924
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
7925
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
7731
7926
  const data = new Uint8Array(37);
7732
7927
  if (index & HARDENED_INDEX) {
7733
7928
  if (!privateKey) {
@@ -7738,15 +7933,15 @@ var HDWallet = class {
7738
7933
  }
7739
7934
  data.set(privateKey, 1);
7740
7935
  } else {
7741
- data.set((0, import_utils35.arrayify)(this.publicKey));
7936
+ data.set((0, import_utils34.arrayify)(this.publicKey));
7742
7937
  }
7743
- data.set((0, import_math20.toBytes)(index, 4), 33);
7744
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7938
+ data.set((0, import_math21.toBytes)(index, 4), 33);
7939
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7745
7940
  const IL = bytes.slice(0, 32);
7746
7941
  const IR = bytes.slice(32);
7747
7942
  if (privateKey) {
7748
7943
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7749
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
7944
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
7750
7945
  return new HDWallet({
7751
7946
  privateKey: ki,
7752
7947
  chainCode: IR,
@@ -7755,7 +7950,7 @@ var HDWallet = class {
7755
7950
  parentFingerprint: this.fingerprint
7756
7951
  });
7757
7952
  }
7758
- const signer = new Signer((0, import_utils35.hexlify)(IL));
7953
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
7759
7954
  const Ki = signer.addPoint(publicKey);
7760
7955
  return new HDWallet({
7761
7956
  publicKey: Ki,
@@ -7790,12 +7985,12 @@ var HDWallet = class {
7790
7985
  );
7791
7986
  }
7792
7987
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
7793
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
7988
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
7794
7989
  const parentFingerprint = this.parentFingerprint;
7795
- const index = (0, import_math20.toHex)(this.index, 4);
7990
+ const index = (0, import_math21.toHex)(this.index, 4);
7796
7991
  const chainCode = this.chainCode;
7797
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
7798
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7992
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
7993
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7799
7994
  return base58check(extendedKey);
7800
7995
  }
7801
7996
  /**
@@ -7807,13 +8002,13 @@ var HDWallet = class {
7807
8002
  static fromSeed(seed) {
7808
8003
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
7809
8004
  return new HDWallet({
7810
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
7811
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8005
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8006
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
7812
8007
  });
7813
8008
  }
7814
8009
  static fromExtendedKey(extendedKey) {
7815
8010
  const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7816
- const bytes = (0, import_utils35.arrayify)(decoded);
8011
+ const bytes = (0, import_utils34.arrayify)(decoded);
7817
8012
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7818
8013
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7819
8014
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -7822,9 +8017,9 @@ var HDWallet = class {
7822
8017
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7823
8018
  }
7824
8019
  const depth = bytes[4];
7825
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
7826
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7827
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8020
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8021
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8022
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
7828
8023
  const key = bytes.slice(45, 78);
7829
8024
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7830
8025
  throw new import_errors20.FuelError(
@@ -8017,16 +8212,15 @@ var seedTestWallet = async (wallet, quantities) => {
8017
8212
  process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
8018
8213
  wallet.provider
8019
8214
  );
8020
- const resources = await genesisWallet.getResourcesToSpend(quantities);
8021
- const { minGasPrice } = genesisWallet.provider.getGasConfig();
8022
- const baseAssetId = genesisWallet.provider.getBaseAssetId();
8023
- const request = new ScriptTransactionRequest({
8024
- baseAssetId,
8025
- gasLimit: 1e4,
8026
- gasPrice: minGasPrice
8215
+ const request = new ScriptTransactionRequest();
8216
+ quantities.forEach((quantity) => {
8217
+ const { amount, assetId } = coinQuantityfy(quantity);
8218
+ request.addCoinOutput(wallet.address, amount, assetId);
8027
8219
  });
8028
- request.addResources(resources);
8029
- quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
8220
+ const txCost = await genesisWallet.provider.getTransactionCost(request);
8221
+ request.gasLimit = txCost.gasUsed;
8222
+ request.maxFee = txCost.maxFee;
8223
+ await genesisWallet.fund(request, txCost);
8030
8224
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
8031
8225
  };
8032
8226
 
@@ -8040,12 +8234,12 @@ var generateTestWallet = async (provider, quantities) => {
8040
8234
  };
8041
8235
 
8042
8236
  // src/test-utils/launchNode.ts
8043
- var import_configs11 = require("@fuel-ts/address/configs");
8044
- var import_math21 = require("@fuel-ts/math");
8045
- var import_utils36 = require("@fuel-ts/utils");
8237
+ var import_configs13 = require("@fuel-ts/address/configs");
8238
+ var import_utils35 = require("@fuel-ts/utils");
8046
8239
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8047
8240
  var import_child_process = require("child_process");
8048
8241
  var import_crypto6 = require("crypto");
8242
+ var import_ethers4 = require("ethers");
8049
8243
  var import_fs = require("fs");
8050
8244
  var import_os = __toESM(require("os"));
8051
8245
  var import_path = __toESM(require("path"));
@@ -8094,13 +8288,13 @@ var launchNode = async ({
8094
8288
  // eslint-disable-next-line no-async-promise-executor
8095
8289
  new Promise(async (resolve, reject) => {
8096
8290
  const remainingArgs = extractRemainingArgs(args, [
8097
- "--chain",
8291
+ "--snapshot",
8098
8292
  "--consensus-key",
8099
8293
  "--db-type",
8100
8294
  "--poa-instant"
8101
8295
  ]);
8102
- const chainConfigPath = getFlagValueFromArgs(args, "--chain");
8103
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8296
+ const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
8297
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
8104
8298
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8105
8299
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8106
8300
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
@@ -8118,36 +8312,54 @@ var launchNode = async ({
8118
8312
  let chainConfigPathToUse;
8119
8313
  const prefix = basePath || import_os.default.tmpdir();
8120
8314
  const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
8121
- const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
8315
+ const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "chainConfigs");
8122
8316
  if (chainConfigPath) {
8123
8317
  chainConfigPathToUse = chainConfigPath;
8124
8318
  } else {
8125
8319
  if (!(0, import_fs.existsSync)(tempDirPath)) {
8126
8320
  (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8127
8321
  }
8128
- const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
8129
- let chainConfig = import_utils36.defaultChainConfig;
8322
+ let { stateConfigJson } = import_utils35.defaultChainConfigs;
8323
+ const { chainConfigJson, metadataJson } = import_utils35.defaultChainConfigs;
8324
+ stateConfigJson = {
8325
+ ...stateConfigJson,
8326
+ coins: [
8327
+ ...stateConfigJson.coins.map((coin) => ({
8328
+ ...coin,
8329
+ amount: "18446744073709551615"
8330
+ }))
8331
+ ],
8332
+ messages: stateConfigJson.messages.map((message) => ({
8333
+ ...message,
8334
+ amount: "18446744073709551615"
8335
+ }))
8336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8337
+ };
8130
8338
  if (!process.env.GENESIS_SECRET) {
8131
8339
  const pk = Signer.generatePrivateKey();
8132
8340
  const signer = new Signer(pk);
8133
- process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8134
- chainConfig = {
8135
- ...import_utils36.defaultChainConfig,
8136
- initial_state: {
8137
- ...import_utils36.defaultChainConfig.initial_state,
8138
- coins: [
8139
- ...import_utils36.defaultChainConfig.initial_state.coins,
8140
- {
8141
- owner: signer.address.toHexString(),
8142
- amount: (0, import_math21.toHex)(1e9),
8143
- asset_id: import_utils36.defaultChainConfig?.consensus_parameters?.base_asset_id ?? import_configs11.ZeroBytes32
8144
- }
8145
- ]
8146
- }
8147
- };
8341
+ process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
8342
+ stateConfigJson.coins.push({
8343
+ tx_id: (0, import_utils35.hexlify)((0, import_ethers4.randomBytes)(34)),
8344
+ owner: signer.address.toHexString(),
8345
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8346
+ amount: "18446744073709551615",
8347
+ asset_id: import_configs13.BaseAssetId,
8348
+ output_index: 0,
8349
+ tx_pointer_block_height: 0,
8350
+ tx_pointer_tx_idx: 0
8351
+ });
8148
8352
  }
8149
- (0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
8150
- chainConfigPathToUse = tempChainConfigFilePath;
8353
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8354
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8355
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8356
+ const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8357
+ const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8358
+ const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8359
+ (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8360
+ (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8361
+ (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8362
+ chainConfigPathToUse = tempDirPath;
8151
8363
  }
8152
8364
  const child = (0, import_child_process.spawn)(
8153
8365
  command,
@@ -8156,10 +8368,10 @@ var launchNode = async ({
8156
8368
  ["--ip", ipToUse],
8157
8369
  ["--port", portToUse],
8158
8370
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8159
- ["--min-gas-price", "0"],
8371
+ ["--min-gas-price", "1"],
8160
8372
  poaInstant ? ["--poa-instant", "true"] : [],
8161
8373
  ["--consensus-key", consensusKey],
8162
- ["--chain", chainConfigPathToUse],
8374
+ ["--snapshot", chainConfigPathToUse],
8163
8375
  "--vm-backtrace",
8164
8376
  "--utxo-validation",
8165
8377
  "--debug",
@@ -8206,10 +8418,9 @@ var launchNode = async ({
8206
8418
  })
8207
8419
  );
8208
8420
  var generateWallets = async (count, provider) => {
8209
- const baseAssetId = provider.getBaseAssetId();
8210
8421
  const wallets = [];
8211
8422
  for (let i = 0; i < count; i += 1) {
8212
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8423
+ const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
8213
8424
  wallets.push(wallet);
8214
8425
  }
8215
8426
  return wallets;
@@ -8219,7 +8430,7 @@ var launchNodeAndGetWallets = async ({
8219
8430
  walletCount = 10
8220
8431
  } = {}) => {
8221
8432
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8222
- const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8433
+ const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8223
8434
  const wallets = await generateWallets(walletCount, provider);
8224
8435
  const cleanup = () => {
8225
8436
  closeNode();