@fuel-ts/account 0.0.0-rc-2021-20240409111335 → 0.0.0-rc-1976-20240409134753

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

Potentially problematic release.


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

Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +4 -5
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +1 -1
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +1 -1
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +1 -1
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +616 -868
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +610 -848
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +453 -690
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +2 -10
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +328 -894
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +3 -3
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +2 -4
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  26. package/dist/providers/message.d.ts +1 -3
  27. package/dist/providers/message.d.ts.map +1 -1
  28. package/dist/providers/provider.d.ts +34 -45
  29. package/dist/providers/provider.d.ts.map +1 -1
  30. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/input.d.ts +2 -2
  32. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  34. package/dist/providers/transaction-request/transaction-request.d.ts +29 -9
  35. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  36. package/dist/providers/transaction-request/utils.d.ts +0 -3
  37. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  38. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  39. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
  40. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
  42. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  43. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  44. package/dist/providers/utils/gas.d.ts +2 -8
  45. package/dist/providers/utils/gas.d.ts.map +1 -1
  46. package/dist/test-utils/launchNode.d.ts.map +1 -1
  47. package/dist/test-utils.global.js +1117 -1583
  48. package/dist/test-utils.global.js.map +1 -1
  49. package/dist/test-utils.js +607 -824
  50. package/dist/test-utils.js.map +1 -1
  51. package/dist/test-utils.mjs +465 -682
  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
- addAmountToCoinQuantities: () => addAmountToCoinQuantities,
98
+ addAmountToAsset: () => addAmountToAsset,
99
99
  addOperation: () => addOperation,
100
100
  assemblePanicError: () => assemblePanicError,
101
101
  assembleReceiptByType: () => assembleReceiptByType,
