@fuel-ts/account 0.0.0-rc-2040-20240415161844 → 0.0.0-rc-2021-20240415193305

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

Potentially problematic release.


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

Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +5 -4
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +1 -1
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +1 -1
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +1 -1
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +833 -560
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +834 -555
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +684 -406
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +10 -2
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +906 -324
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +1 -1
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  26. package/dist/providers/message.d.ts +7 -1
  27. package/dist/providers/message.d.ts.map +1 -1
  28. package/dist/providers/provider.d.ts +48 -27
  29. package/dist/providers/provider.d.ts.map +1 -1
  30. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/input.d.ts +2 -2
  32. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  34. package/dist/providers/transaction-request/transaction-request.d.ts +8 -25
  35. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  36. package/dist/providers/transaction-request/utils.d.ts +3 -0
  37. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  38. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  39. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  40. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  42. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  43. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  44. package/dist/providers/utils/gas.d.ts +8 -2
  45. package/dist/providers/utils/gas.d.ts.map +1 -1
  46. package/dist/test-utils/launchNode.d.ts.map +1 -1
  47. package/dist/test-utils.global.js +1579 -1068
  48. package/dist/test-utils.global.js.map +1 -1
  49. package/dist/test-utils.js +809 -548
  50. package/dist/test-utils.js.map +1 -1
  51. package/dist/test-utils.mjs +678 -417
  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
package/dist/index.js CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
95
95
  WalletLocked: () => WalletLocked,
96
96
  WalletManager: () => WalletManager,
97
97
  WalletUnlocked: () => WalletUnlocked,
98
- addAmountToAsset: () => addAmountToAsset,
98
+ addAmountToCoinQuantities: () => addAmountToCoinQuantities,
99
99
  addOperation: () => addOperation,
100
100
  assemblePanicError: () => assemblePanicError,
101
101
  assembleReceiptByType: () => assembleReceiptByType,
@@ -104,9 +104,10 @@ __export(src_exports, {
104
104
  assets: () => assets,
105
105
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
106
106
  cacheFor: () => cacheFor,
107
+ cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
108
+ calculateGasFee: () => calculateGasFee,
107
109
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
108
110
  calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
109
- calculatePriceWithFactor: () => calculatePriceWithFactor,
110
111
  calculateTransactionFee: () => calculateTransactionFee,
111
112
  coinQuantityfy: () => coinQuantityfy,
112
113
  deferPromise: () => deferPromise,
@@ -187,8 +188,9 @@ var import_address4 = require("@fuel-ts/address");
187
188
  var import_configs12 = require("@fuel-ts/address/configs");
188
189
  var import_errors16 = require("@fuel-ts/errors");
189
190
  var import_interfaces = require("@fuel-ts/interfaces");
190
- var import_math18 = require("@fuel-ts/math");
191
- var import_utils28 = require("@fuel-ts/utils");
191
+ var import_math19 = require("@fuel-ts/math");
192
+ var import_utils27 = require("@fuel-ts/utils");
193
+ var import_ramda4 = require("ramda");
192
194
 
193
195
  // src/providers/coin-quantity.ts
194
196
  var import_configs = require("@fuel-ts/address/configs");
@@ -214,7 +216,7 @@ var coinQuantityfy = (coinQuantityLike) => {
214
216
  max: max2 ? (0, import_math.bn)(max2) : void 0
215
217
  };
216
218
  };
217
- var addAmountToAsset = (params) => {
219
+ var addAmountToCoinQuantities = (params) => {
218
220
  const { amount, assetId } = params;
219
221
  const coinQuantities = [...params.coinQuantities];
220
222
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -229,11 +231,11 @@ var addAmountToAsset = (params) => {
229
231
  // src/providers/provider.ts
230
232
  var import_address3 = require("@fuel-ts/address");
231
233
  var import_errors14 = require("@fuel-ts/errors");
232
- var import_math15 = require("@fuel-ts/math");
233
- var import_transactions18 = require("@fuel-ts/transactions");
234
- var import_utils23 = require("@fuel-ts/utils");
234
+ var import_math16 = require("@fuel-ts/math");
235
+ var import_transactions19 = require("@fuel-ts/transactions");
236
+ var import_utils22 = require("@fuel-ts/utils");
235
237
  var import_versions = require("@fuel-ts/versions");
236
- var import_utils24 = require("@noble/curves/abstract/utils");
238
+ var import_utils23 = require("@noble/curves/abstract/utils");
237
239
  var import_ethers = require("ethers");
238
240
  var import_graphql_request = require("graphql-request");
239
241
  var import_ramda3 = require("ramda");
@@ -242,14 +244,10 @@ var import_ramda3 = require("ramda");
242
244
  var import_graphql_tag = __toESM(require("graphql-tag"));
243
245
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
244
246
  fragment receiptFragment on Receipt {
245
- contract {
246
- id
247
- }
247
+ id
248
248
  pc
249
249
  is
250
- to {
251
- id
252
- }
250
+ to
253
251
  toAddress
254
252
  amount
255
253
  assetId
@@ -287,10 +285,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
287
285
  id
288
286
  }
289
287
  time
288
+ receipts {
289
+ ...receiptFragment
290
+ }
290
291
  programState {
291
292
  returnType
292
293
  data
293
294
  }
295
+ receipts {
296
+ ...receiptFragment
297
+ }
294
298
  }
295
299
  ... on FailureStatus {
296
300
  block {
@@ -298,26 +302,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
298
302
  }
299
303
  time
300
304
  reason
305
+ receipts {
306
+ ...receiptFragment
307
+ }
301
308
  }
302
309
  ... on SqueezedOutStatus {
303
310
  reason
304
311
  }
305
312
  }
306
- `;
313
+ ${ReceiptFragmentFragmentDoc}`;
307
314
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
308
315
  fragment transactionFragment on Transaction {
309
316
  id
310
317
  rawPayload
311
- gasPrice
312
- receipts {
313
- ...receiptFragment
314
- }
315
318
  status {
316
319
  ...transactionStatusFragment
317
320
  }
318
321
  }
319
- ${ReceiptFragmentFragmentDoc}
320
- ${TransactionStatusFragmentFragmentDoc}`;
322
+ ${TransactionStatusFragmentFragmentDoc}`;
321
323
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
322
324
  fragment inputEstimatePredicatesFragment on Input {
323
325
  ... on InputCoin {
@@ -335,6 +337,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
335
337
  }
336
338
  }
337
339
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
340
+ var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
341
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
342
+ reason
343
+ programState {
344
+ returnType
345
+ data
346
+ }
347
+ }
348
+ `;
349
+ var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
350
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
351
+ programState {
352
+ returnType
353
+ data
354
+ }
355
+ }
356
+ `;
357
+ var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
358
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
359
+ ... on DryRunFailureStatus {
360
+ ...dryRunFailureStatusFragment
361
+ }
362
+ ... on DryRunSuccessStatus {
363
+ ...dryRunSuccessStatusFragment
364
+ }
365
+ }
366
+ ${DryRunFailureStatusFragmentFragmentDoc}
367
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
368
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
369
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
370
+ id
371
+ status {
372
+ ...dryRunTransactionStatusFragment
373
+ }
374
+ receipts {
375
+ ...receiptFragment
376
+ }
377
+ }
378
+ ${DryRunTransactionStatusFragmentFragmentDoc}
379
+ ${ReceiptFragmentFragmentDoc}`;
338
380
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
339
381
  fragment coinFragment on Coin {
340
382
  __typename
@@ -342,7 +384,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
342
384
  owner
343
385
  amount
344
386
  assetId
345
- maturity
346
387
  blockCreated
347
388
  txCreatedIdx
348
389
  }
@@ -381,26 +422,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
381
422
  messageBlockHeader {
382
423
  id
383
424
  daHeight
425
+ consensusParametersVersion
426
+ stateTransitionBytecodeVersion
384
427
  transactionsCount
428
+ messageReceiptCount
385
429
  transactionsRoot
430
+ messageOutboxRoot
431
+ eventInboxRoot
386
432
  height
387
433
  prevRoot
388
434
  time
389
435
  applicationHash
390
- messageReceiptRoot
391
- messageReceiptCount
392
436
  }
393
437
  commitBlockHeader {
394
438
  id
395
439
  daHeight
440
+ consensusParametersVersion
441
+ stateTransitionBytecodeVersion
396
442
  transactionsCount
443
+ messageReceiptCount
397
444
  transactionsRoot
445
+ messageOutboxRoot
446
+ eventInboxRoot
398
447
  height
399
448
  prevRoot
400
449
  time
401
450
  applicationHash
402
- messageReceiptRoot
403
- messageReceiptCount
404
451
  }
405
452
  sender
406
453
  recipient
@@ -419,8 +466,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
419
466
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
420
467
  fragment blockFragment on Block {
421
468
  id
469
+ height
422
470
  header {
423
- height
424
471
  time
425
472
  }
426
473
  transactions {
@@ -478,6 +525,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
478
525
  `;
479
526
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
480
527
  fragment GasCostsFragment on GasCosts {
528
+ version {
529
+ ... on Version {
530
+ value
531
+ }
532
+ }
481
533
  add
482
534
  addi
483
535
  aloc
@@ -490,7 +542,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
490
542
  cb
491
543
  cfei
492
544
  cfsi
493
- croo
494
545
  div
495
546
  divi
496
547
  ecr1
@@ -573,6 +624,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
573
624
  ccp {
574
625
  ...DependentCostFragment
575
626
  }
627
+ croo {
628
+ ...DependentCostFragment
629
+ }
576
630
  csiz {
577
631
  ...DependentCostFragment
578
632
  }
@@ -632,6 +686,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
632
686
  ${DependentCostFragmentFragmentDoc}`;
633
687
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
634
688
  fragment consensusParametersFragment on ConsensusParameters {
689
+ version {
690
+ ... on Version {
691
+ value
692
+ }
693
+ }
635
694
  txParams {
636
695
  ...TxParametersFragment
637
696
  }
@@ -691,18 +750,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
691
750
  fragment nodeInfoFragment on NodeInfo {
692
751
  utxoValidation
693
752
  vmBacktrace
694
- minGasPrice
695
753
  maxTx
696
754
  maxDepth
697
755
  nodeVersion
698
- peers {
699
- id
700
- addresses
701
- clientVersion
702
- blockHeight
703
- lastHeartbeatMs
704
- appScore
705
- }
706
756
  }
707
757
  `;
708
758
  var GetVersionDocument = import_graphql_tag.default`
@@ -737,13 +787,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
737
787
  query getTransactionWithReceipts($transactionId: TransactionId!) {
738
788
  transaction(id: $transactionId) {
739
789
  ...transactionFragment
740
- receipts {
741
- ...receiptFragment
742
- }
743
790
  }
744
791
  }
745
- ${TransactionFragmentFragmentDoc}
746
- ${ReceiptFragmentFragmentDoc}`;
792
+ ${TransactionFragmentFragmentDoc}`;
747
793
  var GetTransactionsDocument = import_graphql_tag.default`
748
794
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
749
795
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -871,6 +917,20 @@ var GetBalanceDocument = import_graphql_tag.default`
871
917
  }
872
918
  }
873
919
  ${BalanceFragmentFragmentDoc}`;
920
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
921
+ query getLatestGasPrice {
922
+ latestGasPrice {
923
+ gasPrice
924
+ }
925
+ }
926
+ `;
927
+ var EstimateGasPriceDocument = import_graphql_tag.default`
928
+ query estimateGasPrice($blockHorizon: U32!) {
929
+ estimateGasPrice(blockHorizon: $blockHorizon) {
930
+ gasPrice
931
+ }
932
+ }
933
+ `;
874
934
  var GetBalancesDocument = import_graphql_tag.default`
875
935
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
876
936
  balances(
@@ -925,12 +985,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
925
985
  }
926
986
  `;
927
987
  var DryRunDocument = import_graphql_tag.default`
928
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
929
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
930
- ...receiptFragment
988
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
989
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
990
+ ...dryRunTransactionExecutionStatusFragment
931
991
  }
932
992
  }
933
- ${ReceiptFragmentFragmentDoc}`;
993
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
934
994
  var SubmitDocument = import_graphql_tag.default`
