@fuel-ts/account 0.82.0 → 0.84.0

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 (76) hide show
  1. package/README.md +18 -15
  2. package/dist/account.d.ts +8 -7
  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 +2445 -2185
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +1074 -667
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +909 -505
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +12 -24
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +950 -376
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +3 -3
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +9 -3
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +72 -54
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/resource.d.ts +0 -1
  30. package/dist/providers/resource.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  32. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/helpers.d.ts +8 -0
  34. package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
  35. package/dist/providers/transaction-request/input.d.ts +2 -2
  36. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  37. package/dist/providers/transaction-request/script-transaction-request.d.ts +2 -3
  38. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  39. package/dist/providers/transaction-request/transaction-request.d.ts +17 -38
  40. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  41. package/dist/providers/transaction-request/utils.d.ts +4 -0
  42. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  43. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  44. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +4 -2
  45. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  46. package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts +20 -0
  47. package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts.map +1 -0
  48. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  49. package/dist/providers/transaction-summary/index.d.ts +1 -1
  50. package/dist/providers/transaction-summary/index.d.ts.map +1 -1
  51. package/dist/providers/transaction-summary/operations.d.ts +4 -0
  52. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  53. package/dist/providers/transaction-summary/status.d.ts +5 -1
  54. package/dist/providers/transaction-summary/status.d.ts.map +1 -1
  55. package/dist/providers/transaction-summary/types.d.ts +6 -1
  56. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  57. package/dist/providers/utils/gas.d.ts +14 -7
  58. package/dist/providers/utils/gas.d.ts.map +1 -1
  59. package/dist/providers/utils/merge-quantities.d.ts +1 -1
  60. package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
  61. package/dist/test-utils/launchNode.d.ts +1 -1
  62. package/dist/test-utils/launchNode.d.ts.map +1 -1
  63. package/dist/test-utils/resources.d.ts +4 -0
  64. package/dist/test-utils/resources.d.ts.map +1 -0
  65. package/dist/test-utils/transactionRequest.d.ts +5 -0
  66. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  67. package/dist/test-utils.global.js +3171 -2680
  68. package/dist/test-utils.global.js.map +1 -1
  69. package/dist/test-utils.js +1046 -655
  70. package/dist/test-utils.js.map +1 -1
  71. package/dist/test-utils.mjs +896 -505
  72. package/dist/test-utils.mjs.map +1 -1
  73. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  74. package/package.json +18 -18
  75. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +0 -21
  76. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -29,37 +29,36 @@ var __privateMethod = (obj, member, method) => {
29
29
 
30
30
  // src/account.ts
31
31
  import { Address as Address3 } from "@fuel-ts/address";
32
- import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
33
32
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
34
33
  import { AbstractAccount } from "@fuel-ts/interfaces";
35
- import { bn as bn17 } from "@fuel-ts/math";
36
- import { arrayify as arrayify14 } from "@fuel-ts/utils";
34
+ import { bn as bn20 } from "@fuel-ts/math";
35
+ import { arrayify as arrayify14, isDefined as isDefined2 } from "@fuel-ts/utils";
36
+ import { clone as clone4 } from "ramda";
37
37
 
38
38
  // src/providers/coin-quantity.ts
39
- import { BaseAssetId } from "@fuel-ts/address/configs";
40
39
  import { bn } from "@fuel-ts/math";
41
40
  import { hexlify } from "@fuel-ts/utils";
42
41
  var coinQuantityfy = (coinQuantityLike) => {
43
42
  let assetId;
44
43
  let amount;
45
- let max2;
44
+ let max;
46
45
  if (Array.isArray(coinQuantityLike)) {
47
46
  amount = coinQuantityLike[0];
48
- assetId = coinQuantityLike[1] ?? BaseAssetId;
49
- max2 = coinQuantityLike[2] ?? void 0;
47
+ assetId = coinQuantityLike[1];
48
+ max = coinQuantityLike[2] ?? void 0;
50
49
  } else {
51
50
  amount = coinQuantityLike.amount;
52
- assetId = coinQuantityLike.assetId ?? BaseAssetId;
53
- max2 = coinQuantityLike.max ?? void 0;
51
+ assetId = coinQuantityLike.assetId;
52
+ max = coinQuantityLike.max ?? void 0;
54
53
  }
55
54
  const bnAmount = bn(amount);
56
55
  return {
57
56
  assetId: hexlify(assetId),
58
57
  amount: bnAmount.lt(1) ? bn(1) : bnAmount,
59
- max: max2 ? bn(max2) : void 0
58
+ max: max ? bn(max) : void 0
60
59
  };
61
60
  };
62
- var addAmountToAsset = (params) => {
61
+ var addAmountToCoinQuantities = (params) => {
63
62
  const { amount, assetId } = params;
64
63
  const coinQuantities = [...params.coinQuantities];
65
64
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -74,9 +73,9 @@ var addAmountToAsset = (params) => {
74
73
  // src/providers/provider.ts
75
74
  import { Address as Address2 } from "@fuel-ts/address";
76
75
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
77
- import { BN, bn as bn15, max } from "@fuel-ts/math";
76
+ import { BN, bn as bn17 } from "@fuel-ts/math";
78
77
  import {
79
- InputType as InputType6,
78
+ InputType as InputType7,
80
79
  TransactionType as TransactionType8,
81
80
  InputMessageCoder,
82
81
  TransactionCoder as TransactionCoder5
@@ -84,22 +83,25 @@ import {
84
83
  import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
85
84
  import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
86
85
  import { equalBytes } from "@noble/curves/abstract/utils";
87
- import { Network } from "ethers";
88
86
  import { GraphQLClient } from "graphql-request";
89
87
  import { clone as clone3 } from "ramda";
90
88
 
91
89
  // src/providers/__generated__/operations.ts
92
90
  import gql from "graphql-tag";
91
+ var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
92
+ fragment transactionStatusSubscriptionFragment on TransactionStatus {
93
+ type: __typename
94
+ ... on SqueezedOutStatus {
95
+ reason
96
+ }
97
+ }
98
+ `;
93
99
  var ReceiptFragmentFragmentDoc = gql`
94
100
  fragment receiptFragment on Receipt {
95
- contract {
96
- id
97
- }
101
+ id
98
102
  pc
99
103
  is
100
- to {
101
- id
102
- }
104
+ to
103
105
  toAddress
104
106
  amount
105
107
  assetId
@@ -141,33 +143,38 @@ var TransactionStatusFragmentFragmentDoc = gql`
141
143
  returnType
142
144
  data
143
145
  }
146
+ receipts {
147
+ ...receiptFragment
148
+ }
149
+ totalGas
150
+ totalFee
144
151
  }
145
152
  ... on FailureStatus {
146
153
  block {
147
154
  id
148
155
  }
156
+ totalGas
157
+ totalFee
149
158
  time
150
159
  reason
160
+ receipts {
161
+ ...receiptFragment
162
+ }
151
163
  }
152
164
  ... on SqueezedOutStatus {
153
165
  reason
154
166
  }
155
167
  }
156
- `;
168
+ ${ReceiptFragmentFragmentDoc}`;
157
169
  var TransactionFragmentFragmentDoc = gql`
158
170
  fragment transactionFragment on Transaction {
159
171
  id
160
172
  rawPayload
161
- gasPrice
162
- receipts {
163
- ...receiptFragment
164
- }
165
173
  status {
166
174
  ...transactionStatusFragment
167
175
  }
168
176
  }
169
- ${ReceiptFragmentFragmentDoc}
170
- ${TransactionStatusFragmentFragmentDoc}`;
177
+ ${TransactionStatusFragmentFragmentDoc}`;
171
178
  var InputEstimatePredicatesFragmentFragmentDoc = gql`
172
179
  fragment inputEstimatePredicatesFragment on Input {
173
180
  ... on InputCoin {
@@ -185,6 +192,50 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
185
192
  }
186
193
  }
187
194
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
195
+ var DryRunFailureStatusFragmentFragmentDoc = gql`
196
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
197
+ totalGas
198
+ totalFee
199
+ reason
200
+ programState {
201
+ returnType
202
+ data
203
+ }
204
+ }
205
+ `;
206
+ var DryRunSuccessStatusFragmentFragmentDoc = gql`
207
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
208
+ totalGas
209
+ totalFee
210
+ programState {
211
+ returnType
212
+ data
213
+ }
214
+ }
215
+ `;
216
+ var DryRunTransactionStatusFragmentFragmentDoc = gql`
217
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
218
+ ... on DryRunFailureStatus {
219
+ ...dryRunFailureStatusFragment
220
+ }
221
+ ... on DryRunSuccessStatus {
222
+ ...dryRunSuccessStatusFragment
223
+ }
224
+ }
225
+ ${DryRunFailureStatusFragmentFragmentDoc}
226
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
227
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
228
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
229
+ id
230
+ status {
231
+ ...dryRunTransactionStatusFragment
232
+ }
233
+ receipts {
234
+ ...receiptFragment
235
+ }
236
+ }
237
+ ${DryRunTransactionStatusFragmentFragmentDoc}
238
+ ${ReceiptFragmentFragmentDoc}`;
188
239
  var CoinFragmentFragmentDoc = gql`
189
240
  fragment coinFragment on Coin {
190
241
  __typename
@@ -192,7 +243,6 @@ var CoinFragmentFragmentDoc = gql`
192
243
  owner
193
244
  amount
194
245
  assetId
195
- maturity
196
246
  blockCreated
197
247
  txCreatedIdx
198
248
  }
@@ -231,26 +281,32 @@ var MessageProofFragmentFragmentDoc = gql`
231
281
  messageBlockHeader {
232
282
  id
233
283
  daHeight
284
+ consensusParametersVersion
285
+ stateTransitionBytecodeVersion
234
286
  transactionsCount
287
+ messageReceiptCount
235
288
  transactionsRoot
289
+ messageOutboxRoot
290
+ eventInboxRoot
236
291
  height
237
292
  prevRoot
238
293
  time
239
294
  applicationHash
240
- messageReceiptRoot
241
- messageReceiptCount
242
295
  }
243
296
  commitBlockHeader {
244
297
  id
245
298
  daHeight
299
+ consensusParametersVersion
300
+ stateTransitionBytecodeVersion
246
301
  transactionsCount
302
+ messageReceiptCount
247
303
  transactionsRoot
304
+ messageOutboxRoot
305
+ eventInboxRoot
248
306
  height
249
307
  prevRoot
250
308
  time
251
309
  applicationHash
252
- messageReceiptRoot
253
- messageReceiptCount
254
310
  }
255
311
  sender
256
312
  recipient
@@ -269,8 +325,8 @@ var BalanceFragmentFragmentDoc = gql`
269
325
  var BlockFragmentFragmentDoc = gql`
270
326
  fragment blockFragment on Block {
271
327
  id
328
+ height
272
329
  header {
273
- height
274
330
  time
275
331
  }
276
332
  transactions {
@@ -280,15 +336,18 @@ var BlockFragmentFragmentDoc = gql`
280
336
  `;
281
337
  var TxParametersFragmentFragmentDoc = gql`
282
338
  fragment TxParametersFragment on TxParameters {
339
+ version
283
340
  maxInputs
284
341
  maxOutputs
285
342
  maxWitnesses
286
343
  maxGasPerTx
287
344
  maxSize
345
+ maxBytecodeSubsections
288
346
  }
289
347
  `;
290
348
  var PredicateParametersFragmentFragmentDoc = gql`
291
349
  fragment PredicateParametersFragment on PredicateParameters {
350
+ version
292
351
  maxPredicateLength
293
352
  maxPredicateDataLength
294
353
  maxGasPerPredicate
@@ -297,18 +356,21 @@ var PredicateParametersFragmentFragmentDoc = gql`
297
356
  `;
298
357
  var ScriptParametersFragmentFragmentDoc = gql`
299
358
  fragment ScriptParametersFragment on ScriptParameters {
359
+ version
300
360
  maxScriptLength
301
361
  maxScriptDataLength
302
362
  }
303
363
  `;
304
364
  var ContractParametersFragmentFragmentDoc = gql`
305
365
  fragment ContractParametersFragment on ContractParameters {
366
+ version
306
367
  contractMaxSize
307
368
  maxStorageSlots
308
369
  }
309
370
  `;
310
371
  var FeeParametersFragmentFragmentDoc = gql`
311
372
  fragment FeeParametersFragment on FeeParameters {
373
+ version
312
374
  gasPriceFactor
313
375
  gasPerByte
314
376
  }
@@ -328,6 +390,7 @@ var DependentCostFragmentFragmentDoc = gql`
328
390
  `;
329
391
  var GasCostsFragmentFragmentDoc = gql`
330
392
  fragment GasCostsFragment on GasCosts {
393
+ version
331
394
  add
332
395
  addi
333
396
  aloc
@@ -340,7 +403,6 @@ var GasCostsFragmentFragmentDoc = gql`
340
403
  cb
341
404
  cfei
342
405
  cfsi
343
- croo
344
406
  div
345
407
  divi
346
408
  ecr1
@@ -423,6 +485,9 @@ var GasCostsFragmentFragmentDoc = gql`
423
485
  ccp {
424
486
  ...DependentCostFragment
425
487
  }
488
+ croo {
489
+ ...DependentCostFragment
490
+ }
426
491
  csiz {
427
492
  ...DependentCostFragment
428
493
  }
@@ -482,6 +547,7 @@ var GasCostsFragmentFragmentDoc = gql`
482
547
  ${DependentCostFragmentFragmentDoc}`;
483
548
  var ConsensusParametersFragmentFragmentDoc = gql`
484
549
  fragment consensusParametersFragment on ConsensusParameters {
550
+ version
485
551
  txParams {
486
552
  ...TxParametersFragment
487
553
  }
@@ -541,17 +607,16 @@ var NodeInfoFragmentFragmentDoc = gql`
541
607
  fragment nodeInfoFragment on NodeInfo {
542
608
  utxoValidation
543
609
  vmBacktrace
544
- minGasPrice
545
610
  maxTx
546
611
  maxDepth
547
612
  nodeVersion
548
- peers {
549
- id
550
- addresses
551
- clientVersion
613
+ }
614
+ `;
615
+ var RelayedTransactionStatusFragmentFragmentDoc = gql`
616
+ fragment relayedTransactionStatusFragment on RelayedTransactionStatus {
617
+ ... on RelayedTransactionFailed {
552
618
  blockHeight
553
- lastHeartbeatMs
554
- appScore
619
+ failure
555
620
  }
556
621
  }
557
622
  `;
@@ -587,13 +652,9 @@ var GetTransactionWithReceiptsDocument = gql`
587
652
  query getTransactionWithReceipts($transactionId: TransactionId!) {
588
653
  transaction(id: $transactionId) {
589
654
  ...transactionFragment
590
- receipts {
591
- ...receiptFragment
592
- }
593
655
  }
594
656
  }
595
- ${TransactionFragmentFragmentDoc}
596
- ${ReceiptFragmentFragmentDoc}`;
657
+ ${TransactionFragmentFragmentDoc}`;
597
658
  var GetTransactionsDocument = gql`
598
659
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
599
660
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -721,6 +782,20 @@ var GetBalanceDocument = gql`
721
782
  }
722
783
  }
723
784
  ${BalanceFragmentFragmentDoc}`;
785
+ var GetLatestGasPriceDocument = gql`
786
+ query getLatestGasPrice {
787
+ latestGasPrice {
788
+ gasPrice
789
+ }
790
+ }
791
+ `;
792
+ var EstimateGasPriceDocument = gql`
793
+ query estimateGasPrice($blockHorizon: U32!) {
794
+ estimateGasPrice(blockHorizon: $blockHorizon) {
795
+ gasPrice
796
+ }
797
+ }
798
+ `;
724
799
  var GetBalancesDocument = gql`
725
800
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
726
801
  balances(
@@ -774,13 +849,20 @@ var GetMessageStatusDocument = gql`
774
849
  }
775
850
  }
776
851
  `;
852
+ var GetRelayedTransactionStatusDocument = gql`
853
+ query getRelayedTransactionStatus($relayedTransactionId: RelayedTransactionId!) {
854
+ relayedTransactionStatus(id: $relayedTransactionId) {
855
+ ...relayedTransactionStatusFragment
856
+ }
857
+ }
858
+ ${RelayedTransactionStatusFragmentFragmentDoc}`;
777
859
  var DryRunDocument = gql`
778
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
779
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
780
- ...receiptFragment
860
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
861
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
862
+ ...dryRunTransactionExecutionStatusFragment
781
863
  }
782
864
  }
783
- ${ReceiptFragmentFragmentDoc}`;
865
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
784
866
  var SubmitDocument = gql`
785
867
  mutation submit($encodedTransaction: HexString!) {
786
868
  submit(tx: $encodedTransaction) {
@@ -796,20 +878,27 @@ var ProduceBlocksDocument = gql`
796
878
  )
797
879
  }
798
880
  `;
881
+ var GetMessageByNonceDocument = gql`
882
+ query getMessageByNonce($nonce: Nonce!) {
883
+ message(nonce: $nonce) {
884
+ ...messageFragment
885
+ }
886
+ }
887
+ ${MessageFragmentFragmentDoc}`;
799
888
  var SubmitAndAwaitDocument = gql`
800
889
  subscription submitAndAwait($encodedTransaction: HexString!) {
801
890
  submitAndAwait(tx: $encodedTransaction) {
802
- ...transactionStatusFragment
891
+ ...transactionStatusSubscriptionFragment
803
892
  }
804
893
  }
805
- ${TransactionStatusFragmentFragmentDoc}`;
894
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
806
895
  var StatusChangeDocument = gql`
807
896
  subscription statusChange($transactionId: TransactionId!) {
808
897
  statusChange(id: $transactionId) {
809
- ...transactionStatusFragment
898
+ ...transactionStatusSubscriptionFragment
810
899
  }
811
900
  }
812
- ${TransactionStatusFragmentFragmentDoc}`;
901
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
813
902
  function getSdk(requester) {
814
903
  return {
815
904
  getVersion(variables, options) {
@@ -863,6 +952,12 @@ function getSdk(requester) {
863
952
  getBalance(variables, options) {
864
953
  return requester(GetBalanceDocument, variables, options);
865
954
  },
955
+ getLatestGasPrice(variables, options) {
956
+ return requester(GetLatestGasPriceDocument, variables, options);
957
+ },
958
+ estimateGasPrice(variables, options) {
959
+ return requester(EstimateGasPriceDocument, variables, options);
960
+ },
866
961
  getBalances(variables, options) {
867
962
  return requester(GetBalancesDocument, variables, options);
868
963
  },
@@ -875,6 +970,9 @@ function getSdk(requester) {
875
970
  getMessageStatus(variables, options) {
876
971
  return requester(GetMessageStatusDocument, variables, options);
877
972
  },
973
+ getRelayedTransactionStatus(variables, options) {
974
+ return requester(GetRelayedTransactionStatusDocument, variables, options);
975
+ },
878
976
  dryRun(variables, options) {
879
977
  return requester(DryRunDocument, variables, options);
880
978
  },
@@ -884,6 +982,9 @@ function getSdk(requester) {
884
982
  produceBlocks(variables, options) {
885
983
  return requester(ProduceBlocksDocument, variables, options);
886
984
  },
985
+ getMessageByNonce(variables, options) {
986
+ return requester(GetMessageByNonceDocument, variables, options);
987
+ },
887
988
  submitAndAwait(variables, options) {
888
989
  return requester(SubmitAndAwaitDocument, variables, options);
889
990
  },
@@ -1056,10 +1157,9 @@ var inputify = (value) => {
1056
1157
  txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
1057
1158
  },
1058
1159
  witnessIndex: value.witnessIndex,
1059
- maturity: value.maturity ?? 0,
1060
1160
  predicateGasUsed: bn2(value.predicateGasUsed),
1061
- predicateLength: predicate.length,
1062
- predicateDataLength: predicateData.length,
1161
+ predicateLength: bn2(predicate.length),
1162
+ predicateDataLength: bn2(predicateData.length),
1063
1163
  predicate: hexlify3(predicate),
1064
1164
  predicateData: hexlify3(predicateData)
1065
1165
  };
@@ -1090,8 +1190,8 @@ var inputify = (value) => {
1090
1190
  nonce: hexlify3(value.nonce),
1091
1191
  witnessIndex: value.witnessIndex,
1092
1192
  predicateGasUsed: bn2(value.predicateGasUsed),
1093
- predicateLength: predicate.length,
1094
- predicateDataLength: predicateData.length,
1193
+ predicateLength: bn2(predicate.length),
1194
+ predicateDataLength: bn2(predicateData.length),
1095
1195
  predicate: hexlify3(predicate),
1096
1196
  predicateData: hexlify3(predicateData),
1097
1197
  data: hexlify3(data),
@@ -1167,7 +1267,7 @@ var outputify = (value) => {
1167
1267
  // src/providers/transaction-request/transaction-request.ts
1168
1268
  import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1169
1269
  import { Address, addressify } from "@fuel-ts/address";
1170
- import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1270
+ import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1171
1271
  import { randomBytes } from "@fuel-ts/crypto";
1172
1272
  import { bn as bn7 } from "@fuel-ts/math";
1173
1273
  import {
@@ -1177,7 +1277,7 @@ import {
1177
1277
  OutputType as OutputType2,
1178
1278
  TransactionType
1179
1279
  } from "@fuel-ts/transactions";
1180
- import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
1280
+ import { concat, hexlify as hexlify7, isDefined } from "@fuel-ts/utils";
1181
1281
 
1182
1282
  // src/providers/resource.ts
1183
1283
  var isRawCoin = (resource) => "utxoId" in resource;
@@ -1221,8 +1321,8 @@ function assembleReceiptByType(receipt) {
1221
1321
  case "CALL" /* Call */: {
1222
1322
  const callReceipt = {
1223
1323
  type: ReceiptType.Call,
1224
- from: hexOrZero(receipt.contract?.id),
1225
- to: hexOrZero(receipt?.to?.id),
1324
+ from: hexOrZero(receipt.id || receipt.contractId),
1325
+ to: hexOrZero(receipt?.to),
1226
1326
  amount: bn4(receipt.amount),
1227
1327
  assetId: hexOrZero(receipt.assetId),
1228
1328
  gas: bn4(receipt.gas),
@@ -1236,7 +1336,7 @@ function assembleReceiptByType(receipt) {
1236
1336
  case "RETURN" /* Return */: {
1237
1337
  const returnReceipt = {
1238
1338
  type: ReceiptType.Return,
1239
- id: hexOrZero(receipt.contract?.id),
1339
+ id: hexOrZero(receipt.id || receipt.contractId),
1240
1340
  val: bn4(receipt.val),
1241
1341
  pc: bn4(receipt.pc),
1242
1342
  is: bn4(receipt.is)
@@ -1246,7 +1346,7 @@ function assembleReceiptByType(receipt) {
1246
1346
  case "RETURN_DATA" /* ReturnData */: {
1247
1347
  const returnDataReceipt = {
1248
1348
  type: ReceiptType.ReturnData,
1249
- id: hexOrZero(receipt.contract?.id),
1349
+ id: hexOrZero(receipt.id || receipt.contractId),
1250
1350
  ptr: bn4(receipt.ptr),
1251
1351
  len: bn4(receipt.len),
1252
1352
  digest: hexOrZero(receipt.digest),
@@ -1258,7 +1358,7 @@ function assembleReceiptByType(receipt) {
1258
1358
  case "PANIC" /* Panic */: {
1259
1359
  const panicReceipt = {
1260
1360
  type: ReceiptType.Panic,
1261
- id: hexOrZero(receipt.contract?.id),
1361
+ id: hexOrZero(receipt.id),
1262
1362
  reason: bn4(receipt.reason),
1263
1363
  pc: bn4(receipt.pc),
1264
1364
  is: bn4(receipt.is),
@@ -1269,7 +1369,7 @@ function assembleReceiptByType(receipt) {
1269
1369
  case "REVERT" /* Revert */: {
1270
1370
  const revertReceipt = {
1271
1371
  type: ReceiptType.Revert,
1272
- id: hexOrZero(receipt.contract?.id),
1372
+ id: hexOrZero(receipt.id || receipt.contractId),
1273
1373
  val: bn4(receipt.ra),
1274
1374
  pc: bn4(receipt.pc),
1275
1375
  is: bn4(receipt.is)
@@ -1279,7 +1379,7 @@ function assembleReceiptByType(receipt) {
1279
1379
  case "LOG" /* Log */: {
1280
1380
  const logReceipt = {
1281
1381
  type: ReceiptType.Log,
1282
- id: hexOrZero(receipt.contract?.id),
1382
+ id: hexOrZero(receipt.id || receipt.contractId),
1283
1383
  val0: bn4(receipt.ra),
1284
1384
  val1: bn4(receipt.rb),
1285
1385
  val2: bn4(receipt.rc),
@@ -1292,7 +1392,7 @@ function assembleReceiptByType(receipt) {
1292
1392
  case "LOG_DATA" /* LogData */: {
1293
1393
  const logDataReceipt = {
1294
1394
  type: ReceiptType.LogData,
1295
- id: hexOrZero(receipt.contract?.id),
1395
+ id: hexOrZero(receipt.id || receipt.contractId),
1296
1396
  val0: bn4(receipt.ra),
1297
1397
  val1: bn4(receipt.rb),
1298
1398
  ptr: bn4(receipt.ptr),
@@ -1306,8 +1406,8 @@ function assembleReceiptByType(receipt) {
1306
1406
  case "TRANSFER" /* Transfer */: {
1307
1407
  const transferReceipt = {
1308
1408
  type: ReceiptType.Transfer,
1309
- from: hexOrZero(receipt.contract?.id),
1310
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1409
+ from: hexOrZero(receipt.id || receipt.contractId),
1410
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1311
1411
  amount: bn4(receipt.amount),
1312
1412
  assetId: hexOrZero(receipt.assetId),
1313
1413
  pc: bn4(receipt.pc),
@@ -1318,8 +1418,8 @@ function assembleReceiptByType(receipt) {
1318
1418
  case "TRANSFER_OUT" /* TransferOut */: {
1319
1419
  const transferOutReceipt = {
1320
1420
  type: ReceiptType.TransferOut,
1321
- from: hexOrZero(receipt.contract?.id),
1322
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1421
+ from: hexOrZero(receipt.id || receipt.contractId),
1422
+ to: hexOrZero(receipt.toAddress || receipt.to),
1323
1423
  amount: bn4(receipt.amount),
1324
1424
  assetId: hexOrZero(receipt.assetId),
1325
1425
  pc: bn4(receipt.pc),
@@ -1362,7 +1462,7 @@ function assembleReceiptByType(receipt) {
1362
1462
  return receiptMessageOut;
1363
1463
  }
1364
1464
  case "MINT" /* Mint */: {
1365
- const contractId = hexOrZero(receipt.contract?.id);
1465
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1366
1466
  const subId = hexOrZero(receipt.subId);
1367
1467
  const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
1368
1468
  const mintReceipt = {
@@ -1377,7 +1477,7 @@ function assembleReceiptByType(receipt) {
1377
1477
  return mintReceipt;
1378
1478
  }
1379
1479
  case "BURN" /* Burn */: {
1380
- const contractId = hexOrZero(receipt.contract?.id);
1480
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1381
1481
  const subId = hexOrZero(receipt.subId);
1382
1482
  const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
1383
1483
  const burnReceipt = {
@@ -1462,7 +1562,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1462
1562
  import { bn as bn5 } from "@fuel-ts/math";
1463
1563
  import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
1464
1564
  import { arrayify as arrayify3 } from "@fuel-ts/utils";
1465
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1466
1565
  var getGasUsedFromReceipts = (receipts) => {
1467
1566
  const scriptResult = receipts.filter(
1468
1567
  (receipt) => receipt.type === ReceiptType2.ScriptResult
@@ -1483,18 +1582,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1483
1582
  }
1484
1583
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1485
1584
  const witnessCache = [];
1486
- const totalGas = inputs.reduce((total, input) => {
1585
+ const chargeableInputs = inputs.filter((input) => {
1586
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1587
+ if (isCoinOrMessage) {
1588
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1589
+ return true;
1590
+ }
1591
+ if (!witnessCache.includes(input.witnessIndex)) {
1592
+ witnessCache.push(input.witnessIndex);
1593
+ return true;
1594
+ }
1595
+ }
1596
+ return false;
1597
+ });
1598
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1599
+ const totalGas = chargeableInputs.reduce((total, input) => {
1487
1600
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1488
1601
  return total.add(
1489
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1602
+ vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1490
1603
  );
1491
1604
  }
1492
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1493
- witnessCache.push(input.witnessIndex);
1494
- return total.add(gasCosts.ecr1);
1495
- }
1496
- return total;
1497
- }, bn5());
1605
+ return total.add(gasCosts.ecr1);
1606
+ }, bn5(0));
1498
1607
  return totalGas;
1499
1608
  }
1500
1609
  function getMinGas(params) {
@@ -1506,12 +1615,20 @@ function getMinGas(params) {
1506
1615
  return minGas;
1507
1616
  }
1508
1617
  function getMaxGas(params) {
1509
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
1618
+ const {
1619
+ gasPerByte,
1620
+ witnessesLength,
1621
+ witnessLimit,
1622
+ minGas,
1623
+ gasLimit = bn5(0),
1624
+ maxGasPerTx
1625
+ } = params;
1510
1626
  let remainingAllowedWitnessGas = bn5(0);
1511
1627
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1512
1628
  remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1513
1629
  }
1514
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1630
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1631
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1515
1632
  }
1516
1633
  function calculateMetadataGasForTxCreate({
1517
1634
  gasCosts,
@@ -1533,6 +1650,10 @@ function calculateMetadataGasForTxScript({
1533
1650
  }) {
1534
1651
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1535
1652
  }
1653
+ var calculateGasFee = (params) => {
1654
+ const { gas, gasPrice, priceFactor, tip } = params;
1655
+ return gas.mul(gasPrice).div(priceFactor).add(bn5(tip));
1656
+ };
1536
1657
 
1537
1658
  // src/providers/utils/json.ts
1538
1659
  import { hexlify as hexlify5 } from "@fuel-ts/utils";
@@ -1689,7 +1810,7 @@ var witnessify = (value) => {
1689
1810
  // src/providers/transaction-request/transaction-request.ts
1690
1811
  var BaseTransactionRequest = class {
1691
1812
  /** Gas price for transaction */
1692
- gasPrice;
1813
+ tip;
1693
1814
  /** Block until which tx cannot be included */
1694
1815
  maturity;
1695
1816
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1708,7 +1829,7 @@ var BaseTransactionRequest = class {
1708
1829
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1709
1830
  */
1710
1831
  constructor({
1711
- gasPrice,
1832
+ tip,
1712
1833
  maturity,
1713
1834
  maxFee,
1714
1835
  witnessLimit,
@@ -1716,10 +1837,10 @@ var BaseTransactionRequest = class {
1716
1837
  outputs,
1717
1838
  witnesses
1718
1839
  } = {}) {
1719
- this.gasPrice = bn7(gasPrice);
1720
- this.maturity = maturity ?? 0;
1721
- this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1722
- this.maxFee = maxFee ? bn7(maxFee) : void 0;
1840
+ this.tip = tip ? bn7(tip) : void 0;
1841
+ this.maturity = maturity && maturity > 0 ? maturity : void 0;
1842
+ this.witnessLimit = isDefined(witnessLimit) ? bn7(witnessLimit) : void 0;
1843
+ this.maxFee = bn7(maxFee);
1723
1844
  this.inputs = inputs ?? [];
1724
1845
  this.outputs = outputs ?? [];
1725
1846
  this.witnesses = witnesses ?? [];
@@ -1727,22 +1848,21 @@ var BaseTransactionRequest = class {
1727
1848
  static getPolicyMeta(req) {
1728
1849
  let policyTypes = 0;
1729
1850
  const policies = [];
1730
- if (req.gasPrice) {
1731
- policyTypes += PolicyType.GasPrice;
1732
- policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
1851
+ const { tip, witnessLimit, maturity } = req;
1852
+ if (bn7(tip).gt(0)) {
1853
+ policyTypes += PolicyType.Tip;
1854
+ policies.push({ data: bn7(tip), type: PolicyType.Tip });
1733
1855
  }
1734
- if (req.witnessLimit) {
1856
+ if (isDefined(witnessLimit) && bn7(witnessLimit).gte(0)) {
1735
1857
  policyTypes += PolicyType.WitnessLimit;
1736
- policies.push({ data: req.witnessLimit, type: PolicyType.WitnessLimit });
1858
+ policies.push({ data: bn7(witnessLimit), type: PolicyType.WitnessLimit });
1737
1859
  }
1738
- if (req.maturity > 0) {
1860
+ if (maturity && maturity > 0) {
1739
1861
  policyTypes += PolicyType.Maturity;
1740
- policies.push({ data: req.maturity, type: PolicyType.Maturity });
1741
- }
1742
- if (req.maxFee) {
1743
- policyTypes += PolicyType.MaxFee;
1744
- policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
1862
+ policies.push({ data: maturity, type: PolicyType.Maturity });
1745
1863
  }
1864
+ policyTypes += PolicyType.MaxFee;
1865
+ policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
1746
1866
  return {
1747
1867
  policyTypes,
1748
1868
  policies
@@ -1913,13 +2033,11 @@ var BaseTransactionRequest = class {
1913
2033
  * assetId, if one it was not added yet.
1914
2034
  *
1915
2035
  * @param coin - Coin resource.
1916
- * @param predicate - Predicate bytes.
1917
- * @param predicateData - Predicate data bytes.
1918
2036
  */
1919
- addCoinInput(coin, predicate) {
2037
+ addCoinInput(coin) {
1920
2038
  const { assetId, owner, amount } = coin;
1921
2039
  let witnessIndex;
1922
- if (predicate) {
2040
+ if (coin.predicate) {
1923
2041
  witnessIndex = 0;
1924
2042
  } else {
1925
2043
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1934,25 +2052,21 @@ var BaseTransactionRequest = class {
1934
2052
  amount,
1935
2053
  assetId,
1936
2054
  txPointer: "0x00000000000000000000000000000000",
1937
- witnessIndex,
1938
- predicate: predicate?.bytes
2055
+ witnessIndex
1939
2056
  };
1940
2057
  this.pushInput(input);
1941
2058
  this.addChangeOutput(owner, assetId);
1942
2059
  }
1943
2060
  /**
1944
2061
  * Adds a single message input to the transaction and a change output for the
1945
- * baseAssetId, if one it was not added yet.
2062
+ * asset against the message
1946
2063
  *
1947
2064
  * @param message - Message resource.
1948
- * @param predicate - Predicate bytes.
1949
- * @param predicateData - Predicate data bytes.
1950
2065
  */
1951
- addMessageInput(message, predicate) {
1952
- const { recipient, sender, amount } = message;
1953
- const assetId = BaseAssetId2;
2066
+ addMessageInput(message) {
2067
+ const { recipient, sender, amount, assetId } = message;
1954
2068
  let witnessIndex;
1955
- if (predicate) {
2069
+ if (message.predicate) {
1956
2070
  witnessIndex = 0;
1957
2071
  } else {
1958
2072
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1966,8 +2080,7 @@ var BaseTransactionRequest = class {
1966
2080
  sender: sender.toB256(),
1967
2081
  recipient: recipient.toB256(),
1968
2082
  amount,
1969
- witnessIndex,
1970
- predicate: predicate?.bytes
2083
+ witnessIndex
1971
2084
  };
1972
2085
  this.pushInput(input);
1973
2086
  this.addChangeOutput(recipient, assetId);
@@ -1998,32 +2111,6 @@ var BaseTransactionRequest = class {
1998
2111
  resources.forEach((resource) => this.addResource(resource));
1999
2112
  return this;
2000
2113
  }
2001
- /**
2002
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2003
- * outputs from the related assetIds.
2004
- *
2005
- * @param resources - The resources to add.
2006
- * @returns This transaction.
2007
- */
2008
- addPredicateResource(resource, predicate) {
2009
- if (isCoin(resource)) {
2010
- this.addCoinInput(resource, predicate);
2011
- } else {
2012
- this.addMessageInput(resource, predicate);
2013
- }
2014
- return this;
2015
- }
2016
- /**
2017
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2018
- * from the related assetIds.
2019
- *
2020
- * @param resources - The resources to add.
2021
- * @returns This transaction.
2022
- */
2023
- addPredicateResources(resources, predicate) {
2024
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2025
- return this;
2026
- }
2027
2114
  /**
2028
2115
  * Adds a coin output to the transaction.
2029
2116
  *
@@ -2031,7 +2118,7 @@ var BaseTransactionRequest = class {
2031
2118
  * @param amount - Amount of coin.
2032
2119
  * @param assetId - Asset ID of coin.
2033
2120
  */
2034
- addCoinOutput(to, amount, assetId = BaseAssetId2) {
2121
+ addCoinOutput(to, amount, assetId) {
2035
2122
  this.pushOutput({
2036
2123
  type: OutputType2.Coin,
2037
2124
  to: addressify(to).toB256(),
@@ -2063,7 +2150,7 @@ var BaseTransactionRequest = class {
2063
2150
  * @param to - Address of the owner.
2064
2151
  * @param assetId - Asset ID of coin.
2065
2152
  */
2066
- addChangeOutput(to, assetId = BaseAssetId2) {
2153
+ addChangeOutput(to, assetId) {
2067
2154
  const changeOutput = this.getChangeOutputs().find(
2068
2155
  (output) => hexlify7(output.assetId) === assetId
2069
2156
  );
@@ -2091,8 +2178,11 @@ var BaseTransactionRequest = class {
2091
2178
  * @hidden
2092
2179
  */
2093
2180
  calculateMinGas(chainInfo) {
2094
- const { gasCosts, consensusParameters } = chainInfo;
2095
- const { gasPerByte } = consensusParameters;
2181
+ const { consensusParameters } = chainInfo;
2182
+ const {
2183
+ gasCosts,
2184
+ feeParameters: { gasPerByte }
2185
+ } = consensusParameters;
2096
2186
  return getMinGas({
2097
2187
  gasPerByte,
2098
2188
  gasCosts,
@@ -2103,7 +2193,10 @@ var BaseTransactionRequest = class {
2103
2193
  }
2104
2194
  calculateMaxGas(chainInfo, minGas) {
2105
2195
  const { consensusParameters } = chainInfo;
2106
- const { gasPerByte } = consensusParameters;
2196
+ const {
2197
+ feeParameters: { gasPerByte },
2198
+ txParameters: { maxGasPerTx }
2199
+ } = consensusParameters;
2107
2200
  const witnessesLength = this.toTransaction().witnesses.reduce(
2108
2201
  (acc, wit) => acc + wit.dataLength,
2109
2202
  0
@@ -2112,7 +2205,8 @@ var BaseTransactionRequest = class {
2112
2205
  gasPerByte,
2113
2206
  minGas,
2114
2207
  witnessesLength,
2115
- witnessLimit: this.witnessLimit
2208
+ witnessLimit: this.witnessLimit,
2209
+ maxGasPerTx
2116
2210
  });
2117
2211
  }
2118
2212
  /**
@@ -2120,8 +2214,9 @@ var BaseTransactionRequest = class {
2120
2214
  * quantities array.
2121
2215
  *
2122
2216
  * @param quantities - CoinQuantity Array.
2217
+ * @param baseAssetId - The base asset to fund the transaction.
2123
2218
  */
2124
- fundWithFakeUtxos(quantities, resourcesOwner) {
2219
+ fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
2125
2220
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2126
2221
  if ("assetId" in input) {
2127
2222
  return input.assetId === assetId;
@@ -2130,24 +2225,27 @@ var BaseTransactionRequest = class {
2130
2225
  });
2131
2226
  const updateAssetInput = (assetId, quantity) => {
2132
2227
  const assetInput = findAssetInput(assetId);
2228
+ let usedQuantity = quantity;
2229
+ if (assetId === baseAssetId) {
2230
+ usedQuantity = bn7("1000000000000000000");
2231
+ }
2133
2232
  if (assetInput && "assetId" in assetInput) {
2134
2233
  assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2135
- assetInput.amount = quantity;
2234
+ assetInput.amount = usedQuantity;
2136
2235
  } else {
2137
2236
  this.addResources([
2138
2237
  {
2139
2238
  id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2140
- amount: quantity,
2239
+ amount: usedQuantity,
2141
2240
  assetId,
2142
2241
  owner: resourcesOwner || Address.fromRandom(),
2143
- maturity: 0,
2144
2242
  blockCreated: bn7(1),
2145
2243
  txCreatedIdx: bn7(1)
2146
2244
  }
2147
2245
  ]);
2148
2246
  }
2149
2247
  };
2150
- updateAssetInput(BaseAssetId2, bn7(1e11));
2248
+ updateAssetInput(baseAssetId, bn7(1e11));
2151
2249
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2152
2250
  }
2153
2251
  /**
@@ -2172,7 +2270,7 @@ var BaseTransactionRequest = class {
2172
2270
  toJSON() {
2173
2271
  return normalizeJSON(this);
2174
2272
  }
2175
- updatePredicateInputs(inputs) {
2273
+ updatePredicateGasUsed(inputs) {
2176
2274
  this.inputs.forEach((i) => {
2177
2275
  let correspondingInput;
2178
2276
  switch (i.type) {
@@ -2194,6 +2292,15 @@ var BaseTransactionRequest = class {
2194
2292
  }
2195
2293
  });
2196
2294
  }
2295
+ shiftPredicateData() {
2296
+ this.inputs.forEach((input) => {
2297
+ if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
2298
+ input.predicateData = input.padPredicateData(
2299
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2300
+ );
2301
+ }
2302
+ });
2303
+ }
2197
2304
  };
2198
2305
 
2199
2306
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2317,12 +2424,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2317
2424
  *
2318
2425
  * @param createTransactionRequestLike - The initial values for the instance
2319
2426
  */
2320
- constructor({
2321
- bytecodeWitnessIndex,
2322
- salt,
2323
- storageSlots,
2324
- ...rest
2325
- } = {}) {
2427
+ constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2326
2428
  super(rest);
2327
2429
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2328
2430
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -2340,9 +2442,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2340
2442
  return {
2341
2443
  type: TransactionType3.Create,
2342
2444
  ...baseTransaction,
2343
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2344
2445
  bytecodeWitnessIndex,
2345
- storageSlotsCount: storageSlots.length,
2446
+ storageSlotsCount: bn9(storageSlots.length),
2346
2447
  salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
2347
2448
  storageSlots
2348
2449
  };
@@ -2465,8 +2566,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2465
2566
  type: TransactionType4.Script,
2466
2567
  scriptGasLimit: this.gasLimit,
2467
2568
  ...super.getBaseTransaction(),
2468
- scriptLength: script.length,
2469
- scriptDataLength: scriptData.length,
2569
+ scriptLength: bn10(script.length),
2570
+ scriptDataLength: bn10(scriptData.length),
2470
2571
  receiptsRoot: ZeroBytes327,
2471
2572
  script: hexlify10(script),
2472
2573
  scriptData: hexlify10(scriptData)
@@ -2530,7 +2631,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2530
2631
  }
2531
2632
  calculateMaxGas(chainInfo, minGas) {
2532
2633
  const { consensusParameters } = chainInfo;
2533
- const { gasPerByte } = consensusParameters;
2634
+ const {
2635
+ feeParameters: { gasPerByte },
2636
+ txParameters: { maxGasPerTx }
2637
+ } = consensusParameters;
2534
2638
  const witnessesLength = this.toTransaction().witnesses.reduce(
2535
2639
  (acc, wit) => acc + wit.dataLength,
2536
2640
  0
@@ -2540,7 +2644,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2540
2644
  minGas,
2541
2645
  witnessesLength,
2542
2646
  witnessLimit: this.witnessLimit,
2543
- gasLimit: this.gasLimit
2647
+ gasLimit: this.gasLimit,
2648
+ maxGasPerTx
2544
2649
  });
2545
2650
  }
2546
2651
  /**
@@ -2597,7 +2702,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2597
2702
 
2598
2703
  // src/providers/transaction-request/utils.ts
2599
2704
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2600
- import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2705
+ import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2601
2706
  var transactionRequestify = (obj) => {
2602
2707
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2603
2708
  return obj;
@@ -2615,41 +2720,58 @@ var transactionRequestify = (obj) => {
2615
2720
  }
2616
2721
  }
2617
2722
  };
2723
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2724
+ (acc, input) => {
2725
+ if (input.type === InputType5.Coin && input.owner === owner.toB256()) {
2726
+ acc.utxos.push(input.id);
2727
+ }
2728
+ if (input.type === InputType5.Message && input.recipient === owner.toB256()) {
2729
+ acc.messages.push(input.nonce);
2730
+ }
2731
+ return acc;
2732
+ },
2733
+ {
2734
+ utxos: [],
2735
+ messages: []
2736
+ }
2737
+ );
2618
2738
 
2619
2739
  // src/providers/transaction-response/transaction-response.ts
2620
2740
  import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2621
- import { bn as bn14 } from "@fuel-ts/math";
2741
+ import { bn as bn16 } from "@fuel-ts/math";
2622
2742
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2623
2743
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2624
2744
 
2625
2745
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2746
+ import { bn as bn15 } from "@fuel-ts/math";
2747
+ import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2626
2748
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2627
2749
 
2628
- // src/providers/transaction-summary/calculate-transaction-fee.ts
2750
+ // src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
2629
2751
  import { bn as bn11 } from "@fuel-ts/math";
2630
2752
  import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
2631
2753
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2632
- var calculateTransactionFee = (params) => {
2754
+ var calculateTXFeeForSummary = (params) => {
2633
2755
  const {
2634
- gasUsed,
2756
+ gasPrice,
2635
2757
  rawPayload,
2636
- consensusParameters: { gasCosts, feeParams }
2758
+ tip,
2759
+ totalFee,
2760
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2637
2761
  } = params;
2762
+ if (totalFee) {
2763
+ return totalFee;
2764
+ }
2638
2765
  const gasPerByte = bn11(feeParams.gasPerByte);
2639
2766
  const gasPriceFactor = bn11(feeParams.gasPriceFactor);
2640
2767
  const transactionBytes = arrayify9(rawPayload);
2641
2768
  const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
2642
- if (transaction.type === TransactionType6.Mint) {
2643
- return {
2644
- fee: bn11(0),
2645
- minFee: bn11(0),
2646
- maxFee: bn11(0),
2647
- feeFromGasUsed: bn11(0)
2648
- };
2649
- }
2650
2769
  const { type, witnesses, inputs, policies } = transaction;
2651
2770
  let metadataGas = bn11(0);
2652
2771
  let gasLimit = bn11(0);
2772
+ if (type !== TransactionType6.Create && type !== TransactionType6.Script) {
2773
+ return bn11(0);
2774
+ }
2653
2775
  if (type === TransactionType6.Create) {
2654
2776
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2655
2777
  const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
@@ -2676,7 +2798,6 @@ var calculateTransactionFee = (params) => {
2676
2798
  metadataGas,
2677
2799
  txBytesSize: transactionBytes.length
2678
2800
  });
2679
- const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2680
2801
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2681
2802
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2682
2803
  const maxGas = getMaxGas({
@@ -2684,18 +2805,16 @@ var calculateTransactionFee = (params) => {
2684
2805
  minGas,
2685
2806
  witnessesLength,
2686
2807
  gasLimit,
2687
- witnessLimit
2808
+ witnessLimit,
2809
+ maxGasPerTx
2688
2810
  });
2689
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2690
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2691
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2692
- const fee = minFee.add(feeFromGasUsed);
2693
- return {
2694
- fee,
2695
- minFee,
2696
- maxFee,
2697
- feeFromGasUsed
2698
- };
2811
+ const maxFee = calculateGasFee({
2812
+ gasPrice,
2813
+ gas: maxGas,
2814
+ priceFactor: gasPriceFactor,
2815
+ tip
2816
+ });
2817
+ return maxFee;
2699
2818
  };
2700
2819
 
2701
2820
  // src/providers/transaction-summary/operations.ts
@@ -2750,7 +2869,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2750
2869
 
2751
2870
  // src/providers/transaction-summary/input.ts
2752
2871
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2753
- import { InputType as InputType5 } from "@fuel-ts/transactions";
2872
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2754
2873
  function getInputsByTypes(inputs, types) {
2755
2874
  return inputs.filter((i) => types.includes(i.type));
2756
2875
  }
@@ -2758,16 +2877,16 @@ function getInputsByType(inputs, type) {
2758
2877
  return inputs.filter((i) => i.type === type);
2759
2878
  }
2760
2879
  function getInputsCoin(inputs) {
2761
- return getInputsByType(inputs, InputType5.Coin);
2880
+ return getInputsByType(inputs, InputType6.Coin);
2762
2881
  }
2763
2882
  function getInputsMessage(inputs) {
2764
- return getInputsByType(inputs, InputType5.Message);
2883
+ return getInputsByType(inputs, InputType6.Message);
2765
2884
  }
2766
2885
  function getInputsCoinAndMessage(inputs) {
2767
- return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2886
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2768
2887
  }
2769
2888
  function getInputsContract(inputs) {
2770
- return getInputsByType(inputs, InputType5.Contract);
2889
+ return getInputsByType(inputs, InputType6.Contract);
2771
2890
  }
2772
2891
  function getInputFromAssetId(inputs, assetId) {
2773
2892
  const coinInputs = getInputsCoin(inputs);
@@ -2786,7 +2905,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2786
2905
  if (!contractInput) {
2787
2906
  return void 0;
2788
2907
  }
2789
- if (contractInput.type !== InputType5.Contract) {
2908
+ if (contractInput.type !== InputType6.Contract) {
2790
2909
  throw new FuelError9(
2791
2910
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2792
2911
  `Contract input should be of type 'contract'.`
@@ -2795,10 +2914,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2795
2914
  return contractInput;
2796
2915
  }
2797
2916
  function getInputAccountAddress(input) {
2798
- if (input.type === InputType5.Coin) {
2917
+ if (input.type === InputType6.Coin) {
2799
2918
  return input.owner.toString();
2800
2919
  }
2801
- if (input.type === InputType5.Message) {
2920
+ if (input.type === InputType6.Message) {
2802
2921
  return input.recipient.toString();
2803
2922
  }
2804
2923
  return "";
@@ -2830,6 +2949,8 @@ var TransactionTypeName = /* @__PURE__ */ ((TransactionTypeName2) => {
2830
2949
  TransactionTypeName2["Create"] = "Create";
2831
2950
  TransactionTypeName2["Mint"] = "Mint";
2832
2951
  TransactionTypeName2["Script"] = "Script";
2952
+ TransactionTypeName2["Upgrade"] = "Upgrade";
2953
+ TransactionTypeName2["Upload"] = "Upload";
2833
2954
  return TransactionTypeName2;
2834
2955
  })(TransactionTypeName || {});
2835
2956
  var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
@@ -2895,6 +3016,12 @@ function isTypeCreate(transactionType) {
2895
3016
  function isTypeScript(transactionType) {
2896
3017
  return isType(transactionType, "Script" /* Script */);
2897
3018
  }
3019
+ function isTypeUpgrade(transactionType) {
3020
+ return isType(transactionType, "Upgrade" /* Upgrade */);
3021
+ }
3022
+ function isTypeUpload(transactionType) {
3023
+ return isType(transactionType, "Upload" /* Upload */);
3024
+ }
2898
3025
  function hasSameAssetId(a) {
2899
3026
  return (b) => a.assetId === b.assetId;
2900
3027
  }
@@ -3241,6 +3368,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3241
3368
 
3242
3369
  // src/providers/transaction-summary/status.ts
3243
3370
  import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
3371
+ import { bn as bn14 } from "@fuel-ts/math";
3244
3372
  var getTransactionStatusName = (gqlStatus) => {
3245
3373
  switch (gqlStatus) {
3246
3374
  case "FailureStatus":
@@ -3262,6 +3390,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3262
3390
  let time;
3263
3391
  let blockId;
3264
3392
  let status;
3393
+ let totalFee;
3394
+ let totalGas;
3265
3395
  let isStatusFailure = false;
3266
3396
  let isStatusSuccess = false;
3267
3397
  let isStatusPending = false;
@@ -3272,11 +3402,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3272
3402
  time = gqlTransactionStatus.time;
3273
3403
  blockId = gqlTransactionStatus.block.id;
3274
3404
  isStatusSuccess = true;
3405
+ totalFee = bn14(gqlTransactionStatus.totalFee);
3406
+ totalGas = bn14(gqlTransactionStatus.totalGas);
3275
3407
  break;
3276
3408
  case "FailureStatus":
3277
3409
  time = gqlTransactionStatus.time;
3278
3410
  blockId = gqlTransactionStatus.block.id;
3279
3411
  isStatusFailure = true;
3412
+ totalFee = bn14(gqlTransactionStatus.totalFee);
3413
+ totalGas = bn14(gqlTransactionStatus.totalGas);
3280
3414
  break;
3281
3415
  case "SubmittedStatus":
3282
3416
  time = gqlTransactionStatus.time;
@@ -3289,6 +3423,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3289
3423
  time,
3290
3424
  blockId,
3291
3425
  status,
3426
+ totalFee,
3427
+ totalGas,
3292
3428
  isStatusFailure,
3293
3429
  isStatusSuccess,
3294
3430
  isStatusPending
@@ -3308,7 +3444,9 @@ function assembleTransactionSummary(params) {
3308
3444
  gqlTransactionStatus,
3309
3445
  abiMap = {},
3310
3446
  maxInputs,
3311
- gasCosts
3447
+ gasCosts,
3448
+ maxGasPerTx,
3449
+ gasPrice
3312
3450
  } = params;
3313
3451
  const gasUsed = getGasUsedFromReceipts(receipts);
3314
3452
  const rawPayload = hexlify11(transactionBytes);
@@ -3322,18 +3460,22 @@ function assembleTransactionSummary(params) {
3322
3460
  maxInputs
3323
3461
  });
3324
3462
  const typeName = getTransactionTypeName(transaction.type);
3325
- const { fee } = calculateTransactionFee({
3326
- gasUsed,
3463
+ const tip = bn15(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3464
+ const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
3465
+ const fee = calculateTXFeeForSummary({
3466
+ totalFee,
3467
+ gasPrice,
3327
3468
  rawPayload,
3469
+ tip,
3328
3470
  consensusParameters: {
3329
3471
  gasCosts,
3472
+ maxGasPerTx,
3330
3473
  feeParams: {
3331
3474
  gasPerByte,
3332
3475
  gasPriceFactor
3333
3476
  }
3334
3477
  }
3335
3478
  });
3336
- const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time } = processGraphqlStatus(gqlTransactionStatus);
3337
3479
  const mintedAssets = extractMintedAssetsFromReceipts(receipts);
3338
3480
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3339
3481
  let date;
@@ -3342,6 +3484,7 @@ function assembleTransactionSummary(params) {
3342
3484
  }
3343
3485
  const transactionSummary = {
3344
3486
  id,
3487
+ tip,
3345
3488
  fee,
3346
3489
  gasUsed,
3347
3490
  operations,
@@ -3355,6 +3498,8 @@ function assembleTransactionSummary(params) {
3355
3498
  isTypeMint: isTypeMint(transaction.type),
3356
3499
  isTypeCreate: isTypeCreate(transaction.type),
3357
3500
  isTypeScript: isTypeScript(transaction.type),
3501
+ isTypeUpgrade: isTypeUpgrade(transaction.type),
3502
+ isTypeUpload: isTypeUpload(transaction.type),
3358
3503
  isStatusFailure,
3359
3504
  isStatusSuccess,
3360
3505
  isStatusPending,
@@ -3386,7 +3531,7 @@ var TransactionResponse = class {
3386
3531
  /** Current provider */
3387
3532
  provider;
3388
3533
  /** Gas used on the transaction */
3389
- gasUsed = bn14(0);
3534
+ gasUsed = bn16(0);
3390
3535
  /** The graphql Transaction with receipts object. */
3391
3536
  gqlTransaction;
3392
3537
  abis;
@@ -3464,9 +3609,14 @@ var TransactionResponse = class {
3464
3609
  const decodedTransaction = this.decodeTransaction(
3465
3610
  transaction
3466
3611
  );
3467
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3468
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3469
- const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3612
+ let txReceipts = [];
3613
+ if (transaction?.status && "receipts" in transaction.status) {
3614
+ txReceipts = transaction.status.receipts;
3615
+ }
3616
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3617
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3618
+ const gasPrice = await this.provider.getLatestGasPrice();
3619
+ const maxInputs = this.provider.getChain().consensusParameters.txParameters.maxInputs;
3470
3620
  const transactionSummary = assembleTransactionSummary({
3471
3621
  id: this.id,
3472
3622
  receipts,
@@ -3477,7 +3627,9 @@ var TransactionResponse = class {
3477
3627
  gasPriceFactor,
3478
3628
  abiMap: contractsAbiMap,
3479
3629
  maxInputs,
3480
- gasCosts
3630
+ gasCosts,
3631
+ maxGasPerTx,
3632
+ gasPrice
3481
3633
  });
3482
3634
  return transactionSummary;
3483
3635
  }
@@ -3583,7 +3735,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3583
3735
  }
3584
3736
 
3585
3737
  // src/providers/utils/merge-quantities.ts
3586
- var mergeQuantities = (arr1, arr2) => {
3738
+ var mergeQuantities = (...coinQuantities) => {
3587
3739
  const resultMap = {};
3588
3740
  function addToMap({ amount, assetId }) {
3589
3741
  if (resultMap[assetId]) {
@@ -3592,8 +3744,7 @@ var mergeQuantities = (arr1, arr2) => {
3592
3744
  resultMap[assetId] = amount;
3593
3745
  }
3594
3746
  }
3595
- arr1.forEach(addToMap);
3596
- arr2.forEach(addToMap);
3747
+ coinQuantities.forEach((arr) => arr.forEach(addToMap));
3597
3748
  return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3598
3749
  };
3599
3750
 
@@ -3601,32 +3752,60 @@ var mergeQuantities = (arr1, arr2) => {
3601
3752
  var MAX_RETRIES = 10;
3602
3753
  var processGqlChain = (chain) => {
3603
3754
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3604
- const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3755
+ const {
3756
+ contractParams,
3757
+ feeParams,
3758
+ predicateParams,
3759
+ scriptParams,
3760
+ txParams,
3761
+ gasCosts,
3762
+ baseAssetId,
3763
+ chainId,
3764
+ version
3765
+ } = consensusParameters;
3605
3766
  return {
3606
3767
  name,
3607
- baseChainHeight: bn15(daHeight),
3768
+ baseChainHeight: bn17(daHeight),
3608
3769
  consensusParameters: {
3609
- contractMaxSize: bn15(contractParams.contractMaxSize),
3610
- maxInputs: bn15(txParams.maxInputs),
3611
- maxOutputs: bn15(txParams.maxOutputs),
3612
- maxWitnesses: bn15(txParams.maxWitnesses),
3613
- maxGasPerTx: bn15(txParams.maxGasPerTx),
3614
- maxScriptLength: bn15(scriptParams.maxScriptLength),
3615
- maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
3616
- maxStorageSlots: bn15(contractParams.maxStorageSlots),
3617
- maxPredicateLength: bn15(predicateParams.maxPredicateLength),
3618
- maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
3619
- maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
3620
- gasPriceFactor: bn15(feeParams.gasPriceFactor),
3621
- gasPerByte: bn15(feeParams.gasPerByte),
3622
- maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3623
- chainId: bn15(consensusParameters.chainId),
3770
+ version,
3771
+ chainId: bn17(chainId),
3772
+ baseAssetId,
3773
+ feeParameters: {
3774
+ version: feeParams.version,
3775
+ gasPerByte: bn17(feeParams.gasPerByte),
3776
+ gasPriceFactor: bn17(feeParams.gasPriceFactor)
3777
+ },
3778
+ contractParameters: {
3779
+ version: contractParams.version,
3780
+ contractMaxSize: bn17(contractParams.contractMaxSize),
3781
+ maxStorageSlots: bn17(contractParams.maxStorageSlots)
3782
+ },
3783
+ txParameters: {
3784
+ version: txParams.version,
3785
+ maxInputs: bn17(txParams.maxInputs),
3786
+ maxOutputs: bn17(txParams.maxOutputs),
3787
+ maxWitnesses: bn17(txParams.maxWitnesses),
3788
+ maxGasPerTx: bn17(txParams.maxGasPerTx),
3789
+ maxSize: bn17(txParams.maxSize),
3790
+ maxBytecodeSubsections: bn17(txParams.maxBytecodeSubsections)
3791
+ },
3792
+ predicateParameters: {
3793
+ version: predicateParams.version,
3794
+ maxPredicateLength: bn17(predicateParams.maxPredicateLength),
3795
+ maxPredicateDataLength: bn17(predicateParams.maxPredicateDataLength),
3796
+ maxGasPerPredicate: bn17(predicateParams.maxGasPerPredicate),
3797
+ maxMessageDataLength: bn17(predicateParams.maxMessageDataLength)
3798
+ },
3799
+ scriptParameters: {
3800
+ version: scriptParams.version,
3801
+ maxScriptLength: bn17(scriptParams.maxScriptLength),
3802
+ maxScriptDataLength: bn17(scriptParams.maxScriptDataLength)
3803
+ },
3624
3804
  gasCosts
3625
3805
  },
3626
- gasCosts,
3627
3806
  latestBlock: {
3628
3807
  id: latestBlock.id,
3629
- height: bn15(latestBlock.header.height),
3808
+ height: bn17(latestBlock.height),
3630
3809
  time: latestBlock.header.time,
3631
3810
  transactions: latestBlock.transactions.map((i) => ({
3632
3811
  id: i.id
@@ -3720,10 +3899,13 @@ var _Provider = class {
3720
3899
  * Returns some helpful parameters related to gas fees.
3721
3900
  */
3722
3901
  getGasConfig() {
3723
- const { minGasPrice } = this.getNode();
3724
- const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3902
+ const {
3903
+ txParameters: { maxGasPerTx },
3904
+ predicateParameters: { maxGasPerPredicate },
3905
+ feeParameters: { gasPriceFactor, gasPerByte },
3906
+ gasCosts
3907
+ } = this.getChain().consensusParameters;
3725
3908
  return {
3726
- minGasPrice,
3727
3909
  maxGasPerTx,
3728
3910
  maxGasPerPredicate,
3729
3911
  gasPriceFactor,
@@ -3771,7 +3953,18 @@ var _Provider = class {
3771
3953
  createOperations() {
3772
3954
  const fetchFn = _Provider.getFetchFn(this.options);
3773
3955
  const gqlClient = new GraphQLClient(this.url, {
3774
- fetch: (url, requestInit) => fetchFn(url, requestInit, this.options)
3956
+ fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
3957
+ responseMiddleware: (response) => {
3958
+ if ("response" in response) {
3959
+ const graphQlResponse = response.response;
3960
+ if (Array.isArray(graphQlResponse?.errors)) {
3961
+ throw new FuelError13(
3962
+ FuelError13.CODES.INVALID_REQUEST,
3963
+ graphQlResponse.errors.map((err) => err.message).join("\n\n")
3964
+ );
3965
+ }
3966
+ }
3967
+ }
3775
3968
  });
3776
3969
  const executeQuery = (query, vars) => {
3777
3970
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
@@ -3799,21 +3992,6 @@ var _Provider = class {
3799
3992
  } = await this.operations.getVersion();
3800
3993
  return nodeVersion;
3801
3994
  }
3802
- /**
3803
- * @hidden
3804
- *
3805
- * Returns the network configuration of the connected Fuel node.
3806
- *
3807
- * @returns A promise that resolves to the network configuration object
3808
- */
3809
- async getNetwork() {
3810
- const {
3811
- name,
3812
- consensusParameters: { chainId }
3813
- } = await this.getChain();
3814
- const network = new Network(name, chainId.toNumber());
3815
- return Promise.resolve(network);
3816
- }
3817
3995
  /**
3818
3996
  * Returns the block number.
3819
3997
  *
@@ -3821,7 +3999,7 @@ var _Provider = class {
3821
3999
  */
3822
4000
  async getBlockNumber() {
3823
4001
  const { chain } = await this.operations.getChain();
3824
- return bn15(chain.latestBlock.header.height, 10);
4002
+ return bn17(chain.latestBlock.height, 10);
3825
4003
  }
3826
4004
  /**
3827
4005
  * Returns the chain information.
@@ -3831,13 +4009,11 @@ var _Provider = class {
3831
4009
  async fetchNode() {
3832
4010
  const { nodeInfo } = await this.operations.getNodeInfo();
3833
4011
  const processedNodeInfo = {
3834
- maxDepth: bn15(nodeInfo.maxDepth),
3835
- maxTx: bn15(nodeInfo.maxTx),
3836
- minGasPrice: bn15(nodeInfo.minGasPrice),
4012
+ maxDepth: bn17(nodeInfo.maxDepth),
4013
+ maxTx: bn17(nodeInfo.maxTx),
3837
4014
  nodeVersion: nodeInfo.nodeVersion,
3838
4015
  utxoValidation: nodeInfo.utxoValidation,
3839
- vmBacktrace: nodeInfo.vmBacktrace,
3840
- peers: nodeInfo.peers
4016
+ vmBacktrace: nodeInfo.vmBacktrace
3841
4017
  };
3842
4018
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3843
4019
  return processedNodeInfo;
@@ -3863,6 +4039,17 @@ var _Provider = class {
3863
4039
  } = this.getChain();
3864
4040
  return chainId.toNumber();
3865
4041
  }
4042
+ /**
4043
+ * Returns the base asset ID for the current provider network
4044
+ *
4045
+ * @returns the base asset ID
4046
+ */
4047
+ getBaseAssetId() {
4048
+ const {
4049
+ consensusParameters: { baseAssetId }
4050
+ } = this.getChain();
4051
+ return baseAssetId;
4052
+ }
3866
4053
  /**
3867
4054
  * Submits a transaction to the chain to be executed.
3868
4055
  *
@@ -3923,14 +4110,13 @@ var _Provider = class {
3923
4110
  return this.estimateTxDependencies(transactionRequest);
3924
4111
  }
3925
4112
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3926
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3927
- encodedTransaction,
4113
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4114
+ encodedTransactions: encodedTransaction,
3928
4115
  utxoValidation: utxoValidation || false
3929
4116
  });
3930
- const receipts = gqlReceipts.map(processGqlReceipt);
3931
- return {
3932
- receipts
3933
- };
4117
+ const [{ receipts: rawReceipts, status: dryRunStatus }] = dryRunStatuses;
4118
+ const receipts = rawReceipts.map(processGqlReceipt);
4119
+ return { receipts, dryRunStatus };
3934
4120
  }
3935
4121
  /**
3936
4122
  * Verifies whether enough gas is available to complete transaction.
@@ -3956,7 +4142,7 @@ var _Provider = class {
3956
4142
  } = response;
3957
4143
  if (inputs) {
3958
4144
  inputs.forEach((input, index) => {
3959
- if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
4145
+ if ("predicateGasUsed" in input && bn17(input.predicateGasUsed).gt(0)) {
3960
4146
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3961
4147
  }
3962
4148
  });
@@ -3969,9 +4155,6 @@ var _Provider = class {
3969
4155
  * If there are missing variable outputs,
3970
4156
  * `addVariableOutputs` is called on the transaction.
3971
4157
  *
3972
- * @privateRemarks
3973
- * TODO: Investigate support for missing contract IDs
3974
- * TODO: Add support for missing output messages
3975
4158
  *
3976
4159
  * @param transactionRequest - The transaction request object.
3977
4160
  * @returns A promise.
@@ -3984,16 +4167,19 @@ var _Provider = class {
3984
4167
  missingContractIds: []
3985
4168
  };
3986
4169
  }
3987
- await this.estimatePredicates(transactionRequest);
3988
4170
  let receipts = [];
3989
4171
  const missingContractIds = [];
3990
4172
  let outputVariables = 0;
4173
+ let dryRunStatus;
3991
4174
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3992
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3993
- encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
4175
+ const {
4176
+ dryRun: [{ receipts: rawReceipts, status }]
4177
+ } = await this.operations.dryRun({
4178
+ encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
3994
4179
  utxoValidation: false
3995
4180
  });
3996
- receipts = gqlReceipts.map(processGqlReceipt);
4181
+ receipts = rawReceipts.map(processGqlReceipt);
4182
+ dryRunStatus = status;
3997
4183
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3998
4184
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3999
4185
  if (hasMissingOutputs) {
@@ -4003,6 +4189,10 @@ var _Provider = class {
4003
4189
  transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
4004
4190
  missingContractIds.push(contractId);
4005
4191
  });
4192
+ const { maxFee } = await this.estimateTxGasAndFee({
4193
+ transactionRequest
4194
+ });
4195
+ transactionRequest.maxFee = maxFee;
4006
4196
  } else {
4007
4197
  break;
4008
4198
  }
@@ -4010,37 +4200,136 @@ var _Provider = class {
4010
4200
  return {
4011
4201
  receipts,
4012
4202
  outputVariables,
4013
- missingContractIds
4203
+ missingContractIds,
4204
+ dryRunStatus
4014
4205
  };
4015
4206
  }
4207
+ /**
4208
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4209
+ *
4210
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4211
+ * further modifications are identified. The method iteratively updates these transactions
4212
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4213
+ *
4214
+ * @param transactionRequests - Array of transaction request objects.
4215
+ * @returns A promise that resolves to an array of results for each transaction.
4216
+ */
4217
+ async estimateMultipleTxDependencies(transactionRequests) {
4218
+ const results = transactionRequests.map(() => ({
4219
+ receipts: [],
4220
+ outputVariables: 0,
4221
+ missingContractIds: [],
4222
+ dryRunStatus: void 0
4223
+ }));
4224
+ const allRequests = clone3(transactionRequests);
4225
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4226
+ allRequests.forEach((req, index) => {
4227
+ if (req.type === TransactionType8.Script) {
4228
+ serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
4229
+ }
4230
+ });
4231
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4232
+ let attempt = 0;
4233
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4234
+ const encodedTransactions = transactionsToProcess.map(
4235
+ (index) => serializedTransactionsMap.get(index)
4236
+ );
4237
+ const dryRunResults = await this.operations.dryRun({
4238
+ encodedTransactions,
4239
+ utxoValidation: false
4240
+ });
4241
+ const nextRoundTransactions = [];
4242
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4243
+ const requestIdx = transactionsToProcess[i];
4244
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4245
+ const result = results[requestIdx];
4246
+ result.receipts = rawReceipts.map(processGqlReceipt);
4247
+ result.dryRunStatus = status;
4248
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4249
+ result.receipts
4250
+ );
4251
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4252
+ const request = allRequests[requestIdx];
4253
+ if (hasMissingOutputs && request?.type === TransactionType8.Script) {
4254
+ result.outputVariables += missingOutputVariables.length;
4255
+ request.addVariableOutputs(missingOutputVariables.length);
4256
+ missingOutputContractIds.forEach(({ contractId }) => {
4257
+ request.addContractInputAndOutput(Address2.fromString(contractId));
4258
+ result.missingContractIds.push(contractId);
4259
+ });
4260
+ const { maxFee } = await this.estimateTxGasAndFee({
4261
+ transactionRequest: request
4262
+ });
4263
+ request.maxFee = maxFee;
4264
+ serializedTransactionsMap.set(requestIdx, hexlify12(request.toTransactionBytes()));
4265
+ nextRoundTransactions.push(requestIdx);
4266
+ }
4267
+ }
4268
+ transactionsToProcess = nextRoundTransactions;
4269
+ attempt += 1;
4270
+ }
4271
+ return results;
4272
+ }
4273
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4274
+ if (estimateTxDependencies) {
4275
+ return this.estimateMultipleTxDependencies(transactionRequests);
4276
+ }
4277
+ const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
4278
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4279
+ encodedTransactions,
4280
+ utxoValidation: utxoValidation || false
4281
+ });
4282
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4283
+ const receipts = rawReceipts.map(processGqlReceipt);
4284
+ return { receipts, dryRunStatus: status };
4285
+ });
4286
+ return results;
4287
+ }
4016
4288
  /**
4017
4289
  * Estimates the transaction gas and fee based on the provided transaction request.
4018
4290
  * @param transactionRequest - The transaction request object.
4019
4291
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4020
4292
  */
4021
- estimateTxGasAndFee(params) {
4293
+ async estimateTxGasAndFee(params) {
4022
4294
  const { transactionRequest } = params;
4023
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4295
+ let { gasPrice } = params;
4024
4296
  const chainInfo = this.getChain();
4025
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4026
- transactionRequest.gasPrice = gasPrice;
4297
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4027
4298
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4028
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4299
+ if (!gasPrice) {
4300
+ gasPrice = await this.estimateGasPrice(10);
4301
+ }
4302
+ const minFee = calculateGasFee({
4303
+ gasPrice: bn17(gasPrice),
4304
+ gas: minGas,
4305
+ priceFactor: gasPriceFactor,
4306
+ tip: transactionRequest.tip
4307
+ }).add(1);
4308
+ let gasLimit = bn17(0);
4029
4309
  if (transactionRequest.type === TransactionType8.Script) {
4310
+ gasLimit = transactionRequest.gasLimit;
4030
4311
  if (transactionRequest.gasLimit.eq(0)) {
4031
4312
  transactionRequest.gasLimit = minGas;
4032
4313
  transactionRequest.gasLimit = maxGasPerTx.sub(
4033
4314
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4034
4315
  );
4316
+ gasLimit = transactionRequest.gasLimit;
4035
4317
  }
4036
4318
  }
4037
4319
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4038
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4320
+ const maxFee = calculateGasFee({
4321
+ gasPrice: bn17(gasPrice),
4322
+ gas: maxGas,
4323
+ priceFactor: gasPriceFactor,
4324
+ tip: transactionRequest.tip
4325
+ }).add(1);
4039
4326
  return {
4040
4327
  minGas,
4041
4328
  minFee,
4042
4329
  maxGas,
4043
- maxFee
4330
+ maxFee,
4331
+ gasPrice,
4332
+ gasLimit
4044
4333
  };
4045
4334
  }
4046
4335
  /**
@@ -4058,15 +4347,17 @@ var _Provider = class {
4058
4347
  if (estimateTxDependencies) {
4059
4348
  return this.estimateTxDependencies(transactionRequest);
4060
4349
  }
4061
- const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
4062
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4063
- encodedTransaction,
4350
+ const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
4351
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4352
+ encodedTransactions,
4064
4353
  utxoValidation: true
4065
4354
  });
4066
- const receipts = gqlReceipts.map(processGqlReceipt);
4067
- return {
4068
- receipts
4069
- };
4355
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4356
+ const { id, receipts, status } = dryRunStatus;
4357
+ const processedReceipts = receipts.map(processGqlReceipt);
4358
+ return { id, receipts: processedReceipts, status };
4359
+ });
4360
+ return { receipts: callResult[0].receipts };
4070
4361
  }
4071
4362
  /**
4072
4363
  * Returns a transaction cost to enable user
@@ -4083,77 +4374,79 @@ var _Provider = class {
4083
4374
  * @param tolerance - The tolerance to add on top of the gasUsed.
4084
4375
  * @returns A promise that resolves to the transaction cost object.
4085
4376
  */
4086
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4087
- estimateTxDependencies = true,
4088
- estimatePredicates = true,
4089
- resourcesOwner,
4090
- signatureCallback
4091
- } = {}) {
4377
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4092
4378
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
4093
- const { minGasPrice } = this.getGasConfig();
4094
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
4095
4379
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
4380
+ const baseAssetId = this.getBaseAssetId();
4096
4381
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4097
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4098
- txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4382
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4383
+ txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4384
+ txRequestClone.maxFee = bn17(0);
4099
4385
  if (isScriptTransaction) {
4100
- txRequestClone.gasLimit = bn15(0);
4386
+ txRequestClone.gasLimit = bn17(0);
4101
4387
  }
4102
- if (estimatePredicates) {
4103
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4104
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4105
- }
4106
- await this.estimatePredicates(txRequestClone);
4388
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4389
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4107
4390
  }
4391
+ const signedRequest = clone3(txRequestClone);
4392
+ let addedSignatures = 0;
4108
4393
  if (signatureCallback && isScriptTransaction) {
4109
- await signatureCallback(txRequestClone);
4394
+ const lengthBefore = signedRequest.witnesses.length;
4395
+ await signatureCallback(signedRequest);
4396
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4110
4397
  }
4111
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4112
- transactionRequest: txRequestClone
4398
+ await this.estimatePredicates(signedRequest);
4399
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4400
+ transactionRequest: signedRequest
4113
4401
  });
4114
4402
  let receipts = [];
4403
+ let dryRunStatus;
4115
4404
  let missingContractIds = [];
4116
4405
  let outputVariables = 0;
4117
- let gasUsed = bn15(0);
4118
- if (isScriptTransaction && estimateTxDependencies) {
4119
- txRequestClone.gasPrice = bn15(0);
4120
- const result = await this.estimateTxDependencies(txRequestClone);
4121
- receipts = result.receipts;
4122
- outputVariables = result.outputVariables;
4123
- missingContractIds = result.missingContractIds;
4406
+ let gasUsed = bn17(0);
4407
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4408
+ txRequestClone.maxFee = maxFee;
4409
+ if (isScriptTransaction) {
4410
+ txRequestClone.gasLimit = gasLimit;
4411
+ if (signatureCallback) {
4412
+ await signatureCallback(txRequestClone);
4413
+ }
4414
+ ({ receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone));
4124
4415
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4125
4416
  txRequestClone.gasLimit = gasUsed;
4126
- txRequestClone.gasPrice = setGasPrice;
4127
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4128
- transactionRequest: txRequestClone
4417
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4418
+ transactionRequest: txRequestClone,
4419
+ gasPrice
4129
4420
  }));
4130
4421
  }
4131
4422
  return {
4132
4423
  requiredQuantities: allQuantities,
4133
4424
  receipts,
4134
4425
  gasUsed,
4135
- minGasPrice,
4136
- gasPrice: setGasPrice,
4426
+ gasPrice,
4137
4427
  minGas,
4138
4428
  maxGas,
4139
4429
  minFee,
4140
4430
  maxFee,
4141
- estimatedInputs: txRequestClone.inputs,
4142
4431
  outputVariables,
4143
- missingContractIds
4432
+ missingContractIds,
4433
+ addedSignatures,
4434
+ estimatedPredicates: txRequestClone.inputs,
4435
+ dryRunStatus
4144
4436
  };
4145
4437
  }
4146
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4438
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4147
4439
  const ownerAddress = Address2.fromAddressOrString(owner);
4148
4440
  const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
4149
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4441
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4442
+ quantitiesToContract
4443
+ });
4150
4444
  transactionRequest.addResources(
4151
4445
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4152
4446
  );
4153
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4154
- transactionRequest,
4155
- forwardingQuantities
4156
- );
4447
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4448
+ quantitiesToContract
4449
+ });
4157
4450
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4158
4451
  return {
4159
4452
  resources,
@@ -4175,11 +4468,10 @@ var _Provider = class {
4175
4468
  return coins.map((coin) => ({
4176
4469
  id: coin.utxoId,
4177
4470
  assetId: coin.assetId,
4178
- amount: bn15(coin.amount),
4471
+ amount: bn17(coin.amount),
4179
4472
  owner: Address2.fromAddressOrString(coin.owner),
4180
- maturity: bn15(coin.maturity).toNumber(),
4181
- blockCreated: bn15(coin.blockCreated),
4182
- txCreatedIdx: bn15(coin.txCreatedIdx)
4473
+ blockCreated: bn17(coin.blockCreated),
4474
+ txCreatedIdx: bn17(coin.txCreatedIdx)
4183
4475
  }));
4184
4476
  }
4185
4477
  /**
@@ -4216,9 +4508,9 @@ var _Provider = class {
4216
4508
  switch (coin.__typename) {
4217
4509
  case "MessageCoin":
4218
4510
  return {
4219
- amount: bn15(coin.amount),
4511
+ amount: bn17(coin.amount),
4220
4512
  assetId: coin.assetId,
4221
- daHeight: bn15(coin.daHeight),
4513
+ daHeight: bn17(coin.daHeight),
4222
4514
  sender: Address2.fromAddressOrString(coin.sender),
4223
4515
  recipient: Address2.fromAddressOrString(coin.recipient),
4224
4516
  nonce: coin.nonce
@@ -4226,12 +4518,11 @@ var _Provider = class {
4226
4518
  case "Coin":
4227
4519
  return {
4228
4520
  id: coin.utxoId,
4229
- amount: bn15(coin.amount),
4521
+ amount: bn17(coin.amount),
4230
4522
  assetId: coin.assetId,
4231
4523
  owner: Address2.fromAddressOrString(coin.owner),
4232
- maturity: bn15(coin.maturity).toNumber(),
4233
- blockCreated: bn15(coin.blockCreated),
4234
- txCreatedIdx: bn15(coin.txCreatedIdx)
4524
+ blockCreated: bn17(coin.blockCreated),
4525
+ txCreatedIdx: bn17(coin.txCreatedIdx)
4235
4526
  };
4236
4527
  default:
4237
4528
  return null;
@@ -4248,13 +4539,13 @@ var _Provider = class {
4248
4539
  async getBlock(idOrHeight) {
4249
4540
  let variables;
4250
4541
  if (typeof idOrHeight === "number") {
4251
- variables = { height: bn15(idOrHeight).toString(10) };
4542
+ variables = { height: bn17(idOrHeight).toString(10) };
4252
4543
  } else if (idOrHeight === "latest") {
4253
4544
  variables = { height: (await this.getBlockNumber()).toString(10) };
4254
4545
  } else if (idOrHeight.length === 66) {
4255
4546
  variables = { blockId: idOrHeight };
4256
4547
  } else {
4257
- variables = { blockId: bn15(idOrHeight).toString(10) };
4548
+ variables = { blockId: bn17(idOrHeight).toString(10) };
4258
4549
  }
4259
4550
  const { block } = await this.operations.getBlock(variables);
4260
4551
  if (!block) {
@@ -4262,7 +4553,7 @@ var _Provider = class {
4262
4553
  }
4263
4554
  return {
4264
4555
  id: block.id,
4265
- height: bn15(block.header.height),
4556
+ height: bn17(block.height),
4266
4557
  time: block.header.time,
4267
4558
  transactionIds: block.transactions.map((tx) => tx.id)
4268
4559
  };
@@ -4277,7 +4568,7 @@ var _Provider = class {
4277
4568
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4278
4569
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4279
4570
  id: block.id,
4280
- height: bn15(block.header.height),
4571
+ height: bn17(block.height),
4281
4572
  time: block.header.time,
4282
4573
  transactionIds: block.transactions.map((tx) => tx.id)
4283
4574
  }));
@@ -4292,7 +4583,7 @@ var _Provider = class {
4292
4583
  async getBlockWithTransactions(idOrHeight) {
4293
4584
  let variables;
4294
4585
  if (typeof idOrHeight === "number") {
4295
- variables = { blockHeight: bn15(idOrHeight).toString(10) };
4586
+ variables = { blockHeight: bn17(idOrHeight).toString(10) };
4296
4587
  } else if (idOrHeight === "latest") {
4297
4588
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4298
4589
  } else {
@@ -4304,7 +4595,7 @@ var _Provider = class {
4304
4595
  }
4305
4596
  return {
4306
4597
  id: block.id,
4307
- height: bn15(block.header.height, 10),
4598
+ height: bn17(block.height, 10),
4308
4599
  time: block.header.time,
4309
4600
  transactionIds: block.transactions.map((tx) => tx.id),
4310
4601
  transactions: block.transactions.map(
@@ -4353,7 +4644,7 @@ var _Provider = class {
4353
4644
  contract: Address2.fromAddressOrString(contractId).toB256(),
4354
4645
  asset: hexlify12(assetId)
4355
4646
  });
4356
- return bn15(contractBalance.amount, 10);
4647
+ return bn17(contractBalance.amount, 10);
4357
4648
  }
4358
4649
  /**
4359
4650
  * Returns the balance for the given owner for the given asset ID.
@@ -4367,7 +4658,7 @@ var _Provider = class {
4367
4658
  owner: Address2.fromAddressOrString(owner).toB256(),
4368
4659
  assetId: hexlify12(assetId)
4369
4660
  });
4370
- return bn15(balance.amount, 10);
4661
+ return bn17(balance.amount, 10);
4371
4662
  }
4372
4663
  /**
4373
4664
  * Returns balances for the given owner.
@@ -4385,7 +4676,7 @@ var _Provider = class {
4385
4676
  const balances = result.balances.edges.map((edge) => edge.node);
4386
4677
  return balances.map((balance) => ({
4387
4678
  assetId: balance.assetId,
4388
- amount: bn15(balance.amount)
4679
+ amount: bn17(balance.amount)
4389
4680
  }));
4390
4681
  }
4391
4682
  /**
@@ -4407,15 +4698,15 @@ var _Provider = class {
4407
4698
  sender: message.sender,
4408
4699
  recipient: message.recipient,
4409
4700
  nonce: message.nonce,
4410
- amount: bn15(message.amount),
4701
+ amount: bn17(message.amount),
4411
4702
  data: message.data
4412
4703
  }),
4413
4704
  sender: Address2.fromAddressOrString(message.sender),
4414
4705
  recipient: Address2.fromAddressOrString(message.recipient),
4415
4706
  nonce: message.nonce,
4416
- amount: bn15(message.amount),
4707
+ amount: bn17(message.amount),
4417
4708
  data: InputMessageCoder.decodeData(message.data),
4418
- daHeight: bn15(message.daHeight)
4709
+ daHeight: bn17(message.daHeight)
4419
4710
  }));
4420
4711
  }
4421
4712
  /**
@@ -4468,44 +4759,60 @@ var _Provider = class {
4468
4759
  } = result.messageProof;
4469
4760
  return {
4470
4761
  messageProof: {
4471
- proofIndex: bn15(messageProof.proofIndex),
4762
+ proofIndex: bn17(messageProof.proofIndex),
4472
4763
  proofSet: messageProof.proofSet
4473
4764
  },
4474
4765
  blockProof: {
4475
- proofIndex: bn15(blockProof.proofIndex),
4766
+ proofIndex: bn17(blockProof.proofIndex),
4476
4767
  proofSet: blockProof.proofSet
4477
4768
  },
4478
4769
  messageBlockHeader: {
4479
4770
  id: messageBlockHeader.id,
4480
- daHeight: bn15(messageBlockHeader.daHeight),
4481
- transactionsCount: bn15(messageBlockHeader.transactionsCount),
4771
+ daHeight: bn17(messageBlockHeader.daHeight),
4772
+ transactionsCount: Number(messageBlockHeader.transactionsCount),
4482
4773
  transactionsRoot: messageBlockHeader.transactionsRoot,
4483
- height: bn15(messageBlockHeader.height),
4774
+ height: bn17(messageBlockHeader.height),
4484
4775
  prevRoot: messageBlockHeader.prevRoot,
4485
4776
  time: messageBlockHeader.time,
4486
4777
  applicationHash: messageBlockHeader.applicationHash,
4487
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4488
- messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
4778
+ messageReceiptCount: Number(messageBlockHeader.messageReceiptCount),
4779
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4780
+ consensusParametersVersion: Number(messageBlockHeader.consensusParametersVersion),
4781
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4782
+ stateTransitionBytecodeVersion: Number(messageBlockHeader.stateTransitionBytecodeVersion)
4489
4783
  },
4490
4784
  commitBlockHeader: {
4491
4785
  id: commitBlockHeader.id,
4492
- daHeight: bn15(commitBlockHeader.daHeight),
4493
- transactionsCount: bn15(commitBlockHeader.transactionsCount),
4786
+ daHeight: bn17(commitBlockHeader.daHeight),
4787
+ transactionsCount: Number(commitBlockHeader.transactionsCount),
4494
4788
  transactionsRoot: commitBlockHeader.transactionsRoot,
4495
- height: bn15(commitBlockHeader.height),
4789
+ height: bn17(commitBlockHeader.height),
4496
4790
  prevRoot: commitBlockHeader.prevRoot,
4497
4791
  time: commitBlockHeader.time,
4498
4792
  applicationHash: commitBlockHeader.applicationHash,
4499
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4500
- messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
4793
+ messageReceiptCount: Number(commitBlockHeader.messageReceiptCount),
4794
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4795
+ consensusParametersVersion: Number(commitBlockHeader.consensusParametersVersion),
4796
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4797
+ stateTransitionBytecodeVersion: Number(commitBlockHeader.stateTransitionBytecodeVersion)
4501
4798
  },
4502
4799
  sender: Address2.fromAddressOrString(sender),
4503
4800
  recipient: Address2.fromAddressOrString(recipient),
4504
4801
  nonce,
4505
- amount: bn15(amount),
4802
+ amount: bn17(amount),
4506
4803
  data
4507
4804
  };
4508
4805
  }
4806
+ async getLatestGasPrice() {
4807
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4808
+ return bn17(latestGasPrice.gasPrice);
4809
+ }
4810
+ async estimateGasPrice(blockHorizon) {
4811
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4812
+ blockHorizon: String(blockHorizon)
4813
+ });
4814
+ return bn17(estimateGasPrice.gasPrice);
4815
+ }
4509
4816
  /**
4510
4817
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4511
4818
  *
@@ -4525,15 +4832,37 @@ var _Provider = class {
4525
4832
  */
4526
4833
  async produceBlocks(amount, startTime) {
4527
4834
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4528
- blocksToProduce: bn15(amount).toString(10),
4835
+ blocksToProduce: bn17(amount).toString(10),
4529
4836
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4530
4837
  });
4531
- return bn15(latestBlockHeight);
4838
+ return bn17(latestBlockHeight);
4532
4839
  }
4533
4840
  // eslint-disable-next-line @typescript-eslint/require-await
4534
4841
  async getTransactionResponse(transactionId) {
4535
4842
  return new TransactionResponse(transactionId, this);
4536
4843
  }
4844
+ /**
4845
+ * Returns Message for given nonce.
4846
+ *
4847
+ * @param nonce - The nonce of the message to retrieve.
4848
+ * @returns A promise that resolves to the Message object.
4849
+ */
4850
+ async getMessageByNonce(nonce) {
4851
+ const { message } = await this.operations.getMessageByNonce({ nonce });
4852
+ if (!message) {
4853
+ return null;
4854
+ }
4855
+ return message;
4856
+ }
4857
+ async getRelayedTransactionStatus(relayedTransactionId) {
4858
+ const { relayedTransactionStatus } = await this.operations.getRelayedTransactionStatus({
4859
+ relayedTransactionId
4860
+ });
4861
+ if (!relayedTransactionStatus) {
4862
+ return null;
4863
+ }
4864
+ return relayedTransactionStatus;
4865
+ }
4537
4866
  };
4538
4867
  var Provider = _Provider;
4539
4868
  _cacheInputs = new WeakSet();
@@ -4542,7 +4871,7 @@ cacheInputs_fn = function(inputs) {
4542
4871
  return;
4543
4872
  }
4544
4873
  inputs.forEach((input) => {
4545
- if (input.type === InputType6.Coin) {
4874
+ if (input.type === InputType7.Coin) {
4546
4875
  this.cache?.set(input.id);
4547
4876
  }
4548
4877
  });
@@ -4552,7 +4881,7 @@ __publicField(Provider, "nodeInfoCache", {});
4552
4881
 
4553
4882
  // src/providers/transaction-summary/get-transaction-summary.ts
4554
4883
  import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4555
- import { bn as bn16 } from "@fuel-ts/math";
4884
+ import { bn as bn18 } from "@fuel-ts/math";
4556
4885
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4557
4886
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4558
4887
  async function getTransactionSummary(params) {
@@ -4570,21 +4899,32 @@ async function getTransactionSummary(params) {
4570
4899
  arrayify12(gqlTransaction.rawPayload),
4571
4900
  0
4572
4901
  );
4573
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4902
+ let txReceipts = [];
4903
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4904
+ txReceipts = gqlTransaction.status.receipts;
4905
+ }
4906
+ const receipts = txReceipts.map(processGqlReceipt);
4574
4907
  const {
4575
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4908
+ consensusParameters: {
4909
+ feeParameters: { gasPerByte, gasPriceFactor },
4910
+ txParameters: { maxInputs, maxGasPerTx },
4911
+ gasCosts
4912
+ }
4576
4913
  } = provider.getChain();
4914
+ const gasPrice = await provider.getLatestGasPrice();
4577
4915
  const transactionInfo = assembleTransactionSummary({
4578
4916
  id: gqlTransaction.id,
4579
4917
  receipts,
4580
4918
  transaction: decodedTransaction,
4581
4919
  transactionBytes: arrayify12(gqlTransaction.rawPayload),
4582
4920
  gqlTransactionStatus: gqlTransaction.status,
4583
- gasPerByte: bn16(gasPerByte),
4584
- gasPriceFactor: bn16(gasPriceFactor),
4921
+ gasPerByte: bn18(gasPerByte),
4922
+ gasPriceFactor: bn18(gasPriceFactor),
4585
4923
  abiMap,
4586
4924
  maxInputs,
4587
- gasCosts
4925
+ gasCosts,
4926
+ maxGasPerTx,
4927
+ gasPrice
4588
4928
  });
4589
4929
  return {
4590
4930
  gqlTransaction,
@@ -4594,10 +4934,11 @@ async function getTransactionSummary(params) {
4594
4934
  async function getTransactionSummaryFromRequest(params) {
4595
4935
  const { provider, transactionRequest, abiMap } = params;
4596
4936
  const { receipts } = await provider.call(transactionRequest);
4597
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4598
- const maxInputs = provider.getChain().consensusParameters.maxInputs;
4937
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4938
+ const maxInputs = provider.getChain().consensusParameters.txParameters.maxInputs;
4599
4939
  const transaction = transactionRequest.toTransaction();
4600
4940
  const transactionBytes = transactionRequest.toTransactionBytes();
4941
+ const gasPrice = await provider.getLatestGasPrice();
4601
4942
  const transactionSummary = assembleTransactionSummary({
4602
4943
  receipts,
4603
4944
  transaction,
@@ -4606,7 +4947,9 @@ async function getTransactionSummaryFromRequest(params) {
4606
4947
  gasPerByte,
4607
4948
  gasPriceFactor,
4608
4949
  maxInputs,
4609
- gasCosts
4950
+ gasCosts,
4951
+ maxGasPerTx,
4952
+ gasPrice
4610
4953
  });
4611
4954
  return transactionSummary;
4612
4955
  }
@@ -4615,13 +4958,22 @@ async function getTransactionsSummaries(params) {
4615
4958
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4616
4959
  const { edges, pageInfo } = transactionsByOwner;
4617
4960
  const {
4618
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4961
+ consensusParameters: {
4962
+ feeParameters: { gasPerByte, gasPriceFactor },
4963
+ txParameters: { maxInputs, maxGasPerTx },
4964
+ gasCosts
4965
+ }
4619
4966
  } = provider.getChain();
4967
+ const gasPrice = await provider.getLatestGasPrice();
4620
4968
  const transactions = edges.map((edge) => {
4621
4969
  const { node: gqlTransaction } = edge;
4622
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4970
+ const { id, rawPayload, status } = gqlTransaction;
4623
4971
  const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
4624
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4972
+ let txReceipts = [];
4973
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4974
+ txReceipts = gqlTransaction.status.receipts;
4975
+ }
4976
+ const receipts = txReceipts.map(processGqlReceipt);
4625
4977
  const transactionSummary = assembleTransactionSummary({
4626
4978
  id,
4627
4979
  receipts,
@@ -4632,7 +4984,9 @@ async function getTransactionsSummaries(params) {
4632
4984
  gasPerByte,
4633
4985
  gasPriceFactor,
4634
4986
  maxInputs,
4635
- gasCosts
4987
+ gasCosts,
4988
+ maxGasPerTx,
4989
+ gasPrice
4636
4990
  });
4637
4991
  const output = {
4638
4992
  gqlTransaction,
@@ -4767,6 +5121,22 @@ var assets = [
4767
5121
  }
4768
5122
  ];
4769
5123
 
5124
+ // src/providers/transaction-request/helpers.ts
5125
+ import { bn as bn19 } from "@fuel-ts/math";
5126
+ import { InputType as InputType8 } from "@fuel-ts/transactions";
5127
+ var isRequestInputCoin = (input) => input.type === InputType8.Coin;
5128
+ var isRequestInputMessage = (input) => input.type === InputType8.Message;
5129
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
5130
+ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
5131
+ if (isRequestInputCoin(input) && input.assetId === assetId) {
5132
+ return acc.add(input.amount);
5133
+ }
5134
+ if (isRequestInputMessage(input) && assetId === baseAsset) {
5135
+ return acc.add(input.amount);
5136
+ }
5137
+ return acc;
5138
+ }, bn19(0));
5139
+
4770
5140
  // src/utils/formatTransferToContractScriptData.ts
4771
5141
  import { BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
4772
5142
  import { BN as BN2 } from "@fuel-ts/math";
@@ -4804,6 +5174,7 @@ var assembleTransferToContractScript = async (params) => {
4804
5174
  };
4805
5175
 
4806
5176
  // src/account.ts
5177
+ var MAX_FUNDING_ATTEMPTS = 2;
4807
5178
  var Account = class extends AbstractAccount {
4808
5179
  /**
4809
5180
  * The address associated with the account.
@@ -4926,8 +5297,9 @@ var Account = class extends AbstractAccount {
4926
5297
  * @param assetId - The asset ID to check the balance for.
4927
5298
  * @returns A promise that resolves to the balance amount.
4928
5299
  */
4929
- async getBalance(assetId = BaseAssetId3) {
4930
- const amount = await this.provider.getBalance(this.address, assetId);
5300
+ async getBalance(assetId) {
5301
+ const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
5302
+ const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4931
5303
  return amount;
4932
5304
  }
4933
5305
  /**
@@ -4960,44 +5332,35 @@ var Account = class extends AbstractAccount {
4960
5332
  * Adds resources to the transaction enough to fund it.
4961
5333
  *
4962
5334
  * @param request - The transaction request.
4963
- * @param coinQuantities - The coin quantities required to execute the transaction.
5335
+ * @param requiredQuantities - The coin quantities required to execute the transaction.
4964
5336
  * @param fee - The estimated transaction fee.
4965
5337
  * @returns A promise that resolves when the resources are added to the transaction.
4966
5338
  */
4967
- async fund(request, coinQuantities, fee) {
4968
- const updatedQuantities = addAmountToAsset({
4969
- amount: bn17(fee),
4970
- assetId: BaseAssetId3,
4971
- coinQuantities
5339
+ async fund(request, params) {
5340
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5341
+ const baseAssetId = this.provider.getBaseAssetId();
5342
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn20(0);
5343
+ const txRequest = request;
5344
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5345
+ amount: bn20(fee),
5346
+ assetId: baseAssetId,
5347
+ coinQuantities: requiredQuantities
4972
5348
  });
4973
5349
  const quantitiesDict = {};
4974
- updatedQuantities.forEach(({ amount, assetId }) => {
5350
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4975
5351
  quantitiesDict[assetId] = {
4976
5352
  required: amount,
4977
- owned: bn17(0)
5353
+ owned: bn20(0)
4978
5354
  };
4979
5355
  });
4980
- const cachedUtxos = [];
4981
- const cachedMessages = [];
4982
- const owner = this.address.toB256();
4983
- request.inputs.forEach((input) => {
4984
- const isResource = "amount" in input;
4985
- if (isResource) {
4986
- const isCoin2 = "owner" in input;
4987
- if (isCoin2) {
4988
- const assetId = String(input.assetId);
4989
- if (input.owner === owner && quantitiesDict[assetId]) {
4990
- const amount = bn17(input.amount);
4991
- quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4992
- cachedUtxos.push(input.id);
4993
- }
4994
- } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4995
- quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4996
- cachedMessages.push(input.nonce);
4997
- }
5356
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
5357
+ const isCoin2 = isRequestInputCoin(input);
5358
+ const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
5359
+ if (quantitiesDict[assetId]) {
5360
+ quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
4998
5361
  }
4999
5362
  });
5000
- const missingQuantities = [];
5363
+ let missingQuantities = [];
5001
5364
  Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {
5002
5365
  if (owned.lt(required)) {
5003
5366
  missingQuantities.push({
@@ -5006,14 +5369,54 @@ var Account = class extends AbstractAccount {
5006
5369
  });
5007
5370
  }
5008
5371
  });
5009
- const needsToBeFunded = missingQuantities.length;
5010
- if (needsToBeFunded) {
5011
- const resources = await this.getResourcesToSpend(missingQuantities, {
5012
- messages: cachedMessages,
5013
- utxos: cachedUtxos
5014
- });
5372
+ let needsToBeFunded = missingQuantities.length > 0;
5373
+ let fundingAttempts = 0;
5374
+ while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
5375
+ const resources = await this.getResourcesToSpend(
5376
+ missingQuantities,
5377
+ cacheTxInputsFromOwner(request.inputs, this.address)
5378
+ );
5015
5379
  request.addResources(resources);
5380
+ txRequest.shiftPredicateData();
5381
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5382
+ const requestToReestimate2 = clone4(txRequest);
5383
+ if (addedSignatures) {
5384
+ Array.from({ length: addedSignatures }).forEach(
5385
+ () => requestToReestimate2.addEmptyWitness()
5386
+ );
5387
+ }
5388
+ const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
5389
+ transactionRequest: requestToReestimate2
5390
+ });
5391
+ const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
5392
+ request.inputs,
5393
+ baseAssetId,
5394
+ baseAssetId
5395
+ );
5396
+ const totalBaseAssetRequiredWithFee = requiredInBaseAsset.add(newFee);
5397
+ if (totalBaseAssetOnInputs.gt(totalBaseAssetRequiredWithFee)) {
5398
+ needsToBeFunded = false;
5399
+ } else {
5400
+ missingQuantities = [
5401
+ {
5402
+ amount: totalBaseAssetRequiredWithFee.sub(totalBaseAssetOnInputs),
5403
+ assetId: baseAssetId
5404
+ }
5405
+ ];
5406
+ }
5407
+ fundingAttempts += 1;
5016
5408
  }
5409
+ txRequest.shiftPredicateData();
5410
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5411
+ const requestToReestimate = clone4(txRequest);
5412
+ if (addedSignatures) {
5413
+ Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
5414
+ }
5415
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5416
+ transactionRequest: requestToReestimate
5417
+ });
5418
+ txRequest.maxFee = maxFee;
5419
+ return txRequest;
5017
5420
  }
5018
5421
  /**
5019
5422
  * A helper that creates a transfer transaction request and returns it.
@@ -5021,28 +5424,25 @@ var Account = class extends AbstractAccount {
5021
5424
  * @param destination - The address of the destination.
5022
5425
  * @param amount - The amount of coins to transfer.
5023
5426
  * @param assetId - The asset ID of the coins to transfer.
5024
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5427
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5025
5428
  * @returns A promise that resolves to the prepared transaction request.
5026
5429
  */
5027
- async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5028
- const { minGasPrice } = this.provider.getGasConfig();
5029
- const params = { gasPrice: minGasPrice, ...txParams };
5030
- const request = new ScriptTransactionRequest(params);
5031
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
5032
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5430
+ async createTransfer(destination, amount, assetId, txParams = {}) {
5431
+ const request = new ScriptTransactionRequest(txParams);
5432
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5433
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
5434
+ const txCost = await this.provider.getTransactionCost(request, {
5033
5435
  estimateTxDependencies: true,
5034
5436
  resourcesOwner: this
5035
5437
  });
5036
- request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
5037
- request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
5038
- this.validateGas({
5039
- gasUsed,
5040
- gasPrice: request.gasPrice,
5041
- gasLimit: request.gasLimit,
5042
- minGasPrice
5438
+ this.validateGasLimitAndMaxFee({
5439
+ gasUsed: txCost.gasUsed,
5440
+ maxFee: txCost.maxFee,
5441
+ txParams
5043
5442
  });
5044
- await this.fund(request, requiredQuantities, maxFee);
5045
- request.updatePredicateInputs(estimatedInputs);
5443
+ request.gasLimit = txCost.gasUsed;
5444
+ request.maxFee = txCost.maxFee;
5445
+ await this.fund(request, txCost);
5046
5446
  return request;
5047
5447
  }
5048
5448
  /**
@@ -5051,17 +5451,18 @@ var Account = class extends AbstractAccount {
5051
5451
  * @param destination - The address of the destination.
5052
5452
  * @param amount - The amount of coins to transfer.
5053
5453
  * @param assetId - The asset ID of the coins to transfer.
5054
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5454
+ * @param txParams - The transaction parameters (gasLimit, maturity).
5055
5455
  * @returns A promise that resolves to the transaction response.
5056
5456
  */
5057
- async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5058
- if (bn17(amount).lte(0)) {
5457
+ async transfer(destination, amount, assetId, txParams = {}) {
5458
+ if (bn20(amount).lte(0)) {
5059
5459
  throw new FuelError15(
5060
5460
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5061
5461
  "Transfer amount must be a positive number."
5062
5462
  );
5063
5463
  }
5064
- const request = await this.createTransfer(destination, amount, assetId, txParams);
5464
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5465
+ const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5065
5466
  return this.sendTransaction(request, { estimateTxDependencies: false });
5066
5467
  }
5067
5468
  /**
@@ -5073,39 +5474,38 @@ var Account = class extends AbstractAccount {
5073
5474
  * @param txParams - The optional transaction parameters.
5074
5475
  * @returns A promise that resolves to the transaction response.
5075
5476
  */
5076
- async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5077
- if (bn17(amount).lte(0)) {
5477
+ async transferToContract(contractId, amount, assetId, txParams = {}) {
5478
+ if (bn20(amount).lte(0)) {
5078
5479
  throw new FuelError15(
5079
5480
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5080
5481
  "Transfer amount must be a positive number."
5081
5482
  );
5082
5483
  }
5083
5484
  const contractAddress = Address3.fromAddressOrString(contractId);
5084
- const { minGasPrice } = this.provider.getGasConfig();
5085
- const params = { gasPrice: minGasPrice, ...txParams };
5485
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5086
5486
  const { script, scriptData } = await assembleTransferToContractScript({
5087
5487
  hexlifiedContractId: contractAddress.toB256(),
5088
- amountToTransfer: bn17(amount),
5089
- assetId
5488
+ amountToTransfer: bn20(amount),
5489
+ assetId: assetIdToTransfer
5090
5490
  });
5091
5491
  const request = new ScriptTransactionRequest({
5092
- ...params,
5492
+ ...txParams,
5093
5493
  script,
5094
5494
  scriptData
5095
5495
  });
5096
5496
  request.addContractInputAndOutput(contractAddress);
5097
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5098
- request,
5099
- [{ amount: bn17(amount), assetId: String(assetId) }]
5100
- );
5101
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5102
- this.validateGas({
5103
- gasUsed,
5104
- gasPrice: request.gasPrice,
5105
- gasLimit: request.gasLimit,
5106
- minGasPrice
5497
+ const txCost = await this.provider.getTransactionCost(request, {
5498
+ resourcesOwner: this,
5499
+ quantitiesToContract: [{ amount: bn20(amount), assetId: String(assetIdToTransfer) }]
5500
+ });
5501
+ this.validateGasLimitAndMaxFee({
5502
+ gasUsed: txCost.gasUsed,
5503
+ maxFee: txCost.maxFee,
5504
+ txParams
5107
5505
  });
5108
- await this.fund(request, requiredQuantities, maxFee);
5506
+ request.gasLimit = txCost.gasUsed;
5507
+ request.maxFee = txCost.maxFee;
5508
+ await this.fund(request, txCost);
5109
5509
  return this.sendTransaction(request);
5110
5510
  }
5111
5511
  /**
@@ -5117,34 +5517,31 @@ var Account = class extends AbstractAccount {
5117
5517
  * @returns A promise that resolves to the transaction response.
5118
5518
  */
5119
5519
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5120
- const { minGasPrice } = this.provider.getGasConfig();
5121
5520
  const recipientAddress = Address3.fromAddressOrString(recipient);
5122
5521
  const recipientDataArray = arrayify14(
5123
5522
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5124
5523
  );
5125
5524
  const amountDataArray = arrayify14(
5126
- "0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
5525
+ "0x".concat(bn20(amount).toHex().substring(2).padStart(16, "0"))
5127
5526
  );
5128
5527
  const script = new Uint8Array([
5129
5528
  ...arrayify14(withdrawScript.bytes),
5130
5529
  ...recipientDataArray,
5131
5530
  ...amountDataArray
5132
5531
  ]);
5133
- const params = { script, gasPrice: minGasPrice, ...txParams };
5532
+ const params = { script, ...txParams };
5533
+ const baseAssetId = this.provider.getBaseAssetId();
5134
5534
  const request = new ScriptTransactionRequest(params);
5135
- const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
5136
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5137
- request,
5138
- forwardingQuantities
5139
- );
5140
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5141
- this.validateGas({
5142
- gasUsed,
5143
- gasPrice: request.gasPrice,
5144
- gasLimit: request.gasLimit,
5145
- minGasPrice
5535
+ const quantitiesToContract = [{ amount: bn20(amount), assetId: baseAssetId }];
5536
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5537
+ this.validateGasLimitAndMaxFee({
5538
+ gasUsed: txCost.gasUsed,
5539
+ maxFee: txCost.maxFee,
5540
+ txParams
5146
5541
  });
5147
- await this.fund(request, requiredQuantities, maxFee);
5542
+ request.maxFee = txCost.maxFee;
5543
+ request.gasLimit = txCost.gasUsed;
5544
+ await this.fund(request, txCost);
5148
5545
  return this.sendTransaction(request);
5149
5546
  }
5150
5547
  async signMessage(message) {
@@ -5202,22 +5599,21 @@ var Account = class extends AbstractAccount {
5202
5599
  }
5203
5600
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5204
5601
  }
5205
- validateGas({
5602
+ validateGasLimitAndMaxFee({
5603
+ txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
5206
5604
  gasUsed,
5207
- gasPrice,
5208
- gasLimit,
5209
- minGasPrice
5605
+ maxFee
5210
5606
  }) {
5211
- if (minGasPrice.gt(gasPrice)) {
5607
+ if (isDefined2(setGasLimit) && gasUsed.gt(setGasLimit)) {
5212
5608
  throw new FuelError15(
5213
- ErrorCode15.GAS_PRICE_TOO_LOW,
5214
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5609
+ ErrorCode15.GAS_LIMIT_TOO_LOW,
5610
+ `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5215
5611
  );
5216
5612
  }
5217
- if (gasUsed.gt(gasLimit)) {
5613
+ if (isDefined2(setMaxFee) && maxFee.gt(setMaxFee)) {
5218
5614
  throw new FuelError15(
5219
- ErrorCode15.GAS_LIMIT_TOO_LOW,
5220
- `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
5615
+ ErrorCode15.MAX_FEE_TOO_LOW,
5616
+ `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
5221
5617
  );
5222
5618
  }
5223
5619
  }
@@ -5509,7 +5905,7 @@ var BaseWalletUnlocked = class extends Account {
5509
5905
  * @param transactionRequestLike - The transaction request to send.
5510
5906
  * @returns A promise that resolves to the TransactionResponse object.
5511
5907
  */
5512
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5908
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5513
5909
  const transactionRequest = transactionRequestify(transactionRequestLike);
5514
5910
  if (estimateTxDependencies) {
5515
5911
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5550,7 +5946,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5550
5946
  // src/hdwallet/hdwallet.ts
5551
5947
  import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5552
5948
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5553
- import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5949
+ import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5554
5950
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5555
5951
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5556
5952
 
@@ -8022,7 +8418,7 @@ var HDWallet = class {
8022
8418
  const IR = bytes.slice(32);
8023
8419
  if (privateKey) {
8024
8420
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8025
- const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
8421
+ const ki = bn21(IL).add(privateKey).mod(N).toBytes(32);
8026
8422
  return new HDWallet({
8027
8423
  privateKey: ki,
8028
8424
  chainCode: IR,
@@ -8709,9 +9105,8 @@ import {
8709
9105
  SCRIPT_FIXED_SIZE
8710
9106
  } from "@fuel-ts/abi-coder";
8711
9107
  import { Address as Address9 } from "@fuel-ts/address";
8712
- import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8713
9108
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8714
- import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
9109
+ import { ByteArrayCoder, InputType as InputType9 } from "@fuel-ts/transactions";
8715
9110
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8716
9111
 
8717
9112
  // src/predicate/utils/getPredicateRoot.ts
@@ -8771,35 +9166,22 @@ var Predicate = class extends Account {
8771
9166
  const request = transactionRequestify(transactionRequestLike);
8772
9167
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8773
9168
  request.inputs?.forEach((input) => {
8774
- if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
8775
- input.predicate = this.bytes;
8776
- input.predicateData = this.getPredicateData(policies.length);
9169
+ if (input.type === InputType9.Coin && hexlify19(input.owner) === this.address.toB256()) {
9170
+ input.predicate = hexlify19(this.bytes);
9171
+ input.predicateData = hexlify19(this.getPredicateData(policies.length));
8777
9172
  }
8778
9173
  });
8779
9174
  return request;
8780
9175
  }
8781
- /**
8782
- * A helper that creates a transfer transaction request and returns it.
8783
- *
8784
- * @param destination - The address of the destination.
8785
- * @param amount - The amount of coins to transfer.
8786
- * @param assetId - The asset ID of the coins to transfer.
8787
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8788
- * @returns A promise that resolves to the prepared transaction request.
8789
- */
8790
- async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8791
- const request = await super.createTransfer(destination, amount, assetId, txParams);
8792
- return this.populateTransactionPredicateData(request);
8793
- }
8794
9176
  /**
8795
9177
  * Sends a transaction with the populated predicate data.
8796
9178
  *
8797
9179
  * @param transactionRequestLike - The transaction request-like object.
8798
9180
  * @returns A promise that resolves to the transaction response.
8799
9181
  */
8800
- sendTransaction(transactionRequestLike, options) {
8801
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8802
- return super.sendTransaction(transactionRequest, options);
9182
+ sendTransaction(transactionRequestLike) {
9183
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9184
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8803
9185
  }
8804
9186
  /**
8805
9187
  * Simulates a transaction with the populated predicate data.
@@ -8808,8 +9190,8 @@ var Predicate = class extends Account {
8808
9190
  * @returns A promise that resolves to the call result.
8809
9191
  */
8810
9192
  simulateTransaction(transactionRequestLike) {
8811
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8812
- return super.simulateTransaction(transactionRequest);
9193
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9194
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8813
9195
  }
8814
9196
  getPredicateData(policiesLength) {
8815
9197
  if (!this.predicateData.length) {
@@ -8818,7 +9200,7 @@ var Predicate = class extends Account {
8818
9200
  const mainFn = this.interface?.functions.main;
8819
9201
  const paddedCode = new ByteArrayCoder(this.bytes.length).encode(this.bytes);
8820
9202
  const VM_TX_MEMORY = calculateVmTxMemory2({
8821
- maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
9203
+ maxInputs: this.provider.getChain().consensusParameters.txParameters.maxInputs.toNumber()
8822
9204
  });
8823
9205
  const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
8824
9206
  return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
@@ -8855,6 +9237,25 @@ var Predicate = class extends Account {
8855
9237
  predicateInterface: abiInterface
8856
9238
  };
8857
9239
  }
9240
+ /**
9241
+ * Retrieves resources satisfying the spend query for the account.
9242
+ *
9243
+ * @param quantities - IDs of coins to exclude.
9244
+ * @param excludedIds - IDs of resources to be excluded from the query.
9245
+ * @returns A promise that resolves to an array of Resources.
9246
+ */
9247
+ async getResourcesToSpend(quantities, excludedIds) {
9248
+ const resources = await this.provider.getResourcesToSpend(
9249
+ this.address,
9250
+ quantities,
9251
+ excludedIds
9252
+ );
9253
+ return resources.map((resource) => ({
9254
+ ...resource,
9255
+ predicate: hexlify19(this.bytes),
9256
+ padPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
9257
+ }));
9258
+ }
8858
9259
  /**
8859
9260
  * Sets the configurable constants for the predicate.
8860
9261
  *
@@ -9603,7 +10004,7 @@ export {
9603
10004
  WalletLocked,
9604
10005
  WalletManager,
9605
10006
  WalletUnlocked,
9606
- addAmountToAsset,
10007
+ addAmountToCoinQuantities,
9607
10008
  addOperation,
9608
10009
  assemblePanicError,
9609
10010
  assembleReceiptByType,
@@ -9612,10 +10013,11 @@ export {
9612
10013
  assets,
9613
10014
  buildBlockExplorerUrl,
9614
10015
  cacheFor,
10016
+ cacheTxInputsFromOwner,
10017
+ calculateGasFee,
9615
10018
  calculateMetadataGasForTxCreate,
9616
10019
  calculateMetadataGasForTxScript,
9617
- calculatePriceWithFactor,
9618
- calculateTransactionFee,
10020
+ calculateTXFeeForSummary,
9619
10021
  coinQuantityfy,
9620
10022
  deferPromise,
9621
10023
  dispatchFuelConnectorEvent,
@@ -9675,6 +10077,8 @@ export {
9675
10077
  isTypeCreate,
9676
10078
  isTypeMint,
9677
10079
  isTypeScript,
10080
+ isTypeUpgrade,
10081
+ isTypeUpload,
9678
10082
  normalizeJSON,
9679
10083
  outputify,
9680
10084
  processGqlReceipt,