@@ -104,10 +104,9 @@ __export(src_exports, {
104
104
  assets: () => assets,
105
105
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
106
106
  cacheFor: () => cacheFor,
107
- cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
108
- calculateGasFee: () => calculateGasFee,
109
107
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
110
108
  calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
109
+ calculatePriceWithFactor: () => calculatePriceWithFactor,
111
110
  calculateTransactionFee: () => calculateTransactionFee,
112
111
  coinQuantityfy: () => coinQuantityfy,
113
112
  deferPromise: () => deferPromise,
@@ -185,38 +184,35 @@ module.exports = __toCommonJS(src_exports);
185
184
 
186
185
  // src/account.ts
187
186
  var import_address4 = require("@fuel-ts/address");
188
- var import_configs12 = require("@fuel-ts/address/configs");
189
187
  var import_errors16 = require("@fuel-ts/errors");
190
188
  var import_interfaces = require("@fuel-ts/interfaces");
191
- var import_math19 = require("@fuel-ts/math");
192
- var import_utils27 = require("@fuel-ts/utils");
193
- var import_ramda4 = require("ramda");
189
+ var import_math18 = require("@fuel-ts/math");
190
+ var import_utils28 = require("@fuel-ts/utils");
194
191
 
195
192
  // src/providers/coin-quantity.ts
196
- var import_configs = require("@fuel-ts/address/configs");
197
193
  var import_math = require("@fuel-ts/math");
198
194
  var import_utils = require("@fuel-ts/utils");
199
195
  var coinQuantityfy = (coinQuantityLike) => {
200
196
  let assetId;
201
197
  let amount;
202
- let max;
198
+ let max2;
203
199
  if (Array.isArray(coinQuantityLike)) {
204
200
  amount = coinQuantityLike[0];
205
- assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
206
- max = coinQuantityLike[2] ?? void 0;
201
+ assetId = coinQuantityLike[1];
202
+ max2 = coinQuantityLike[2];
207
203
  } else {
208
204
  amount = coinQuantityLike.amount;
209
- assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
210
- max = coinQuantityLike.max ?? void 0;
205
+ assetId = coinQuantityLike.assetId;
206
+ max2 = coinQuantityLike.max ?? void 0;
211
207
  }
212
208
  const bnAmount = (0, import_math.bn)(amount);
213
209
  return {
214
210
  assetId: (0, import_utils.hexlify)(assetId),
215
211
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
216
- max: max ? (0, import_math.bn)(max) : void 0
212
+ max: max2 ? (0, import_math.bn)(max2) : void 0
217
213
  };
218
214
  };
219
- var addAmountToCoinQuantities = (params) => {
215
+ var addAmountToAsset = (params) => {
220
216
  const { amount, assetId } = params;
221
217
  const coinQuantities = [...params.coinQuantities];
222
218
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -231,12 +227,12 @@ var addAmountToCoinQuantities = (params) => {
231
227
  // src/providers/provider.ts
232
228
  var import_address3 = require("@fuel-ts/address");
233
229
  var import_errors14 = require("@fuel-ts/errors");
234
- var import_math16 = require("@fuel-ts/math");
235
- var import_transactions19 = require("@fuel-ts/transactions");
236
- var import_utils22 = require("@fuel-ts/utils");
230
+ var import_math15 = require("@fuel-ts/math");
231
+ var import_transactions18 = require("@fuel-ts/transactions");
232
+ var import_utils23 = require("@fuel-ts/utils");
237
233
  var import_versions = require("@fuel-ts/versions");
238
- var import_utils23 = require("@noble/curves/abstract/utils");
239
- var import_ethers2 = require("ethers");
234
+ var import_utils24 = require("@noble/curves/abstract/utils");
235
+ var import_ethers = require("ethers");
240
236
  var import_graphql_request = require("graphql-request");
241
237
  var import_ramda3 = require("ramda");
242
238
 
@@ -244,10 +240,14 @@ var import_ramda3 = require("ramda");
244
240
  var import_graphql_tag = __toESM(require("graphql-tag"));
245
241
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
246
242
  fragment receiptFragment on Receipt {
247
- id
243
+ contract {
244
+ id
245
+ }
248
246
  pc
249
247
  is
250
- to
248
+ to {
249
+ id
250
+ }
251
251
  toAddress
252
252
  amount
253
253
  assetId
@@ -285,16 +285,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
285
285
  id
286
286
  }
287
287
  time
288
- receipts {
289
- ...receiptFragment
290
- }
291
288
  programState {
292
289
  returnType
293
290
  data
294
291
  }
295
- receipts {
296
- ...receiptFragment
297
- }
298
292
  }
299
293
  ... on FailureStatus {
300
294
  block {
@@ -302,24 +296,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
302
296
  }
303
297
  time
304
298
  reason
305
- receipts {
306
- ...receiptFragment
307
- }
308
299
  }
309
300
  ... on SqueezedOutStatus {
310
301
  reason
311
302
  }
312
303
  }
313
- ${ReceiptFragmentFragmentDoc}`;
304
+ `;
314
305
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
315
306
  fragment transactionFragment on Transaction {
316
307
  id
317
308
  rawPayload
309
+ gasPrice
310
+ receipts {
311
+ ...receiptFragment
312
+ }
318
313
  status {
319
314
  ...transactionStatusFragment
320
315
  }
321
316
  }
322
- ${TransactionStatusFragmentFragmentDoc}`;
317
+ ${ReceiptFragmentFragmentDoc}
318
+ ${TransactionStatusFragmentFragmentDoc}`;
323
319
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
324
320
  fragment inputEstimatePredicatesFragment on Input {
325
321
  ... on InputCoin {
@@ -337,46 +333,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
337
333
  }
338
334
  }
339
335
  ${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}`;
380
336
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
381
337
  fragment coinFragment on Coin {
382
338
  __typename
@@ -384,6 +340,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
384
340
  owner
385
341
  amount
386
342
  assetId
343
+ maturity
387
344
  blockCreated
388
345
  txCreatedIdx
389
346
  }
@@ -428,6 +385,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
428
385
  prevRoot
429
386
  time
430
387
  applicationHash
388
+ messageReceiptRoot
431
389
  messageReceiptCount
432
390
  }
433
391
  commitBlockHeader {
@@ -439,6 +397,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
439
397
  prevRoot
440
398
  time
441
399
  applicationHash
400
+ messageReceiptRoot
442
401
  messageReceiptCount
443
402
  }
444
403
  sender
@@ -458,8 +417,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
458
417
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
459
418
  fragment blockFragment on Block {
460
419
  id
461
- height
462
420
  header {
421
+ height
463
422
  time
464
423
  }
465
424
  transactions {
@@ -517,11 +476,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
517
476
  `;
518
477
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
519
478
  fragment GasCostsFragment on GasCosts {
520
- version {
521
- ... on Version {
522
- value
523
- }
524
- }
525
479
  add
526
480
  addi
527
481
  aloc
@@ -534,6 +488,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
534
488
  cb
535
489
  cfei
536
490
  cfsi
491
+ croo
537
492
  div
538
493
  divi
539
494
  ecr1
@@ -616,9 +571,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
616
571
  ccp {
617
572
  ...DependentCostFragment
618
573
  }
619
- croo {
620
- ...DependentCostFragment
621
- }
622
574
  csiz {
623
575
  ...DependentCostFragment
624
576
  }
@@ -678,11 +630,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
678
630
  ${DependentCostFragmentFragmentDoc}`;
679
631
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
680
632
  fragment consensusParametersFragment on ConsensusParameters {
681
- version {
682
- ... on Version {
683
- value
684
- }
685
- }
686
633
  txParams {
687
634
  ...TxParametersFragment
688
635
  }
@@ -742,9 +689,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
742
689
  fragment nodeInfoFragment on NodeInfo {
743
690
  utxoValidation
744
691
  vmBacktrace
692
+ minGasPrice
745
693
  maxTx
746
694
  maxDepth
747
695
  nodeVersion
696
+ peers {
697
+ id
698
+ addresses
699
+ clientVersion
700
+ blockHeight
701
+ lastHeartbeatMs
702
+ appScore
703
+ }
748
704
  }
749
705
  `;
750
706
  var GetVersionDocument = import_graphql_tag.default`
@@ -779,9 +735,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
779
735
  query getTransactionWithReceipts($transactionId: TransactionId!) {
780
736
  transaction(id: $transactionId) {
781
737
  ...transactionFragment
738
+ receipts {
739
+ ...receiptFragment
740
+ }
782
741
  }
783
742
  }
784
- ${TransactionFragmentFragmentDoc}`;
743
+ ${TransactionFragmentFragmentDoc}
744
+ ${ReceiptFragmentFragmentDoc}`;
785
745
  var GetTransactionsDocument = import_graphql_tag.default`
786
746
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
787
747
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -909,20 +869,6 @@ var GetBalanceDocument = import_graphql_tag.default`
909
869
  }
910
870
  }
911
871
  ${BalanceFragmentFragmentDoc}`;
912
- var GetLatestGasPriceDocument = import_graphql_tag.default`
913
- query getLatestGasPrice {
914
- latestGasPrice {
915
- gasPrice
916
- }
917
- }
918
- `;
919
- var EstimateGasPriceDocument = import_graphql_tag.default`
920
- query estimateGasPrice($blockHorizon: U32!) {
921
- estimateGasPrice(blockHorizon: $blockHorizon) {
922
- gasPrice
923
- }
924
- }
925
- `;
926
872
  var GetBalancesDocument = import_graphql_tag.default`
927
873
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
928
874
  balances(
@@ -977,12 +923,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
977
923
  }
978
924
  `;
979
925
  var DryRunDocument = import_graphql_tag.default`
980
- mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
981
- dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
982
- ...dryRunTransactionExecutionStatusFragment
926
+ mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
927
+ dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
928
+ ...receiptFragment
983
929
  }
984
930
  }
985
- ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
931
+ ${ReceiptFragmentFragmentDoc}`;
986
932
  var SubmitDocument = import_graphql_tag.default`
987
933
  mutation submit($encodedTransaction: HexString!) {
988
934
  submit(tx: $encodedTransaction) {
@@ -1065,12 +1011,6 @@ function getSdk(requester) {
1065
1011
  getBalance(variables, options) {
1066
1012
  return requester(GetBalanceDocument, variables, options);
1067
1013
  },
1068
- getLatestGasPrice(variables, options) {
1069
- return requester(GetLatestGasPriceDocument, variables, options);
1070
- },
1071
- estimateGasPrice(variables, options) {
1072
- return requester(EstimateGasPriceDocument, variables, options);
1073
- },
1074
1014
  getBalances(variables, options) {
1075
1015
  return requester(GetBalancesDocument, variables, options);
1076
1016
  },
@@ -1144,9 +1084,7 @@ var _FuelGraphqlSubscriber = class {
1144
1084
  } catch (e) {
1145
1085
  throw new import_errors.FuelError(
1146
1086
  import_errors.ErrorCode.STREAM_PARSING_ERROR,
1147
- `Error while parsing stream data response: ${text}
1148
-
1149
- Thrown error: ${e}`
1087
+ `Error while parsing stream data response: ${text}`
1150
1088
  );
1151
1089
  }
1152
1090
  if (Array.isArray(errors)) {
@@ -1233,7 +1171,7 @@ var MemoryCache = class {
1233
1171
  };
1234
1172
 
1235
1173
  // src/providers/transaction-request/input.ts
1236
- var import_configs2 = require("@fuel-ts/address/configs");
1174
+ var import_configs = require("@fuel-ts/address/configs");
1237
1175
  var import_errors3 = require("@fuel-ts/errors");
1238
1176
  var import_math2 = require("@fuel-ts/math");
1239
1177
  var import_transactions = require("@fuel-ts/transactions");
@@ -1247,7 +1185,7 @@ var inputify = (value) => {
1247
1185
  return {
1248
1186
  type: import_transactions.InputType.Coin,
1249
1187
  txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
1250
- outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 34)),
1188
+ outputIndex: (0, import_utils3.arrayify)(value.id)[32],
1251
1189
  owner: (0, import_utils3.hexlify)(value.owner),
1252
1190
  amount: (0, import_math2.bn)(value.amount),
1253
1191
  assetId: (0, import_utils3.hexlify)(value.assetId),
@@ -1256,9 +1194,10 @@ var inputify = (value) => {
1256
1194
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1257
1195
  },
1258
1196
  witnessIndex: value.witnessIndex,
1197
+ maturity: value.maturity ?? 0,
1259
1198
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1260
- predicateLength: (0, import_math2.bn)(predicate.length),
1261
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1199
+ predicateLength: predicate.length,
1200
+ predicateDataLength: predicateData.length,
1262
1201
  predicate: (0, import_utils3.hexlify)(predicate),
1263
1202
  predicateData: (0, import_utils3.hexlify)(predicateData)
1264
1203
  };
@@ -1266,10 +1205,10 @@ var inputify = (value) => {
1266
1205
  case import_transactions.InputType.Contract: {
1267
1206
  return {
1268
1207
  type: import_transactions.InputType.Contract,
1269
- txID: import_configs2.ZeroBytes32,
1208
+ txID: import_configs.ZeroBytes32,
1270
1209
  outputIndex: 0,
1271
- balanceRoot: import_configs2.ZeroBytes32,
1272
- stateRoot: import_configs2.ZeroBytes32,
1210
+ balanceRoot: import_configs.ZeroBytes32,
1211
+ stateRoot: import_configs.ZeroBytes32,
1273
1212
  txPointer: {
1274
1213
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1275
1214
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1289,8 +1228,8 @@ var inputify = (value) => {
1289
1228
  nonce: (0, import_utils3.hexlify)(value.nonce),
1290
1229
  witnessIndex: value.witnessIndex,
1291
1230
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1292
- predicateLength: (0, import_math2.bn)(predicate.length),
1293
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1231
+ predicateLength: predicate.length,
1232
+ predicateDataLength: predicateData.length,
1294
1233
  predicate: (0, import_utils3.hexlify)(predicate),
1295
1234
  predicateData: (0, import_utils3.hexlify)(predicateData),
1296
1235
  data: (0, import_utils3.hexlify)(data),
@@ -1307,7 +1246,7 @@ var inputify = (value) => {
1307
1246
  };
1308
1247
 
1309
1248
  // src/providers/transaction-request/output.ts
1310
- var import_configs3 = require("@fuel-ts/address/configs");
1249
+ var import_configs2 = require("@fuel-ts/address/configs");
1311
1250
  var import_errors4 = require("@fuel-ts/errors");
1312
1251
  var import_math3 = require("@fuel-ts/math");
1313
1252
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1327,8 +1266,8 @@ var outputify = (value) => {
1327
1266
  return {
1328
1267
  type: import_transactions2.OutputType.Contract,
1329
1268
  inputIndex: value.inputIndex,
1330
- balanceRoot: import_configs3.ZeroBytes32,
1331
- stateRoot: import_configs3.ZeroBytes32
1269
+ balanceRoot: import_configs2.ZeroBytes32,
1270
+ stateRoot: import_configs2.ZeroBytes32
1332
1271
  };
1333
1272
  }
1334
1273
  case import_transactions2.OutputType.Change: {
@@ -1342,9 +1281,9 @@ var outputify = (value) => {
1342
1281
  case import_transactions2.OutputType.Variable: {
1343
1282
  return {
1344
1283
  type: import_transactions2.OutputType.Variable,
1345
- to: import_configs3.ZeroBytes32,
1284
+ to: import_configs2.ZeroBytes32,
1346
1285
  amount: (0, import_math3.bn)(0),
1347
- assetId: import_configs3.ZeroBytes32
1286
+ assetId: import_configs2.ZeroBytes32
1348
1287
  };
1349
1288
  }
1350
1289
  case import_transactions2.OutputType.ContractCreated: {
@@ -1365,11 +1304,10 @@ var outputify = (value) => {
1365
1304
 
1366
1305
  // src/providers/transaction-request/transaction-request.ts
1367
1306
  var import_address = require("@fuel-ts/address");
1368
- var import_configs7 = require("@fuel-ts/address/configs");
1307
+ var import_configs6 = require("@fuel-ts/address/configs");
1369
1308
  var import_math7 = require("@fuel-ts/math");
1370
1309
  var import_transactions6 = require("@fuel-ts/transactions");
1371
1310
  var import_utils9 = require("@fuel-ts/utils");
1372
- var import_ethers = require("ethers");
1373
1311
 
1374
1312
  // src/providers/resource.ts
1375
1313
  var isRawCoin = (resource) => "utxoId" in resource;
@@ -1378,13 +1316,13 @@ var isCoin = (resource) => "id" in resource;
1378
1316
  var isMessage = (resource) => "recipient" in resource;
1379
1317
 
1380
1318
  // src/providers/utils/receipts.ts
1381
- var import_configs4 = require("@fuel-ts/address/configs");
1319
+ var import_configs3 = require("@fuel-ts/address/configs");
1382
1320
  var import_errors5 = require("@fuel-ts/errors");
1383
1321
  var import_math4 = require("@fuel-ts/math");
1384
1322
  var import_transactions3 = require("@fuel-ts/transactions");
1385
- var import_configs5 = require("@fuel-ts/transactions/configs");
1323
+ var import_configs4 = require("@fuel-ts/transactions/configs");
1386
1324
  var import_utils5 = require("@fuel-ts/utils");
1387
- var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1325
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1388
1326
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1389
1327
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1390
1328
  (memo, receipt) => {
@@ -1401,15 +1339,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1401
1339
  missingOutputContractIds: []
1402
1340
  }
1403
1341
  );
1404
- var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1342
+ var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1405
1343
  function assembleReceiptByType(receipt) {
1406
1344
  const { receiptType } = receipt;
1407
1345
  switch (receiptType) {
1408
1346
  case "CALL" /* Call */: {
1409
1347
  const callReceipt = {
1410
1348
  type: import_transactions3.ReceiptType.Call,
1411
- from: hexOrZero(receipt.id || receipt.contractId),
1412
- to: hexOrZero(receipt?.to),
1349
+ from: hexOrZero(receipt.contract?.id),
1350
+ to: hexOrZero(receipt?.to?.id),
1413
1351
  amount: (0, import_math4.bn)(receipt.amount),
1414
1352
  assetId: hexOrZero(receipt.assetId),
1415
1353
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1423,7 +1361,7 @@ function assembleReceiptByType(receipt) {
1423
1361
  case "RETURN" /* Return */: {
1424
1362
  const returnReceipt = {
1425
1363
  type: import_transactions3.ReceiptType.Return,
1426
- id: hexOrZero(receipt.id || receipt.contractId),
1364
+ id: hexOrZero(receipt.contract?.id),
1427
1365
  val: (0, import_math4.bn)(receipt.val),
1428
1366
  pc: (0, import_math4.bn)(receipt.pc),
1429
1367
  is: (0, import_math4.bn)(receipt.is)
@@ -1433,7 +1371,7 @@ function assembleReceiptByType(receipt) {
1433
1371
  case "RETURN_DATA" /* ReturnData */: {
1434
1372
  const returnDataReceipt = {
1435
1373
  type: import_transactions3.ReceiptType.ReturnData,
1436
- id: hexOrZero(receipt.id || receipt.contractId),
1374
+ id: hexOrZero(receipt.contract?.id),
1437
1375
  ptr: (0, import_math4.bn)(receipt.ptr),
1438
1376
  len: (0, import_math4.bn)(receipt.len),
1439
1377
  digest: hexOrZero(receipt.digest),
@@ -1445,7 +1383,7 @@ function assembleReceiptByType(receipt) {
1445
1383
  case "PANIC" /* Panic */: {
1446
1384
  const panicReceipt = {
1447
1385
  type: import_transactions3.ReceiptType.Panic,
1448
- id: hexOrZero(receipt.id),
1386
+ id: hexOrZero(receipt.contract?.id),
1449
1387
  reason: (0, import_math4.bn)(receipt.reason),
1450
1388
  pc: (0, import_math4.bn)(receipt.pc),
1451
1389
  is: (0, import_math4.bn)(receipt.is),
@@ -1456,7 +1394,7 @@ function assembleReceiptByType(receipt) {
1456
1394
  case "REVERT" /* Revert */: {
1457
1395
  const revertReceipt = {
1458
1396
  type: import_transactions3.ReceiptType.Revert,
1459
- id: hexOrZero(receipt.id || receipt.contractId),
1397
+ id: hexOrZero(receipt.contract?.id),
1460
1398
  val: (0, import_math4.bn)(receipt.ra),
1461
1399
  pc: (0, import_math4.bn)(receipt.pc),
1462
1400
  is: (0, import_math4.bn)(receipt.is)
@@ -1466,7 +1404,7 @@ function assembleReceiptByType(receipt) {
1466
1404
  case "LOG" /* Log */: {
1467
1405
  const logReceipt = {
1468
1406
  type: import_transactions3.ReceiptType.Log,
1469
- id: hexOrZero(receipt.id || receipt.contractId),
1407
+ id: hexOrZero(receipt.contract?.id),
1470
1408
  val0: (0, import_math4.bn)(receipt.ra),
1471
1409
  val1: (0, import_math4.bn)(receipt.rb),
1472
1410
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1479,7 +1417,7 @@ function assembleReceiptByType(receipt) {
1479
1417
  case "LOG_DATA" /* LogData */: {
1480
1418
  const logDataReceipt = {
1481
1419
  type: import_transactions3.ReceiptType.LogData,
1482
- id: hexOrZero(receipt.id || receipt.contractId),
1420
+ id: hexOrZero(receipt.contract?.id),
1483
1421
  val0: (0, import_math4.bn)(receipt.ra),
1484
1422
  val1: (0, import_math4.bn)(receipt.rb),
1485
1423
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1493,8 +1431,8 @@ function assembleReceiptByType(receipt) {
1493
1431
  case "TRANSFER" /* Transfer */: {
1494
1432
  const transferReceipt = {
1495
1433
  type: import_transactions3.ReceiptType.Transfer,
1496
- from: hexOrZero(receipt.id || receipt.contractId),
1497
- to: hexOrZero(receipt.toAddress || receipt?.to),
1434
+ from: hexOrZero(receipt.contract?.id),
1435
+ to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1498
1436
  amount: (0, import_math4.bn)(receipt.amount),
1499
1437
  assetId: hexOrZero(receipt.assetId),
1500
1438
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1505,8 +1443,8 @@ function assembleReceiptByType(receipt) {
1505
1443
  case "TRANSFER_OUT" /* TransferOut */: {
1506
1444
  const transferOutReceipt = {
1507
1445
  type: import_transactions3.ReceiptType.TransferOut,
1508
- from: hexOrZero(receipt.id || receipt.contractId),
1509
- to: hexOrZero(receipt.toAddress || receipt.to),
1446
+ from: hexOrZero(receipt.contract?.id),
1447
+ to: hexOrZero(receipt.toAddress || receipt.to?.id),
1510
1448
  amount: (0, import_math4.bn)(receipt.amount),
1511
1449
  assetId: hexOrZero(receipt.assetId),
1512
1450
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1549,7 +1487,7 @@ function assembleReceiptByType(receipt) {
1549
1487
  return receiptMessageOut;
1550
1488
  }
1551
1489
  case "MINT" /* Mint */: {
1552
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1490
+ const contractId = hexOrZero(receipt.contract?.id);
1553
1491
  const subId = hexOrZero(receipt.subId);
1554
1492
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1555
1493
  const mintReceipt = {
@@ -1564,7 +1502,7 @@ function assembleReceiptByType(receipt) {
1564
1502
  return mintReceipt;
1565
1503
  }
1566
1504
  case "BURN" /* Burn */: {
1567
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1505
+ const contractId = hexOrZero(receipt.contract?.id);
1568
1506
  const subId = hexOrZero(receipt.subId);
1569
1507
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1570
1508
  const burnReceipt = {
@@ -1649,6 +1587,7 @@ var buildBlockExplorerUrl = (options = {}) => {
1649
1587
  var import_math5 = require("@fuel-ts/math");
1650
1588
  var import_transactions4 = require("@fuel-ts/transactions");
1651
1589
  var import_utils6 = require("@fuel-ts/utils");
1590
+ var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1652
1591
  var getGasUsedFromReceipts = (receipts) => {
1653
1592
  const scriptResult = receipts.filter(
1654
1593
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1669,28 +1608,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1669
1608
  }
1670
1609
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1671
1610
  const witnessCache = [];
1672
- const chargeableInputs = inputs.filter((input) => {
1673
- const isCoinOrMessage = "owner" in input || "sender" in input;
1674
- if (isCoinOrMessage) {
1675
- if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1676
- return true;
1677
- }
1678
- if (!witnessCache.includes(input.witnessIndex)) {
1679
- witnessCache.push(input.witnessIndex);
1680
- return true;
1681
- }
1682
- }
1683
- return false;
1684
- });
1685
- const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1686
- const totalGas = chargeableInputs.reduce((total, input) => {
1611
+ const totalGas = inputs.reduce((total, input) => {
1687
1612
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1688
1613
  return total.add(
1689
- vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1614
+ resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1690
1615
  );
1691
1616
  }
1692
- return total.add(gasCosts.ecr1);
1693
- }, (0, import_math5.bn)(0));
1617
+ if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1618
+ witnessCache.push(input.witnessIndex);
1619
+ return total.add(gasCosts.ecr1);
1620
+ }
1621
+ return total;
1622
+ }, (0, import_math5.bn)());
1694
1623
  return totalGas;
1695
1624
  }
1696
1625
  function getMinGas(params) {
@@ -1702,20 +1631,12 @@ function getMinGas(params) {
1702
1631
  return minGas;
1703
1632
  }
1704
1633
  function getMaxGas(params) {
1705
- const {
1706
- gasPerByte,
1707
- witnessesLength,
1708
- witnessLimit,
1709
- minGas,
1710
- gasLimit = (0, import_math5.bn)(0),
1711
- maxGasPerTx
1712
- } = params;
1634
+ const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1713
1635
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1714
1636
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1715
1637
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1716
1638
  }
1717
- const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1718
- return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1639
+ return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1719
1640
  }
1720
1641
  function calculateMetadataGasForTxCreate({
1721
1642
  gasCosts,
@@ -1737,10 +1658,6 @@ function calculateMetadataGasForTxScript({
1737
1658
  }) {
1738
1659
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1739
1660
  }
1740
- var calculateGasFee = (params) => {
1741
- const { gas, gasPrice, priceFactor, tip } = params;
1742
- return gas.mul(gasPrice).div(priceFactor).add(tip);
1743
- };
1744
1661
 
1745
1662
  // src/providers/utils/json.ts
1746
1663
  var import_utils7 = require("@fuel-ts/utils");
@@ -1786,16 +1703,16 @@ function sleep(time) {
1786
1703
  var import_errors7 = require("@fuel-ts/errors");
1787
1704
  var import_math6 = require("@fuel-ts/math");
1788
1705
  var import_transactions5 = require("@fuel-ts/transactions");
1789
- var import_configs6 = require("@fuel-ts/transactions/configs");
1706
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1790
1707
  var assemblePanicError = (status) => {
1791
1708
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1792
1709
  const reason = status.reason;
1793
- if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1710
+ if (import_configs5.PANIC_REASONS.includes(status.reason)) {
1794
1711
  errorMessage = `${errorMessage}
1795
1712
 
1796
1713
  You can read more about this error at:
1797
1714
 
1798
- ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1715
+ ${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
1799
1716
  }
1800
1717
  return { errorMessage, reason };
1801
1718
  };
@@ -1807,28 +1724,28 @@ var assembleRevertError = (receipts, logs) => {
1807
1724
  if (revertReceipt) {
1808
1725
  const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1809
1726
  switch (reasonHex) {
1810
- case import_configs6.FAILED_REQUIRE_SIGNAL: {
1727
+ case import_configs5.FAILED_REQUIRE_SIGNAL: {
1811
1728
  reason = "require";
1812
1729
  errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1813
1730
  break;
1814
1731
  }
1815
- case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1732
+ case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
1816
1733
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1817
1734
  reason = "assert_eq";
1818
1735
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1819
1736
  break;
1820
1737
  }
1821
- case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1738
+ case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
1822
1739
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1823
1740
  reason = "assert_ne";
1824
1741
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1825
1742
  break;
1826
1743
  }
1827
- case import_configs6.FAILED_ASSERT_SIGNAL:
1744
+ case import_configs5.FAILED_ASSERT_SIGNAL:
1828
1745
  reason = "assert";
1829
1746
  errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1830
1747
  break;
1831
- case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1748
+ case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1832
1749
  reason = "MissingOutputChange";
1833
1750
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1834
1751
  break;
@@ -1889,7 +1806,7 @@ var witnessify = (value) => {
1889
1806
  // src/providers/transaction-request/transaction-request.ts
1890
1807
  var BaseTransactionRequest = class {
1891
1808
  /** Gas price for transaction */
1892
- tip;
1809
+ gasPrice;
1893
1810
  /** Block until which tx cannot be included */
1894
1811
  maturity;
1895
1812
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1902,34 +1819,38 @@ var BaseTransactionRequest = class {
1902
1819
  outputs = [];
1903
1820
  /** List of witnesses */
1904
1821
  witnesses = [];
1822
+ /** Base asset ID - should be fetched from the chain */
1823
+ baseAssetId = import_configs6.ZeroBytes32;
1905
1824
  /**
1906
1825
  * Constructor for initializing a base transaction request.
1907
1826
  *
1908
1827
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1909
1828
  */
1910
1829
  constructor({
1911
- tip,
1830
+ gasPrice,
1912
1831
  maturity,
1913
1832
  maxFee,
1914
1833
  witnessLimit,
1915
1834
  inputs,
1916
1835
  outputs,
1917
- witnesses
1836
+ witnesses,
1837
+ baseAssetId
1918
1838
  } = {}) {
1919
- this.tip = (0, import_math7.bn)(tip);
1839
+ this.gasPrice = (0, import_math7.bn)(gasPrice);
1920
1840
  this.maturity = maturity ?? 0;
1921
1841
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1922
1842
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
1923
1843
  this.inputs = inputs ?? [];
1924
1844
  this.outputs = outputs ?? [];
1925
1845
  this.witnesses = witnesses ?? [];
1846
+ this.baseAssetId = baseAssetId ?? import_configs6.ZeroBytes32;
1926
1847
  }
1927
1848
  static getPolicyMeta(req) {
1928
1849
  let policyTypes = 0;
1929
1850
  const policies = [];
1930
- if (req.tip) {
1931
- policyTypes += import_transactions6.PolicyType.Tip;
1932
- policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1851
+ if (req.gasPrice) {
1852
+ policyTypes += import_transactions6.PolicyType.GasPrice;
1853
+ policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1933
1854
  }
1934
1855
  if (req.witnessLimit) {
1935
1856
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -2015,7 +1936,7 @@ var BaseTransactionRequest = class {
2015
1936
  * @returns The index of the created witness.
2016
1937
  */
2017
1938
  addEmptyWitness() {
2018
- this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
1939
+ this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
2019
1940
  return this.witnesses.length - 1;
2020
1941
  }
2021
1942
  /**
@@ -2116,10 +2037,10 @@ var BaseTransactionRequest = class {
2116
2037
  * @param predicate - Predicate bytes.
2117
2038
  * @param predicateData - Predicate data bytes.
2118
2039
  */
2119
- addCoinInput(coin) {
2040
+ addCoinInput(coin, predicate) {
2120
2041
  const { assetId, owner, amount } = coin;
2121
2042
  let witnessIndex;
2122
- if (coin.predicate) {
2043
+ if (predicate) {
2123
2044
  witnessIndex = 0;
2124
2045
  } else {
2125
2046
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -2134,7 +2055,9 @@ var BaseTransactionRequest = class {
2134
2055
  amount,
2135
2056
  assetId,
2136
2057
  txPointer: "0x00000000000000000000000000000000",
2137
- witnessIndex
2058
+ witnessIndex,
2059
+ predicate: predicate?.bytes,
2060
+ predicateData: predicate?.predicateDataBytes
2138
2061
  };
2139
2062
  this.pushInput(input);
2140
2063
  this.addChangeOutput(owner, assetId);
@@ -2145,13 +2068,11 @@ var BaseTransactionRequest = class {
2145
2068
  *
2146
2069
  * @param message - Message resource.
2147
2070
  * @param predicate - Predicate bytes.
2148
- * @param predicateData - Predicate data bytes.
2149
2071
  */
2150
- addMessageInput(message) {
2072
+ addMessageInput(message, predicate) {
2151
2073
  const { recipient, sender, amount } = message;
2152
- const assetId = import_configs7.BaseAssetId;
2153
2074
  let witnessIndex;
2154
- if (message.predicate) {
2075
+ if (predicate) {
2155
2076
  witnessIndex = 0;
2156
2077
  } else {
2157
2078
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -2165,10 +2086,12 @@ var BaseTransactionRequest = class {
2165
2086
  sender: sender.toB256(),
2166
2087
  recipient: recipient.toB256(),
2167
2088
  amount,
2168
- witnessIndex
2089
+ witnessIndex,
2090
+ predicate: predicate?.bytes,
2091
+ predicateData: predicate?.predicateDataBytes
2169
2092
  };
2170
2093
  this.pushInput(input);
2171
- this.addChangeOutput(recipient, assetId);
2094
+ this.addChangeOutput(recipient, this.baseAssetId);
2172
2095
  }
2173
2096
  /**
2174
2097
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -2196,6 +2119,32 @@ var BaseTransactionRequest = class {
2196
2119
  resources.forEach((resource) => this.addResource(resource));
2197
2120
  return this;
2198
2121
  }
2122
+ /**
2123
+ * Adds multiple resources to the transaction by adding coin/message inputs and change
2124
+ * outputs from the related assetIds.
2125
+ *
2126
+ * @param resources - The resources to add.
2127
+ * @returns This transaction.
2128
+ */
2129
+ addPredicateResource(resource, predicate) {
2130
+ if (isCoin(resource)) {
2131
+ this.addCoinInput(resource, predicate);
2132
+ } else {
2133
+ this.addMessageInput(resource, predicate);
2134
+ }
2135
+ return this;
2136
+ }
2137
+ /**
2138
+ * Adds multiple predicate coin/message inputs to the transaction and change outputs
2139
+ * from the related assetIds.
2140
+ *
2141
+ * @param resources - The resources to add.
2142
+ * @returns This transaction.
2143
+ */
2144
+ addPredicateResources(resources, predicate) {
2145
+ resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2146
+ return this;
2147
+ }
2199
2148
  /**
2200
2149
  * Adds a coin output to the transaction.
2201
2150
  *
@@ -2203,12 +2152,12 @@ var BaseTransactionRequest = class {
2203
2152
  * @param amount - Amount of coin.
2204
2153
  * @param assetId - Asset ID of coin.
2205
2154
  */
2206
- addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2155
+ addCoinOutput(to, amount, assetId) {
2207
2156
  this.pushOutput({
2208
2157
  type: import_transactions6.OutputType.Coin,
2209
2158
  to: (0, import_address.addressify)(to).toB256(),
2210
2159
  amount,
2211
- assetId
2160
+ assetId: assetId ?? this.baseAssetId
2212
2161
  });
2213
2162
  return this;
2214
2163
  }
@@ -2235,7 +2184,7 @@ var BaseTransactionRequest = class {
2235
2184
  * @param to - Address of the owner.
2236
2185
  * @param assetId - Asset ID of coin.
2237
2186
  */
2238
- addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2187
+ addChangeOutput(to, assetId) {
2239
2188
  const changeOutput = this.getChangeOutputs().find(
2240
2189
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2241
2190
  );
@@ -2243,7 +2192,7 @@ var BaseTransactionRequest = class {
2243
2192
  this.pushOutput({
2244
2193
  type: import_transactions6.OutputType.Change,
2245
2194
  to: (0, import_address.addressify)(to).toB256(),
2246
- assetId
2195
+ assetId: assetId ?? this.baseAssetId
2247
2196
  });
2248
2197
  }
2249
2198
  }
@@ -2275,7 +2224,7 @@ var BaseTransactionRequest = class {
2275
2224
  }
2276
2225
  calculateMaxGas(chainInfo, minGas) {
2277
2226
  const { consensusParameters } = chainInfo;
2278
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2227
+ const { gasPerByte } = consensusParameters;
2279
2228
  const witnessesLength = this.toTransaction().witnesses.reduce(
2280
2229
  (acc, wit) => acc + wit.dataLength,
2281
2230
  0
@@ -2284,8 +2233,7 @@ var BaseTransactionRequest = class {
2284
2233
  gasPerByte,
2285
2234
  minGas,
2286
2235
  witnessesLength,
2287
- witnessLimit: this.witnessLimit,
2288
- maxGasPerTx
2236
+ witnessLimit: this.witnessLimit
2289
2237
  });
2290
2238
  }
2291
2239
  /**
@@ -2295,6 +2243,12 @@ var BaseTransactionRequest = class {
2295
2243
  * @param quantities - CoinQuantity Array.
2296
2244
  */
2297
2245
  fundWithFakeUtxos(quantities, resourcesOwner) {
2246
+ let idCounter = 0;
2247
+ const generateId = () => {
2248
+ const counterString = String(idCounter++);
2249
+ const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2250
+ return id;
2251
+ };
2298
2252
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2299
2253
  if ("assetId" in input) {
2300
2254
  return input.assetId === assetId;
@@ -2303,27 +2257,24 @@ var BaseTransactionRequest = class {
2303
2257
  });
2304
2258
  const updateAssetInput = (assetId, quantity) => {
2305
2259
  const assetInput = findAssetInput(assetId);
2306
- let usedQuantity = quantity;
2307
- if (assetId === import_configs7.BaseAssetId) {
2308
- usedQuantity = (0, import_math7.bn)("1000000000000000000");
2309
- }
2310
2260
  if (assetInput && "assetId" in assetInput) {
2311
- assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34));
2312
- assetInput.amount = usedQuantity;
2261
+ assetInput.id = generateId();
2262
+ assetInput.amount = quantity;
2313
2263
  } else {
2314
2264
  this.addResources([
2315
2265
  {
2316
- id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34)),
2317
- amount: usedQuantity,
2266
+ id: generateId(),
2267
+ amount: quantity,
2318
2268
  assetId,
2319
2269
  owner: resourcesOwner || import_address.Address.fromRandom(),
2270
+ maturity: 0,
2320
2271
  blockCreated: (0, import_math7.bn)(1),
2321
2272
  txCreatedIdx: (0, import_math7.bn)(1)
2322
2273
  }
2323
2274
  ]);
2324
2275
  }
2325
2276
  };
2326
- updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2277
+ updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
2327
2278
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2328
2279
  }
2329
2280
  /**
@@ -2348,7 +2299,7 @@ var BaseTransactionRequest = class {
2348
2299
  toJSON() {
2349
2300
  return normalizeJSON(this);
2350
2301
  }
2351
- updatePredicateGasUsed(inputs) {
2302
+ updatePredicateInputs(inputs) {
2352
2303
  this.inputs.forEach((i) => {
2353
2304
  let correspondingInput;
2354
2305
  switch (i.type) {
@@ -2370,25 +2321,16 @@ var BaseTransactionRequest = class {
2370
2321
  }
2371
2322
  });
2372
2323
  }
2373
- shiftPredicateData() {
2374
- this.inputs.forEach((input) => {
2375
- if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2376
- input.predicateData = input.paddPredicateData(
2377
- BaseTransactionRequest.getPolicyMeta(this).policies.length
2378
- );
2379
- }
2380
- });
2381
- }
2382
2324
  };
2383
2325
 
2384
2326
  // src/providers/transaction-request/create-transaction-request.ts
2385
- var import_configs9 = require("@fuel-ts/address/configs");
2327
+ var import_configs8 = require("@fuel-ts/address/configs");
2386
2328
  var import_math9 = require("@fuel-ts/math");
2387
2329
  var import_transactions8 = require("@fuel-ts/transactions");
2388
2330
  var import_utils13 = require("@fuel-ts/utils");
2389
2331
 
2390
2332
  // src/providers/transaction-request/hash-transaction.ts
2391
- var import_configs8 = require("@fuel-ts/address/configs");
2333
+ var import_configs7 = require("@fuel-ts/address/configs");
2392
2334
  var import_hasher = require("@fuel-ts/hasher");
2393
2335
  var import_math8 = require("@fuel-ts/math");
2394
2336
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2397,7 +2339,7 @@ var import_ramda2 = require("ramda");
2397
2339
  function hashTransaction(transactionRequest, chainId) {
2398
2340
  const transaction = transactionRequest.toTransaction();
2399
2341
  if (transaction.type === import_transactions7.TransactionType.Script) {
2400
- transaction.receiptsRoot = import_configs8.ZeroBytes32;
2342
+ transaction.receiptsRoot = import_configs7.ZeroBytes32;
2401
2343
  }
2402
2344
  transaction.inputs = transaction.inputs.map((input) => {
2403
2345
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2419,10 +2361,10 @@ function hashTransaction(transactionRequest, chainId) {
2419
2361
  blockHeight: 0,
2420
2362
  txIndex: 0
2421
2363
  };
2422
- inputClone.txID = import_configs8.ZeroBytes32;
2364
+ inputClone.txID = import_configs7.ZeroBytes32;
2423
2365
  inputClone.outputIndex = 0;
2424
- inputClone.balanceRoot = import_configs8.ZeroBytes32;
2425
- inputClone.stateRoot = import_configs8.ZeroBytes32;
2366
+ inputClone.balanceRoot = import_configs7.ZeroBytes32;
2367
+ inputClone.stateRoot = import_configs7.ZeroBytes32;
2426
2368
  return inputClone;
2427
2369
  }
2428
2370
  default:
@@ -2433,8 +2375,8 @@ function hashTransaction(transactionRequest, chainId) {
2433
2375
  const outputClone = (0, import_ramda2.clone)(output);
2434
2376
  switch (outputClone.type) {
2435
2377
  case import_transactions7.OutputType.Contract: {
2436
- outputClone.balanceRoot = import_configs8.ZeroBytes32;
2437
- outputClone.stateRoot = import_configs8.ZeroBytes32;
2378
+ outputClone.balanceRoot = import_configs7.ZeroBytes32;
2379
+ outputClone.stateRoot = import_configs7.ZeroBytes32;
2438
2380
  return outputClone;
2439
2381
  }
2440
2382
  case import_transactions7.OutputType.Change: {
@@ -2442,9 +2384,9 @@ function hashTransaction(transactionRequest, chainId) {
2442
2384
  return outputClone;
2443
2385
  }
2444
2386
  case import_transactions7.OutputType.Variable: {
2445
- outputClone.to = import_configs8.ZeroBytes32;
2387
+ outputClone.to = import_configs7.ZeroBytes32;
2446
2388
  outputClone.amount = (0, import_math8.bn)(0);
2447
- outputClone.assetId = import_configs8.ZeroBytes32;
2389
+ outputClone.assetId = import_configs7.ZeroBytes32;
2448
2390
  return outputClone;
2449
2391
  }
2450
2392
  default:
@@ -2510,7 +2452,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2510
2452
  } = {}) {
2511
2453
  super(rest);
2512
2454
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2513
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2455
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2514
2456
  this.storageSlots = [...storageSlots ?? []];
2515
2457
  }
2516
2458
  /**
@@ -2525,9 +2467,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2525
2467
  return {
2526
2468
  type: import_transactions8.TransactionType.Create,
2527
2469
  ...baseTransaction,
2470
+ bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2528
2471
  bytecodeWitnessIndex,
2529
- storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2530
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2472
+ storageSlotsCount: storageSlots.length,
2473
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2531
2474
  storageSlots
2532
2475
  };
2533
2476
  }
@@ -2577,7 +2520,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2577
2520
  // src/providers/transaction-request/script-transaction-request.ts
2578
2521
  var import_abi_coder = require("@fuel-ts/abi-coder");
2579
2522
  var import_address2 = require("@fuel-ts/address");
2580
- var import_configs10 = require("@fuel-ts/address/configs");
2523
+ var import_configs9 = require("@fuel-ts/address/configs");
2581
2524
  var import_math10 = require("@fuel-ts/math");
2582
2525
  var import_transactions9 = require("@fuel-ts/transactions");
2583
2526
  var import_utils15 = require("@fuel-ts/utils");
@@ -2649,9 +2592,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2649
2592
  type: import_transactions9.TransactionType.Script,
2650
2593
  scriptGasLimit: this.gasLimit,
2651
2594
  ...super.getBaseTransaction(),
2652
- scriptLength: (0, import_math10.bn)(script.length),
2653
- scriptDataLength: (0, import_math10.bn)(scriptData.length),
2654
- receiptsRoot: import_configs10.ZeroBytes32,
2595
+ scriptLength: script.length,
2596
+ scriptDataLength: scriptData.length,
2597
+ receiptsRoot: import_configs9.ZeroBytes32,
2655
2598
  script: (0, import_utils15.hexlify)(script),
2656
2599
  scriptData: (0, import_utils15.hexlify)(scriptData)
2657
2600
  };
@@ -2714,7 +2657,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2714
2657
  }
2715
2658
  calculateMaxGas(chainInfo, minGas) {
2716
2659
  const { consensusParameters } = chainInfo;
2717
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2660
+ const { gasPerByte } = consensusParameters;
2718
2661
  const witnessesLength = this.toTransaction().witnesses.reduce(
2719
2662
  (acc, wit) => acc + wit.dataLength,
2720
2663
  0
@@ -2724,8 +2667,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2724
2667
  minGas,
2725
2668
  witnessesLength,
2726
2669
  witnessLimit: this.witnessLimit,
2727
- gasLimit: this.gasLimit,
2728
- maxGasPerTx
2670
+ gasLimit: this.gasLimit
2729
2671
  });
2730
2672
  }
2731
2673
  /**
@@ -2800,32 +2742,15 @@ var transactionRequestify = (obj) => {
2800
2742
  }
2801
2743
  }
2802
2744
  };
2803
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2804
- (acc, input) => {
2805
- if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2806
- acc.utxos.push(input.id);
2807
- }
2808
- if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2809
- acc.messages.push(input.nonce);
2810
- }
2811
- return acc;
2812
- },
2813
- {
2814
- utxos: [],
2815
- messages: []
2816
- }
2817
- );
2818
2745
 
2819
2746
  // src/providers/transaction-response/transaction-response.ts
2820
2747
  var import_errors13 = require("@fuel-ts/errors");
2821
- var import_math15 = require("@fuel-ts/math");
2822
- var import_transactions18 = require("@fuel-ts/transactions");
2823
- var import_utils20 = require("@fuel-ts/utils");
2748
+ var import_math14 = require("@fuel-ts/math");
2749
+ var import_transactions17 = require("@fuel-ts/transactions");
2750
+ var import_utils21 = require("@fuel-ts/utils");
2824
2751
 
2825
2752
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2826
- var import_math14 = require("@fuel-ts/math");
2827
- var import_transactions16 = require("@fuel-ts/transactions");
2828
- var import_utils18 = require("@fuel-ts/utils");
2753
+ var import_utils19 = require("@fuel-ts/utils");
2829
2754
 
2830
2755
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2831
2756
  var import_math11 = require("@fuel-ts/math");
@@ -2833,10 +2758,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
2833
2758
  var import_utils16 = require("@fuel-ts/utils");
2834
2759
  var calculateTransactionFee = (params) => {
2835
2760
  const {
2836
- gasPrice,
2761
+ gasUsed,
2837
2762
  rawPayload,
2838
- tip,
2839
- consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2763
+ consensusParameters: { gasCosts, feeParams }
2840
2764
  } = params;
2841
2765
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2842
2766
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2846,7 +2770,8 @@ var calculateTransactionFee = (params) => {
2846
2770
  return {
2847
2771
  fee: (0, import_math11.bn)(0),
2848
2772
  minFee: (0, import_math11.bn)(0),
2849
- maxFee: (0, import_math11.bn)(0)
2773
+ maxFee: (0, import_math11.bn)(0),
2774
+ feeFromGasUsed: (0, import_math11.bn)(0)
2850
2775
  };
2851
2776
  }
2852
2777
  const { type, witnesses, inputs, policies } = transaction;
@@ -2878,6 +2803,7 @@ var calculateTransactionFee = (params) => {
2878
2803
  metadataGas,
2879
2804
  txBytesSize: transactionBytes.length
2880
2805
  });
2806
+ const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2881
2807
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2882
2808
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2883
2809
  const maxGas = getMaxGas({
@@ -2885,30 +2811,22 @@ var calculateTransactionFee = (params) => {
2885
2811
  minGas,
2886
2812
  witnessesLength,
2887
2813
  gasLimit,
2888
- witnessLimit,
2889
- maxGasPerTx
2890
- });
2891
- const minFee = calculateGasFee({
2892
- gasPrice,
2893
- gas: minGas,
2894
- priceFactor: gasPriceFactor,
2895
- tip
2896
- });
2897
- const maxFee = calculateGasFee({
2898
- gasPrice,
2899
- gas: maxGas,
2900
- priceFactor: gasPriceFactor,
2901
- tip
2814
+ witnessLimit
2902
2815
  });
2816
+ const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2817
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2818
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2819
+ const fee = minFee.add(feeFromGasUsed);
2903
2820
  return {
2821
+ fee,
2904
2822
  minFee,
2905
2823
  maxFee,
2906
- fee: maxFee
2824
+ feeFromGasUsed
2907
2825
  };
2908
2826
  };
2909
2827
 
2910
2828
  // src/providers/transaction-summary/operations.ts
2911
- var import_configs11 = require("@fuel-ts/address/configs");
2829
+ var import_configs10 = require("@fuel-ts/address/configs");
2912
2830
  var import_errors11 = require("@fuel-ts/errors");
2913
2831
  var import_math13 = require("@fuel-ts/math");
2914
2832
  var import_transactions14 = require("@fuel-ts/transactions");
@@ -3253,7 +3171,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
3253
3171
  const { to: toAddress, assetId, amount } = receipt;
3254
3172
  let { from: fromAddress } = receipt;
3255
3173
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
3256
- if (import_configs11.ZeroBytes32 === fromAddress) {
3174
+ if (import_configs10.ZeroBytes32 === fromAddress) {
3257
3175
  const change = changeOutputs.find((output) => output.assetId === assetId);
3258
3176
  fromAddress = change?.to || fromAddress;
3259
3177
  }
@@ -3517,12 +3435,10 @@ function assembleTransactionSummary(params) {
3517
3435
  gqlTransactionStatus,
3518
3436
  abiMap = {},
3519
3437
  maxInputs,
3520
- gasCosts,
3521
- maxGasPerTx,
3522
- gasPrice
3438
+ gasCosts
3523
3439
  } = params;
3524
3440
  const gasUsed = getGasUsedFromReceipts(receipts);
3525
- const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3441
+ const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3526
3442
  const operations = getOperations({
3527
3443
  transactionType: transaction.type,
3528
3444
  inputs: transaction.inputs || [],
@@ -3533,14 +3449,11 @@ function assembleTransactionSummary(params) {
3533
3449
  maxInputs
3534
3450
  });
3535
3451
  const typeName = getTransactionTypeName(transaction.type);
3536
- const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3537
3452
  const { fee } = calculateTransactionFee({
3538
- gasPrice,
3453
+ gasUsed,
3539
3454
  rawPayload,
3540
- tip,
3541
3455
  consensusParameters: {
3542
3456
  gasCosts,
3543
- maxGasPerTx,
3544
3457
  feeParams: {
3545
3458
  gasPerByte,
3546
3459
  gasPriceFactor
@@ -3552,7 +3465,7 @@ function assembleTransactionSummary(params) {
3552
3465
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3553
3466
  let date;
3554
3467
  if (time) {
3555
- date = import_utils18.DateTime.fromTai64(time);
3468
+ date = import_utils19.DateTime.fromTai64(time);
3556
3469
  }
3557
3470
  const transactionSummary = {
3558
3471
  id,
@@ -3580,12 +3493,12 @@ function assembleTransactionSummary(params) {
3580
3493
 
3581
3494
  // src/providers/transaction-response/getDecodedLogs.ts
3582
3495
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
3583
- var import_transactions17 = require("@fuel-ts/transactions");
3496
+ var import_transactions16 = require("@fuel-ts/transactions");
3584
3497
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3585
3498
  return receipts.reduce((logs, receipt) => {
3586
- if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3499
+ if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3587
3500
  const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3588
- const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3501
+ const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3589
3502
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3590
3503
  logs.push(decodedLog);
3591
3504
  }
@@ -3600,7 +3513,7 @@ var TransactionResponse = class {
3600
3513
  /** Current provider */
3601
3514
  provider;
3602
3515
  /** Gas used on the transaction */
3603
- gasUsed = (0, import_math15.bn)(0);
3516
+ gasUsed = (0, import_math14.bn)(0);
3604
3517
  /** The graphql Transaction with receipts object. */
3605
3518
  gqlTransaction;
3606
3519
  abis;
@@ -3658,8 +3571,8 @@ var TransactionResponse = class {
3658
3571
  * @returns The decoded transaction.
3659
3572
  */
3660
3573
  decodeTransaction(transactionWithReceipts) {
3661
- return new import_transactions18.TransactionCoder().decode(
3662
- (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3574
+ return new import_transactions17.TransactionCoder().decode(
3575
+ (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3663
3576
  0
3664
3577
  )?.[0];
3665
3578
  }
@@ -3678,27 +3591,20 @@ var TransactionResponse = class {
3678
3591
  const decodedTransaction = this.decodeTransaction(
3679
3592
  transaction
3680
3593
  );
3681
- let txReceipts = [];
3682
- if (transaction?.status && "receipts" in transaction.status) {
3683
- txReceipts = transaction.status.receipts;
3684
- }
3685
- const receipts = txReceipts.map(processGqlReceipt) || [];
3686
- const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3687
- const gasPrice = await this.provider.getLatestGasPrice();
3594
+ const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3595
+ const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3688
3596
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3689
3597
  const transactionSummary = assembleTransactionSummary({
3690
3598
  id: this.id,
3691
3599
  receipts,
3692
3600
  transaction: decodedTransaction,
3693
- transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3601
+ transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3694
3602
  gqlTransactionStatus: transaction.status,
3695
3603
  gasPerByte,
3696
3604
  gasPriceFactor,
3697
3605
  abiMap: contractsAbiMap,
3698
3606
  maxInputs,
3699
- gasCosts,
3700
- maxGasPerTx,
3701
- gasPrice
3607
+ gasCosts
3702
3608
  });
3703
3609
  return transactionSummary;
3704
3610
  }
@@ -3825,29 +3731,30 @@ var processGqlChain = (chain) => {
3825
3731
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3826
3732
  return {
3827
3733
  name,
3828
- baseChainHeight: (0, import_math16.bn)(daHeight),
3734
+ baseChainHeight: (0, import_math15.bn)(daHeight),
3829
3735
  consensusParameters: {
3830
- contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3831
- maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3832
- maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3833
- maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3834
- maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3835
- maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3836
- maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3837
- maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3838
- maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3839
- maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3840
- maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3841
- gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3842
- gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3843
- maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3844
- chainId: (0, import_math16.bn)(consensusParameters.chainId),
3736
+ contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3737
+ maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3738
+ maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3739
+ maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3740
+ maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3741
+ maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3742
+ maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3743
+ maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3744
+ maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3745
+ maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3746
+ maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3747
+ gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3748
+ gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3749
+ maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3750
+ chainId: (0, import_math15.bn)(consensusParameters.chainId),
3751
+ baseAssetId: consensusParameters.baseAssetId,
3845
3752
  gasCosts
3846
3753
  },
3847
3754
  gasCosts,
3848
3755
  latestBlock: {
3849
3756
  id: latestBlock.id,
3850
- height: (0, import_math16.bn)(latestBlock.height),
3757
+ height: (0, import_math15.bn)(latestBlock.header.height),
3851
3758
  time: latestBlock.header.time,
3852
3759
  transactions: latestBlock.transactions.map((i) => ({
3853
3760
  id: i.id
@@ -3941,8 +3848,10 @@ var _Provider = class {
3941
3848
  * Returns some helpful parameters related to gas fees.
3942
3849
  */
3943
3850
  getGasConfig() {
3851
+ const { minGasPrice } = this.getNode();
3944
3852
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3945
3853
  return {
3854
+ minGasPrice,
3946
3855
  maxGasPerTx,
3947
3856
  maxGasPerPredicate,
3948
3857
  gasPriceFactor,
@@ -4030,7 +3939,7 @@ var _Provider = class {
4030
3939
  name,
4031
3940
  consensusParameters: { chainId }
4032
3941
  } = await this.getChain();
4033
- const network = new import_ethers2.Network(name, chainId.toNumber());
3942
+ const network = new import_ethers.Network(name, chainId.toNumber());
4034
3943
  return Promise.resolve(network);
4035
3944
  }
4036
3945
  /**
@@ -4040,7 +3949,7 @@ var _Provider = class {
4040
3949
  */
4041
3950
  async getBlockNumber() {
4042
3951
  const { chain } = await this.operations.getChain();
4043
- return (0, import_math16.bn)(chain.latestBlock.height, 10);
3952
+ return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
4044
3953
  }
4045
3954
  /**
4046
3955
  * Returns the chain information.
@@ -4050,11 +3959,13 @@ var _Provider = class {
4050
3959
  async fetchNode() {
4051
3960
  const { nodeInfo } = await this.operations.getNodeInfo();
4052
3961
  const processedNodeInfo = {
4053
- maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4054
- maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3962
+ maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3963
+ maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3964
+ minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
4055
3965
  nodeVersion: nodeInfo.nodeVersion,
4056
3966
  utxoValidation: nodeInfo.utxoValidation,
4057
- vmBacktrace: nodeInfo.vmBacktrace
3967
+ vmBacktrace: nodeInfo.vmBacktrace,
3968
+ peers: nodeInfo.peers
4058
3969
  };
4059
3970
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
4060
3971
  return processedNodeInfo;
@@ -4080,6 +3991,17 @@ var _Provider = class {
4080
3991
  } = this.getChain();
4081
3992
  return chainId.toNumber();
4082
3993
  }
3994
+ /**
3995
+ * Returns the base asset ID
3996
+ *
3997
+ * @returns A promise that resolves to the base asset ID
3998
+ */
3999
+ getBaseAssetId() {
4000
+ const {
4001
+ consensusParameters: { baseAssetId }
4002
+ } = this.getChain();
4003
+ return baseAssetId;
4004
+ }
4083
4005
  /**
4084
4006
  * Submits a transaction to the chain to be executed.
4085
4007
  *
@@ -4096,9 +4018,9 @@ var _Provider = class {
4096
4018
  if (estimateTxDependencies) {
4097
4019
  await this.estimateTxDependencies(transactionRequest);
4098
4020
  }
4099
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4021
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4100
4022
  let abis;
4101
- if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4023
+ if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4102
4024
  abis = transactionRequest.abis;
4103
4025
  }
4104
4026
  if (awaitExecution) {
@@ -4139,14 +4061,15 @@ var _Provider = class {
4139
4061
  if (estimateTxDependencies) {
4140
4062
  return this.estimateTxDependencies(transactionRequest);
4141
4063
  }
4142
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4143
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4144
- encodedTransactions: encodedTransaction,
4064
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4065
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
4066
+ encodedTransaction,
4145
4067
  utxoValidation: utxoValidation || false
4146
4068
  });
4147
- const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4148
- const receipts = rawReceipts.map(processGqlReceipt);
4149
- return { receipts, dryrunStatus: status };
4069
+ const receipts = gqlReceipts.map(processGqlReceipt);
4070
+ return {
4071
+ receipts
4072
+ };
4150
4073
  }
4151
4074
  /**
4152
4075
  * Verifies whether enough gas is available to complete transaction.
@@ -4157,13 +4080,13 @@ var _Provider = class {
4157
4080
  async estimatePredicates(transactionRequest) {
4158
4081
  const shouldEstimatePredicates = Boolean(
4159
4082
  transactionRequest.inputs.find(
4160
- (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()
4083
+ (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()
4161
4084
  )
4162
4085
  );
4163
4086
  if (!shouldEstimatePredicates) {
4164
4087
  return transactionRequest;
4165
4088
  }
4166
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4089
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4167
4090
  const response = await this.operations.estimatePredicates({
4168
4091
  encodedTransaction
4169
4092
  });
@@ -4172,7 +4095,7 @@ var _Provider = class {
4172
4095
  } = response;
4173
4096
  if (inputs) {
4174
4097
  inputs.forEach((input, index) => {
4175
- if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
4098
+ if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
4176
4099
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4177
4100
  }
4178
4101
  });
@@ -4185,31 +4108,31 @@ var _Provider = class {
4185
4108
  * If there are missing variable outputs,
4186
4109
  * `addVariableOutputs` is called on the transaction.
4187
4110
  *
4111
+ * @privateRemarks
4112
+ * TODO: Investigate support for missing contract IDs
4113
+ * TODO: Add support for missing output messages
4188
4114
  *
4189
4115
  * @param transactionRequest - The transaction request object.
4190
4116
  * @returns A promise.
4191
4117
  */
4192
4118
  async estimateTxDependencies(transactionRequest) {
4193
- if (transactionRequest.type === import_transactions19.TransactionType.Create) {
4119
+ if (transactionRequest.type === import_transactions18.TransactionType.Create) {
4194
4120
  return {
4195
4121
  receipts: [],
4196
4122
  outputVariables: 0,
4197
4123
  missingContractIds: []
4198
4124
  };
4199
4125
  }
4126
+ await this.estimatePredicates(transactionRequest);
4200
4127
  let receipts = [];
4201
4128
  const missingContractIds = [];
4202
4129
  let outputVariables = 0;
4203
- let dryrunStatus;
4204
4130
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
4205
- const {
4206
- dryRun: [{ receipts: rawReceipts, status }]
4207
- } = await this.operations.dryRun({
4208
- encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4131
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
4132
+ encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
4209
4133
  utxoValidation: false
4210
4134
  });
4211
- receipts = rawReceipts.map(processGqlReceipt);
4212
- dryrunStatus = status;
4135
+ receipts = gqlReceipts.map(processGqlReceipt);
4213
4136
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4214
4137
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4215
4138
  if (hasMissingOutputs) {
@@ -4219,11 +4142,6 @@ var _Provider = class {
4219
4142
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4220
4143
  missingContractIds.push(contractId);
4221
4144
  });
4222
- const { maxFee } = await this.estimateTxGasAndFee({
4223
- transactionRequest,
4224
- optimizeGas: false
4225
- });
4226
- transactionRequest.maxFee = maxFee;
4227
4145
  } else {
4228
4146
  break;
4229
4147
  }
@@ -4231,133 +4149,7 @@ var _Provider = class {
4231
4149
  return {
4232
4150
  receipts,
4233
4151
  outputVariables,
4234
- missingContractIds,
4235
- dryrunStatus
4236
- };
4237
- }
4238
- /**
4239
- * Dry runs multiple transactions and checks for missing dependencies in batches.
4240
- *
4241
- * Transactions are dry run in batches. After each dry run, transactions requiring
4242
- * further modifications are identified. The method iteratively updates these transactions
4243
- * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4244
- *
4245
- * @param transactionRequests - Array of transaction request objects.
4246
- * @returns A promise that resolves to an array of results for each transaction.
4247
- */
4248
- async estimateMultipleTxDependencies(transactionRequests) {
4249
- const results = transactionRequests.map(() => ({
4250
- receipts: [],
4251
- outputVariables: 0,
4252
- missingContractIds: [],
4253
- dryrunStatus: void 0
4254
- }));
4255
- const allRequests = (0, import_ramda3.clone)(transactionRequests);
4256
- const serializedTransactionsMap = /* @__PURE__ */ new Map();
4257
- allRequests.forEach((req, index) => {
4258
- if (req.type === import_transactions19.TransactionType.Script) {
4259
- serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4260
- }
4261
- });
4262
- let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4263
- let attempt = 0;
4264
- while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4265
- const encodedTransactions = transactionsToProcess.map(
4266
- (index) => serializedTransactionsMap.get(index)
4267
- );
4268
- const dryRunResults = await this.operations.dryRun({
4269
- encodedTransactions,
4270
- utxoValidation: false
4271
- });
4272
- const nextRoundTransactions = [];
4273
- for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4274
- const currentResultIndex = transactionsToProcess[i];
4275
- const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4276
- results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4277
- results[currentResultIndex].dryrunStatus = status;
4278
- const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4279
- results[currentResultIndex].receipts
4280
- );
4281
- const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4282
- const requestToProcess = allRequests[currentResultIndex];
4283
- if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4284
- results[currentResultIndex].outputVariables += missingOutputVariables.length;
4285
- requestToProcess.addVariableOutputs(missingOutputVariables.length);
4286
- missingOutputContractIds.forEach(({ contractId }) => {
4287
- requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4288
- results[currentResultIndex].missingContractIds.push(contractId);
4289
- });
4290
- const { maxFee } = await this.estimateTxGasAndFee({
4291
- transactionRequest: requestToProcess,
4292
- optimizeGas: false
4293
- });
4294
- requestToProcess.maxFee = maxFee;
4295
- serializedTransactionsMap.set(
4296
- currentResultIndex,
4297
- (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4298
- );
4299
- nextRoundTransactions.push(currentResultIndex);
4300
- allRequests[currentResultIndex] = requestToProcess;
4301
- }
4302
- }
4303
- transactionsToProcess = nextRoundTransactions;
4304
- attempt += 1;
4305
- }
4306
- return results;
4307
- }
4308
- async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4309
- if (estimateTxDependencies) {
4310
- return this.estimateMultipleTxDependencies(transactionRequests);
4311
- }
4312
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4313
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4314
- encodedTransactions,
4315
- utxoValidation: utxoValidation || false
4316
- });
4317
- const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4318
- const receipts = rawReceipts.map(processGqlReceipt);
4319
- return { receipts, dryrunStatus: status };
4320
- });
4321
- return results;
4322
- }
4323
- async estimateTxGasAndFee(params) {
4324
- const { transactionRequest, optimizeGas = true } = params;
4325
- let { gasPrice } = params;
4326
- const chainInfo = this.getChain();
4327
- const { gasPriceFactor } = this.getGasConfig();
4328
- const minGas = transactionRequest.calculateMinGas(chainInfo);
4329
- if (!gasPrice) {
4330
- gasPrice = await this.estimateGasPrice(10);
4331
- }
4332
- const minFee = calculateGasFee({
4333
- gasPrice: (0, import_math16.bn)(gasPrice),
4334
- gas: minGas,
4335
- priceFactor: gasPriceFactor,
4336
- tip: transactionRequest.tip
4337
- }).add(1);
4338
- let gasLimit = (0, import_math16.bn)(0);
4339
- if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4340
- gasLimit = transactionRequest.gasLimit;
4341
- if (!optimizeGas) {
4342
- transactionRequest.gasLimit = minGas;
4343
- gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
4344
- transactionRequest.gasLimit = gasLimit;
4345
- }
4346
- }
4347
- const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4348
- const maxFee = calculateGasFee({
4349
- gasPrice: (0, import_math16.bn)(gasPrice),
4350
- gas: maxGas,
4351
- priceFactor: gasPriceFactor,
4352
- tip: transactionRequest.tip
4353
- }).add(1);
4354
- return {
4355
- minGas,
4356
- minFee,
4357
- maxGas,
4358
- maxFee,
4359
- gasPrice,
4360
- gasLimit
4152
+ missingContractIds
4361
4153
  };
4362
4154
  }
4363
4155
  /**
@@ -4375,17 +4167,15 @@ var _Provider = class {
4375
4167
  if (estimateTxDependencies) {
4376
4168
  return this.estimateTxDependencies(transactionRequest);
4377
4169
  }
4378
- const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4379
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4380
- encodedTransactions,
4170
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4171
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
4172
+ encodedTransaction,
4381
4173
  utxoValidation: true
4382
4174
  });
4383
- const callResult = dryRunStatuses.map((dryRunStatus) => {
4384
- const { id, receipts, status } = dryRunStatus;
4385
- const processedReceipts = receipts.map(processGqlReceipt);
4386
- return { id, receipts: processedReceipts, status };
4387
- });
4388
- return { receipts: callResult[0].receipts };
4175
+ const receipts = gqlReceipts.map(processGqlReceipt);
4176
+ return {
4177
+ receipts
4178
+ };
4389
4179
  }
4390
4180
  /**
4391
4181
  * Returns a transaction cost to enable user
@@ -4402,80 +4192,80 @@ var _Provider = class {
4402
4192
  * @param tolerance - The tolerance to add on top of the gasUsed.
4403
4193
  * @returns A promise that resolves to the transaction cost object.
4404
4194
  */
4405
- async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4195
+ async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4196
+ estimateTxDependencies = true,
4197
+ estimatePredicates = true,
4198
+ resourcesOwner,
4199
+ signatureCallback
4200
+ } = {}) {
4406
4201
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4407
- const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4202
+ const chainInfo = this.getChain();
4203
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4204
+ const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4205
+ const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4408
4206
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4409
- const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4207
+ const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4410
4208
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4411
- txRequestClone.maxFee = (0, import_math16.bn)(0);
4412
- if (isScriptTransaction) {
4413
- txRequestClone.gasLimit = (0, import_math16.bn)(0);
4414
- }
4415
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4416
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4209
+ if (estimatePredicates) {
4210
+ if (isScriptTransaction) {
4211
+ txRequestClone.gasLimit = (0, import_math15.bn)(0);
4212
+ }
4213
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4214
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4215
+ }
4216
+ await this.estimatePredicates(txRequestClone);
4417
4217
  }
4418
- const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4419
- let addedSignatures = 0;
4420
4218
  if (signatureCallback && isScriptTransaction) {
4421
- const lengthBefore = signedRequest.witnesses.length;
4422
- await signatureCallback(signedRequest);
4423
- addedSignatures = signedRequest.witnesses.length - lengthBefore;
4424
- }
4425
- await this.estimatePredicates(signedRequest);
4426
- let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4427
- transactionRequest: signedRequest,
4428
- optimizeGas: false
4429
- });
4430
- txRequestClone.maxFee = maxFee;
4219
+ await signatureCallback(txRequestClone);
4220
+ }
4221
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
4222
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4431
4223
  let receipts = [];
4432
4224
  let missingContractIds = [];
4433
4225
  let outputVariables = 0;
4434
- let gasUsed = (0, import_math16.bn)(0);
4435
- txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4436
- if (isScriptTransaction) {
4437
- if (signatureCallback) {
4438
- await signatureCallback(txRequestClone);
4439
- }
4440
- txRequestClone.gasLimit = gasLimit;
4226
+ if (isScriptTransaction && estimateTxDependencies) {
4227
+ txRequestClone.gasPrice = (0, import_math15.bn)(0);
4228
+ txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4441
4229
  const result = await this.estimateTxDependencies(txRequestClone);
4442
4230
  receipts = result.receipts;
4443
4231
  outputVariables = result.outputVariables;
4444
4232
  missingContractIds = result.missingContractIds;
4445
- gasUsed = getGasUsedFromReceipts(receipts);
4446
- txRequestClone.gasLimit = gasUsed;
4447
- ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4448
- transactionRequest: txRequestClone,
4449
- gasPrice
4450
- }));
4451
4233
  }
4234
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
4235
+ const usedFee = calculatePriceWithFactor(
4236
+ gasUsed,
4237
+ gasPrice,
4238
+ gasPriceFactor
4239
+ ).normalizeZeroToOne();
4240
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4241
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4452
4242
  return {
4453
4243
  requiredQuantities: allQuantities,
4454
4244
  receipts,
4455
4245
  gasUsed,
4246
+ minGasPrice,
4456
4247
  gasPrice,
4457
4248
  minGas,
4458
4249
  maxGas,
4250
+ usedFee,
4459
4251
  minFee,
4460
4252
  maxFee,
4253
+ estimatedInputs: txRequestClone.inputs,
4461
4254
  outputVariables,
4462
- missingContractIds,
4463
- addedSignatures,
4464
- estimatedPredicates: txRequestClone.inputs
4255
+ missingContractIds
4465
4256
  };
4466
4257
  }
4467
- async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4258
+ async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4468
4259
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4469
4260
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4470
- const transactionCost = await this.getTransactionCost(transactionRequest, {
4471
- quantitiesToContract
4472
- });
4261
+ const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4473
4262
  transactionRequest.addResources(
4474
4263
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4475
4264
  );
4476
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4477
- quantitiesToContract
4478
- });
4265
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4266
+ transactionRequest,
4267
+ forwardingQuantities
4268
+ );
4479
4269
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4480
4270
  return {
4481
4271
  resources,
@@ -4491,16 +4281,17 @@ var _Provider = class {
4491
4281
  const result = await this.operations.getCoins({
4492
4282
  first: 10,
4493
4283
  ...paginationArgs,
4494
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4284
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4495
4285
  });
4496
4286
  const coins = result.coins.edges.map((edge) => edge.node);
4497
4287
  return coins.map((coin) => ({
4498
4288
  id: coin.utxoId,
4499
4289
  assetId: coin.assetId,
4500
- amount: (0, import_math16.bn)(coin.amount),
4290
+ amount: (0, import_math15.bn)(coin.amount),
4501
4291
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4502
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4503
- txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4292
+ maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4293
+ blockCreated: (0, import_math15.bn)(coin.blockCreated),
4294
+ txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4504
4295
  }));
4505
4296
  }
4506
4297
  /**
@@ -4514,19 +4305,19 @@ var _Provider = class {
4514
4305
  async getResourcesToSpend(owner, quantities, excludedIds) {
4515
4306
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4516
4307
  const excludeInput = {
4517
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4518
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4308
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4309
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4519
4310
  };
4520
4311
  if (this.cache) {
4521
4312
  const uniqueUtxos = new Set(
4522
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4313
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4523
4314
  );
4524
4315
  excludeInput.utxos = Array.from(uniqueUtxos);
4525
4316
  }
4526
4317
  const coinsQuery = {
4527
4318
  owner: ownerAddress.toB256(),
4528
4319
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4529
- assetId: (0, import_utils22.hexlify)(assetId),
4320
+ assetId: (0, import_utils23.hexlify)(assetId),
4530
4321
  amount: amount.toString(10),
4531
4322
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4532
4323
  })),
@@ -4537,9 +4328,9 @@ var _Provider = class {
4537
4328
  switch (coin.__typename) {
4538
4329
  case "MessageCoin":
4539
4330
  return {
4540
- amount: (0, import_math16.bn)(coin.amount),
4331
+ amount: (0, import_math15.bn)(coin.amount),
4541
4332
  assetId: coin.assetId,
4542
- daHeight: (0, import_math16.bn)(coin.daHeight),
4333
+ daHeight: (0, import_math15.bn)(coin.daHeight),
4543
4334
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4544
4335
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4545
4336
  nonce: coin.nonce
@@ -4547,11 +4338,12 @@ var _Provider = class {
4547
4338
  case "Coin":
4548
4339
  return {
4549
4340
  id: coin.utxoId,
4550
- amount: (0, import_math16.bn)(coin.amount),
4341
+ amount: (0, import_math15.bn)(coin.amount),
4551
4342
  assetId: coin.assetId,
4552
4343
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4553
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4554
- txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4344
+ maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4345
+ blockCreated: (0, import_math15.bn)(coin.blockCreated),
4346
+ txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4555
4347
  };
4556
4348
  default:
4557
4349
  return null;
@@ -4568,13 +4360,13 @@ var _Provider = class {
4568
4360
  async getBlock(idOrHeight) {
4569
4361
  let variables;
4570
4362
  if (typeof idOrHeight === "number") {
4571
- variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4363
+ variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4572
4364
  } else if (idOrHeight === "latest") {
4573
4365
  variables = { height: (await this.getBlockNumber()).toString(10) };
4574
4366
  } else if (idOrHeight.length === 66) {
4575
4367
  variables = { blockId: idOrHeight };
4576
4368
  } else {
4577
- variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4369
+ variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4578
4370
  }
4579
4371
  const { block } = await this.operations.getBlock(variables);
4580
4372
  if (!block) {
@@ -4582,7 +4374,7 @@ var _Provider = class {
4582
4374
  }
4583
4375
  return {
4584
4376
  id: block.id,
4585
- height: (0, import_math16.bn)(block.height),
4377
+ height: (0, import_math15.bn)(block.header.height),
4586
4378
  time: block.header.time,
4587
4379
  transactionIds: block.transactions.map((tx) => tx.id)
4588
4380
  };
@@ -4597,7 +4389,7 @@ var _Provider = class {
4597
4389
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4598
4390
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4599
4391
  id: block.id,
4600
- height: (0, import_math16.bn)(block.height),
4392
+ height: (0, import_math15.bn)(block.header.height),
4601
4393
  time: block.header.time,
4602
4394
  transactionIds: block.transactions.map((tx) => tx.id)
4603
4395
  }));
@@ -4612,7 +4404,7 @@ var _Provider = class {
4612
4404
  async getBlockWithTransactions(idOrHeight) {
4613
4405
  let variables;
4614
4406
  if (typeof idOrHeight === "number") {
4615
- variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4407
+ variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4616
4408
  } else if (idOrHeight === "latest") {
4617
4409
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4618
4410
  } else {
@@ -4624,11 +4416,11 @@ var _Provider = class {
4624
4416
  }
4625
4417
  return {
4626
4418
  id: block.id,
4627
- height: (0, import_math16.bn)(block.height, 10),
4419
+ height: (0, import_math15.bn)(block.header.height, 10),
4628
4420
  time: block.header.time,
4629
4421
  transactionIds: block.transactions.map((tx) => tx.id),
4630
4422
  transactions: block.transactions.map(
4631
- (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4423
+ (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4632
4424
  )
4633
4425
  };
4634
4426
  }
@@ -4643,8 +4435,8 @@ var _Provider = class {
4643
4435
  if (!transaction) {
4644
4436
  return null;
4645
4437
  }
4646
- return new import_transactions19.TransactionCoder().decode(
4647
- (0, import_utils22.arrayify)(transaction.rawPayload),
4438
+ return new import_transactions18.TransactionCoder().decode(
4439
+ (0, import_utils23.arrayify)(transaction.rawPayload),
4648
4440
  0
4649
4441
  )?.[0];
4650
4442
  }
@@ -4671,9 +4463,9 @@ var _Provider = class {
4671
4463
  async getContractBalance(contractId, assetId) {
4672
4464
  const { contractBalance } = await this.operations.getContractBalance({
4673
4465
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4674
- asset: (0, import_utils22.hexlify)(assetId)
4466
+ asset: (0, import_utils23.hexlify)(assetId)
4675
4467
  });
4676
- return (0, import_math16.bn)(contractBalance.amount, 10);
4468
+ return (0, import_math15.bn)(contractBalance.amount, 10);
4677
4469
  }
4678
4470
  /**
4679
4471
  * Returns the balance for the given owner for the given asset ID.
@@ -4685,9 +4477,9 @@ var _Provider = class {
4685
4477
  async getBalance(owner, assetId) {
4686
4478
  const { balance } = await this.operations.getBalance({
4687
4479
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4688
- assetId: (0, import_utils22.hexlify)(assetId)
4480
+ assetId: (0, import_utils23.hexlify)(assetId)
4689
4481
  });
4690
- return (0, import_math16.bn)(balance.amount, 10);
4482
+ return (0, import_math15.bn)(balance.amount, 10);
4691
4483
  }
4692
4484
  /**
4693
4485
  * Returns balances for the given owner.
@@ -4705,7 +4497,7 @@ var _Provider = class {
4705
4497
  const balances = result.balances.edges.map((edge) => edge.node);
4706
4498
  return balances.map((balance) => ({
4707
4499
  assetId: balance.assetId,
4708
- amount: (0, import_math16.bn)(balance.amount)
4500
+ amount: (0, import_math15.bn)(balance.amount)
4709
4501
  }));
4710
4502
  }
4711
4503
  /**
@@ -4723,19 +4515,19 @@ var _Provider = class {
4723
4515
  });
4724
4516
  const messages = result.messages.edges.map((edge) => edge.node);
4725
4517
  return messages.map((message) => ({
4726
- messageId: import_transactions19.InputMessageCoder.getMessageId({
4518
+ messageId: import_transactions18.InputMessageCoder.getMessageId({
4727
4519
  sender: message.sender,
4728
4520
  recipient: message.recipient,
4729
4521
  nonce: message.nonce,
4730
- amount: (0, import_math16.bn)(message.amount),
4522
+ amount: (0, import_math15.bn)(message.amount),
4731
4523
  data: message.data
4732
4524
  }),
4733
4525
  sender: import_address3.Address.fromAddressOrString(message.sender),
4734
4526
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4735
4527
  nonce: message.nonce,
4736
- amount: (0, import_math16.bn)(message.amount),
4737
- data: import_transactions19.InputMessageCoder.decodeData(message.data),
4738
- daHeight: (0, import_math16.bn)(message.daHeight)
4528
+ amount: (0, import_math15.bn)(message.amount),
4529
+ data: import_transactions18.InputMessageCoder.decodeData(message.data),
4530
+ daHeight: (0, import_math15.bn)(message.daHeight)
4739
4531
  }));
4740
4532
  }
4741
4533
  /**
@@ -4788,52 +4580,44 @@ var _Provider = class {
4788
4580
  } = result.messageProof;
4789
4581
  return {
4790
4582
  messageProof: {
4791
- proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4583
+ proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4792
4584
  proofSet: messageProof.proofSet
4793
4585
  },
4794
4586
  blockProof: {
4795
- proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4587
+ proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4796
4588
  proofSet: blockProof.proofSet
4797
4589
  },
4798
4590
  messageBlockHeader: {
4799
4591
  id: messageBlockHeader.id,
4800
- daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4801
- transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4592
+ daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4593
+ transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4802
4594
  transactionsRoot: messageBlockHeader.transactionsRoot,
4803
- height: (0, import_math16.bn)(messageBlockHeader.height),
4595
+ height: (0, import_math15.bn)(messageBlockHeader.height),
4804
4596
  prevRoot: messageBlockHeader.prevRoot,
4805
4597
  time: messageBlockHeader.time,
4806
4598
  applicationHash: messageBlockHeader.applicationHash,
4807
- messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount)
4599
+ messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4600
+ messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4808
4601
  },
4809
4602
  commitBlockHeader: {
4810
4603
  id: commitBlockHeader.id,
4811
- daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4812
- transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4604
+ daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4605
+ transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4813
4606
  transactionsRoot: commitBlockHeader.transactionsRoot,
4814
- height: (0, import_math16.bn)(commitBlockHeader.height),
4607
+ height: (0, import_math15.bn)(commitBlockHeader.height),
4815
4608
  prevRoot: commitBlockHeader.prevRoot,
4816
4609
  time: commitBlockHeader.time,
4817
4610
  applicationHash: commitBlockHeader.applicationHash,
4818
- messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount)
4611
+ messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4612
+ messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4819
4613
  },
4820
4614
  sender: import_address3.Address.fromAddressOrString(sender),
4821
4615
  recipient: import_address3.Address.fromAddressOrString(recipient),
4822
4616
  nonce,
4823
- amount: (0, import_math16.bn)(amount),
4617
+ amount: (0, import_math15.bn)(amount),
4824
4618
  data
4825
4619
  };
4826
4620
  }
4827
- async getLatestGasPrice() {
4828
- const { latestGasPrice } = await this.operations.getLatestGasPrice();
4829
- return (0, import_math16.bn)(latestGasPrice.gasPrice);
4830
- }
4831
- async estimateGasPrice(blockHorizon) {
4832
- const { estimateGasPrice } = await this.operations.estimateGasPrice({
4833
- blockHorizon: String(blockHorizon)
4834
- });
4835
- return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4836
- }
4837
4621
  /**
4838
4622
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4839
4623
  *
@@ -4853,10 +4637,10 @@ var _Provider = class {
4853
4637
  */
4854
4638
  async produceBlocks(amount, startTime) {
4855
4639
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4856
- blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4857
- startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4640
+ blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4641
+ startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4858
4642
  });
4859
- return (0, import_math16.bn)(latestBlockHeight);
4643
+ return (0, import_math15.bn)(latestBlockHeight);
4860
4644
  }
4861
4645
  // eslint-disable-next-line @typescript-eslint/require-await
4862
4646
  async getTransactionResponse(transactionId) {
@@ -4870,7 +4654,7 @@ cacheInputs_fn = function(inputs) {
4870
4654
  return;
4871
4655
  }
4872
4656
  inputs.forEach((input) => {
4873
- if (input.type === import_transactions19.InputType.Coin) {
4657
+ if (input.type === import_transactions18.InputType.Coin) {
4874
4658
  this.cache?.set(input.id);
4875
4659
  }
4876
4660
  });
@@ -4880,9 +4664,9 @@ __publicField(Provider, "nodeInfoCache", {});
4880
4664
 
4881
4665
  // src/providers/transaction-summary/get-transaction-summary.ts
4882
4666
  var import_errors15 = require("@fuel-ts/errors");
4883
- var import_math17 = require("@fuel-ts/math");
4884
- var import_transactions20 = require("@fuel-ts/transactions");
4885
- var import_utils25 = require("@fuel-ts/utils");
4667
+ var import_math16 = require("@fuel-ts/math");
4668
+ var import_transactions19 = require("@fuel-ts/transactions");
4669
+ var import_utils26 = require("@fuel-ts/utils");
4886
4670
  async function getTransactionSummary(params) {
4887
4671
  const { id, provider, abiMap } = params;
4888
4672
  const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
@@ -4894,32 +4678,25 @@ async function getTransactionSummary(params) {
4894
4678
  `Transaction not found for given id: ${id}.`
4895
4679
  );
4896
4680
  }
4897
- const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
4898
- (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4681
+ const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
4682
+ (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4899
4683
  0
4900
4684
  );
4901
- let txReceipts = [];
4902
- if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4903
- txReceipts = gqlTransaction.status.receipts;
4904
- }
4905
- const receipts = txReceipts.map(processGqlReceipt);
4685
+ const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4906
4686
  const {
4907
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4687
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4908
4688
  } = provider.getChain();
4909
- const gasPrice = await provider.getLatestGasPrice();
4910
4689
  const transactionInfo = assembleTransactionSummary({
4911
4690
  id: gqlTransaction.id,
4912
4691
  receipts,
4913
4692
  transaction: decodedTransaction,
4914
- transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4693
+ transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4915
4694
  gqlTransactionStatus: gqlTransaction.status,
4916
- gasPerByte: (0, import_math17.bn)(gasPerByte),
4917
- gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
4695
+ gasPerByte: (0, import_math16.bn)(gasPerByte),
4696
+ gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
4918
4697
  abiMap,
4919
4698
  maxInputs,
4920
- gasCosts,
4921
- maxGasPerTx,
4922
- gasPrice
4699
+ gasCosts
4923
4700
  });
4924
4701
  return {
4925
4702
  gqlTransaction,
@@ -4929,11 +4706,10 @@ async function getTransactionSummary(params) {
4929
4706
  async function getTransactionSummaryFromRequest(params) {
4930
4707
  const { provider, transactionRequest, abiMap } = params;
4931
4708
  const { receipts } = await provider.call(transactionRequest);
4932
- const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4709
+ const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4933
4710
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4934
4711
  const transaction = transactionRequest.toTransaction();
4935
4712
  const transactionBytes = transactionRequest.toTransactionBytes();
4936
- const gasPrice = await provider.getLatestGasPrice();
4937
4713
  const transactionSummary = assembleTransactionSummary({
4938
4714
  receipts,
4939
4715
  transaction,
@@ -4942,9 +4718,7 @@ async function getTransactionSummaryFromRequest(params) {
4942
4718
  gasPerByte,
4943
4719
  gasPriceFactor,
4944
4720
  maxInputs,
4945
- gasCosts,
4946
- maxGasPerTx,
4947
- gasPrice
4721
+ gasCosts
4948
4722
  });
4949
4723
  return transactionSummary;
4950
4724
  }
@@ -4953,31 +4727,24 @@ async function getTransactionsSummaries(params) {
4953
4727
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4954
4728
  const { edges, pageInfo } = transactionsByOwner;
4955
4729
  const {
4956
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4730
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4957
4731
  } = provider.getChain();
4958
- const gasPrice = await provider.getLatestGasPrice();
4959
4732
  const transactions = edges.map((edge) => {
4960
4733
  const { node: gqlTransaction } = edge;
4961
- const { id, rawPayload, status } = gqlTransaction;
4962
- const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
4963
- let txReceipts = [];
4964
- if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4965
- txReceipts = gqlTransaction.status.receipts;
4966
- }
4967
- const receipts = txReceipts.map(processGqlReceipt);
4734
+ const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4735
+ const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
4736
+ const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4968
4737
  const transactionSummary = assembleTransactionSummary({
4969
4738
  id,
4970
4739
  receipts,
4971
4740
  transaction: decodedTransaction,
4972
- transactionBytes: (0, import_utils25.arrayify)(rawPayload),
4741
+ transactionBytes: (0, import_utils26.arrayify)(rawPayload),
4973
4742
  gqlTransactionStatus: status,
4974
4743
  abiMap,
4975
4744
  gasPerByte,
4976
4745
  gasPriceFactor,
4977
4746
  maxInputs,
4978
- gasCosts,
4979
- maxGasPerTx,
4980
- gasPrice
4747
+ gasCosts
4981
4748
  });
4982
4749
  const output = {
4983
4750
  gqlTransaction,
@@ -5114,17 +4881,17 @@ var assets = [
5114
4881
 
5115
4882
  // src/utils/formatTransferToContractScriptData.ts
5116
4883
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
5117
- var import_math18 = require("@fuel-ts/math");
5118
- var import_utils26 = require("@fuel-ts/utils");
4884
+ var import_math17 = require("@fuel-ts/math");
4885
+ var import_utils27 = require("@fuel-ts/utils");
5119
4886
  var asm = __toESM(require("@fuels/vm-asm"));
5120
4887
  var formatTransferToContractScriptData = (params) => {
5121
4888
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
5122
4889
  const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
5123
- const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4890
+ const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
5124
4891
  const scriptData = Uint8Array.from([
5125
- ...(0, import_utils26.arrayify)(hexlifiedContractId),
4892
+ ...(0, import_utils27.arrayify)(hexlifiedContractId),
5126
4893
  ...encoded,
5127
- ...(0, import_utils26.arrayify)(assetId)
4894
+ ...(0, import_utils27.arrayify)(assetId)
5128
4895
  ]);
5129
4896
  return scriptData;
5130
4897
  };
@@ -5271,8 +5038,9 @@ var Account = class extends import_interfaces.AbstractAccount {
5271
5038
  * @param assetId - The asset ID to check the balance for.
5272
5039
  * @returns A promise that resolves to the balance amount.
5273
5040
  */
5274
- async getBalance(assetId = import_configs12.BaseAssetId) {
5275
- const amount = await this.provider.getBalance(this.address, assetId);
5041
+ async getBalance(assetId) {
5042
+ const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
5043
+ const amount = await this.provider.getBalance(this.address, assetIdToFetch);
5276
5044
  return amount;
5277
5045
  }
5278
5046
  /**
@@ -5309,33 +5077,37 @@ var Account = class extends import_interfaces.AbstractAccount {
5309
5077
  * @param fee - The estimated transaction fee.
5310
5078
  * @returns A promise that resolves when the resources are added to the transaction.
5311
5079
  */
5312
- async fund(request, params) {
5313
- const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5314
- const txRequest = request;
5315
- const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5316
- amount: (0, import_math19.bn)(fee),
5317
- assetId: import_configs12.BaseAssetId,
5318
- coinQuantities: requiredQuantities
5080
+ async fund(request, coinQuantities, fee) {
5081
+ const baseAssetId = this.provider.getBaseAssetId();
5082
+ const updatedQuantities = addAmountToAsset({
5083
+ amount: (0, import_math18.bn)(fee),
5084
+ assetId: baseAssetId,
5085
+ coinQuantities
5319
5086
  });
5320
5087
  const quantitiesDict = {};
5321
- requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5088
+ updatedQuantities.forEach(({ amount, assetId }) => {
5322
5089
  quantitiesDict[assetId] = {
5323
5090
  required: amount,
5324
- owned: (0, import_math19.bn)(0)
5091
+ owned: (0, import_math18.bn)(0)
5325
5092
  };
5326
5093
  });
5327
- txRequest.inputs.forEach((input) => {
5094
+ const cachedUtxos = [];
5095
+ const cachedMessages = [];
5096
+ const owner = this.address.toB256();
5097
+ request.inputs.forEach((input) => {
5328
5098
  const isResource = "amount" in input;
5329
5099
  if (isResource) {
5330
5100
  const isCoin2 = "owner" in input;
5331
5101
  if (isCoin2) {
5332
5102
  const assetId = String(input.assetId);
5333
- if (quantitiesDict[assetId]) {
5334
- const amount = (0, import_math19.bn)(input.amount);
5103
+ if (input.owner === owner && quantitiesDict[assetId]) {
5104
+ const amount = (0, import_math18.bn)(input.amount);
5335
5105
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5106
+ cachedUtxos.push(input.id);
5336
5107
  }
5337
- } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5338
- quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5108
+ } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
5109
+ quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
5110
+ cachedMessages.push(input.nonce);
5339
5111
  }
5340
5112
  }
5341
5113
  });
@@ -5350,23 +5122,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5350
5122
  });
5351
5123
  const needsToBeFunded = missingQuantities.length;
5352
5124
  if (needsToBeFunded) {
5353
- const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5354
- const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5355
- txRequest.addResources(resources);
5356
- }
5357
- txRequest.shiftPredicateData();
5358
- txRequest.updatePredicateGasUsed(estimatedPredicates);
5359
- const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
5360
- if (addedSignatures) {
5361
- Array.from({ length: addedSignatures }).forEach(
5362
- () => requestToBeReEstimate.addEmptyWitness()
5363
- );
5125
+ const resources = await this.getResourcesToSpend(missingQuantities, {
5126
+ messages: cachedMessages,
5127
+ utxos: cachedUtxos
5128
+ });
5129
+ request.addResources(resources);
5364
5130
  }
5365
- const { maxFee } = await this.provider.estimateTxGasAndFee({
5366
- transactionRequest: requestToBeReEstimate
5367
- });
5368
- txRequest.maxFee = maxFee;
5369
- return txRequest;
5370
5131
  }
5371
5132
  /**
5372
5133
  * A helper that creates a transfer transaction request and returns it.
@@ -5374,25 +5135,29 @@ var Account = class extends import_interfaces.AbstractAccount {
5374
5135
  * @param destination - The address of the destination.
5375
5136
  * @param amount - The amount of coins to transfer.
5376
5137
  * @param assetId - The asset ID of the coins to transfer.
5377
- * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5138
+ * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5378
5139
  * @returns A promise that resolves to the prepared transaction request.
5379
5140
  */
5380
- async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5381
- const request = new ScriptTransactionRequest(txParams);
5382
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5383
- const txCost = await this.provider.getTransactionCost(request, {
5141
+ async createTransfer(destination, amount, assetId, txParams = {}) {
5142
+ const { minGasPrice } = this.provider.getGasConfig();
5143
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5144
+ const params = { gasPrice: minGasPrice, ...txParams };
5145
+ const request = new ScriptTransactionRequest(params);
5146
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
5147
+ const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5384
5148
  estimateTxDependencies: true,
5385
5149
  resourcesOwner: this
5386
5150
  });
5387
- if ("gasLimit" in txParams) {
5388
- this.validateGas({
5389
- gasUsed: txCost.gasUsed,
5390
- gasLimit: request.gasLimit
5391
- });
5392
- }
5393
- request.gasLimit = txCost.gasUsed;
5394
- request.maxFee = txCost.maxFee;
5395
- await this.fund(request, txCost);
5151
+ request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
5152
+ request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
5153
+ this.validateGas({
5154
+ gasUsed,
5155
+ gasPrice: request.gasPrice,
5156
+ gasLimit: request.gasLimit,
5157
+ minGasPrice
5158
+ });
5159
+ await this.fund(request, requiredQuantities, maxFee);
5160
+ request.updatePredicateInputs(estimatedInputs);
5396
5161
  return request;
5397
5162
  }
5398
5163
  /**
@@ -5404,14 +5169,15 @@ var Account = class extends import_interfaces.AbstractAccount {
5404
5169
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5405
5170
  * @returns A promise that resolves to the transaction response.
5406
5171
  */
5407
- async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5408
- if ((0, import_math19.bn)(amount).lte(0)) {
5172
+ async transfer(destination, amount, assetId, txParams = {}) {
5173
+ if ((0, import_math18.bn)(amount).lte(0)) {
5409
5174
  throw new import_errors16.FuelError(
5410
5175
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5411
5176
  "Transfer amount must be a positive number."
5412
5177
  );
5413
5178
  }
5414
- const request = await this.createTransfer(destination, amount, assetId, txParams);
5179
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5180
+ const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5415
5181
  return this.sendTransaction(request, { estimateTxDependencies: false });
5416
5182
  }
5417
5183
  /**
@@ -5423,38 +5189,40 @@ var Account = class extends import_interfaces.AbstractAccount {
5423
5189
  * @param txParams - The optional transaction parameters.
5424
5190
  * @returns A promise that resolves to the transaction response.
5425
5191
  */
5426
- async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5427
- if ((0, import_math19.bn)(amount).lte(0)) {
5192
+ async transferToContract(contractId, amount, assetId, txParams = {}) {
5193
+ if ((0, import_math18.bn)(amount).lte(0)) {
5428
5194
  throw new import_errors16.FuelError(
5429
5195
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5430
5196
  "Transfer amount must be a positive number."
5431
5197
  );
5432
5198
  }
5433
5199
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5200
+ const { minGasPrice } = this.provider.getGasConfig();
5201
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5202
+ const params = { gasPrice: minGasPrice, ...txParams };
5434
5203
  const { script, scriptData } = await assembleTransferToContractScript({
5435
5204
  hexlifiedContractId: contractAddress.toB256(),
5436
- amountToTransfer: (0, import_math19.bn)(amount),
5437
- assetId
5205
+ amountToTransfer: (0, import_math18.bn)(amount),
5206
+ assetId: assetIdToTransfer
5438
5207
  });
5439
5208
  const request = new ScriptTransactionRequest({
5440
- ...txParams,
5209
+ ...params,
5441
5210
  script,
5442
5211
  scriptData
5443
5212
  });
5444
5213
  request.addContractInputAndOutput(contractAddress);
5445
- const txCost = await this.provider.getTransactionCost(request, {
5446
- resourcesOwner: this,
5447
- quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
5214
+ const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5215
+ request,
5216
+ [{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
5217
+ );
5218
+ request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5219
+ this.validateGas({
5220
+ gasUsed,
5221
+ gasPrice: request.gasPrice,
5222
+ gasLimit: request.gasLimit,
5223
+ minGasPrice
5448
5224
  });
5449
- if (txParams.gasLimit) {
5450
- this.validateGas({
5451
- gasUsed: txCost.gasUsed,
5452
- gasLimit: request.gasLimit
5453
- });
5454
- }
5455
- request.gasLimit = txCost.gasUsed;
5456
- request.maxFee = txCost.maxFee;
5457
- await this.fund(request, txCost);
5225
+ await this.fund(request, requiredQuantities, maxFee);
5458
5226
  return this.sendTransaction(request);
5459
5227
  }
5460
5228
  /**
@@ -5466,31 +5234,35 @@ var Account = class extends import_interfaces.AbstractAccount {
5466
5234
  * @returns A promise that resolves to the transaction response.
5467
5235
  */
5468
5236
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5237
+ const { minGasPrice } = this.provider.getGasConfig();
5238
+ const baseAssetId = this.provider.getBaseAssetId();
5469
5239
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5470
- const recipientDataArray = (0, import_utils27.arrayify)(
5240
+ const recipientDataArray = (0, import_utils28.arrayify)(
5471
5241
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5472
5242
  );
5473
- const amountDataArray = (0, import_utils27.arrayify)(
5474
- "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
5243
+ const amountDataArray = (0, import_utils28.arrayify)(
5244
+ "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5475
5245
  );
5476
5246
  const script = new Uint8Array([
5477
- ...(0, import_utils27.arrayify)(withdrawScript.bytes),
5247
+ ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5478
5248
  ...recipientDataArray,
5479
5249
  ...amountDataArray
5480
5250
  ]);
5481
- const params = { script, ...txParams };
5251
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5482
5252
  const request = new ScriptTransactionRequest(params);
5483
- const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5484
- const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5485
- if (txParams.gasLimit) {
5486
- this.validateGas({
5487
- gasUsed: txCost.gasUsed,
5488
- gasLimit: request.gasLimit
5489
- });
5490
- }
5491
- request.maxFee = txCost.maxFee;
5492
- request.gasLimit = txCost.gasUsed;
5493
- await this.fund(request, txCost);
5253
+ const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
5254
+ const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5255
+ request,
5256
+ forwardingQuantities
5257
+ );
5258
+ request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5259
+ this.validateGas({
5260
+ gasUsed,
5261
+ gasPrice: request.gasPrice,
5262
+ gasLimit: request.gasLimit,
5263
+ minGasPrice
5264
+ });
5265
+ await this.fund(request, requiredQuantities, maxFee);
5494
5266
  return this.sendTransaction(request);
5495
5267
  }
5496
5268
  async signMessage(message) {
@@ -5548,7 +5320,18 @@ var Account = class extends import_interfaces.AbstractAccount {
5548
5320
  }
5549
5321
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5550
5322
  }
5551
- validateGas({ gasUsed, gasLimit }) {
5323
+ validateGas({
5324
+ gasUsed,
5325
+ gasPrice,
5326
+ gasLimit,
5327
+ minGasPrice
5328
+ }) {
5329
+ if (minGasPrice.gt(gasPrice)) {
5330
+ throw new import_errors16.FuelError(
5331
+ import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
5332
+ `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5333
+ );
5334
+ }
5552
5335
  if (gasUsed.gt(gasLimit)) {
5553
5336
  throw new import_errors16.FuelError(
5554
5337
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -5560,14 +5343,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5560
5343
 
5561
5344
  // src/wallet/base-wallet-unlocked.ts
5562
5345
  var import_hasher3 = require("@fuel-ts/hasher");
5563
- var import_utils30 = require("@fuel-ts/utils");
5346
+ var import_utils31 = require("@fuel-ts/utils");
5564
5347
 
5565
5348
  // src/signer/signer.ts
5566
5349
  var import_address5 = require("@fuel-ts/address");
5567
5350
  var import_crypto = require("@fuel-ts/crypto");
5568
5351
  var import_hasher2 = require("@fuel-ts/hasher");
5569
- var import_math20 = require("@fuel-ts/math");
5570
- var import_utils28 = require("@fuel-ts/utils");
5352
+ var import_math19 = require("@fuel-ts/math");
5353
+ var import_utils29 = require("@fuel-ts/utils");
5571
5354
  var import_secp256k1 = require("@noble/curves/secp256k1");
5572
5355
  var Signer = class {
5573
5356
  address;
@@ -5586,10 +5369,10 @@ var Signer = class {
5586
5369
  privateKey = `0x${privateKey}`;
5587
5370
  }
5588
5371
  }
5589
- const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5590
- this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5591
- this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5592
- this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5372
+ const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
5373
+ this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5374
+ this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5375
+ this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5593
5376
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5594
5377
  }
5595
5378
  /**
@@ -5603,11 +5386,11 @@ var Signer = class {
5603
5386
  * @returns hashed signature
5604
5387
  */
5605
5388
  sign(data) {
5606
- const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5607
- const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5608
- const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
5389
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5390
+ const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
5391
+ const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5609
5392
  s[0] |= (signature.recovery || 0) << 7;
5610
- return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5393
+ return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5611
5394
  }
5612
5395
  /**
5613
5396
  * Add point on the current elliptic curve
@@ -5616,8 +5399,8 @@ var Signer = class {
5616
5399
  * @returns compressed point on the curve
5617
5400
  */
5618
5401
  addPoint(point) {
5619
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5620
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
5402
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5403
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5621
5404
  const result = p0.add(p1);
5622
5405
  return `0x${result.toHex(true)}`;
5623
5406
  }
@@ -5629,16 +5412,16 @@ var Signer = class {
5629
5412
  * @returns public key from signature from the
5630
5413
  */
5631
5414
  static recoverPublicKey(data, signature) {
5632
- const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5415
+ const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5633
5416
  const r = signedMessageBytes.slice(0, 32);
5634
5417
  const s = signedMessageBytes.slice(32, 64);
5635
5418
  const recoveryParam = (s[0] & 128) >> 7;
5636
5419
  s[0] &= 127;
5637
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5420
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5638
5421
  recoveryParam
5639
5422
  );
5640
- const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5641
- return (0, import_utils28.hexlify)(publicKey);
5423
+ const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5424
+ return (0, import_utils29.hexlify)(publicKey);
5642
5425
  }
5643
5426
  /**
5644
5427
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5657,7 +5440,7 @@ var Signer = class {
5657
5440
  * @returns random 32-byte hashed
5658
5441
  */
5659
5442
  static generatePrivateKey(entropy) {
5660
- return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
5443
+ 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);
5661
5444
  }
5662
5445
  /**
5663
5446
  * Extended publicKey from a compact publicKey
@@ -5666,8 +5449,8 @@ var Signer = class {
5666
5449
  * @returns extended publicKey
5667
5450
  */
5668
5451
  static extendPublicKey(publicKey) {
5669
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5670
- return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5452
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5453
+ return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5671
5454
  }
5672
5455
  };
5673
5456
 
@@ -5675,7 +5458,7 @@ var Signer = class {
5675
5458
  var import_address6 = require("@fuel-ts/address");
5676
5459
  var import_crypto2 = require("@fuel-ts/crypto");
5677
5460
  var import_errors17 = require("@fuel-ts/errors");
5678
- var import_utils29 = require("@fuel-ts/utils");
5461
+ var import_utils30 = require("@fuel-ts/utils");
5679
5462
  var import_uuid = require("uuid");
5680
5463
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5681
5464
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5758,7 +5541,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5758
5541
  );
5759
5542
  }
5760
5543
  const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5761
- const privateKey = (0, import_utils29.hexlify)(buffer);
5544
+ const privateKey = (0, import_utils30.hexlify)(buffer);
5762
5545
  return privateKey;
5763
5546
  }
5764
5547
 
@@ -5803,7 +5586,7 @@ var BaseWalletUnlocked = class extends Account {
5803
5586
  */
5804
5587
  async signMessage(message) {
5805
5588
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5806
- return (0, import_utils30.hexlify)(signedMessage);
5589
+ return (0, import_utils31.hexlify)(signedMessage);
5807
5590
  }
5808
5591
  /**
5809
5592
  * Signs a transaction with the wallet's private key.
@@ -5816,7 +5599,7 @@ var BaseWalletUnlocked = class extends Account {
5816
5599
  const chainId = this.provider.getChainId();
5817
5600
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5818
5601
  const signature = await this.signer().sign(hashedTransaction);
5819
- return (0, import_utils30.hexlify)(signature);
5602
+ return (0, import_utils31.hexlify)(signature);
5820
5603
  }
5821
5604
  /**
5822
5605
  * Populates a transaction with the witnesses signature.
@@ -5836,7 +5619,7 @@ var BaseWalletUnlocked = class extends Account {
5836
5619
  * @param transactionRequestLike - The transaction request to send.
5837
5620
  * @returns A promise that resolves to the TransactionResponse object.
5838
5621
  */
5839
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5622
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5840
5623
  const transactionRequest = transactionRequestify(transactionRequestLike);
5841
5624
  if (estimateTxDependencies) {
5842
5625
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5877,16 +5660,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5877
5660
  // src/hdwallet/hdwallet.ts
5878
5661
  var import_errors20 = require("@fuel-ts/errors");
5879
5662
  var import_hasher6 = require("@fuel-ts/hasher");
5880
- var import_math21 = require("@fuel-ts/math");
5881
- var import_utils34 = require("@fuel-ts/utils");
5882
- var import_ethers4 = require("ethers");
5663
+ var import_math20 = require("@fuel-ts/math");
5664
+ var import_utils35 = require("@fuel-ts/utils");
5665
+ var import_ethers3 = require("ethers");
5883
5666
 
5884
5667
  // src/mnemonic/mnemonic.ts
5885
5668
  var import_crypto3 = require("@fuel-ts/crypto");
5886
5669
  var import_errors19 = require("@fuel-ts/errors");
5887
5670
  var import_hasher5 = require("@fuel-ts/hasher");
5888
- var import_utils32 = require("@fuel-ts/utils");
5889
- var import_ethers3 = require("ethers");
5671
+ var import_utils33 = require("@fuel-ts/utils");
5672
+ var import_ethers2 = require("ethers");
5890
5673
 
5891
5674
  // src/wordlists/words/english.ts
5892
5675
  var english = [
@@ -7949,7 +7732,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
7949
7732
  // src/mnemonic/utils.ts
7950
7733
  var import_errors18 = require("@fuel-ts/errors");
7951
7734
  var import_hasher4 = require("@fuel-ts/hasher");
7952
- var import_utils31 = require("@fuel-ts/utils");
7735
+ var import_utils32 = require("@fuel-ts/utils");
7953
7736
  function toUtf8Bytes(stri) {
7954
7737
  const str = stri.normalize("NFKD");
7955
7738
  const result = [];
@@ -8016,14 +7799,14 @@ function entropyToMnemonicIndices(entropy) {
8016
7799
  }
8017
7800
  }
8018
7801
  const checksumBits = entropy.length / 4;
8019
- const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7802
+ const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8020
7803
  indices[indices.length - 1] <<= checksumBits;
8021
7804
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
8022
7805
  return indices;
8023
7806
  }
8024
7807
  function mnemonicWordsToEntropy(words, wordlist) {
8025
7808
  const size = Math.ceil(11 * words.length / 8);
8026
- const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7809
+ const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
8027
7810
  let offset = 0;
8028
7811
  for (let i = 0; i < words.length; i += 1) {
8029
7812
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -8043,7 +7826,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
8043
7826
  const entropyBits = 32 * words.length / 3;
8044
7827
  const checksumBits = words.length / 3;
8045
7828
  const checksumMask = getUpperMask(checksumBits);
8046
- const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7829
+ const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8047
7830
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
8048
7831
  throw new import_errors18.FuelError(
8049
7832
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -8118,7 +7901,7 @@ var Mnemonic = class {
8118
7901
  static mnemonicToEntropy(phrase, wordlist = english) {
8119
7902
  const words = getWords(phrase);
8120
7903
  assertMnemonic(words);
8121
- return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7904
+ return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8122
7905
  }
8123
7906
  /**
8124
7907
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -8126,7 +7909,7 @@ var Mnemonic = class {
8126
7909
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8127
7910
  */
8128
7911
  static entropyToMnemonic(entropy, wordlist = english) {
8129
- const entropyBytes = (0, import_utils32.arrayify)(entropy);
7912
+ const entropyBytes = (0, import_utils33.arrayify)(entropy);
8130
7913
  assertWordList(wordlist);
8131
7914
  assertEntropy(entropyBytes);
8132
7915
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -8140,7 +7923,7 @@ var Mnemonic = class {
8140
7923
  assertMnemonic(getWords(phrase));
8141
7924
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
8142
7925
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
8143
- return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7926
+ return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8144
7927
  }
8145
7928
  /**
8146
7929
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -8195,14 +7978,14 @@ var Mnemonic = class {
8195
7978
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8196
7979
  */
8197
7980
  static masterKeysFromSeed(seed) {
8198
- const seedArray = (0, import_utils32.arrayify)(seed);
7981
+ const seedArray = (0, import_utils33.arrayify)(seed);
8199
7982
  if (seedArray.length < 16 || seedArray.length > 64) {
8200
7983
  throw new import_errors19.FuelError(
8201
7984
  import_errors19.ErrorCode.INVALID_SEED,
8202
7985
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
8203
7986
  );
8204
7987
  }
8205
- return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
7988
+ return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
8206
7989
  }
8207
7990
  /**
8208
7991
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8213,22 +7996,22 @@ var Mnemonic = class {
8213
7996
  */
8214
7997
  static seedToExtendedKey(seed, testnet = false) {
8215
7998
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8216
- const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7999
+ const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8217
8000
  const depth = "0x00";
8218
8001
  const fingerprint = "0x00000000";
8219
8002
  const index = "0x00000000";
8220
8003
  const chainCode = masterKey.slice(32);
8221
8004
  const privateKey = masterKey.slice(0, 32);
8222
- const extendedKey = (0, import_utils32.concat)([
8005
+ const extendedKey = (0, import_utils33.concat)([
8223
8006
  prefix,
8224
8007
  depth,
8225
8008
  fingerprint,
8226
8009
  index,
8227
8010
  chainCode,
8228
- (0, import_utils32.concat)(["0x00", privateKey])
8011
+ (0, import_utils33.concat)(["0x00", privateKey])
8229
8012
  ]);
8230
- const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8231
- return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
8013
+ const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8014
+ return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8232
8015
  }
8233
8016
  /**
8234
8017
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8243,7 +8026,7 @@ var Mnemonic = class {
8243
8026
  * @returns A randomly generated mnemonic
8244
8027
  */
8245
8028
  static generate(size = 32, extraEntropy = "") {
8246
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
8029
+ 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);
8247
8030
  return Mnemonic.entropyToMnemonic(entropy);
8248
8031
  }
8249
8032
  };
@@ -8251,12 +8034,12 @@ var mnemonic_default = Mnemonic;
8251
8034
 
8252
8035
  // src/hdwallet/hdwallet.ts
8253
8036
  var HARDENED_INDEX = 2147483648;
8254
- var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
8255
- var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
8256
- var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
8257
- var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
8037
+ var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8038
+ var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8039
+ var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8040
+ var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8258
8041
  function base58check(data) {
8259
- return (0, import_ethers4.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8042
+ 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)]));
8260
8043
  }
8261
8044
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8262
8045
  if (isPublic) {
@@ -8265,11 +8048,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8265
8048
  return testnet ? TestnetPRV2 : MainnetPRV2;
8266
8049
  }
8267
8050
  function isPublicExtendedKey(extendedKey) {
8268
- return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
8051
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8269
8052
  }
8270
8053
  function isValidExtendedKey(extendedKey) {
8271
8054
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8272
- (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
8055
+ (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8273
8056
  );
8274
8057
  }
8275
8058
  function parsePath(path, depth = 0) {
@@ -8287,8 +8070,8 @@ function parsePath(path, depth = 0) {
8287
8070
  var HDWallet = class {
8288
8071
  depth = 0;
8289
8072
  index = 0;
8290
- fingerprint = (0, import_utils34.hexlify)("0x00000000");
8291
- parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
8073
+ fingerprint = (0, import_utils35.hexlify)("0x00000000");
8074
+ parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8292
8075
  privateKey;
8293
8076
  publicKey;
8294
8077
  chainCode;
@@ -8300,8 +8083,8 @@ var HDWallet = class {
8300
8083
  constructor(config) {
8301
8084
  if (config.privateKey) {
8302
8085
  const signer = new Signer(config.privateKey);
8303
- this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
8304
- this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
8086
+ this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8087
+ this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8305
8088
  } else {
8306
8089
  if (!config.publicKey) {
8307
8090
  throw new import_errors20.FuelError(
@@ -8309,10 +8092,10 @@ var HDWallet = class {
8309
8092
  "Both public and private Key cannot be missing. At least one should be provided."
8310
8093
  );
8311
8094
  }
8312
- this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
8095
+ this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8313
8096
  }
8314
8097
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8315
- this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8098
+ this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8316
8099
  this.depth = config.depth || this.depth;
8317
8100
  this.index = config.index || this.index;
8318
8101
  this.chainCode = config.chainCode;
@@ -8328,9 +8111,9 @@ var HDWallet = class {
8328
8111
  * @returns A new instance of HDWallet on the derived index
8329
8112
  */
8330
8113
  deriveIndex(index) {
8331
- const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
8332
- const publicKey = (0, import_utils34.arrayify)(this.publicKey);
8333
- const chainCode = (0, import_utils34.arrayify)(this.chainCode);
8114
+ const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8115
+ const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8116
+ const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8334
8117
  const data = new Uint8Array(37);
8335
8118
  if (index & HARDENED_INDEX) {
8336
8119
  if (!privateKey) {
@@ -8341,15 +8124,15 @@ var HDWallet = class {
8341
8124
  }
8342
8125
  data.set(privateKey, 1);
8343
8126
  } else {
8344
- data.set((0, import_utils34.arrayify)(this.publicKey));
8127
+ data.set((0, import_utils35.arrayify)(this.publicKey));
8345
8128
  }
8346
- data.set((0, import_math21.toBytes)(index, 4), 33);
8347
- const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
8129
+ data.set((0, import_math20.toBytes)(index, 4), 33);
8130
+ const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8348
8131
  const IL = bytes.slice(0, 32);
8349
8132
  const IR = bytes.slice(32);
8350
8133
  if (privateKey) {
8351
8134
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8352
- const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
8135
+ const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
8353
8136
  return new HDWallet({
8354
8137
  privateKey: ki,
8355
8138
  chainCode: IR,
@@ -8358,7 +8141,7 @@ var HDWallet = class {
8358
8141
  parentFingerprint: this.fingerprint
8359
8142
  });
8360
8143
  }
8361
- const signer = new Signer((0, import_utils34.hexlify)(IL));
8144
+ const signer = new Signer((0, import_utils35.hexlify)(IL));
8362
8145
  const Ki = signer.addPoint(publicKey);
8363
8146
  return new HDWallet({
8364
8147
  publicKey: Ki,
@@ -8393,12 +8176,12 @@ var HDWallet = class {
8393
8176
  );
8394
8177
  }
8395
8178
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8396
- const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8179
+ const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8397
8180
  const parentFingerprint = this.parentFingerprint;
8398
- const index = (0, import_math21.toHex)(this.index, 4);
8181
+ const index = (0, import_math20.toHex)(this.index, 4);
8399
8182
  const chainCode = this.chainCode;
8400
- const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8401
- const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8183
+ const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8184
+ const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8402
8185
  return base58check(extendedKey);
8403
8186
  }
8404
8187
  /**
@@ -8410,13 +8193,13 @@ var HDWallet = class {
8410
8193
  static fromSeed(seed) {
8411
8194
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8412
8195
  return new HDWallet({
8413
- chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8414
- privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
8196
+ chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8197
+ privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8415
8198
  });
8416
8199
  }
8417
8200
  static fromExtendedKey(extendedKey) {
8418
- const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
8419
- const bytes = (0, import_utils34.arrayify)(decoded);
8201
+ const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8202
+ const bytes = (0, import_utils35.arrayify)(decoded);
8420
8203
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8421
8204
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8422
8205
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8425,9 +8208,9 @@ var HDWallet = class {
8425
8208
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8426
8209
  }
8427
8210
  const depth = bytes[4];
8428
- const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8429
- const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8430
- const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
8211
+ const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8212
+ const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8213
+ const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8431
8214
  const key = bytes.slice(45, 78);
8432
8215
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8433
8216
  throw new import_errors20.FuelError(
@@ -9030,21 +8813,20 @@ var StorageAbstract = class {
9030
8813
  // src/predicate/predicate.ts
9031
8814
  var import_abi_coder5 = require("@fuel-ts/abi-coder");
9032
8815
  var import_address10 = require("@fuel-ts/address");
9033
- var import_configs13 = require("@fuel-ts/address/configs");
9034
8816
  var import_errors25 = require("@fuel-ts/errors");
9035
- var import_transactions21 = require("@fuel-ts/transactions");
9036
- var import_utils36 = require("@fuel-ts/utils");
8817
+ var import_transactions20 = require("@fuel-ts/transactions");
8818
+ var import_utils37 = require("@fuel-ts/utils");
9037
8819
 
9038
8820
  // src/predicate/utils/getPredicateRoot.ts
9039
8821
  var import_hasher7 = require("@fuel-ts/hasher");
9040
8822
  var import_merkle = require("@fuel-ts/merkle");
9041
- var import_utils35 = require("@fuel-ts/utils");
8823
+ var import_utils36 = require("@fuel-ts/utils");
9042
8824
  var getPredicateRoot = (bytecode) => {
9043
8825
  const chunkSize = 16 * 1024;
9044
- const bytes = (0, import_utils35.arrayify)(bytecode);
9045
- const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
9046
- const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
9047
- const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
8826
+ const bytes = (0, import_utils36.arrayify)(bytecode);
8827
+ const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
8828
+ const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
8829
+ const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
9048
8830
  return predicateRoot;
9049
8831
  };
9050
8832
 
@@ -9081,7 +8863,6 @@ var Predicate = class extends Account {
9081
8863
  this.interface = predicateInterface;
9082
8864
  if (inputData !== void 0 && inputData.length > 0) {
9083
8865
  this.predicateData = inputData;
9084
- this.predicateDataBytes = this.getPredicateData(0);
9085
8866
  }
9086
8867
  }
9087
8868
  /**
@@ -9094,9 +8875,9 @@ var Predicate = class extends Account {
9094
8875
  const request = transactionRequestify(transactionRequestLike);
9095
8876
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
9096
8877
  request.inputs?.forEach((input) => {
9097
- if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
9098
- input.predicate = (0, import_utils36.hexlify)(this.bytes);
9099
- input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
8878
+ if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
8879
+ input.predicate = this.bytes;
8880
+ input.predicateData = this.getPredicateData(policies.length);
9100
8881
  }
9101
8882
  });
9102
8883
  return request;
@@ -9110,8 +8891,10 @@ var Predicate = class extends Account {
9110
8891
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
9111
8892
  * @returns A promise that resolves to the prepared transaction request.
9112
8893
  */
9113
- async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
9114
- return super.createTransfer(destination, amount, assetId, txParams);
8894
+ async createTransfer(destination, amount, assetId, txParams = {}) {
8895
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8896
+ const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8897
+ return this.populateTransactionPredicateData(request);
9115
8898
  }
9116
8899
  /**
9117
8900
  * Sends a transaction with the populated predicate data.
@@ -9119,9 +8902,9 @@ var Predicate = class extends Account {
9119
8902
  * @param transactionRequestLike - The transaction request-like object.
9120
8903
  * @returns A promise that resolves to the transaction response.
9121
8904
  */
9122
- sendTransaction(transactionRequestLike) {
9123
- const transactionRequest = transactionRequestify(transactionRequestLike);
9124
- return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8905
+ sendTransaction(transactionRequestLike, options) {
8906
+ const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8907
+ return super.sendTransaction(transactionRequest, options);
9125
8908
  }
9126
8909
  /**
9127
8910
  * Simulates a transaction with the populated predicate data.
@@ -9130,15 +8913,15 @@ var Predicate = class extends Account {
9130
8913
  * @returns A promise that resolves to the call result.
9131
8914
  */
9132
8915
  simulateTransaction(transactionRequestLike) {
9133
- const transactionRequest = transactionRequestify(transactionRequestLike);
9134
- return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8916
+ const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8917
+ return super.simulateTransaction(transactionRequest);
9135
8918
  }
9136
8919
  getPredicateData(policiesLength) {
9137
8920
  if (!this.predicateData.length) {
9138
8921
  return new Uint8Array();
9139
8922
  }
9140
8923
  const mainFn = this.interface?.functions.main;
9141
- const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
8924
+ const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
9142
8925
  const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
9143
8926
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
9144
8927
  });
@@ -9154,7 +8937,7 @@ var Predicate = class extends Account {
9154
8937
  * @returns An object containing the new predicate bytes and interface.
9155
8938
  */
9156
8939
  static processPredicateData(bytes, jsonAbi, configurableConstants) {
9157
- let predicateBytes = (0, import_utils36.arrayify)(bytes);
8940
+ let predicateBytes = (0, import_utils37.arrayify)(bytes);
9158
8941
  let abiInterface;
9159
8942
  if (jsonAbi) {
9160
8943
  abiInterface = new import_abi_coder5.Interface(jsonAbi);
@@ -9177,26 +8960,6 @@ var Predicate = class extends Account {
9177
8960
  predicateInterface: abiInterface
9178
8961
  };
9179
8962
  }
9180
- /**
9181
- * Retrieves resources satisfying the spend query for the account.
9182
- *
9183
- * @param quantities - IDs of coins to exclude.
9184
- * @param excludedIds - IDs of resources to be excluded from the query.
9185
- * @returns A promise that resolves to an array of Resources.
9186
- */
9187
- async getResourcesToSpend(quantities, excludedIds) {
9188
- const resources = await this.provider.getResourcesToSpend(
9189
- this.address,
9190
- quantities,
9191
- excludedIds
9192
- );
9193
- return resources.map((resource) => ({
9194
- ...resource,
9195
- predicate: (0, import_utils36.hexlify)(this.bytes),
9196
- predicateData: (0, import_utils36.hexlify)(this.predicateDataBytes),
9197
- paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
9198
- }));
9199
- }
9200
8963
  /**
9201
8964
  * Sets the configurable constants for the predicate.
9202
8965
  *
@@ -9946,7 +9709,7 @@ __publicField(Fuel, "defaultConfig", {});
9946
9709
  WalletLocked,
9947
9710
  WalletManager,
9948
9711
  WalletUnlocked,
9949
- addAmountToCoinQuantities,
9712
+ addAmountToAsset,
9950
9713
  addOperation,
9951
9714
  assemblePanicError,
9952
9715
  assembleReceiptByType,
@@ -9955,10 +9718,9 @@ __publicField(Fuel, "defaultConfig", {});
9955
9718
  assets,
9956
9719
  buildBlockExplorerUrl,
9957
9720
  cacheFor,
9958
- cacheTxInputsFromOwner,
9959
- calculateGasFee,
9960
9721
  calculateMetadataGasForTxCreate,
9961
9722
  calculateMetadataGasForTxScript,
9723
+ calculatePriceWithFactor,
9962
9724
  calculateTransactionFee,
9963
9725
  coinQuantityfy,
9964
9726
  deferPromise,