935
995
  mutation submit($encodedTransaction: HexString!) {
936
996
  submit(tx: $encodedTransaction) {
@@ -1013,6 +1073,12 @@ function getSdk(requester) {
1013
1073
  getBalance(variables, options) {
1014
1074
  return requester(GetBalanceDocument, variables, options);
1015
1075
  },
1076
+ getLatestGasPrice(variables, options) {
1077
+ return requester(GetLatestGasPriceDocument, variables, options);
1078
+ },
1079
+ estimateGasPrice(variables, options) {
1080
+ return requester(EstimateGasPriceDocument, variables, options);
1081
+ },
1016
1082
  getBalances(variables, options) {
1017
1083
  return requester(GetBalancesDocument, variables, options);
1018
1084
  },
@@ -1082,11 +1148,14 @@ var _FuelGraphqlSubscriber = class {
1082
1148
  let data;
1083
1149
  let errors;
1084
1150
  try {
1085
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
1151
+ const sanitizedText = text.replace(/\s/g, "");
1152
+ ({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
1086
1153
  } catch (e) {
1087
1154
  throw new import_errors.FuelError(
1088
1155
  import_errors.ErrorCode.STREAM_PARSING_ERROR,
1089
- `Error while parsing stream data response: ${text}`
1156
+ `Error while parsing stream data response: ${text}
1157
+
1158
+ Thrown error: ${e}`
1090
1159
  );
1091
1160
  }
1092
1161
  if (Array.isArray(errors)) {
@@ -1173,6 +1242,7 @@ var MemoryCache = class {
1173
1242
  };
1174
1243
 
1175
1244
  // src/providers/transaction-request/input.ts
1245
+ var import_abi_coder = require("@fuel-ts/abi-coder");
1176
1246
  var import_configs2 = require("@fuel-ts/address/configs");
1177
1247
  var import_errors3 = require("@fuel-ts/errors");
1178
1248
  var import_math2 = require("@fuel-ts/math");
@@ -1186,8 +1256,8 @@ var inputify = (value) => {
1186
1256
  const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
1187
1257
  return {
1188
1258
  type: import_transactions.InputType.Coin,
1189
- txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
1190
- outputIndex: (0, import_utils3.arrayify)(value.id)[32],
1259
+ txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
1260
+ outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
1191
1261
  owner: (0, import_utils3.hexlify)(value.owner),
1192
1262
  amount: (0, import_math2.bn)(value.amount),
1193
1263
  assetId: (0, import_utils3.hexlify)(value.assetId),
@@ -1196,10 +1266,9 @@ var inputify = (value) => {
1196
1266
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1197
1267
  },
1198
1268
  witnessIndex: value.witnessIndex,
1199
- maturity: value.maturity ?? 0,
1200
1269
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1201
- predicateLength: predicate.length,
1202
- predicateDataLength: predicateData.length,
1270
+ predicateLength: (0, import_math2.bn)(predicate.length),
1271
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1203
1272
  predicate: (0, import_utils3.hexlify)(predicate),
1204
1273
  predicateData: (0, import_utils3.hexlify)(predicateData)
1205
1274
  };
@@ -1230,8 +1299,8 @@ var inputify = (value) => {
1230
1299
  nonce: (0, import_utils3.hexlify)(value.nonce),
1231
1300
  witnessIndex: value.witnessIndex,
1232
1301
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1233
- predicateLength: predicate.length,
1234
- predicateDataLength: predicateData.length,
1302
+ predicateLength: (0, import_math2.bn)(predicate.length),
1303
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1235
1304
  predicate: (0, import_utils3.hexlify)(predicate),
1236
1305
  predicateData: (0, import_utils3.hexlify)(predicateData),
1237
1306
  data: (0, import_utils3.hexlify)(data),
@@ -1305,8 +1374,10 @@ var outputify = (value) => {
1305
1374
  };
1306
1375
 
1307
1376
  // src/providers/transaction-request/transaction-request.ts
1377
+ var import_abi_coder2 = require("@fuel-ts/abi-coder");
1308
1378
  var import_address = require("@fuel-ts/address");
1309
1379
  var import_configs7 = require("@fuel-ts/address/configs");
1380
+ var import_crypto = require("@fuel-ts/crypto");
1310
1381
  var import_math7 = require("@fuel-ts/math");
1311
1382
  var import_transactions6 = require("@fuel-ts/transactions");
1312
1383
  var import_utils9 = require("@fuel-ts/utils");
@@ -1348,8 +1419,8 @@ function assembleReceiptByType(receipt) {
1348
1419
  case "CALL" /* Call */: {
1349
1420
  const callReceipt = {
1350
1421
  type: import_transactions3.ReceiptType.Call,
1351
- from: hexOrZero(receipt.contract?.id),
1352
- to: hexOrZero(receipt?.to?.id),
1422
+ from: hexOrZero(receipt.id || receipt.contractId),
1423
+ to: hexOrZero(receipt?.to),
1353
1424
  amount: (0, import_math4.bn)(receipt.amount),
1354
1425
  assetId: hexOrZero(receipt.assetId),
1355
1426
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1363,7 +1434,7 @@ function assembleReceiptByType(receipt) {
1363
1434
  case "RETURN" /* Return */: {
1364
1435
  const returnReceipt = {
1365
1436
  type: import_transactions3.ReceiptType.Return,
1366
- id: hexOrZero(receipt.contract?.id),
1437
+ id: hexOrZero(receipt.id || receipt.contractId),
1367
1438
  val: (0, import_math4.bn)(receipt.val),
1368
1439
  pc: (0, import_math4.bn)(receipt.pc),
1369
1440
  is: (0, import_math4.bn)(receipt.is)
@@ -1373,7 +1444,7 @@ function assembleReceiptByType(receipt) {
1373
1444
  case "RETURN_DATA" /* ReturnData */: {
1374
1445
  const returnDataReceipt = {
1375
1446
  type: import_transactions3.ReceiptType.ReturnData,
1376
- id: hexOrZero(receipt.contract?.id),
1447
+ id: hexOrZero(receipt.id || receipt.contractId),
1377
1448
  ptr: (0, import_math4.bn)(receipt.ptr),
1378
1449
  len: (0, import_math4.bn)(receipt.len),
1379
1450
  digest: hexOrZero(receipt.digest),
@@ -1385,7 +1456,7 @@ function assembleReceiptByType(receipt) {
1385
1456
  case "PANIC" /* Panic */: {
1386
1457
  const panicReceipt = {
1387
1458
  type: import_transactions3.ReceiptType.Panic,
1388
- id: hexOrZero(receipt.contract?.id),
1459
+ id: hexOrZero(receipt.id),
1389
1460
  reason: (0, import_math4.bn)(receipt.reason),
1390
1461
  pc: (0, import_math4.bn)(receipt.pc),
1391
1462
  is: (0, import_math4.bn)(receipt.is),
@@ -1396,7 +1467,7 @@ function assembleReceiptByType(receipt) {
1396
1467
  case "REVERT" /* Revert */: {
1397
1468
  const revertReceipt = {
1398
1469
  type: import_transactions3.ReceiptType.Revert,
1399
- id: hexOrZero(receipt.contract?.id),
1470
+ id: hexOrZero(receipt.id || receipt.contractId),
1400
1471
  val: (0, import_math4.bn)(receipt.ra),
1401
1472
  pc: (0, import_math4.bn)(receipt.pc),
1402
1473
  is: (0, import_math4.bn)(receipt.is)
@@ -1406,7 +1477,7 @@ function assembleReceiptByType(receipt) {
1406
1477
  case "LOG" /* Log */: {
1407
1478
  const logReceipt = {
1408
1479
  type: import_transactions3.ReceiptType.Log,
1409
- id: hexOrZero(receipt.contract?.id),
1480
+ id: hexOrZero(receipt.id || receipt.contractId),
1410
1481
  val0: (0, import_math4.bn)(receipt.ra),
1411
1482
  val1: (0, import_math4.bn)(receipt.rb),
1412
1483
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1419,7 +1490,7 @@ function assembleReceiptByType(receipt) {
1419
1490
  case "LOG_DATA" /* LogData */: {
1420
1491
  const logDataReceipt = {
1421
1492
  type: import_transactions3.ReceiptType.LogData,
1422
- id: hexOrZero(receipt.contract?.id),
1493
+ id: hexOrZero(receipt.id || receipt.contractId),
1423
1494
  val0: (0, import_math4.bn)(receipt.ra),
1424
1495
  val1: (0, import_math4.bn)(receipt.rb),
1425
1496
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1433,8 +1504,8 @@ function assembleReceiptByType(receipt) {
1433
1504
  case "TRANSFER" /* Transfer */: {
1434
1505
  const transferReceipt = {
1435
1506
  type: import_transactions3.ReceiptType.Transfer,
1436
- from: hexOrZero(receipt.contract?.id),
1437
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1507
+ from: hexOrZero(receipt.id || receipt.contractId),
1508
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1438
1509
  amount: (0, import_math4.bn)(receipt.amount),
1439
1510
  assetId: hexOrZero(receipt.assetId),
1440
1511
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1445,8 +1516,8 @@ function assembleReceiptByType(receipt) {
1445
1516
  case "TRANSFER_OUT" /* TransferOut */: {
1446
1517
  const transferOutReceipt = {
1447
1518
  type: import_transactions3.ReceiptType.TransferOut,
1448
- from: hexOrZero(receipt.contract?.id),
1449
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1519
+ from: hexOrZero(receipt.id || receipt.contractId),
1520
+ to: hexOrZero(receipt.toAddress || receipt.to),
1450
1521
  amount: (0, import_math4.bn)(receipt.amount),
1451
1522
  assetId: hexOrZero(receipt.assetId),
1452
1523
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1489,7 +1560,7 @@ function assembleReceiptByType(receipt) {
1489
1560
  return receiptMessageOut;
1490
1561
  }
1491
1562
  case "MINT" /* Mint */: {
1492
- const contractId = hexOrZero(receipt.contract?.id);
1563
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1493
1564
  const subId = hexOrZero(receipt.subId);
1494
1565
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1495
1566
  const mintReceipt = {
@@ -1504,7 +1575,7 @@ function assembleReceiptByType(receipt) {
1504
1575
  return mintReceipt;
1505
1576
  }
1506
1577
  case "BURN" /* Burn */: {
1507
- const contractId = hexOrZero(receipt.contract?.id);
1578
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1508
1579
  const subId = hexOrZero(receipt.subId);
1509
1580
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1510
1581
  const burnReceipt = {
@@ -1589,7 +1660,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1589
1660
  var import_math5 = require("@fuel-ts/math");
1590
1661
  var import_transactions4 = require("@fuel-ts/transactions");
1591
1662
  var import_utils6 = require("@fuel-ts/utils");
1592
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1593
1663
  var getGasUsedFromReceipts = (receipts) => {
1594
1664
  const scriptResult = receipts.filter(
1595
1665
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1610,18 +1680,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1610
1680
  }
1611
1681
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1612
1682
  const witnessCache = [];
1613
- const totalGas = inputs.reduce((total, input) => {
1683
+ const chargeableInputs = inputs.filter((input) => {
1684
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1685
+ if (isCoinOrMessage) {
1686
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1687
+ return true;
1688
+ }
1689
+ if (!witnessCache.includes(input.witnessIndex)) {
1690
+ witnessCache.push(input.witnessIndex);
1691
+ return true;
1692
+ }
1693
+ }
1694
+ return false;
1695
+ });
1696
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1697
+ const totalGas = chargeableInputs.reduce((total, input) => {
1614
1698
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1615
1699
  return total.add(
1616
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1700
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1617
1701
  );
1618
1702
  }
1619
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1620
- witnessCache.push(input.witnessIndex);
1621
- return total.add(gasCosts.ecr1);
1622
- }
1623
- return total;
1624
- }, (0, import_math5.bn)());
1703
+ return total.add(gasCosts.ecr1);
1704
+ }, (0, import_math5.bn)(0));
1625
1705
  return totalGas;
1626
1706
  }
1627
1707
  function getMinGas(params) {
@@ -1633,12 +1713,20 @@ function getMinGas(params) {
1633
1713
  return minGas;
1634
1714
  }
1635
1715
  function getMaxGas(params) {
1636
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1716
+ const {
1717
+ gasPerByte,
1718
+ witnessesLength,
1719
+ witnessLimit,
1720
+ minGas,
1721
+ gasLimit = (0, import_math5.bn)(0),
1722
+ maxGasPerTx
1723
+ } = params;
1637
1724
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1638
1725
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1639
1726
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1640
1727
  }
1641
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1728
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1729
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1642
1730
  }
1643
1731
  function calculateMetadataGasForTxCreate({
1644
1732
  gasCosts,
@@ -1660,6 +1748,10 @@ function calculateMetadataGasForTxScript({
1660
1748
  }) {
1661
1749
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1662
1750
  }
1751
+ var calculateGasFee = (params) => {
1752
+ const { gas, gasPrice, priceFactor, tip } = params;
1753
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1754
+ };
1663
1755
 
1664
1756
  // src/providers/utils/json.ts
1665
1757
  var import_utils7 = require("@fuel-ts/utils");
@@ -1808,7 +1900,7 @@ var witnessify = (value) => {
1808
1900
  // src/providers/transaction-request/transaction-request.ts
1809
1901
  var BaseTransactionRequest = class {
1810
1902
  /** Gas price for transaction */
1811
- gasPrice;
1903
+ tip;
1812
1904
  /** Block until which tx cannot be included */
1813
1905
  maturity;
1814
1906
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1827,7 +1919,7 @@ var BaseTransactionRequest = class {
1827
1919
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1828
1920
  */
1829
1921
  constructor({
1830
- gasPrice,
1922
+ tip,
1831
1923
  maturity,
1832
1924
  maxFee,
1833
1925
  witnessLimit,
@@ -1835,7 +1927,7 @@ var BaseTransactionRequest = class {
1835
1927
  outputs,
1836
1928
  witnesses
1837
1929
  } = {}) {
1838
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1930
+ this.tip = (0, import_math7.bn)(tip);
1839
1931
  this.maturity = maturity ?? 0;
1840
1932
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1841
1933
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1846,9 +1938,9 @@ var BaseTransactionRequest = class {
1846
1938
  static getPolicyMeta(req) {
1847
1939
  let policyTypes = 0;
1848
1940
  const policies = [];
1849
- if (req.gasPrice) {
1850
- policyTypes += import_transactions6.PolicyType.GasPrice;
1851
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1941
+ if (req.tip) {
1942
+ policyTypes += import_transactions6.PolicyType.Tip;
1943
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1852
1944
  }
1853
1945
  if (req.witnessLimit) {
1854
1946
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -2035,10 +2127,10 @@ var BaseTransactionRequest = class {
2035
2127
  * @param predicate - Predicate bytes.
2036
2128
  * @param predicateData - Predicate data bytes.
2037
2129
  */
2038
- addCoinInput(coin, predicate) {
2130
+ addCoinInput(coin) {
2039
2131
  const { assetId, owner, amount } = coin;
2040
2132
  let witnessIndex;
2041
- if (predicate) {
2133
+ if (coin.predicate) {
2042
2134
  witnessIndex = 0;
2043
2135
  } else {
2044
2136
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -2053,8 +2145,7 @@ var BaseTransactionRequest = class {
2053
2145
  amount,
2054
2146
  assetId,
2055
2147
  txPointer: "0x00000000000000000000000000000000",
2056
- witnessIndex,
2057
- predicate: predicate?.bytes
2148
+ witnessIndex
2058
2149
  };
2059
2150
  this.pushInput(input);
2060
2151
  this.addChangeOutput(owner, assetId);
@@ -2067,11 +2158,11 @@ var BaseTransactionRequest = class {
2067
2158
  * @param predicate - Predicate bytes.
2068
2159
  * @param predicateData - Predicate data bytes.
2069
2160
  */
2070
- addMessageInput(message, predicate) {
2161
+ addMessageInput(message) {
2071
2162
  const { recipient, sender, amount } = message;
2072
2163
  const assetId = import_configs7.BaseAssetId;
2073
2164
  let witnessIndex;
2074
- if (predicate) {
2165
+ if (message.predicate) {
2075
2166
  witnessIndex = 0;
2076
2167
  } else {
2077
2168
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -2085,8 +2176,7 @@ var BaseTransactionRequest = class {
2085
2176
  sender: sender.toB256(),
2086
2177
  recipient: recipient.toB256(),
2087
2178
  amount,
2088
- witnessIndex,
2089
- predicate: predicate?.bytes
2179
+ witnessIndex
2090
2180
  };
2091
2181
  this.pushInput(input);
2092
2182
  this.addChangeOutput(recipient, assetId);
@@ -2117,32 +2207,6 @@ var BaseTransactionRequest = class {
2117
2207
  resources.forEach((resource) => this.addResource(resource));
2118
2208
  return this;
2119
2209
  }
2120
- /**
2121
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2122
- * outputs from the related assetIds.
2123
- *
2124
- * @param resources - The resources to add.
2125
- * @returns This transaction.
2126
- */
2127
- addPredicateResource(resource, predicate) {
2128
- if (isCoin(resource)) {
2129
- this.addCoinInput(resource, predicate);
2130
- } else {
2131
- this.addMessageInput(resource, predicate);
2132
- }
2133
- return this;
2134
- }
2135
- /**
2136
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2137
- * from the related assetIds.
2138
- *
2139
- * @param resources - The resources to add.
2140
- * @returns This transaction.
2141
- */
2142
- addPredicateResources(resources, predicate) {
2143
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2144
- return this;
2145
- }
2146
2210
  /**
2147
2211
  * Adds a coin output to the transaction.
2148
2212
  *
@@ -2222,7 +2286,7 @@ var BaseTransactionRequest = class {
2222
2286
  }
2223
2287
  calculateMaxGas(chainInfo, minGas) {
2224
2288
  const { consensusParameters } = chainInfo;
2225
- const { gasPerByte } = consensusParameters;
2289
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2226
2290
  const witnessesLength = this.toTransaction().witnesses.reduce(
2227
2291
  (acc, wit) => acc + wit.dataLength,
2228
2292
  0
@@ -2231,7 +2295,8 @@ var BaseTransactionRequest = class {
2231
2295
  gasPerByte,
2232
2296
  minGas,
2233
2297
  witnessesLength,
2234
- witnessLimit: this.witnessLimit
2298
+ witnessLimit: this.witnessLimit,
2299
+ maxGasPerTx
2235
2300
  });
2236
2301
  }
2237
2302
  /**
@@ -2241,12 +2306,6 @@ var BaseTransactionRequest = class {
2241
2306
  * @param quantities - CoinQuantity Array.
2242
2307
  */
2243
2308
  fundWithFakeUtxos(quantities, resourcesOwner) {
2244
- let idCounter = 0;
2245
- const generateId = () => {
2246
- const counterString = String(idCounter++);
2247
- const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2248
- return id;
2249
- };
2250
2309
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2251
2310
  if ("assetId" in input) {
2252
2311
  return input.assetId === assetId;
@@ -2255,17 +2314,20 @@ var BaseTransactionRequest = class {
2255
2314
  });
2256
2315
  const updateAssetInput = (assetId, quantity) => {
2257
2316
  const assetInput = findAssetInput(assetId);
2317
+ let usedQuantity = quantity;
2318
+ if (assetId === import_configs7.BaseAssetId) {
2319
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2320
+ }
2258
2321
  if (assetInput && "assetId" in assetInput) {
2259
- assetInput.id = generateId();
2260
- assetInput.amount = quantity;
2322
+ assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2323
+ assetInput.amount = usedQuantity;
2261
2324
  } else {
2262
2325
  this.addResources([
2263
2326
  {
2264
- id: generateId(),
2265
- amount: quantity,
2327
+ id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2328
+ amount: usedQuantity,
2266
2329
  assetId,
2267
2330
  owner: resourcesOwner || import_address.Address.fromRandom(),
2268
- maturity: 0,
2269
2331
  blockCreated: (0, import_math7.bn)(1),
2270
2332
  txCreatedIdx: (0, import_math7.bn)(1)
2271
2333
  }
@@ -2297,7 +2359,7 @@ var BaseTransactionRequest = class {
2297
2359
  toJSON() {
2298
2360
  return normalizeJSON(this);
2299
2361
  }
2300
- updatePredicateInputs(inputs) {
2362
+ updatePredicateGasUsed(inputs) {
2301
2363
  this.inputs.forEach((i) => {
2302
2364
  let correspondingInput;
2303
2365
  switch (i.type) {
@@ -2319,6 +2381,15 @@ var BaseTransactionRequest = class {
2319
2381
  }
2320
2382
  });
2321
2383
  }
2384
+ shiftPredicateData() {
2385
+ this.inputs.forEach((input) => {
2386
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2387
+ input.predicateData = input.paddPredicateData(
2388
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2389
+ );
2390
+ }
2391
+ });
2392
+ }
2322
2393
  };
2323
2394
 
2324
2395
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2465,9 +2536,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2465
2536
  return {
2466
2537
  type: import_transactions8.TransactionType.Create,
2467
2538
  ...baseTransaction,
2468
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2469
2539
  bytecodeWitnessIndex,
2470
- storageSlotsCount: storageSlots.length,
2540
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2471
2541
  salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2472
2542
  storageSlots
2473
2543
  };
@@ -2516,7 +2586,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2516
2586
  };
2517
2587
 
2518
2588
  // src/providers/transaction-request/script-transaction-request.ts
2519
- var import_abi_coder = require("@fuel-ts/abi-coder");
2589
+ var import_abi_coder3 = require("@fuel-ts/abi-coder");
2520
2590
  var import_address2 = require("@fuel-ts/address");
2521
2591
  var import_configs10 = require("@fuel-ts/address/configs");
2522
2592
  var import_math10 = require("@fuel-ts/math");
@@ -2590,8 +2660,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2590
2660
  type: import_transactions9.TransactionType.Script,
2591
2661
  scriptGasLimit: this.gasLimit,
2592
2662
  ...super.getBaseTransaction(),
2593
- scriptLength: script.length,
2594
- scriptDataLength: scriptData.length,
2663
+ scriptLength: (0, import_math10.bn)(script.length),
2664
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2595
2665
  receiptsRoot: import_configs10.ZeroBytes32,
2596
2666
  script: (0, import_utils15.hexlify)(script),
2597
2667
  scriptData: (0, import_utils15.hexlify)(scriptData)
@@ -2655,7 +2725,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2655
2725
  }
2656
2726
  calculateMaxGas(chainInfo, minGas) {
2657
2727
  const { consensusParameters } = chainInfo;
2658
- const { gasPerByte } = consensusParameters;
2728
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2659
2729
  const witnessesLength = this.toTransaction().witnesses.reduce(
2660
2730
  (acc, wit) => acc + wit.dataLength,
2661
2731
  0
@@ -2665,7 +2735,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2665
2735
  minGas,
2666
2736
  witnessesLength,
2667
2737
  witnessLimit: this.witnessLimit,
2668
- gasLimit: this.gasLimit
2738
+ gasLimit: this.gasLimit,
2739
+ maxGasPerTx
2669
2740
  });
2670
2741
  }
2671
2742
  /**
@@ -2708,7 +2779,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2708
2779
  * @returns The current instance of the `ScriptTransactionRequest`.
2709
2780
  */
2710
2781
  setData(abi, args) {
2711
- const abiInterface = new import_abi_coder.Interface(abi);
2782
+ const abiInterface = new import_abi_coder3.Interface(abi);
2712
2783
  this.scriptData = abiInterface.functions.main.encodeArguments(args);
2713
2784
  return this;
2714
2785
  }
@@ -2740,15 +2811,32 @@ var transactionRequestify = (obj) => {
2740
2811
  }
2741
2812
  }
2742
2813
  };
2814
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2815
+ (acc, input) => {
2816
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2817
+ acc.utxos.push(input.id);
2818
+ }
2819
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2820
+ acc.messages.push(input.nonce);
2821
+ }
2822
+ return acc;
2823
+ },
2824
+ {
2825
+ utxos: [],
2826
+ messages: []
2827
+ }
2828
+ );
2743
2829
 
2744
2830
  // src/providers/transaction-response/transaction-response.ts
2745
2831
  var import_errors13 = require("@fuel-ts/errors");
2746
- var import_math14 = require("@fuel-ts/math");
2747
- var import_transactions17 = require("@fuel-ts/transactions");
2748
- var import_utils21 = require("@fuel-ts/utils");
2832
+ var import_math15 = require("@fuel-ts/math");
2833
+ var import_transactions18 = require("@fuel-ts/transactions");
2834
+ var import_utils20 = require("@fuel-ts/utils");
2749
2835
 
2750
2836
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2751
- var import_utils19 = require("@fuel-ts/utils");
2837
+ var import_math14 = require("@fuel-ts/math");
2838
+ var import_transactions16 = require("@fuel-ts/transactions");
2839
+ var import_utils18 = require("@fuel-ts/utils");
2752
2840
 
2753
2841
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2754
2842
  var import_math11 = require("@fuel-ts/math");
@@ -2756,9 +2844,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
2756
2844
  var import_utils16 = require("@fuel-ts/utils");
2757
2845
  var calculateTransactionFee = (params) => {
2758
2846
  const {
2759
- gasUsed,
2847
+ gasPrice,
2760
2848
  rawPayload,
2761
- consensusParameters: { gasCosts, feeParams }
2849
+ tip,
2850
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2762
2851
  } = params;
2763
2852
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2764
2853
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2768,8 +2857,7 @@ var calculateTransactionFee = (params) => {
2768
2857
  return {
2769
2858
  fee: (0, import_math11.bn)(0),
2770
2859
  minFee: (0, import_math11.bn)(0),
2771
- maxFee: (0, import_math11.bn)(0),
2772
- feeFromGasUsed: (0, import_math11.bn)(0)
2860
+ maxFee: (0, import_math11.bn)(0)
2773
2861
  };
2774
2862
  }
2775
2863
  const { type, witnesses, inputs, policies } = transaction;
@@ -2801,7 +2889,6 @@ var calculateTransactionFee = (params) => {
2801
2889
  metadataGas,
2802
2890
  txBytesSize: transactionBytes.length
2803
2891
  });
2804
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2805
2892
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2806
2893
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2807
2894
  const maxGas = getMaxGas({
@@ -2809,17 +2896,25 @@ var calculateTransactionFee = (params) => {
2809
2896
  minGas,
2810
2897
  witnessesLength,
2811
2898
  gasLimit,
2812
- witnessLimit
2899
+ witnessLimit,
2900
+ maxGasPerTx
2901
+ });
2902
+ const minFee = calculateGasFee({
2903
+ gasPrice,
2904
+ gas: minGas,
2905
+ priceFactor: gasPriceFactor,
2906
+ tip
2907
+ });
2908
+ const maxFee = calculateGasFee({
2909
+ gasPrice,
2910
+ gas: maxGas,
2911
+ priceFactor: gasPriceFactor,
2912
+ tip
2813
2913
  });
2814
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2815
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2816
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2817
- const fee = minFee.add(feeFromGasUsed);
2818
2914
  return {
2819
- fee,
2820
2915
  minFee,
2821
2916
  maxFee,
2822
- feeFromGasUsed
2917
+ fee: maxFee
2823
2918
  };
2824
2919
  };
2825
2920
 
@@ -2830,17 +2925,17 @@ var import_math13 = require("@fuel-ts/math");
2830
2925
  var import_transactions14 = require("@fuel-ts/transactions");
2831
2926
 
2832
2927
  // src/providers/transaction-summary/call.ts
2833
- var import_abi_coder2 = require("@fuel-ts/abi-coder");
2928
+ var import_abi_coder4 = require("@fuel-ts/abi-coder");
2834
2929
  var import_math12 = require("@fuel-ts/math");
2835
2930
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2836
- const abiInterface = new import_abi_coder2.Interface(abi);
2931
+ const abiInterface = new import_abi_coder4.Interface(abi);
2837
2932
  const callFunctionSelector = receipt.param1.toHex(8);
2838
2933
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
2839
2934
  const inputs = functionFragment.jsonFn.inputs;
2840
2935
  let encodedArgs;
2841
2936
  if (functionFragment.isInputDataPointer) {
2842
2937
  if (rawPayload) {
2843
- const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2938
+ const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2844
2939
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2845
2940
  }
2846
2941
  } else {
@@ -3433,10 +3528,12 @@ function assembleTransactionSummary(params) {
3433
3528
  gqlTransactionStatus,
3434
3529
  abiMap = {},
3435
3530
  maxInputs,
3436
- gasCosts
3531
+ gasCosts,
3532
+ maxGasPerTx,
3533
+ gasPrice
3437
3534
  } = params;
3438
3535
  const gasUsed = getGasUsedFromReceipts(receipts);
3439
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3536
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3440
3537
  const operations = getOperations({
3441
3538
  transactionType: transaction.type,
3442
3539
  inputs: transaction.inputs || [],
@@ -3447,11 +3544,14 @@ function assembleTransactionSummary(params) {
3447
3544
  maxInputs
3448
3545
  });
3449
3546
  const typeName = getTransactionTypeName(transaction.type);
3547
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3450
3548
  const { fee } = calculateTransactionFee({
3451
- gasUsed,
3549
+ gasPrice,
3452
3550
  rawPayload,
3551
+ tip,
3453
3552
  consensusParameters: {
3454
3553
  gasCosts,
3554
+ maxGasPerTx,
3455
3555
  feeParams: {
3456
3556
  gasPerByte,
3457
3557
  gasPriceFactor
@@ -3463,7 +3563,7 @@ function assembleTransactionSummary(params) {
3463
3563
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3464
3564
  let date;
3465
3565
  if (time) {
3466
- date = import_utils19.DateTime.fromTai64(time);
3566
+ date = import_utils18.DateTime.fromTai64(time);
3467
3567
  }
3468
3568
  const transactionSummary = {
3469
3569
  id,
@@ -3490,13 +3590,13 @@ function assembleTransactionSummary(params) {
3490
3590
  }
3491
3591
 
3492
3592
  // src/providers/transaction-response/getDecodedLogs.ts
3493
- var import_abi_coder3 = require("@fuel-ts/abi-coder");
3494
- var import_transactions16 = require("@fuel-ts/transactions");
3593
+ var import_abi_coder5 = require("@fuel-ts/abi-coder");
3594
+ var import_transactions17 = require("@fuel-ts/transactions");
3495
3595
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3496
3596
  return receipts.reduce((logs, receipt) => {
3497
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3498
- const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3499
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3597
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3598
+ const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3599
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3500
3600
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3501
3601
  logs.push(decodedLog);
3502
3602
  }
@@ -3511,7 +3611,7 @@ var TransactionResponse = class {
3511
3611
  /** Current provider */
3512
3612
  provider;
3513
3613
  /** Gas used on the transaction */
3514
- gasUsed = (0, import_math14.bn)(0);
3614
+ gasUsed = (0, import_math15.bn)(0);
3515
3615
  /** The graphql Transaction with receipts object. */
3516
3616
  gqlTransaction;
3517
3617
  abis;
@@ -3569,8 +3669,8 @@ var TransactionResponse = class {
3569
3669
  * @returns The decoded transaction.
3570
3670
  */
3571
3671
  decodeTransaction(transactionWithReceipts) {
3572
- return new import_transactions17.TransactionCoder().decode(
3573
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3672
+ return new import_transactions18.TransactionCoder().decode(
3673
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3574
3674
  0
3575
3675
  )?.[0];
3576
3676
  }
@@ -3589,20 +3689,27 @@ var TransactionResponse = class {
3589
3689
  const decodedTransaction = this.decodeTransaction(
3590
3690
  transaction
3591
3691
  );
3592
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3593
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3692
+ let txReceipts = [];
3693
+ if (transaction?.status && "receipts" in transaction.status) {
3694
+ txReceipts = transaction.status.receipts;
3695
+ }
3696
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3697
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3698
+ const gasPrice = await this.provider.getLatestGasPrice();
3594
3699
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3595
3700
  const transactionSummary = assembleTransactionSummary({
3596
3701
  id: this.id,
3597
3702
  receipts,
3598
3703
  transaction: decodedTransaction,
3599
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3704
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3600
3705
  gqlTransactionStatus: transaction.status,
3601
3706
  gasPerByte,
3602
3707
  gasPriceFactor,
3603
3708
  abiMap: contractsAbiMap,
3604
3709
  maxInputs,
3605
- gasCosts
3710
+ gasCosts,
3711
+ maxGasPerTx,
3712
+ gasPrice
3606
3713
  });
3607
3714
  return transactionSummary;
3608
3715
  }
@@ -3729,29 +3836,29 @@ var processGqlChain = (chain) => {
3729
3836
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3730
3837
  return {
3731
3838
  name,
3732
- baseChainHeight: (0, import_math15.bn)(daHeight),
3839
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3733
3840
  consensusParameters: {
3734
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3735
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3736
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3737
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3738
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3739
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3740
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3741
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3742
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3743
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3744
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3745
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3746
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3747
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3748
- chainId: (0, import_math15.bn)(consensusParameters.chainId),
3841
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3842
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3843
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3844
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3845
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3846
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3847
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3848
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3849
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3850
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3851
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3852
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3853
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3854
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3855
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3749
3856
  gasCosts
3750
3857
  },
3751
3858
  gasCosts,
3752
3859
  latestBlock: {
3753
3860
  id: latestBlock.id,
3754
- height: (0, import_math15.bn)(latestBlock.header.height),
3861
+ height: (0, import_math16.bn)(latestBlock.height),
3755
3862
  time: latestBlock.header.time,
3756
3863
  transactions: latestBlock.transactions.map((i) => ({
3757
3864
  id: i.id
@@ -3845,10 +3952,8 @@ var _Provider = class {
3845
3952
  * Returns some helpful parameters related to gas fees.
3846
3953
  */
3847
3954
  getGasConfig() {
3848
- const { minGasPrice } = this.getNode();
3849
3955
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3850
3956
  return {
3851
- minGasPrice,
3852
3957
  maxGasPerTx,
3853
3958
  maxGasPerPredicate,
3854
3959
  gasPriceFactor,
@@ -3946,7 +4051,7 @@ var _Provider = class {
3946
4051
  */
3947
4052
  async getBlockNumber() {
3948
4053
  const { chain } = await this.operations.getChain();
3949
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
4054
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3950
4055
  }
3951
4056
  /**
3952
4057
  * Returns the chain information.
@@ -3956,13 +4061,11 @@ var _Provider = class {
3956
4061
  async fetchNode() {
3957
4062
  const { nodeInfo } = await this.operations.getNodeInfo();
3958
4063
  const processedNodeInfo = {
3959
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3960
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3961
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
4064
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4065
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3962
4066
  nodeVersion: nodeInfo.nodeVersion,
3963
4067
  utxoValidation: nodeInfo.utxoValidation,
3964
- vmBacktrace: nodeInfo.vmBacktrace,
3965
- peers: nodeInfo.peers
4068
+ vmBacktrace: nodeInfo.vmBacktrace
3966
4069
  };
3967
4070
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3968
4071
  return processedNodeInfo;
@@ -4004,9 +4107,9 @@ var _Provider = class {
4004
4107
  if (estimateTxDependencies) {
4005
4108
  await this.estimateTxDependencies(transactionRequest);
4006
4109
  }
4007
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4110
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4008
4111
  let abis;
4009
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4112
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4010
4113
  abis = transactionRequest.abis;
4011
4114
  }
4012
4115
  if (awaitExecution) {
@@ -4047,15 +4150,14 @@ var _Provider = class {
4047
4150
  if (estimateTxDependencies) {
4048
4151
  return this.estimateTxDependencies(transactionRequest);
4049
4152
  }
4050
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4051
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4052
- encodedTransaction,
4153
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4154
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4155
+ encodedTransactions: encodedTransaction,
4053
4156
  utxoValidation: utxoValidation || false
4054
4157
  });
4055
- const receipts = gqlReceipts.map(processGqlReceipt);
4056
- return {
4057
- receipts
4058
- };
4158
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4159
+ const receipts = rawReceipts.map(processGqlReceipt);
4160
+ return { receipts, dryrunStatus: status };
4059
4161
  }
4060
4162
  /**
4061
4163
  * Verifies whether enough gas is available to complete transaction.
@@ -4066,13 +4168,13 @@ var _Provider = class {
4066
4168
  async estimatePredicates(transactionRequest) {
4067
4169
  const shouldEstimatePredicates = Boolean(
4068
4170
  transactionRequest.inputs.find(
4069
- (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()
4171
+ (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()
4070
4172
  )
4071
4173
  );
4072
4174
  if (!shouldEstimatePredicates) {
4073
4175
  return transactionRequest;
4074
4176
  }
4075
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4177
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4076
4178
  const response = await this.operations.estimatePredicates({
4077
4179
  encodedTransaction
4078
4180
  });
@@ -4081,7 +4183,7 @@ var _Provider = class {
4081
4183
  } = response;
4082
4184
  if (inputs) {
4083
4185
  inputs.forEach((input, index) => {
4084
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
4186
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
4085
4187
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4086
4188
  }
4087
4189
  });
@@ -4094,31 +4196,31 @@ var _Provider = class {
4094
4196
  * If there are missing variable outputs,
4095
4197
  * `addVariableOutputs` is called on the transaction.
4096
4198
  *
4097
- * @privateRemarks
4098
- * TODO: Investigate support for missing contract IDs
4099
- * TODO: Add support for missing output messages
4100
4199
  *
4101
4200
  * @param transactionRequest - The transaction request object.
4102
4201
  * @returns A promise.
4103
4202
  */
4104
4203
  async estimateTxDependencies(transactionRequest) {
4105
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
4204
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
4106
4205
  return {
4107
4206
  receipts: [],
4108
4207
  outputVariables: 0,
4109
4208
  missingContractIds: []
4110
4209
  };
4111
4210
  }
4112
- await this.estimatePredicates(transactionRequest);
4113
4211
  let receipts = [];
4114
4212
  const missingContractIds = [];
4115
4213
  let outputVariables = 0;
4214
+ let dryrunStatus;
4116
4215
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
4117
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4118
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
4216
+ const {
4217
+ dryRun: [{ receipts: rawReceipts, status }]
4218
+ } = await this.operations.dryRun({
4219
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4119
4220
  utxoValidation: false
4120
4221
  });
4121
- receipts = gqlReceipts.map(processGqlReceipt);
4222
+ receipts = rawReceipts.map(processGqlReceipt);
4223
+ dryrunStatus = status;
4122
4224
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4123
4225
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4124
4226
  if (hasMissingOutputs) {
@@ -4128,6 +4230,10 @@ var _Provider = class {
4128
4230
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4129
4231
  missingContractIds.push(contractId);
4130
4232
  });
4233
+ const { maxFee } = await this.estimateTxGasAndFee({
4234
+ transactionRequest
4235
+ });
4236
+ transactionRequest.maxFee = maxFee;
4131
4237
  } else {
4132
4238
  break;
4133
4239
  }
@@ -4135,7 +4241,139 @@ var _Provider = class {
4135
4241
  return {
4136
4242
  receipts,
4137
4243
  outputVariables,
4138
- missingContractIds
4244
+ missingContractIds,
4245
+ dryrunStatus
4246
+ };
4247
+ }
4248
+ /**
4249
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4250
+ *
4251
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4252
+ * further modifications are identified. The method iteratively updates these transactions
4253
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4254
+ *
4255
+ * @param transactionRequests - Array of transaction request objects.
4256
+ * @returns A promise that resolves to an array of results for each transaction.
4257
+ */
4258
+ async estimateMultipleTxDependencies(transactionRequests) {
4259
+ const results = transactionRequests.map(() => ({
4260
+ receipts: [],
4261
+ outputVariables: 0,
4262
+ missingContractIds: [],
4263
+ dryrunStatus: void 0
4264
+ }));
4265
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4266
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4267
+ allRequests.forEach((req, index) => {
4268
+ if (req.type === import_transactions19.TransactionType.Script) {
4269
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4270
+ }
4271
+ });
4272
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4273
+ let attempt = 0;
4274
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4275
+ const encodedTransactions = transactionsToProcess.map(
4276
+ (index) => serializedTransactionsMap.get(index)
4277
+ );
4278
+ const dryRunResults = await this.operations.dryRun({
4279
+ encodedTransactions,
4280
+ utxoValidation: false
4281
+ });
4282
+ const nextRoundTransactions = [];
4283
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4284
+ const currentResultIndex = transactionsToProcess[i];
4285
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4286
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4287
+ results[currentResultIndex].dryrunStatus = status;
4288
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4289
+ results[currentResultIndex].receipts
4290
+ );
4291
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4292
+ const requestToProcess = allRequests[currentResultIndex];
4293
+ if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4294
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4295
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4296
+ missingOutputContractIds.forEach(({ contractId }) => {
4297
+ requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4298
+ results[currentResultIndex].missingContractIds.push(contractId);
4299
+ });
4300
+ const { maxFee } = await this.estimateTxGasAndFee({
4301
+ transactionRequest: requestToProcess
4302
+ });
4303
+ requestToProcess.maxFee = maxFee;
4304
+ serializedTransactionsMap.set(
4305
+ currentResultIndex,
4306
+ (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4307
+ );
4308
+ nextRoundTransactions.push(currentResultIndex);
4309
+ allRequests[currentResultIndex] = requestToProcess;
4310
+ }
4311
+ }
4312
+ transactionsToProcess = nextRoundTransactions;
4313
+ attempt += 1;
4314
+ }
4315
+ return results;
4316
+ }
4317
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4318
+ if (estimateTxDependencies) {
4319
+ return this.estimateMultipleTxDependencies(transactionRequests);
4320
+ }
4321
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4322
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4323
+ encodedTransactions,
4324
+ utxoValidation: utxoValidation || false
4325
+ });
4326
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4327
+ const receipts = rawReceipts.map(processGqlReceipt);
4328
+ return { receipts, dryrunStatus: status };
4329
+ });
4330
+ return results;
4331
+ }
4332
+ /**
4333
+ * Estimates the transaction gas and fee based on the provided transaction request.
4334
+ * @param transactionRequest - The transaction request object.
4335
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4336
+ */
4337
+ async estimateTxGasAndFee(params) {
4338
+ const { transactionRequest } = params;
4339
+ let { gasPrice } = params;
4340
+ const chainInfo = this.getChain();
4341
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4342
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
4343
+ if (!gasPrice) {
4344
+ gasPrice = await this.estimateGasPrice(10);
4345
+ }
4346
+ const minFee = calculateGasFee({
4347
+ gasPrice: (0, import_math16.bn)(gasPrice),
4348
+ gas: minGas,
4349
+ priceFactor: gasPriceFactor,
4350
+ tip: transactionRequest.tip
4351
+ }).add(1);
4352
+ let gasLimit = (0, import_math16.bn)(0);
4353
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4354
+ gasLimit = transactionRequest.gasLimit;
4355
+ if (transactionRequest.gasLimit.eq(0)) {
4356
+ transactionRequest.gasLimit = minGas;
4357
+ transactionRequest.gasLimit = maxGasPerTx.sub(
4358
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
4359
+ );
4360
+ gasLimit = transactionRequest.gasLimit;
4361
+ }
4362
+ }
4363
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4364
+ const maxFee = calculateGasFee({
4365
+ gasPrice: (0, import_math16.bn)(gasPrice),
4366
+ gas: maxGas,
4367
+ priceFactor: gasPriceFactor,
4368
+ tip: transactionRequest.tip
4369
+ }).add(1);
4370
+ return {
4371
+ minGas,
4372
+ minFee,
4373
+ maxGas,
4374
+ maxFee,
4375
+ gasPrice,
4376
+ gasLimit
4139
4377
  };
4140
4378
  }
4141
4379
  /**
@@ -4153,15 +4391,17 @@ var _Provider = class {
4153
4391
  if (estimateTxDependencies) {
4154
4392
  return this.estimateTxDependencies(transactionRequest);
4155
4393
  }
4156
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4157
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4158
- encodedTransaction,
4394
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4395
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4396
+ encodedTransactions,
4159
4397
  utxoValidation: true
4160
4398
  });
4161
- const receipts = gqlReceipts.map(processGqlReceipt);
4162
- return {
4163
- receipts
4164
- };
4399
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4400
+ const { id, receipts, status } = dryRunStatus;
4401
+ const processedReceipts = receipts.map(processGqlReceipt);
4402
+ return { id, receipts: processedReceipts, status };
4403
+ });
4404
+ return { receipts: callResult[0].receipts };
4165
4405
  }
4166
4406
  /**
4167
4407
  * Returns a transaction cost to enable user
@@ -4178,80 +4418,79 @@ var _Provider = class {
4178
4418
  * @param tolerance - The tolerance to add on top of the gasUsed.
4179
4419
  * @returns A promise that resolves to the transaction cost object.
4180
4420
  */
4181
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4182
- estimateTxDependencies = true,
4183
- estimatePredicates = true,
4184
- resourcesOwner,
4185
- signatureCallback
4186
- } = {}) {
4421
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4187
4422
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4188
- const chainInfo = this.getChain();
4189
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4190
- const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4191
- const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4423
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4192
4424
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4193
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4425
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4194
4426
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4195
- if (estimatePredicates) {
4196
- if (isScriptTransaction) {
4197
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4198
- }
4199
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4200
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4201
- }
4202
- await this.estimatePredicates(txRequestClone);
4427
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
4428
+ if (isScriptTransaction) {
4429
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
4430
+ }
4431
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4432
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4203
4433
  }
4434
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4435
+ let addedSignatures = 0;
4204
4436
  if (signatureCallback && isScriptTransaction) {
4205
- await signatureCallback(txRequestClone);
4437
+ const lengthBefore = signedRequest.witnesses.length;
4438
+ await signatureCallback(signedRequest);
4439
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4206
4440
  }
4207
- const minGas = txRequestClone.calculateMinGas(chainInfo);
4208
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4441
+ await this.estimatePredicates(signedRequest);
4442
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4443
+ transactionRequest: signedRequest
4444
+ });
4209
4445
  let receipts = [];
4210
4446
  let missingContractIds = [];
4211
4447
  let outputVariables = 0;
4212
- if (isScriptTransaction && estimateTxDependencies) {
4213
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
4214
- txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4448
+ let gasUsed = (0, import_math16.bn)(0);
4449
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4450
+ txRequestClone.maxFee = maxFee;
4451
+ if (isScriptTransaction) {
4452
+ txRequestClone.gasLimit = gasLimit;
4453
+ if (signatureCallback) {
4454
+ await signatureCallback(txRequestClone);
4455
+ }
4215
4456
  const result = await this.estimateTxDependencies(txRequestClone);
4216
4457
  receipts = result.receipts;
4217
4458
  outputVariables = result.outputVariables;
4218
4459
  missingContractIds = result.missingContractIds;
4460
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4461
+ txRequestClone.gasLimit = gasUsed;
4462
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4463
+ transactionRequest: txRequestClone,
4464
+ gasPrice
4465
+ }));
4219
4466
  }
4220
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
4221
- const usedFee = calculatePriceWithFactor(
4222
- gasUsed,
4223
- gasPrice,
4224
- gasPriceFactor
4225
- ).normalizeZeroToOne();
4226
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4227
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4228
4467
  return {
4229
4468
  requiredQuantities: allQuantities,
4230
4469
  receipts,
4231
4470
  gasUsed,
4232
- minGasPrice,
4233
4471
  gasPrice,
4234
4472
  minGas,
4235
4473
  maxGas,
4236
- usedFee,
4237
4474
  minFee,
4238
4475
  maxFee,
4239
- estimatedInputs: txRequestClone.inputs,
4240
4476
  outputVariables,
4241
- missingContractIds
4477
+ missingContractIds,
4478
+ addedSignatures,
4479
+ estimatedPredicates: txRequestClone.inputs
4242
4480
  };
4243
4481
  }
4244
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4482
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4245
4483
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4246
4484
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4247
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4485
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4486
+ quantitiesToContract
4487
+ });
4248
4488
  transactionRequest.addResources(
4249
4489
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4250
4490
  );
4251
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4252
- transactionRequest,
4253
- forwardingQuantities
4254
- );
4491
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4492
+ quantitiesToContract
4493
+ });
4255
4494
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4256
4495
  return {
4257
4496
  resources,
@@ -4267,17 +4506,16 @@ var _Provider = class {
4267
4506
  const result = await this.operations.getCoins({
4268
4507
  first: 10,
4269
4508
  ...paginationArgs,
4270
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4509
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4271
4510
  });
4272
4511
  const coins = result.coins.edges.map((edge) => edge.node);
4273
4512
  return coins.map((coin) => ({
4274
4513
  id: coin.utxoId,
4275
4514
  assetId: coin.assetId,
4276
- amount: (0, import_math15.bn)(coin.amount),
4515
+ amount: (0, import_math16.bn)(coin.amount),
4277
4516
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4278
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4279
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4280
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4517
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4518
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4281
4519
  }));
4282
4520
  }
4283
4521
  /**
@@ -4291,19 +4529,19 @@ var _Provider = class {
4291
4529
  async getResourcesToSpend(owner, quantities, excludedIds) {
4292
4530
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4293
4531
  const excludeInput = {
4294
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4295
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4532
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4533
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4296
4534
  };
4297
4535
  if (this.cache) {
4298
4536
  const uniqueUtxos = new Set(
4299
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4537
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4300
4538
  );
4301
4539
  excludeInput.utxos = Array.from(uniqueUtxos);
4302
4540
  }
4303
4541
  const coinsQuery = {
4304
4542
  owner: ownerAddress.toB256(),
4305
4543
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4306
- assetId: (0, import_utils23.hexlify)(assetId),
4544
+ assetId: (0, import_utils22.hexlify)(assetId),
4307
4545
  amount: amount.toString(10),
4308
4546
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4309
4547
  })),
@@ -4314,9 +4552,9 @@ var _Provider = class {
4314
4552
  switch (coin.__typename) {
4315
4553
  case "MessageCoin":
4316
4554
  return {
4317
- amount: (0, import_math15.bn)(coin.amount),
4555
+ amount: (0, import_math16.bn)(coin.amount),
4318
4556
  assetId: coin.assetId,
4319
- daHeight: (0, import_math15.bn)(coin.daHeight),
4557
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4320
4558
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4321
4559
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4322
4560
  nonce: coin.nonce
@@ -4324,12 +4562,11 @@ var _Provider = class {
4324
4562
  case "Coin":
4325
4563
  return {
4326
4564
  id: coin.utxoId,
4327
- amount: (0, import_math15.bn)(coin.amount),
4565
+ amount: (0, import_math16.bn)(coin.amount),
4328
4566
  assetId: coin.assetId,
4329
4567
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4330
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4331
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4332
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4568
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4569
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4333
4570
  };
4334
4571
  default:
4335
4572
  return null;
@@ -4346,13 +4583,13 @@ var _Provider = class {
4346
4583
  async getBlock(idOrHeight) {
4347
4584
  let variables;
4348
4585
  if (typeof idOrHeight === "number") {
4349
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4586
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4350
4587
  } else if (idOrHeight === "latest") {
4351
4588
  variables = { height: (await this.getBlockNumber()).toString(10) };
4352
4589
  } else if (idOrHeight.length === 66) {
4353
4590
  variables = { blockId: idOrHeight };
4354
4591
  } else {
4355
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4592
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4356
4593
  }
4357
4594
  const { block } = await this.operations.getBlock(variables);
4358
4595
  if (!block) {
@@ -4360,7 +4597,7 @@ var _Provider = class {
4360
4597
  }
4361
4598
  return {
4362
4599
  id: block.id,
4363
- height: (0, import_math15.bn)(block.header.height),
4600
+ height: (0, import_math16.bn)(block.height),
4364
4601
  time: block.header.time,
4365
4602
  transactionIds: block.transactions.map((tx) => tx.id)
4366
4603
  };
@@ -4375,7 +4612,7 @@ var _Provider = class {
4375
4612
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4376
4613
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4377
4614
  id: block.id,
4378
- height: (0, import_math15.bn)(block.header.height),
4615
+ height: (0, import_math16.bn)(block.height),
4379
4616
  time: block.header.time,
4380
4617
  transactionIds: block.transactions.map((tx) => tx.id)
4381
4618
  }));
@@ -4390,7 +4627,7 @@ var _Provider = class {
4390
4627
  async getBlockWithTransactions(idOrHeight) {
4391
4628
  let variables;
4392
4629
  if (typeof idOrHeight === "number") {
4393
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4630
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4394
4631
  } else if (idOrHeight === "latest") {
4395
4632
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4396
4633
  } else {
@@ -4402,11 +4639,11 @@ var _Provider = class {
4402
4639
  }
4403
4640
  return {
4404
4641
  id: block.id,
4405
- height: (0, import_math15.bn)(block.header.height, 10),
4642
+ height: (0, import_math16.bn)(block.height, 10),
4406
4643
  time: block.header.time,
4407
4644
  transactionIds: block.transactions.map((tx) => tx.id),
4408
4645
  transactions: block.transactions.map(
4409
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4646
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4410
4647
  )
4411
4648
  };
4412
4649
  }
@@ -4421,8 +4658,8 @@ var _Provider = class {
4421
4658
  if (!transaction) {
4422
4659
  return null;
4423
4660
  }
4424
- return new import_transactions18.TransactionCoder().decode(
4425
- (0, import_utils23.arrayify)(transaction.rawPayload),
4661
+ return new import_transactions19.TransactionCoder().decode(
4662
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4426
4663
  0
4427
4664
  )?.[0];
4428
4665
  }
@@ -4449,9 +4686,9 @@ var _Provider = class {
4449
4686
  async getContractBalance(contractId, assetId) {
4450
4687
  const { contractBalance } = await this.operations.getContractBalance({
4451
4688
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4452
- asset: (0, import_utils23.hexlify)(assetId)
4689
+ asset: (0, import_utils22.hexlify)(assetId)
4453
4690
  });
4454
- return (0, import_math15.bn)(contractBalance.amount, 10);
4691
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4455
4692
  }
4456
4693
  /**
4457
4694
  * Returns the balance for the given owner for the given asset ID.
@@ -4463,9 +4700,9 @@ var _Provider = class {
4463
4700
  async getBalance(owner, assetId) {
4464
4701
  const { balance } = await this.operations.getBalance({
4465
4702
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4466
- assetId: (0, import_utils23.hexlify)(assetId)
4703
+ assetId: (0, import_utils22.hexlify)(assetId)
4467
4704
  });
4468
- return (0, import_math15.bn)(balance.amount, 10);
4705
+ return (0, import_math16.bn)(balance.amount, 10);
4469
4706
  }
4470
4707
  /**
4471
4708
  * Returns balances for the given owner.
@@ -4483,7 +4720,7 @@ var _Provider = class {
4483
4720
  const balances = result.balances.edges.map((edge) => edge.node);
4484
4721
  return balances.map((balance) => ({
4485
4722
  assetId: balance.assetId,
4486
- amount: (0, import_math15.bn)(balance.amount)
4723
+ amount: (0, import_math16.bn)(balance.amount)
4487
4724
  }));
4488
4725
  }
4489
4726
  /**
@@ -4501,19 +4738,19 @@ var _Provider = class {
4501
4738
  });
4502
4739
  const messages = result.messages.edges.map((edge) => edge.node);
4503
4740
  return messages.map((message) => ({
4504
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4741
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4505
4742
  sender: message.sender,
4506
4743
  recipient: message.recipient,
4507
4744
  nonce: message.nonce,
4508
- amount: (0, import_math15.bn)(message.amount),
4745
+ amount: (0, import_math16.bn)(message.amount),
4509
4746
  data: message.data
4510
4747
  }),
4511
4748
  sender: import_address3.Address.fromAddressOrString(message.sender),
4512
4749
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4513
4750
  nonce: message.nonce,
4514
- amount: (0, import_math15.bn)(message.amount),
4515
- data: import_transactions18.InputMessageCoder.decodeData(message.data),
4516
- daHeight: (0, import_math15.bn)(message.daHeight)
4751
+ amount: (0, import_math16.bn)(message.amount),
4752
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4753
+ daHeight: (0, import_math16.bn)(message.daHeight)
4517
4754
  }));
4518
4755
  }
4519
4756
  /**
@@ -4566,44 +4803,60 @@ var _Provider = class {
4566
4803
  } = result.messageProof;
4567
4804
  return {
4568
4805
  messageProof: {
4569
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4806
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4570
4807
  proofSet: messageProof.proofSet
4571
4808
  },
4572
4809
  blockProof: {
4573
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4810
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4574
4811
  proofSet: blockProof.proofSet
4575
4812
  },
4576
4813
  messageBlockHeader: {
4577
4814
  id: messageBlockHeader.id,
4578
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4579
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4815
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4816
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4580
4817
  transactionsRoot: messageBlockHeader.transactionsRoot,
4581
- height: (0, import_math15.bn)(messageBlockHeader.height),
4818
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4582
4819
  prevRoot: messageBlockHeader.prevRoot,
4583
4820
  time: messageBlockHeader.time,
4584
4821
  applicationHash: messageBlockHeader.applicationHash,
4585
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4586
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4822
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
4823
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4824
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4825
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4826
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4587
4827
  },
4588
4828
  commitBlockHeader: {
4589
4829
  id: commitBlockHeader.id,
4590
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4591
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4830
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4831
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4592
4832
  transactionsRoot: commitBlockHeader.transactionsRoot,
4593
- height: (0, import_math15.bn)(commitBlockHeader.height),
4833
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4594
4834
  prevRoot: commitBlockHeader.prevRoot,
4595
4835
  time: commitBlockHeader.time,
4596
4836
  applicationHash: commitBlockHeader.applicationHash,
4597
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4598
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4837
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
4838
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4839
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4840
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4841
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4599
4842
  },
4600
4843
  sender: import_address3.Address.fromAddressOrString(sender),
4601
4844
  recipient: import_address3.Address.fromAddressOrString(recipient),
4602
4845
  nonce,
4603
- amount: (0, import_math15.bn)(amount),
4846
+ amount: (0, import_math16.bn)(amount),
4604
4847
  data
4605
4848
  };
4606
4849
  }
4850
+ async getLatestGasPrice() {
4851
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4852
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4853
+ }
4854
+ async estimateGasPrice(blockHorizon) {
4855
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4856
+ blockHorizon: String(blockHorizon)
4857
+ });
4858
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4859
+ }
4607
4860
  /**
4608
4861
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4609
4862
  *
@@ -4623,10 +4876,10 @@ var _Provider = class {
4623
4876
  */
4624
4877
  async produceBlocks(amount, startTime) {
4625
4878
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4626
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4627
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4879
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4880
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4628
4881
  });
4629
- return (0, import_math15.bn)(latestBlockHeight);
4882
+ return (0, import_math16.bn)(latestBlockHeight);
4630
4883
  }
4631
4884
  // eslint-disable-next-line @typescript-eslint/require-await
4632
4885
  async getTransactionResponse(transactionId) {
@@ -4640,7 +4893,7 @@ cacheInputs_fn = function(inputs) {
4640
4893
  return;
4641
4894
  }
4642
4895
  inputs.forEach((input) => {
4643
- if (input.type === import_transactions18.InputType.Coin) {
4896
+ if (input.type === import_transactions19.InputType.Coin) {
4644
4897
  this.cache?.set(input.id);
4645
4898
  }
4646
4899
  });
@@ -4650,9 +4903,9 @@ __publicField(Provider, "nodeInfoCache", {});
4650
4903
 
4651
4904
  // src/providers/transaction-summary/get-transaction-summary.ts
4652
4905
  var import_errors15 = require("@fuel-ts/errors");
4653
- var import_math16 = require("@fuel-ts/math");
4654
- var import_transactions19 = require("@fuel-ts/transactions");
4655
- var import_utils26 = require("@fuel-ts/utils");
4906
+ var import_math17 = require("@fuel-ts/math");
4907
+ var import_transactions20 = require("@fuel-ts/transactions");
4908
+ var import_utils25 = require("@fuel-ts/utils");
4656
4909
  async function getTransactionSummary(params) {
4657
4910
  const { id, provider, abiMap } = params;
4658
4911
  const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
@@ -4664,25 +4917,32 @@ async function getTransactionSummary(params) {
4664
4917
  `Transaction not found for given id: ${id}.`
4665
4918
  );
4666
4919
  }
4667
- const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
4668
- (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4920
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
4921
+ (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4669
4922
  0
4670
4923
  );
4671
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4924
+ let txReceipts = [];
4925
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4926
+ txReceipts = gqlTransaction.status.receipts;
4927
+ }
4928
+ const receipts = txReceipts.map(processGqlReceipt);
4672
4929
  const {
4673
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4930
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4674
4931
  } = provider.getChain();
4932
+ const gasPrice = await provider.getLatestGasPrice();
4675
4933
  const transactionInfo = assembleTransactionSummary({
4676
4934
  id: gqlTransaction.id,
4677
4935
  receipts,
4678
4936
  transaction: decodedTransaction,
4679
- transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4937
+ transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4680
4938
  gqlTransactionStatus: gqlTransaction.status,
4681
- gasPerByte: (0, import_math16.bn)(gasPerByte),
4682
- gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
4939
+ gasPerByte: (0, import_math17.bn)(gasPerByte),
4940
+ gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
4683
4941
  abiMap,
4684
4942
  maxInputs,
4685
- gasCosts
4943
+ gasCosts,
4944
+ maxGasPerTx,
4945
+ gasPrice
4686
4946
  });
4687
4947
  return {
4688
4948
  gqlTransaction,
@@ -4692,10 +4952,11 @@ async function getTransactionSummary(params) {
4692
4952
  async function getTransactionSummaryFromRequest(params) {
4693
4953
  const { provider, transactionRequest, abiMap } = params;
4694
4954
  const { receipts } = await provider.call(transactionRequest);
4695
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4955
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4696
4956
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4697
4957
  const transaction = transactionRequest.toTransaction();
4698
4958
  const transactionBytes = transactionRequest.toTransactionBytes();
4959
+ const gasPrice = await provider.getLatestGasPrice();
4699
4960
  const transactionSummary = assembleTransactionSummary({
4700
4961
  receipts,
4701
4962
  transaction,
@@ -4704,7 +4965,9 @@ async function getTransactionSummaryFromRequest(params) {
4704
4965
  gasPerByte,
4705
4966
  gasPriceFactor,
4706
4967
  maxInputs,
4707
- gasCosts
4968
+ gasCosts,
4969
+ maxGasPerTx,
4970
+ gasPrice
4708
4971
  });
4709
4972
  return transactionSummary;
4710
4973
  }
@@ -4713,24 +4976,31 @@ async function getTransactionsSummaries(params) {
4713
4976
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4714
4977
  const { edges, pageInfo } = transactionsByOwner;
4715
4978
  const {
4716
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4979
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4717
4980
  } = provider.getChain();
4981
+ const gasPrice = await provider.getLatestGasPrice();
4718
4982
  const transactions = edges.map((edge) => {
4719
4983
  const { node: gqlTransaction } = edge;
4720
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4721
- const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
4722
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4984
+ const { id, rawPayload, status } = gqlTransaction;
4985
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
4986
+ let txReceipts = [];
4987
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4988
+ txReceipts = gqlTransaction.status.receipts;
4989
+ }
4990
+ const receipts = txReceipts.map(processGqlReceipt);
4723
4991
  const transactionSummary = assembleTransactionSummary({
4724
4992
  id,
4725
4993
  receipts,
4726
4994
  transaction: decodedTransaction,
4727
- transactionBytes: (0, import_utils26.arrayify)(rawPayload),
4995
+ transactionBytes: (0, import_utils25.arrayify)(rawPayload),
4728
4996
  gqlTransactionStatus: status,
4729
4997
  abiMap,
4730
4998
  gasPerByte,
4731
4999
  gasPriceFactor,
4732
5000
  maxInputs,
4733
- gasCosts
5001
+ gasCosts,
5002
+ maxGasPerTx,
5003
+ gasPrice
4734
5004
  });
4735
5005
  const output = {
4736
5006
  gqlTransaction,
@@ -4866,18 +5136,18 @@ var assets = [
4866
5136
  ];
4867
5137
 
4868
5138
  // src/utils/formatTransferToContractScriptData.ts
4869
- var import_abi_coder4 = require("@fuel-ts/abi-coder");
4870
- var import_math17 = require("@fuel-ts/math");
4871
- var import_utils27 = require("@fuel-ts/utils");
5139
+ var import_abi_coder6 = require("@fuel-ts/abi-coder");
5140
+ var import_math18 = require("@fuel-ts/math");
5141
+ var import_utils26 = require("@fuel-ts/utils");
4872
5142
  var asm = __toESM(require("@fuels/vm-asm"));
4873
5143
  var formatTransferToContractScriptData = (params) => {
4874
5144
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4875
- const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4876
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
5145
+ const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
5146
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4877
5147
  const scriptData = Uint8Array.from([
4878
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
5148
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4879
5149
  ...encoded,
4880
- ...(0, import_utils27.arrayify)(assetId)
5150
+ ...(0, import_utils26.arrayify)(assetId)
4881
5151
  ]);
4882
5152
  return scriptData;
4883
5153
  };
@@ -5062,36 +5332,33 @@ var Account = class extends import_interfaces.AbstractAccount {
5062
5332
  * @param fee - The estimated transaction fee.
5063
5333
  * @returns A promise that resolves when the resources are added to the transaction.
5064
5334
  */
5065
- async fund(request, coinQuantities, fee) {
5066
- const updatedQuantities = addAmountToAsset({
5067
- amount: (0, import_math18.bn)(fee),
5335
+ async fund(request, params) {
5336
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5337
+ const txRequest = request;
5338
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5339
+ amount: (0, import_math19.bn)(fee),
5068
5340
  assetId: import_configs12.BaseAssetId,
5069
- coinQuantities
5341
+ coinQuantities: requiredQuantities
5070
5342
  });
5071
5343
  const quantitiesDict = {};
5072
- updatedQuantities.forEach(({ amount, assetId }) => {
5344
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5073
5345
  quantitiesDict[assetId] = {
5074
5346
  required: amount,
5075
- owned: (0, import_math18.bn)(0)
5347
+ owned: (0, import_math19.bn)(0)
5076
5348
  };
5077
5349
  });
5078
- const cachedUtxos = [];
5079
- const cachedMessages = [];
5080
- const owner = this.address.toB256();
5081
- request.inputs.forEach((input) => {
5350
+ txRequest.inputs.forEach((input) => {
5082
5351
  const isResource = "amount" in input;
5083
5352
  if (isResource) {
5084
5353
  const isCoin2 = "owner" in input;
5085
5354
  if (isCoin2) {
5086
5355
  const assetId = String(input.assetId);
5087
- if (input.owner === owner && quantitiesDict[assetId]) {
5088
- const amount = (0, import_math18.bn)(input.amount);
5356
+ if (quantitiesDict[assetId]) {
5357
+ const amount = (0, import_math19.bn)(input.amount);
5089
5358
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5090
- cachedUtxos.push(input.id);
5091
5359
  }
5092
- } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5360
+ } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5093
5361
  quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5094
- cachedMessages.push(input.nonce);
5095
5362
  }
5096
5363
  }
5097
5364
  });
@@ -5106,12 +5373,23 @@ var Account = class extends import_interfaces.AbstractAccount {
5106
5373
  });
5107
5374
  const needsToBeFunded = missingQuantities.length;
5108
5375
  if (needsToBeFunded) {
5109
- const resources = await this.getResourcesToSpend(missingQuantities, {
5110
- messages: cachedMessages,
5111
- utxos: cachedUtxos
5112
- });
5113
- request.addResources(resources);
5376
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5377
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5378
+ txRequest.addResources(resources);
5379
+ }
5380
+ txRequest.shiftPredicateData();
5381
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5382
+ const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
5383
+ if (addedSignatures) {
5384
+ Array.from({ length: addedSignatures }).forEach(
5385
+ () => requestToBeReEstimate.addEmptyWitness()
5386
+ );
5114
5387
  }
5388
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5389
+ transactionRequest: requestToBeReEstimate
5390
+ });
5391
+ txRequest.maxFee = maxFee;
5392
+ return txRequest;
5115
5393
  }
5116
5394
  /**
5117
5395
  * A helper that creates a transfer transaction request and returns it.
@@ -5119,28 +5397,25 @@ var Account = class extends import_interfaces.AbstractAccount {
5119
5397
  * @param destination - The address of the destination.
5120
5398
  * @param amount - The amount of coins to transfer.
5121
5399
  * @param assetId - The asset ID of the coins to transfer.
5122
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5400
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5123
5401
  * @returns A promise that resolves to the prepared transaction request.
5124
5402
  */
5125
5403
  async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5126
- const { minGasPrice } = this.provider.getGasConfig();
5127
- const params = { gasPrice: minGasPrice, ...txParams };
5128
- const request = new ScriptTransactionRequest(params);
5404
+ const request = new ScriptTransactionRequest(txParams);
5129
5405
  request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5130
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5406
+ const txCost = await this.provider.getTransactionCost(request, {
5131
5407
  estimateTxDependencies: true,
5132
5408
  resourcesOwner: this
5133
5409
  });
5134
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
5135
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
5136
- this.validateGas({
5137
- gasUsed,
5138
- gasPrice: request.gasPrice,
5139
- gasLimit: request.gasLimit,
5140
- minGasPrice
5141
- });
5142
- await this.fund(request, requiredQuantities, maxFee);
5143
- request.updatePredicateInputs(estimatedInputs);
5410
+ if ("gasLimit" in txParams) {
5411
+ this.validateGas({
5412
+ gasUsed: txCost.gasUsed,
5413
+ gasLimit: request.gasLimit
5414
+ });
5415
+ }
5416
+ request.gasLimit = txCost.gasUsed;
5417
+ request.maxFee = txCost.maxFee;
5418
+ await this.fund(request, txCost);
5144
5419
  return request;
5145
5420
  }
5146
5421
  /**
@@ -5153,7 +5428,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5153
5428
  * @returns A promise that resolves to the transaction response.
5154
5429
  */
5155
5430
  async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5156
- if ((0, import_math18.bn)(amount).lte(0)) {
5431
+ if ((0, import_math19.bn)(amount).lte(0)) {
5157
5432
  throw new import_errors16.FuelError(
5158
5433
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5159
5434
  "Transfer amount must be a positive number."
@@ -5172,38 +5447,37 @@ var Account = class extends import_interfaces.AbstractAccount {
5172
5447
  * @returns A promise that resolves to the transaction response.
5173
5448
  */
5174
5449
  async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5175
- if ((0, import_math18.bn)(amount).lte(0)) {
5450
+ if ((0, import_math19.bn)(amount).lte(0)) {
5176
5451
  throw new import_errors16.FuelError(
5177
5452
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5178
5453
  "Transfer amount must be a positive number."
5179
5454
  );
5180
5455
  }
5181
5456
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5182
- const { minGasPrice } = this.provider.getGasConfig();
5183
- const params = { gasPrice: minGasPrice, ...txParams };
5184
5457
  const { script, scriptData } = await assembleTransferToContractScript({
5185
5458
  hexlifiedContractId: contractAddress.toB256(),
5186
- amountToTransfer: (0, import_math18.bn)(amount),
5459
+ amountToTransfer: (0, import_math19.bn)(amount),
5187
5460
  assetId
5188
5461
  });
5189
5462
  const request = new ScriptTransactionRequest({
5190
- ...params,
5463
+ ...txParams,
5191
5464
  script,
5192
5465
  scriptData
5193
5466
  });
5194
5467
  request.addContractInputAndOutput(contractAddress);
5195
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5196
- request,
5197
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
5198
- );
5199
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5200
- this.validateGas({
5201
- gasUsed,
5202
- gasPrice: request.gasPrice,
5203
- gasLimit: request.gasLimit,
5204
- minGasPrice
5468
+ const txCost = await this.provider.getTransactionCost(request, {
5469
+ resourcesOwner: this,
5470
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
5205
5471
  });
5206
- await this.fund(request, requiredQuantities, maxFee);
5472
+ if (txParams.gasLimit) {
5473
+ this.validateGas({
5474
+ gasUsed: txCost.gasUsed,
5475
+ gasLimit: request.gasLimit
5476
+ });
5477
+ }
5478
+ request.gasLimit = txCost.gasUsed;
5479
+ request.maxFee = txCost.maxFee;
5480
+ await this.fund(request, txCost);
5207
5481
  return this.sendTransaction(request);
5208
5482
  }
5209
5483
  /**
@@ -5215,34 +5489,31 @@ var Account = class extends import_interfaces.AbstractAccount {
5215
5489
  * @returns A promise that resolves to the transaction response.
5216
5490
  */
5217
5491
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5218
- const { minGasPrice } = this.provider.getGasConfig();
5219
5492
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5220
- const recipientDataArray = (0, import_utils28.arrayify)(
5493
+ const recipientDataArray = (0, import_utils27.arrayify)(
5221
5494
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5222
5495
  );
5223
- const amountDataArray = (0, import_utils28.arrayify)(
5224
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5496
+ const amountDataArray = (0, import_utils27.arrayify)(
5497
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
5225
5498
  );
5226
5499
  const script = new Uint8Array([
5227
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5500
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
5228
5501
  ...recipientDataArray,
5229
5502
  ...amountDataArray
5230
5503
  ]);
5231
- const params = { script, gasPrice: minGasPrice, ...txParams };
5504
+ const params = { script, ...txParams };
5232
5505
  const request = new ScriptTransactionRequest(params);
5233
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
5234
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5235
- request,
5236
- forwardingQuantities
5237
- );
5238
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5239
- this.validateGas({
5240
- gasUsed,
5241
- gasPrice: request.gasPrice,
5242
- gasLimit: request.gasLimit,
5243
- minGasPrice
5244
- });
5245
- await this.fund(request, requiredQuantities, maxFee);
5506
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5507
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5508
+ if (txParams.gasLimit) {
5509
+ this.validateGas({
5510
+ gasUsed: txCost.gasUsed,
5511
+ gasLimit: request.gasLimit
5512
+ });
5513
+ }
5514
+ request.maxFee = txCost.maxFee;
5515
+ request.gasLimit = txCost.gasUsed;
5516
+ await this.fund(request, txCost);
5246
5517
  return this.sendTransaction(request);
5247
5518
  }
5248
5519
  async signMessage(message) {
@@ -5300,18 +5571,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5300
5571
  }
5301
5572
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5302
5573
  }
5303
- validateGas({
5304
- gasUsed,
5305
- gasPrice,
5306
- gasLimit,
5307
- minGasPrice
5308
- }) {
5309
- if (minGasPrice.gt(gasPrice)) {
5310
- throw new import_errors16.FuelError(
5311
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
5312
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5313
- );
5314
- }
5574
+ validateGas({ gasUsed, gasLimit }) {
5315
5575
  if (gasUsed.gt(gasLimit)) {
5316
5576
  throw new import_errors16.FuelError(
5317
5577
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -5323,14 +5583,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5323
5583
 
5324
5584
  // src/wallet/base-wallet-unlocked.ts
5325
5585
  var import_hasher3 = require("@fuel-ts/hasher");
5326
- var import_utils31 = require("@fuel-ts/utils");
5586
+ var import_utils30 = require("@fuel-ts/utils");
5327
5587
 
5328
5588
  // src/signer/signer.ts
5329
5589
  var import_address5 = require("@fuel-ts/address");
5330
- var import_crypto = require("@fuel-ts/crypto");
5590
+ var import_crypto2 = require("@fuel-ts/crypto");
5331
5591
  var import_hasher2 = require("@fuel-ts/hasher");
5332
- var import_math19 = require("@fuel-ts/math");
5333
- var import_utils29 = require("@fuel-ts/utils");
5592
+ var import_math20 = require("@fuel-ts/math");
5593
+ var import_utils28 = require("@fuel-ts/utils");
5334
5594
  var import_secp256k1 = require("@noble/curves/secp256k1");
5335
5595
  var Signer = class {
5336
5596
  address;
@@ -5349,10 +5609,10 @@ var Signer = class {
5349
5609
  privateKey = `0x${privateKey}`;
5350
5610
  }
5351
5611
  }
5352
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
5353
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5354
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5355
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5612
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5613
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5614
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5615
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5356
5616
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5357
5617
  }
5358
5618
  /**
@@ -5366,11 +5626,11 @@ var Signer = class {
5366
5626
  * @returns hashed signature
5367
5627
  */
5368
5628
  sign(data) {
5369
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5370
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
5371
- const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5629
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5630
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5631
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
5372
5632
  s[0] |= (signature.recovery || 0) << 7;
5373
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5633
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5374
5634
  }
5375
5635
  /**
5376
5636
  * Add point on the current elliptic curve
@@ -5379,8 +5639,8 @@ var Signer = class {
5379
5639
  * @returns compressed point on the curve
5380
5640
  */
5381
5641
  addPoint(point) {
5382
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5383
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5642
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5643
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
5384
5644
  const result = p0.add(p1);
5385
5645
  return `0x${result.toHex(true)}`;
5386
5646
  }
@@ -5392,16 +5652,16 @@ var Signer = class {
5392
5652
  * @returns public key from signature from the
5393
5653
  */
5394
5654
  static recoverPublicKey(data, signature) {
5395
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5655
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5396
5656
  const r = signedMessageBytes.slice(0, 32);
5397
5657
  const s = signedMessageBytes.slice(32, 64);
5398
5658
  const recoveryParam = (s[0] & 128) >> 7;
5399
5659
  s[0] &= 127;
5400
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5660
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5401
5661
  recoveryParam
5402
5662
  );
5403
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5404
- return (0, import_utils29.hexlify)(publicKey);
5663
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5664
+ return (0, import_utils28.hexlify)(publicKey);
5405
5665
  }
5406
5666
  /**
5407
5667
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5420,7 +5680,7 @@ var Signer = class {
5420
5680
  * @returns random 32-byte hashed
5421
5681
  */
5422
5682
  static generatePrivateKey(entropy) {
5423
- 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);
5683
+ return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
5424
5684
  }
5425
5685
  /**
5426
5686
  * Extended publicKey from a compact publicKey
@@ -5429,16 +5689,16 @@ var Signer = class {
5429
5689
  * @returns extended publicKey
5430
5690
  */
5431
5691
  static extendPublicKey(publicKey) {
5432
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5433
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5692
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5693
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5434
5694
  }
5435
5695
  };
5436
5696
 
5437
5697
  // src/wallet/keystore-wallet.ts
5438
5698
  var import_address6 = require("@fuel-ts/address");
5439
- var import_crypto2 = require("@fuel-ts/crypto");
5699
+ var import_crypto3 = require("@fuel-ts/crypto");
5440
5700
  var import_errors17 = require("@fuel-ts/errors");
5441
- var import_utils30 = require("@fuel-ts/utils");
5701
+ var import_utils29 = require("@fuel-ts/utils");
5442
5702
  var import_uuid = require("uuid");
5443
5703
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5444
5704
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5452,22 +5712,22 @@ var removeHexPrefix = (hexString) => {
5452
5712
  return hexString;
5453
5713
  };
5454
5714
  async function encryptKeystoreWallet(privateKey, address, password) {
5455
- const privateKeyBuffer = (0, import_crypto2.bufferFromString)(removeHexPrefix(privateKey), "hex");
5715
+ const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
5456
5716
  const ownerAddress = import_address6.Address.fromAddressOrString(address);
5457
- const salt = (0, import_crypto2.randomBytes)(DEFAULT_KEY_SIZE);
5458
- const key = (0, import_crypto2.scrypt)({
5459
- password: (0, import_crypto2.bufferFromString)(password),
5717
+ const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
5718
+ const key = (0, import_crypto3.scrypt)({
5719
+ password: (0, import_crypto3.bufferFromString)(password),
5460
5720
  salt,
5461
5721
  dklen: DEFAULT_KEY_SIZE,
5462
5722
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5463
5723
  r: DEFAULT_KDF_PARAMS_R,
5464
5724
  p: DEFAULT_KDF_PARAMS_P
5465
5725
  });
5466
- const iv = (0, import_crypto2.randomBytes)(DEFAULT_IV_SIZE);
5467
- const ciphertext = await (0, import_crypto2.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5726
+ const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
5727
+ const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5468
5728
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5469
- const macHashUint8Array = (0, import_crypto2.keccak256)(data);
5470
- const mac = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
5729
+ const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5730
+ const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5471
5731
  const keystore = {
5472
5732
  id: (0, import_uuid.v4)(),
5473
5733
  version: 3,
@@ -5475,15 +5735,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5475
5735
  crypto: {
5476
5736
  cipher: "aes-128-ctr",
5477
5737
  mac,
5478
- cipherparams: { iv: (0, import_crypto2.stringFromBuffer)(iv, "hex") },
5479
- ciphertext: (0, import_crypto2.stringFromBuffer)(ciphertext, "hex"),
5738
+ cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
5739
+ ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
5480
5740
  kdf: "scrypt",
5481
5741
  kdfparams: {
5482
5742
  dklen: DEFAULT_KEY_SIZE,
5483
5743
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5484
5744
  p: DEFAULT_KDF_PARAMS_P,
5485
5745
  r: DEFAULT_KDF_PARAMS_R,
5486
- salt: (0, import_crypto2.stringFromBuffer)(salt, "hex")
5746
+ salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
5487
5747
  }
5488
5748
  }
5489
5749
  };
@@ -5499,11 +5759,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5499
5759
  kdfparams: { dklen, n, r, p, salt }
5500
5760
  }
5501
5761
  } = keystoreWallet;
5502
- const ciphertextBuffer = (0, import_crypto2.bufferFromString)(ciphertext, "hex");
5503
- const ivBuffer = (0, import_crypto2.bufferFromString)(iv, "hex");
5504
- const saltBuffer = (0, import_crypto2.bufferFromString)(salt, "hex");
5505
- const passwordBuffer = (0, import_crypto2.bufferFromString)(password);
5506
- const key = (0, import_crypto2.scrypt)({
5762
+ const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
5763
+ const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
5764
+ const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
5765
+ const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
5766
+ const key = (0, import_crypto3.scrypt)({
5507
5767
  password: passwordBuffer,
5508
5768
  salt: saltBuffer,
5509
5769
  n,
@@ -5512,16 +5772,16 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5512
5772
  dklen
5513
5773
  });
5514
5774
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
5515
- const macHashUint8Array = (0, import_crypto2.keccak256)(data);
5516
- const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
5775
+ const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5776
+ const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5517
5777
  if (mac !== macHash) {
5518
5778
  throw new import_errors17.FuelError(
5519
5779
  import_errors17.ErrorCode.INVALID_PASSWORD,
5520
5780
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5521
5781
  );
5522
5782
  }
5523
- const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5524
- const privateKey = (0, import_utils30.hexlify)(buffer);
5783
+ const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5784
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5525
5785
  return privateKey;
5526
5786
  }
5527
5787
 
@@ -5566,7 +5826,7 @@ var BaseWalletUnlocked = class extends Account {
5566
5826
  */
5567
5827
  async signMessage(message) {
5568
5828
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5569
- return (0, import_utils31.hexlify)(signedMessage);
5829
+ return (0, import_utils30.hexlify)(signedMessage);
5570
5830
  }
5571
5831
  /**
5572
5832
  * Signs a transaction with the wallet's private key.
@@ -5579,7 +5839,7 @@ var BaseWalletUnlocked = class extends Account {
5579
5839
  const chainId = this.provider.getChainId();
5580
5840
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5581
5841
  const signature = await this.signer().sign(hashedTransaction);
5582
- return (0, import_utils31.hexlify)(signature);
5842
+ return (0, import_utils30.hexlify)(signature);
5583
5843
  }
5584
5844
  /**
5585
5845
  * Populates a transaction with the witnesses signature.
@@ -5599,7 +5859,7 @@ var BaseWalletUnlocked = class extends Account {
5599
5859
  * @param transactionRequestLike - The transaction request to send.
5600
5860
  * @returns A promise that resolves to the TransactionResponse object.
5601
5861
  */
5602
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5862
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5603
5863
  const transactionRequest = transactionRequestify(transactionRequestLike);
5604
5864
  if (estimateTxDependencies) {
5605
5865
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5640,15 +5900,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5640
5900
  // src/hdwallet/hdwallet.ts
5641
5901
  var import_errors20 = require("@fuel-ts/errors");
5642
5902
  var import_hasher6 = require("@fuel-ts/hasher");
5643
- var import_math20 = require("@fuel-ts/math");
5644
- var import_utils35 = require("@fuel-ts/utils");
5903
+ var import_math21 = require("@fuel-ts/math");
5904
+ var import_utils34 = require("@fuel-ts/utils");
5645
5905
  var import_ethers3 = require("ethers");
5646
5906
 
5647
5907
  // src/mnemonic/mnemonic.ts
5648
- var import_crypto3 = require("@fuel-ts/crypto");
5908
+ var import_crypto4 = require("@fuel-ts/crypto");
5649
5909
  var import_errors19 = require("@fuel-ts/errors");
5650
5910
  var import_hasher5 = require("@fuel-ts/hasher");
5651
- var import_utils33 = require("@fuel-ts/utils");
5911
+ var import_utils32 = require("@fuel-ts/utils");
5652
5912
  var import_ethers2 = require("ethers");
5653
5913
 
5654
5914
  // src/wordlists/words/english.ts
@@ -7712,7 +7972,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
7712
7972
  // src/mnemonic/utils.ts
7713
7973
  var import_errors18 = require("@fuel-ts/errors");
7714
7974
  var import_hasher4 = require("@fuel-ts/hasher");
7715
- var import_utils32 = require("@fuel-ts/utils");
7975
+ var import_utils31 = require("@fuel-ts/utils");
7716
7976
  function toUtf8Bytes(stri) {
7717
7977
  const str = stri.normalize("NFKD");
7718
7978
  const result = [];
@@ -7779,14 +8039,14 @@ function entropyToMnemonicIndices(entropy) {
7779
8039
  }
7780
8040
  }
7781
8041
  const checksumBits = entropy.length / 4;
7782
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8042
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7783
8043
  indices[indices.length - 1] <<= checksumBits;
7784
8044
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7785
8045
  return indices;
7786
8046
  }
7787
8047
  function mnemonicWordsToEntropy(words, wordlist) {
7788
8048
  const size = Math.ceil(11 * words.length / 8);
7789
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
8049
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7790
8050
  let offset = 0;
7791
8051
  for (let i = 0; i < words.length; i += 1) {
7792
8052
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7806,7 +8066,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7806
8066
  const entropyBits = 32 * words.length / 3;
7807
8067
  const checksumBits = words.length / 3;
7808
8068
  const checksumMask = getUpperMask(checksumBits);
7809
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8069
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7810
8070
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7811
8071
  throw new import_errors18.FuelError(
7812
8072
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7881,7 +8141,7 @@ var Mnemonic = class {
7881
8141
  static mnemonicToEntropy(phrase, wordlist = english) {
7882
8142
  const words = getWords(phrase);
7883
8143
  assertMnemonic(words);
7884
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8144
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7885
8145
  }
7886
8146
  /**
7887
8147
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7889,7 +8149,7 @@ var Mnemonic = class {
7889
8149
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7890
8150
  */
7891
8151
  static entropyToMnemonic(entropy, wordlist = english) {
7892
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
8152
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7893
8153
  assertWordList(wordlist);
7894
8154
  assertEntropy(entropyBytes);
7895
8155
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7958,14 +8218,14 @@ var Mnemonic = class {
7958
8218
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7959
8219
  */
7960
8220
  static masterKeysFromSeed(seed) {
7961
- const seedArray = (0, import_utils33.arrayify)(seed);
8221
+ const seedArray = (0, import_utils32.arrayify)(seed);
7962
8222
  if (seedArray.length < 16 || seedArray.length > 64) {
7963
8223
  throw new import_errors19.FuelError(
7964
8224
  import_errors19.ErrorCode.INVALID_SEED,
7965
8225
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7966
8226
  );
7967
8227
  }
7968
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
8228
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7969
8229
  }
7970
8230
  /**
7971
8231
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7976,22 +8236,22 @@ var Mnemonic = class {
7976
8236
  */
7977
8237
  static seedToExtendedKey(seed, testnet = false) {
7978
8238
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7979
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8239
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7980
8240
  const depth = "0x00";
7981
8241
  const fingerprint = "0x00000000";
7982
8242
  const index = "0x00000000";
7983
8243
  const chainCode = masterKey.slice(32);
7984
8244
  const privateKey = masterKey.slice(0, 32);
7985
- const extendedKey = (0, import_utils33.concat)([
8245
+ const extendedKey = (0, import_utils32.concat)([
7986
8246
  prefix,
7987
8247
  depth,
7988
8248
  fingerprint,
7989
8249
  index,
7990
8250
  chainCode,
7991
- (0, import_utils33.concat)(["0x00", privateKey])
8251
+ (0, import_utils32.concat)(["0x00", privateKey])
7992
8252
  ]);
7993
8253
  const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7994
- return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8254
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7995
8255
  }
7996
8256
  /**
7997
8257
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8006,7 +8266,7 @@ var Mnemonic = class {
8006
8266
  * @returns A randomly generated mnemonic
8007
8267
  */
8008
8268
  static generate(size = 32, extraEntropy = "") {
8009
- 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);
8269
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
8010
8270
  return Mnemonic.entropyToMnemonic(entropy);
8011
8271
  }
8012
8272
  };
@@ -8014,12 +8274,12 @@ var mnemonic_default = Mnemonic;
8014
8274
 
8015
8275
  // src/hdwallet/hdwallet.ts
8016
8276
  var HARDENED_INDEX = 2147483648;
8017
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8018
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8019
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8020
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8277
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
8278
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
8279
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
8280
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
8021
8281
  function base58check(data) {
8022
- 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)]));
8282
+ return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8023
8283
  }
8024
8284
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8025
8285
  if (isPublic) {
@@ -8028,11 +8288,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8028
8288
  return testnet ? TestnetPRV2 : MainnetPRV2;
8029
8289
  }
8030
8290
  function isPublicExtendedKey(extendedKey) {
8031
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8291
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
8032
8292
  }
8033
8293
  function isValidExtendedKey(extendedKey) {
8034
8294
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8035
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8295
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
8036
8296
  );
8037
8297
  }
8038
8298
  function parsePath(path, depth = 0) {
@@ -8050,8 +8310,8 @@ function parsePath(path, depth = 0) {
8050
8310
  var HDWallet = class {
8051
8311
  depth = 0;
8052
8312
  index = 0;
8053
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
8054
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8313
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
8314
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
8055
8315
  privateKey;
8056
8316
  publicKey;
8057
8317
  chainCode;
@@ -8063,8 +8323,8 @@ var HDWallet = class {
8063
8323
  constructor(config) {
8064
8324
  if (config.privateKey) {
8065
8325
  const signer = new Signer(config.privateKey);
8066
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8067
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8326
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
8327
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
8068
8328
  } else {
8069
8329
  if (!config.publicKey) {
8070
8330
  throw new import_errors20.FuelError(
@@ -8072,7 +8332,7 @@ var HDWallet = class {
8072
8332
  "Both public and private Key cannot be missing. At least one should be provided."
8073
8333
  );
8074
8334
  }
8075
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8335
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
8076
8336
  }
8077
8337
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8078
8338
  this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
@@ -8091,9 +8351,9 @@ var HDWallet = class {
8091
8351
  * @returns A new instance of HDWallet on the derived index
8092
8352
  */
8093
8353
  deriveIndex(index) {
8094
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8095
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8096
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8354
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
8355
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
8356
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
8097
8357
  const data = new Uint8Array(37);
8098
8358
  if (index & HARDENED_INDEX) {
8099
8359
  if (!privateKey) {
@@ -8104,15 +8364,15 @@ var HDWallet = class {
8104
8364
  }
8105
8365
  data.set(privateKey, 1);
8106
8366
  } else {
8107
- data.set((0, import_utils35.arrayify)(this.publicKey));
8367
+ data.set((0, import_utils34.arrayify)(this.publicKey));
8108
8368
  }
8109
- data.set((0, import_math20.toBytes)(index, 4), 33);
8110
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8369
+ data.set((0, import_math21.toBytes)(index, 4), 33);
8370
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8111
8371
  const IL = bytes.slice(0, 32);
8112
8372
  const IR = bytes.slice(32);
8113
8373
  if (privateKey) {
8114
8374
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8115
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
8375
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
8116
8376
  return new HDWallet({
8117
8377
  privateKey: ki,
8118
8378
  chainCode: IR,
@@ -8121,7 +8381,7 @@ var HDWallet = class {
8121
8381
  parentFingerprint: this.fingerprint
8122
8382
  });
8123
8383
  }
8124
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8384
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
8125
8385
  const Ki = signer.addPoint(publicKey);
8126
8386
  return new HDWallet({
8127
8387
  publicKey: Ki,
@@ -8156,12 +8416,12 @@ var HDWallet = class {
8156
8416
  );
8157
8417
  }
8158
8418
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8159
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8419
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8160
8420
  const parentFingerprint = this.parentFingerprint;
8161
- const index = (0, import_math20.toHex)(this.index, 4);
8421
+ const index = (0, import_math21.toHex)(this.index, 4);
8162
8422
  const chainCode = this.chainCode;
8163
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8164
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8423
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8424
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8165
8425
  return base58check(extendedKey);
8166
8426
  }
8167
8427
  /**
@@ -8173,13 +8433,13 @@ var HDWallet = class {
8173
8433
  static fromSeed(seed) {
8174
8434
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8175
8435
  return new HDWallet({
8176
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8177
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8436
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8437
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
8178
8438
  });
8179
8439
  }
8180
8440
  static fromExtendedKey(extendedKey) {
8181
8441
  const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8182
- const bytes = (0, import_utils35.arrayify)(decoded);
8442
+ const bytes = (0, import_utils34.arrayify)(decoded);
8183
8443
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8184
8444
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8185
8445
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8188,9 +8448,9 @@ var HDWallet = class {
8188
8448
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8189
8449
  }
8190
8450
  const depth = bytes[4];
8191
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8192
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8193
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8451
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8452
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8453
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
8194
8454
  const key = bytes.slice(45, 78);
8195
8455
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8196
8456
  throw new import_errors20.FuelError(
@@ -8378,7 +8638,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8378
8638
 
8379
8639
  // src/wallet-manager/wallet-manager.ts
8380
8640
  var import_address9 = require("@fuel-ts/address");
8381
- var import_crypto4 = require("@fuel-ts/crypto");
8641
+ var import_crypto5 = require("@fuel-ts/crypto");
8382
8642
  var import_errors23 = require("@fuel-ts/errors");
8383
8643
  var import_events = require("events");
8384
8644
 
@@ -8706,7 +8966,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8706
8966
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8707
8967
  const data = await this.storage.getItem(this.STORAGE_KEY);
8708
8968
  if (data) {
8709
- const state = await (0, import_crypto4.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8969
+ const state = await (0, import_crypto5.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8710
8970
  __privateSet(this, _vaults, __privateMethod(this, _deserializeVaults, deserializeVaults_fn).call(this, state.vaults));
8711
8971
  }
8712
8972
  }
@@ -8715,7 +8975,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8715
8975
  */
8716
8976
  async saveState() {
8717
8977
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8718
- const encryptedData = await (0, import_crypto4.encrypt)(__privateGet(this, _passphrase), {
8978
+ const encryptedData = await (0, import_crypto5.encrypt)(__privateGet(this, _passphrase), {
8719
8979
  vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
8720
8980
  });
8721
8981
  await this.storage.setItem(this.STORAGE_KEY, JSON.stringify(encryptedData));
@@ -8791,23 +9051,23 @@ var StorageAbstract = class {
8791
9051
  };
8792
9052
 
8793
9053
  // src/predicate/predicate.ts
8794
- var import_abi_coder5 = require("@fuel-ts/abi-coder");
9054
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
8795
9055
  var import_address10 = require("@fuel-ts/address");
8796
9056
  var import_configs13 = require("@fuel-ts/address/configs");
8797
9057
  var import_errors25 = require("@fuel-ts/errors");
8798
- var import_transactions20 = require("@fuel-ts/transactions");
8799
- var import_utils37 = require("@fuel-ts/utils");
9058
+ var import_transactions21 = require("@fuel-ts/transactions");
9059
+ var import_utils36 = require("@fuel-ts/utils");
8800
9060
 
8801
9061
  // src/predicate/utils/getPredicateRoot.ts
8802
9062
  var import_hasher7 = require("@fuel-ts/hasher");
8803
9063
  var import_merkle = require("@fuel-ts/merkle");
8804
- var import_utils36 = require("@fuel-ts/utils");
9064
+ var import_utils35 = require("@fuel-ts/utils");
8805
9065
  var getPredicateRoot = (bytecode) => {
8806
9066
  const chunkSize = 16 * 1024;
8807
- const bytes = (0, import_utils36.arrayify)(bytecode);
8808
- const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
8809
- const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
8810
- const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
9067
+ const bytes = (0, import_utils35.arrayify)(bytecode);
9068
+ const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
9069
+ const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
9070
+ const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
8811
9071
  return predicateRoot;
8812
9072
  };
8813
9073
 
@@ -8855,9 +9115,9 @@ var Predicate = class extends Account {
8855
9115
  const request = transactionRequestify(transactionRequestLike);
8856
9116
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8857
9117
  request.inputs?.forEach((input) => {
8858
- if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
8859
- input.predicate = this.bytes;
8860
- input.predicateData = this.getPredicateData(policies.length);
9118
+ if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
9119
+ input.predicate = (0, import_utils36.hexlify)(this.bytes);
9120
+ input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
8861
9121
  }
8862
9122
  });
8863
9123
  return request;
@@ -8872,8 +9132,7 @@ var Predicate = class extends Account {
8872
9132
  * @returns A promise that resolves to the prepared transaction request.
8873
9133
  */
8874
9134
  async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
8875
- const request = await super.createTransfer(destination, amount, assetId, txParams);
8876
- return this.populateTransactionPredicateData(request);
9135
+ return super.createTransfer(destination, amount, assetId, txParams);
8877
9136
  }
8878
9137
  /**
8879
9138
  * Sends a transaction with the populated predicate data.
@@ -8881,9 +9140,9 @@ var Predicate = class extends Account {
8881
9140
  * @param transactionRequestLike - The transaction request-like object.
8882
9141
  * @returns A promise that resolves to the transaction response.
8883
9142
  */
8884
- sendTransaction(transactionRequestLike, options) {
8885
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8886
- return super.sendTransaction(transactionRequest, options);
9143
+ sendTransaction(transactionRequestLike) {
9144
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9145
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8887
9146
  }
8888
9147
  /**
8889
9148
  * Simulates a transaction with the populated predicate data.
@@ -8892,19 +9151,19 @@ var Predicate = class extends Account {
8892
9151
  * @returns A promise that resolves to the call result.
8893
9152
  */
8894
9153
  simulateTransaction(transactionRequestLike) {
8895
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8896
- return super.simulateTransaction(transactionRequest);
9154
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9155
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8897
9156
  }
8898
9157
  getPredicateData(policiesLength) {
8899
9158
  if (!this.predicateData.length) {
8900
9159
  return new Uint8Array();
8901
9160
  }
8902
9161
  const mainFn = this.interface?.functions.main;
8903
- const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
8904
- const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
9162
+ const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
9163
+ const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
8905
9164
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
8906
9165
  });
8907
- const OFFSET = VM_TX_MEMORY + import_abi_coder5.SCRIPT_FIXED_SIZE + import_abi_coder5.INPUT_COIN_FIXED_SIZE + import_abi_coder5.WORD_SIZE + paddedCode.byteLength + policiesLength * import_abi_coder5.WORD_SIZE;
9166
+ const OFFSET = VM_TX_MEMORY + import_abi_coder7.SCRIPT_FIXED_SIZE + import_abi_coder7.INPUT_COIN_FIXED_SIZE + import_abi_coder7.WORD_SIZE + paddedCode.byteLength + policiesLength * import_abi_coder7.WORD_SIZE;
8908
9167
  return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
8909
9168
  }
8910
9169
  /**
@@ -8916,10 +9175,10 @@ var Predicate = class extends Account {
8916
9175
  * @returns An object containing the new predicate bytes and interface.
8917
9176
  */
8918
9177
  static processPredicateData(bytes, jsonAbi, configurableConstants) {
8919
- let predicateBytes = (0, import_utils37.arrayify)(bytes);
9178
+ let predicateBytes = (0, import_utils36.arrayify)(bytes);
8920
9179
  let abiInterface;
8921
9180
  if (jsonAbi) {
8922
- abiInterface = new import_abi_coder5.Interface(jsonAbi);
9181
+ abiInterface = new import_abi_coder7.Interface(jsonAbi);
8923
9182
  if (abiInterface.functions.main === void 0) {
8924
9183
  throw new import_errors25.FuelError(
8925
9184
  import_errors25.ErrorCode.ABI_MAIN_METHOD_MISSING,
@@ -8939,6 +9198,25 @@ var Predicate = class extends Account {
8939
9198
  predicateInterface: abiInterface
8940
9199
  };
8941
9200
  }
9201
+ /**
9202
+ * Retrieves resources satisfying the spend query for the account.
9203
+ *
9204
+ * @param quantities - IDs of coins to exclude.
9205
+ * @param excludedIds - IDs of resources to be excluded from the query.
9206
+ * @returns A promise that resolves to an array of Resources.
9207
+ */
9208
+ async getResourcesToSpend(quantities, excludedIds) {
9209
+ const resources = await this.provider.getResourcesToSpend(
9210
+ this.address,
9211
+ quantities,
9212
+ excludedIds
9213
+ );
9214
+ return resources.map((resource) => ({
9215
+ ...resource,
9216
+ predicate: (0, import_utils36.hexlify)(this.bytes),
9217
+ paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
9218
+ }));
9219
+ }
8942
9220
  /**
8943
9221
  * Sets the configurable constants for the predicate.
8944
9222
  *
@@ -9688,7 +9966,7 @@ __publicField(Fuel, "defaultConfig", {});
9688
9966
  WalletLocked,
9689
9967
  WalletManager,
9690
9968
  WalletUnlocked,
9691
- addAmountToAsset,
9969
+ addAmountToCoinQuantities,
9692
9970
  addOperation,
9693
9971
  assemblePanicError,
9694
9972
  assembleReceiptByType,
@@ -9697,9 +9975,10 @@ __publicField(Fuel, "defaultConfig", {});
9697
9975
  assets,
9698
9976
  buildBlockExplorerUrl,
9699
9977
  cacheFor,
9978
+ cacheTxInputsFromOwner,
9979
+ calculateGasFee,
9700
9980
  calculateMetadataGasForTxCreate,
9701
9981
  calculateMetadataGasForTxScript,
9702
- calculatePriceWithFactor,
9703
9982
  calculateTransactionFee,
9704
9983
  coinQuantityfy,
9705
9984
  deferPromise,