@fuel-ts/account 0.0.0-rc-2021-20240408141516 → 0.0.0-rc-1976-20240409133547

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