@fuel-ts/account 0.0.0-rc-2021-20240409152935 → 0.0.0-rc-1976-20240410103621

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

Potentially problematic release.


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

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