@fuel-ts/account 0.0.0-rc-2021-20240424175107 → 0.0.0-rc-2037-20240424175231

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 (66) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +6 -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 +622 -814
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +659 -837
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +478 -661
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +39 -12
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +359 -810
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +1 -1
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +1 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +1 -6
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +27 -37
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  30. package/dist/providers/transaction-request/helpers.d.ts +10 -0
  31. package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
  32. package/dist/providers/transaction-request/index.d.ts +1 -0
  33. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  34. package/dist/providers/transaction-request/input.d.ts +2 -2
  35. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  36. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  37. package/dist/providers/transaction-request/transaction-request.d.ts +11 -6
  38. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  39. package/dist/providers/transaction-request/utils.d.ts +0 -3
  40. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  41. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
  43. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  44. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
  45. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  46. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  47. package/dist/providers/utils/gas.d.ts +2 -8
  48. package/dist/providers/utils/gas.d.ts.map +1 -1
  49. package/dist/test-utils/index.d.ts +1 -0
  50. package/dist/test-utils/index.d.ts.map +1 -1
  51. package/dist/test-utils/launchNode.d.ts.map +1 -1
  52. package/dist/test-utils/resources.d.ts +4 -0
  53. package/dist/test-utils/resources.d.ts.map +1 -0
  54. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  55. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  56. package/dist/test-utils/transactionRequest.d.ts +5 -0
  57. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  58. package/dist/test-utils.global.js +1089 -1533
  59. package/dist/test-utils.global.js.map +1 -1
  60. package/dist/test-utils.js +624 -820
  61. package/dist/test-utils.js.map +1 -1
  62. package/dist/test-utils.mjs +457 -656
  63. package/dist/test-utils.mjs.map +1 -1
  64. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  65. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  66. package/package.json +16 -16
@@ -27,9 +27,8 @@ import { Address as Address3 } from "@fuel-ts/address";
27
27
  import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
28
28
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
29
29
  import { AbstractAccount } from "@fuel-ts/interfaces";
30
- import { bn as bn18 } from "@fuel-ts/math";
31
- import { arrayify as arrayify14, isDefined } from "@fuel-ts/utils";
32
- import { clone as clone4 } from "ramda";
30
+ import { bn as bn17 } from "@fuel-ts/math";
31
+ import { arrayify as arrayify14 } from "@fuel-ts/utils";
33
32
 
34
33
  // src/providers/coin-quantity.ts
35
34
  import { BaseAssetId } from "@fuel-ts/address/configs";
@@ -38,24 +37,24 @@ import { hexlify } from "@fuel-ts/utils";
38
37
  var coinQuantityfy = (coinQuantityLike) => {
39
38
  let assetId;
40
39
  let amount;
41
- let max;
40
+ let max2;
42
41
  if (Array.isArray(coinQuantityLike)) {
43
42
  amount = coinQuantityLike[0];
44
43
  assetId = coinQuantityLike[1] ?? BaseAssetId;
45
- max = coinQuantityLike[2] ?? void 0;
44
+ max2 = coinQuantityLike[2] ?? void 0;
46
45
  } else {
47
46
  amount = coinQuantityLike.amount;
48
47
  assetId = coinQuantityLike.assetId ?? BaseAssetId;
49
- max = coinQuantityLike.max ?? void 0;
48
+ max2 = coinQuantityLike.max ?? void 0;
50
49
  }
51
50
  const bnAmount = bn(amount);
52
51
  return {
53
52
  assetId: hexlify(assetId),
54
53
  amount: bnAmount.lt(1) ? bn(1) : bnAmount,
55
- max: max ? bn(max) : void 0
54
+ max: max2 ? bn(max2) : void 0
56
55
  };
57
56
  };
58
- var addAmountToCoinQuantities = (params) => {
57
+ var addAmountToAsset = (params) => {
59
58
  const { amount, assetId } = params;
60
59
  const coinQuantities = [...params.coinQuantities];
61
60
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -70,7 +69,7 @@ var addAmountToCoinQuantities = (params) => {
70
69
  // src/providers/provider.ts
71
70
  import { Address as Address2 } from "@fuel-ts/address";
72
71
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
73
- import { BN, bn as bn16 } from "@fuel-ts/math";
72
+ import { BN, bn as bn15, max } from "@fuel-ts/math";
74
73
  import {
75
74
  InputType as InputType7,
76
75
  TransactionType as TransactionType8,
@@ -86,20 +85,16 @@ import { clone as clone3 } from "ramda";
86
85
 
87
86
  // src/providers/__generated__/operations.ts
88
87
  import gql from "graphql-tag";
89
- var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
90
- fragment transactionStatusSubscriptionFragment on TransactionStatus {
91
- type: __typename
92
- ... on SqueezedOutStatus {
93
- reason
94
- }
95
- }
96
- `;
97
88
  var ReceiptFragmentFragmentDoc = gql`
98
89
  fragment receiptFragment on Receipt {
99
- id
90
+ contract {
91
+ id
92
+ }
100
93
  pc
101
94
  is
102
- to
95
+ to {
96
+ id
97
+ }
103
98
  toAddress
104
99
  amount
105
100
  assetId
@@ -137,16 +132,10 @@ var TransactionStatusFragmentFragmentDoc = gql`
137
132
  id
138
133
  }
139
134
  time
140
- receipts {
141
- ...receiptFragment
142
- }
143
135
  programState {
144
136
  returnType
145
137
  data
146
138
  }
147
- receipts {
148
- ...receiptFragment
149
- }
150
139
  }
151
140
  ... on FailureStatus {
152
141
  block {
@@ -154,24 +143,26 @@ var TransactionStatusFragmentFragmentDoc = gql`
154
143
  }
155
144
  time
156
145
  reason
157
- receipts {
158
- ...receiptFragment
159
- }
160
146
  }
161
147
  ... on SqueezedOutStatus {
162
148
  reason
163
149
  }
164
150
  }
165
- ${ReceiptFragmentFragmentDoc}`;
151
+ `;
166
152
  var TransactionFragmentFragmentDoc = gql`
167
153
  fragment transactionFragment on Transaction {
168
154
  id
169
155
  rawPayload
156
+ gasPrice
157
+ receipts {
158
+ ...receiptFragment
159
+ }
170
160
  status {
171
161
  ...transactionStatusFragment
172
162
  }
173
163
  }
174
- ${TransactionStatusFragmentFragmentDoc}`;
164
+ ${ReceiptFragmentFragmentDoc}
165
+ ${TransactionStatusFragmentFragmentDoc}`;
175
166
  var InputEstimatePredicatesFragmentFragmentDoc = gql`
176
167
  fragment inputEstimatePredicatesFragment on Input {
177
168
  ... on InputCoin {
@@ -189,46 +180,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
189
180
  }
190
181
  }
191
182
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
192
- var DryRunFailureStatusFragmentFragmentDoc = gql`
193
- fragment dryRunFailureStatusFragment on DryRunFailureStatus {
194
- reason
195
- programState {
196
- returnType
197
- data
198
- }
199
- }
200
- `;
201
- var DryRunSuccessStatusFragmentFragmentDoc = gql`
202
- fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
203
- programState {
204
- returnType
205
- data
206
- }
207
- }
208
- `;
209
- var DryRunTransactionStatusFragmentFragmentDoc = gql`
210
- fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
211
- ... on DryRunFailureStatus {
212
- ...dryRunFailureStatusFragment
213
- }
214
- ... on DryRunSuccessStatus {
215
- ...dryRunSuccessStatusFragment
216
- }
217
- }
218
- ${DryRunFailureStatusFragmentFragmentDoc}
219
- ${DryRunSuccessStatusFragmentFragmentDoc}`;
220
- var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
221
- fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
222
- id
223
- status {
224
- ...dryRunTransactionStatusFragment
225
- }
226
- receipts {
227
- ...receiptFragment
228
- }
229
- }
230
- ${DryRunTransactionStatusFragmentFragmentDoc}
231
- ${ReceiptFragmentFragmentDoc}`;
232
183
  var CoinFragmentFragmentDoc = gql`
233
184
  fragment coinFragment on Coin {
234
185
  __typename
@@ -236,6 +187,7 @@ var CoinFragmentFragmentDoc = gql`
236
187
  owner
237
188
  amount
238
189
  assetId
190
+ maturity
239
191
  blockCreated
240
192
  txCreatedIdx
241
193
  }
@@ -274,32 +226,26 @@ var MessageProofFragmentFragmentDoc = gql`
274
226
  messageBlockHeader {
275
227
  id
276
228
  daHeight
277
- consensusParametersVersion
278
- stateTransitionBytecodeVersion
279
229
  transactionsCount
280
- messageReceiptCount
281
230
  transactionsRoot
282
- messageOutboxRoot
283
- eventInboxRoot
284
231
  height
285
232
  prevRoot
286
233
  time
287
234
  applicationHash
235
+ messageReceiptRoot
236
+ messageReceiptCount
288
237
  }
289
238
  commitBlockHeader {
290
239
  id
291
240
  daHeight
292
- consensusParametersVersion
293
- stateTransitionBytecodeVersion
294
241
  transactionsCount
295
- messageReceiptCount
296
242
  transactionsRoot
297
- messageOutboxRoot
298
- eventInboxRoot
299
243
  height
300
244
  prevRoot
301
245
  time
302
246
  applicationHash
247
+ messageReceiptRoot
248
+ messageReceiptCount
303
249
  }
304
250
  sender
305
251
  recipient
@@ -318,8 +264,8 @@ var BalanceFragmentFragmentDoc = gql`
318
264
  var BlockFragmentFragmentDoc = gql`
319
265
  fragment blockFragment on Block {
320
266
  id
321
- height
322
267
  header {
268
+ height
323
269
  time
324
270
  }
325
271
  transactions {
@@ -329,7 +275,6 @@ var BlockFragmentFragmentDoc = gql`
329
275
  `;
330
276
  var TxParametersFragmentFragmentDoc = gql`
331
277
  fragment TxParametersFragment on TxParameters {
332
- version
333
278
  maxInputs
334
279
  maxOutputs
335
280
  maxWitnesses
@@ -339,7 +284,6 @@ var TxParametersFragmentFragmentDoc = gql`
339
284
  `;
340
285
  var PredicateParametersFragmentFragmentDoc = gql`
341
286
  fragment PredicateParametersFragment on PredicateParameters {
342
- version
343
287
  maxPredicateLength
344
288
  maxPredicateDataLength
345
289
  maxGasPerPredicate
@@ -348,21 +292,18 @@ var PredicateParametersFragmentFragmentDoc = gql`
348
292
  `;
349
293
  var ScriptParametersFragmentFragmentDoc = gql`
350
294
  fragment ScriptParametersFragment on ScriptParameters {
351
- version
352
295
  maxScriptLength
353
296
  maxScriptDataLength
354
297
  }
355
298
  `;
356
299
  var ContractParametersFragmentFragmentDoc = gql`
357
300
  fragment ContractParametersFragment on ContractParameters {
358
- version
359
301
  contractMaxSize
360
302
  maxStorageSlots
361
303
  }
362
304
  `;
363
305
  var FeeParametersFragmentFragmentDoc = gql`
364
306
  fragment FeeParametersFragment on FeeParameters {
365
- version
366
307
  gasPriceFactor
367
308
  gasPerByte
368
309
  }
@@ -382,7 +323,6 @@ var DependentCostFragmentFragmentDoc = gql`
382
323
  `;
383
324
  var GasCostsFragmentFragmentDoc = gql`
384
325
  fragment GasCostsFragment on GasCosts {
385
- version
386
326
  add
387
327
  addi
388
328
  aloc
@@ -395,6 +335,7 @@ var GasCostsFragmentFragmentDoc = gql`
395
335
  cb
396
336
  cfei
397
337
  cfsi
338
+ croo
398
339
  div
399
340
  divi
400
341
  ecr1
@@ -477,9 +418,6 @@ var GasCostsFragmentFragmentDoc = gql`
477
418
  ccp {
478
419
  ...DependentCostFragment
479
420
  }
480
- croo {
481
- ...DependentCostFragment
482
- }
483
421
  csiz {
484
422
  ...DependentCostFragment
485
423
  }
@@ -539,7 +477,6 @@ var GasCostsFragmentFragmentDoc = gql`
539
477
  ${DependentCostFragmentFragmentDoc}`;
540
478
  var ConsensusParametersFragmentFragmentDoc = gql`
541
479
  fragment consensusParametersFragment on ConsensusParameters {
542
- version
543
480
  txParams {
544
481
  ...TxParametersFragment
545
482
  }
@@ -599,9 +536,18 @@ var NodeInfoFragmentFragmentDoc = gql`
599
536
  fragment nodeInfoFragment on NodeInfo {
600
537
  utxoValidation
601
538
  vmBacktrace
539
+ minGasPrice
602
540
  maxTx
603
541
  maxDepth
604
542
  nodeVersion
543
+ peers {
544
+ id
545
+ addresses
546
+ clientVersion
547
+ blockHeight
548
+ lastHeartbeatMs
549
+ appScore
550
+ }
605
551
  }
606
552
  `;
607
553
  var GetVersionDocument = gql`
@@ -636,9 +582,13 @@ var GetTransactionWithReceiptsDocument = gql`
636
582
  query getTransactionWithReceipts($transactionId: TransactionId!) {
637
583
  transaction(id: $transactionId) {
638
584
  ...transactionFragment
585
+ receipts {
586
+ ...receiptFragment
587
+ }
639
588
  }
640
589
  }
641
- ${TransactionFragmentFragmentDoc}`;
590
+ ${TransactionFragmentFragmentDoc}
591
+ ${ReceiptFragmentFragmentDoc}`;
642
592
  var GetTransactionsDocument = gql`
643
593
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
644
594
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -766,20 +716,6 @@ var GetBalanceDocument = gql`
766
716
  }
767
717
  }
768
718
  ${BalanceFragmentFragmentDoc}`;
769
- var GetLatestGasPriceDocument = gql`
770
- query getLatestGasPrice {
771
- latestGasPrice {
772
- gasPrice
773
- }
774
- }
775
- `;
776
- var EstimateGasPriceDocument = gql`
777
- query estimateGasPrice($blockHorizon: U32!) {
778
- estimateGasPrice(blockHorizon: $blockHorizon) {
779
- gasPrice
780
- }
781
- }
782
- `;
783
719
  var GetBalancesDocument = gql`
784
720
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
785
721
  balances(
@@ -834,12 +770,12 @@ var GetMessageStatusDocument = gql`
834
770
  }
835
771
  `;
836
772
  var DryRunDocument = gql`
837
- mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
838
- dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
839
- ...dryRunTransactionExecutionStatusFragment
773
+ mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
774
+ dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
775
+ ...receiptFragment
840
776
  }
841
777
  }
842
- ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
778
+ ${ReceiptFragmentFragmentDoc}`;
843
779
  var SubmitDocument = gql`
844
780
  mutation submit($encodedTransaction: HexString!) {
845
781
  submit(tx: $encodedTransaction) {
@@ -858,17 +794,17 @@ var ProduceBlocksDocument = gql`
858
794
  var SubmitAndAwaitDocument = gql`
859
795
  subscription submitAndAwait($encodedTransaction: HexString!) {
860
796
  submitAndAwait(tx: $encodedTransaction) {
861
- ...transactionStatusSubscriptionFragment
797
+ ...transactionStatusFragment
862
798
  }
863
799
  }
864
- ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
800
+ ${TransactionStatusFragmentFragmentDoc}`;
865
801
  var StatusChangeDocument = gql`
866
802
  subscription statusChange($transactionId: TransactionId!) {
867
803
  statusChange(id: $transactionId) {
868
- ...transactionStatusSubscriptionFragment
804
+ ...transactionStatusFragment
869
805
  }
870
806
  }
871
- ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
807
+ ${TransactionStatusFragmentFragmentDoc}`;
872
808
  function getSdk(requester) {
873
809
  return {
874
810
  getVersion(variables, options) {
@@ -922,12 +858,6 @@ function getSdk(requester) {
922
858
  getBalance(variables, options) {
923
859
  return requester(GetBalanceDocument, variables, options);
924
860
  },
925
- getLatestGasPrice(variables, options) {
926
- return requester(GetLatestGasPriceDocument, variables, options);
927
- },
928
- estimateGasPrice(variables, options) {
929
- return requester(EstimateGasPriceDocument, variables, options);
930
- },
931
861
  getBalances(variables, options) {
932
862
  return requester(GetBalancesDocument, variables, options);
933
863
  },
@@ -1121,9 +1051,10 @@ var inputify = (value) => {
1121
1051
  txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
1122
1052
  },
1123
1053
  witnessIndex: value.witnessIndex,
1054
+ maturity: value.maturity ?? 0,
1124
1055
  predicateGasUsed: bn2(value.predicateGasUsed),
1125
- predicateLength: bn2(predicate.length),
1126
- predicateDataLength: bn2(predicateData.length),
1056
+ predicateLength: predicate.length,
1057
+ predicateDataLength: predicateData.length,
1127
1058
  predicate: hexlify3(predicate),
1128
1059
  predicateData: hexlify3(predicateData)
1129
1060
  };
@@ -1154,8 +1085,8 @@ var inputify = (value) => {
1154
1085
  nonce: hexlify3(value.nonce),
1155
1086
  witnessIndex: value.witnessIndex,
1156
1087
  predicateGasUsed: bn2(value.predicateGasUsed),
1157
- predicateLength: bn2(predicate.length),
1158
- predicateDataLength: bn2(predicateData.length),
1088
+ predicateLength: predicate.length,
1089
+ predicateDataLength: predicateData.length,
1159
1090
  predicate: hexlify3(predicate),
1160
1091
  predicateData: hexlify3(predicateData),
1161
1092
  data: hexlify3(data),
@@ -1237,7 +1168,7 @@ import { bn as bn7 } from "@fuel-ts/math";
1237
1168
  import {
1238
1169
  PolicyType,
1239
1170
  TransactionCoder,
1240
- InputType as InputType2,
1171
+ InputType as InputType3,
1241
1172
  OutputType as OutputType2,
1242
1173
  TransactionType
1243
1174
  } from "@fuel-ts/transactions";
@@ -1282,8 +1213,8 @@ function assembleReceiptByType(receipt) {
1282
1213
  case "CALL" /* Call */: {
1283
1214
  const callReceipt = {
1284
1215
  type: ReceiptType.Call,
1285
- from: hexOrZero(receipt.id || receipt.contractId),
1286
- to: hexOrZero(receipt?.to),
1216
+ from: hexOrZero(receipt.contract?.id),
1217
+ to: hexOrZero(receipt?.to?.id),
1287
1218
  amount: bn4(receipt.amount),
1288
1219
  assetId: hexOrZero(receipt.assetId),
1289
1220
  gas: bn4(receipt.gas),
@@ -1297,7 +1228,7 @@ function assembleReceiptByType(receipt) {
1297
1228
  case "RETURN" /* Return */: {
1298
1229
  const returnReceipt = {
1299
1230
  type: ReceiptType.Return,
1300
- id: hexOrZero(receipt.id || receipt.contractId),
1231
+ id: hexOrZero(receipt.contract?.id),
1301
1232
  val: bn4(receipt.val),
1302
1233
  pc: bn4(receipt.pc),
1303
1234
  is: bn4(receipt.is)
@@ -1307,7 +1238,7 @@ function assembleReceiptByType(receipt) {
1307
1238
  case "RETURN_DATA" /* ReturnData */: {
1308
1239
  const returnDataReceipt = {
1309
1240
  type: ReceiptType.ReturnData,
1310
- id: hexOrZero(receipt.id || receipt.contractId),
1241
+ id: hexOrZero(receipt.contract?.id),
1311
1242
  ptr: bn4(receipt.ptr),
1312
1243
  len: bn4(receipt.len),
1313
1244
  digest: hexOrZero(receipt.digest),
@@ -1319,7 +1250,7 @@ function assembleReceiptByType(receipt) {
1319
1250
  case "PANIC" /* Panic */: {
1320
1251
  const panicReceipt = {
1321
1252
  type: ReceiptType.Panic,
1322
- id: hexOrZero(receipt.id),
1253
+ id: hexOrZero(receipt.contract?.id),
1323
1254
  reason: bn4(receipt.reason),
1324
1255
  pc: bn4(receipt.pc),
1325
1256
  is: bn4(receipt.is),
@@ -1330,7 +1261,7 @@ function assembleReceiptByType(receipt) {
1330
1261
  case "REVERT" /* Revert */: {
1331
1262
  const revertReceipt = {
1332
1263
  type: ReceiptType.Revert,
1333
- id: hexOrZero(receipt.id || receipt.contractId),
1264
+ id: hexOrZero(receipt.contract?.id),
1334
1265
  val: bn4(receipt.ra),
1335
1266
  pc: bn4(receipt.pc),
1336
1267
  is: bn4(receipt.is)
@@ -1340,7 +1271,7 @@ function assembleReceiptByType(receipt) {
1340
1271
  case "LOG" /* Log */: {
1341
1272
  const logReceipt = {
1342
1273
  type: ReceiptType.Log,
1343
- id: hexOrZero(receipt.id || receipt.contractId),
1274
+ id: hexOrZero(receipt.contract?.id),
1344
1275
  val0: bn4(receipt.ra),
1345
1276
  val1: bn4(receipt.rb),
1346
1277
  val2: bn4(receipt.rc),
@@ -1353,7 +1284,7 @@ function assembleReceiptByType(receipt) {
1353
1284
  case "LOG_DATA" /* LogData */: {
1354
1285
  const logDataReceipt = {
1355
1286
  type: ReceiptType.LogData,
1356
- id: hexOrZero(receipt.id || receipt.contractId),
1287
+ id: hexOrZero(receipt.contract?.id),
1357
1288
  val0: bn4(receipt.ra),
1358
1289
  val1: bn4(receipt.rb),
1359
1290
  ptr: bn4(receipt.ptr),
@@ -1367,8 +1298,8 @@ function assembleReceiptByType(receipt) {
1367
1298
  case "TRANSFER" /* Transfer */: {
1368
1299
  const transferReceipt = {
1369
1300
  type: ReceiptType.Transfer,
1370
- from: hexOrZero(receipt.id || receipt.contractId),
1371
- to: hexOrZero(receipt.toAddress || receipt?.to),
1301
+ from: hexOrZero(receipt.contract?.id),
1302
+ to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1372
1303
  amount: bn4(receipt.amount),
1373
1304
  assetId: hexOrZero(receipt.assetId),
1374
1305
  pc: bn4(receipt.pc),
@@ -1379,8 +1310,8 @@ function assembleReceiptByType(receipt) {
1379
1310
  case "TRANSFER_OUT" /* TransferOut */: {
1380
1311
  const transferOutReceipt = {
1381
1312
  type: ReceiptType.TransferOut,
1382
- from: hexOrZero(receipt.id || receipt.contractId),
1383
- to: hexOrZero(receipt.toAddress || receipt.to),
1313
+ from: hexOrZero(receipt.contract?.id),
1314
+ to: hexOrZero(receipt.toAddress || receipt.to?.id),
1384
1315
  amount: bn4(receipt.amount),
1385
1316
  assetId: hexOrZero(receipt.assetId),
1386
1317
  pc: bn4(receipt.pc),
@@ -1423,7 +1354,7 @@ function assembleReceiptByType(receipt) {
1423
1354
  return receiptMessageOut;
1424
1355
  }
1425
1356
  case "MINT" /* Mint */: {
1426
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1357
+ const contractId = hexOrZero(receipt.contract?.id);
1427
1358
  const subId = hexOrZero(receipt.subId);
1428
1359
  const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
1429
1360
  const mintReceipt = {
@@ -1438,7 +1369,7 @@ function assembleReceiptByType(receipt) {
1438
1369
  return mintReceipt;
1439
1370
  }
1440
1371
  case "BURN" /* Burn */: {
1441
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1372
+ const contractId = hexOrZero(receipt.contract?.id);
1442
1373
  const subId = hexOrZero(receipt.subId);
1443
1374
  const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
1444
1375
  const burnReceipt = {
@@ -1464,6 +1395,7 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
1464
1395
  import { bn as bn5 } from "@fuel-ts/math";
1465
1396
  import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
1466
1397
  import { arrayify as arrayify3 } from "@fuel-ts/utils";
1398
+ var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1467
1399
  var getGasUsedFromReceipts = (receipts) => {
1468
1400
  const scriptResult = receipts.filter(
1469
1401
  (receipt) => receipt.type === ReceiptType2.ScriptResult
@@ -1484,28 +1416,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1484
1416
  }
1485
1417
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1486
1418
  const witnessCache = [];
1487
- const chargeableInputs = inputs.filter((input) => {
1488
- const isCoinOrMessage = "owner" in input || "sender" in input;
1489
- if (isCoinOrMessage) {
1490
- if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1491
- return true;
1492
- }
1493
- if (!witnessCache.includes(input.witnessIndex)) {
1494
- witnessCache.push(input.witnessIndex);
1495
- return true;
1496
- }
1497
- }
1498
- return false;
1499
- });
1500
- const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1501
- const totalGas = chargeableInputs.reduce((total, input) => {
1419
+ const totalGas = inputs.reduce((total, input) => {
1502
1420
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1503
1421
  return total.add(
1504
- vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1422
+ resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1505
1423
  );
1506
1424
  }
1507
- return total.add(gasCosts.ecr1);
1508
- }, bn5(0));
1425
+ if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1426
+ witnessCache.push(input.witnessIndex);
1427
+ return total.add(gasCosts.ecr1);
1428
+ }
1429
+ return total;
1430
+ }, bn5());
1509
1431
  return totalGas;
1510
1432
  }
1511
1433
  function getMinGas(params) {
@@ -1517,20 +1439,12 @@ function getMinGas(params) {
1517
1439
  return minGas;
1518
1440
  }
1519
1441
  function getMaxGas(params) {
1520
- const {
1521
- gasPerByte,
1522
- witnessesLength,
1523
- witnessLimit,
1524
- minGas,
1525
- gasLimit = bn5(0),
1526
- maxGasPerTx
1527
- } = params;
1442
+ const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
1528
1443
  let remainingAllowedWitnessGas = bn5(0);
1529
1444
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1530
1445
  remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1531
1446
  }
1532
- const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1533
- return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1447
+ return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1534
1448
  }
1535
1449
  function calculateMetadataGasForTxCreate({
1536
1450
  gasCosts,
@@ -1552,10 +1466,6 @@ function calculateMetadataGasForTxScript({
1552
1466
  }) {
1553
1467
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1554
1468
  }
1555
- var calculateGasFee = (params) => {
1556
- const { gas, gasPrice, priceFactor, tip } = params;
1557
- return gas.mul(gasPrice).div(priceFactor).add(tip);
1558
- };
1559
1469
 
1560
1470
  // src/providers/utils/json.ts
1561
1471
  import { hexlify as hexlify5 } from "@fuel-ts/utils";
@@ -1687,6 +1597,12 @@ var NoWitnessAtIndexError = class extends Error {
1687
1597
  name = "NoWitnessAtIndexError";
1688
1598
  };
1689
1599
 
1600
+ // src/providers/transaction-request/helpers.ts
1601
+ import { InputType as InputType2 } from "@fuel-ts/transactions";
1602
+ var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1603
+ var isRequestInputMessage = (input) => input.type === InputType2.Message;
1604
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1605
+
1690
1606
  // src/providers/transaction-request/witness.ts
1691
1607
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1692
1608
  var witnessify = (value) => {
@@ -1700,7 +1616,7 @@ var witnessify = (value) => {
1700
1616
  // src/providers/transaction-request/transaction-request.ts
1701
1617
  var BaseTransactionRequest = class {
1702
1618
  /** Gas price for transaction */
1703
- tip;
1619
+ gasPrice;
1704
1620
  /** Block until which tx cannot be included */
1705
1621
  maturity;
1706
1622
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1719,7 +1635,7 @@ var BaseTransactionRequest = class {
1719
1635
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1720
1636
  */
1721
1637
  constructor({
1722
- tip,
1638
+ gasPrice,
1723
1639
  maturity,
1724
1640
  maxFee,
1725
1641
  witnessLimit,
@@ -1727,7 +1643,7 @@ var BaseTransactionRequest = class {
1727
1643
  outputs,
1728
1644
  witnesses
1729
1645
  } = {}) {
1730
- this.tip = bn7(tip);
1646
+ this.gasPrice = bn7(gasPrice);
1731
1647
  this.maturity = maturity ?? 0;
1732
1648
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1733
1649
  this.maxFee = maxFee ? bn7(maxFee) : void 0;
@@ -1738,9 +1654,9 @@ var BaseTransactionRequest = class {
1738
1654
  static getPolicyMeta(req) {
1739
1655
  let policyTypes = 0;
1740
1656
  const policies = [];
1741
- if (req.tip) {
1742
- policyTypes += PolicyType.Tip;
1743
- policies.push({ data: req.tip, type: PolicyType.Tip });
1657
+ if (req.gasPrice) {
1658
+ policyTypes += PolicyType.GasPrice;
1659
+ policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
1744
1660
  }
1745
1661
  if (req.witnessLimit) {
1746
1662
  policyTypes += PolicyType.WitnessLimit;
@@ -1877,7 +1793,7 @@ var BaseTransactionRequest = class {
1877
1793
  */
1878
1794
  getCoinInputs() {
1879
1795
  return this.inputs.filter(
1880
- (input) => input.type === InputType2.Coin
1796
+ (input) => input.type === InputType3.Coin
1881
1797
  );
1882
1798
  }
1883
1799
  /**
@@ -1909,9 +1825,9 @@ var BaseTransactionRequest = class {
1909
1825
  const ownerAddress = addressify(owner);
1910
1826
  const found = this.inputs.find((input) => {
1911
1827
  switch (input.type) {
1912
- case InputType2.Coin:
1828
+ case InputType3.Coin:
1913
1829
  return hexlify7(input.owner) === ownerAddress.toB256();
1914
- case InputType2.Message:
1830
+ case InputType3.Message:
1915
1831
  return hexlify7(input.recipient) === ownerAddress.toB256();
1916
1832
  default:
1917
1833
  return false;
@@ -1924,11 +1840,13 @@ var BaseTransactionRequest = class {
1924
1840
  * assetId, if one it was not added yet.
1925
1841
  *
1926
1842
  * @param coin - Coin resource.
1843
+ * @param predicate - Predicate bytes.
1844
+ * @param predicateData - Predicate data bytes.
1927
1845
  */
1928
1846
  addCoinInput(coin) {
1929
- const { assetId, owner, amount } = coin;
1847
+ const { assetId, owner, amount, id, predicate } = coin;
1930
1848
  let witnessIndex;
1931
- if (coin.predicate) {
1849
+ if (predicate) {
1932
1850
  witnessIndex = 0;
1933
1851
  } else {
1934
1852
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1937,13 +1855,14 @@ var BaseTransactionRequest = class {
1937
1855
  }
1938
1856
  }
1939
1857
  const input = {
1940
- ...coin,
1941
- type: InputType2.Coin,
1858
+ id,
1859
+ type: InputType3.Coin,
1942
1860
  owner: owner.toB256(),
1943
1861
  amount,
1944
1862
  assetId,
1945
1863
  txPointer: "0x00000000000000000000000000000000",
1946
- witnessIndex
1864
+ witnessIndex,
1865
+ predicate
1947
1866
  };
1948
1867
  this.pushInput(input);
1949
1868
  this.addChangeOutput(owner, assetId);
@@ -1953,12 +1872,14 @@ var BaseTransactionRequest = class {
1953
1872
  * baseAssetId, if one it was not added yet.
1954
1873
  *
1955
1874
  * @param message - Message resource.
1875
+ * @param predicate - Predicate bytes.
1876
+ * @param predicateData - Predicate data bytes.
1956
1877
  */
1957
1878
  addMessageInput(message) {
1958
- const { recipient, sender, amount } = message;
1879
+ const { recipient, sender, amount, predicate, nonce } = message;
1959
1880
  const assetId = BaseAssetId2;
1960
1881
  let witnessIndex;
1961
- if (message.predicate) {
1882
+ if (predicate) {
1962
1883
  witnessIndex = 0;
1963
1884
  } else {
1964
1885
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1967,12 +1888,13 @@ var BaseTransactionRequest = class {
1967
1888
  }
1968
1889
  }
1969
1890
  const input = {
1970
- ...message,
1971
- type: InputType2.Message,
1891
+ nonce,
1892
+ type: InputType3.Message,
1972
1893
  sender: sender.toB256(),
1973
1894
  recipient: recipient.toB256(),
1974
1895
  amount,
1975
- witnessIndex
1896
+ witnessIndex,
1897
+ predicate
1976
1898
  };
1977
1899
  this.pushInput(input);
1978
1900
  this.addChangeOutput(recipient, assetId);
@@ -2082,7 +2004,7 @@ var BaseTransactionRequest = class {
2082
2004
  }
2083
2005
  calculateMaxGas(chainInfo, minGas) {
2084
2006
  const { consensusParameters } = chainInfo;
2085
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2007
+ const { gasPerByte } = consensusParameters;
2086
2008
  const witnessesLength = this.toTransaction().witnesses.reduce(
2087
2009
  (acc, wit) => acc + wit.dataLength,
2088
2010
  0
@@ -2091,8 +2013,7 @@ var BaseTransactionRequest = class {
2091
2013
  gasPerByte,
2092
2014
  minGas,
2093
2015
  witnessesLength,
2094
- witnessLimit: this.witnessLimit,
2095
- maxGasPerTx
2016
+ witnessLimit: this.witnessLimit
2096
2017
  });
2097
2018
  }
2098
2019
  /**
@@ -2110,20 +2031,17 @@ var BaseTransactionRequest = class {
2110
2031
  });
2111
2032
  const updateAssetInput = (assetId, quantity) => {
2112
2033
  const assetInput = findAssetInput(assetId);
2113
- let usedQuantity = quantity;
2114
- if (assetId === BaseAssetId2) {
2115
- usedQuantity = bn7("1000000000000000000");
2116
- }
2117
2034
  if (assetInput && "assetId" in assetInput) {
2118
2035
  assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2119
- assetInput.amount = usedQuantity;
2036
+ assetInput.amount = quantity;
2120
2037
  } else {
2121
2038
  this.addResources([
2122
2039
  {
2123
2040
  id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2124
- amount: usedQuantity,
2041
+ amount: quantity,
2125
2042
  assetId,
2126
2043
  owner: resourcesOwner || Address.fromRandom(),
2044
+ maturity: 0,
2127
2045
  blockCreated: bn7(1),
2128
2046
  txCreatedIdx: bn7(1)
2129
2047
  }
@@ -2155,16 +2073,20 @@ var BaseTransactionRequest = class {
2155
2073
  toJSON() {
2156
2074
  return normalizeJSON(this);
2157
2075
  }
2158
- updatePredicateGasUsed(inputs) {
2076
+ removeWitness(index) {
2077
+ this.witnesses.splice(index, 1);
2078
+ this.adjustWitnessIndexes(index);
2079
+ }
2080
+ updatePredicateInputs(inputs) {
2159
2081
  this.inputs.forEach((i) => {
2160
2082
  let correspondingInput;
2161
2083
  switch (i.type) {
2162
- case InputType2.Coin:
2163
- correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2084
+ case InputType3.Coin:
2085
+ correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2164
2086
  break;
2165
- case InputType2.Message:
2087
+ case InputType3.Message:
2166
2088
  correspondingInput = inputs.find(
2167
- (x) => x.type === InputType2.Message && x.sender === i.sender
2089
+ (x) => x.type === InputType3.Message && x.sender === i.sender
2168
2090
  );
2169
2091
  break;
2170
2092
  default:
@@ -2177,12 +2099,10 @@ var BaseTransactionRequest = class {
2177
2099
  }
2178
2100
  });
2179
2101
  }
2180
- shiftPredicateData() {
2181
- this.inputs.forEach((input) => {
2182
- if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
2183
- input.predicateData = input.padPredicateData(
2184
- BaseTransactionRequest.getPolicyMeta(this).policies.length
2185
- );
2102
+ adjustWitnessIndexes(removedIndex) {
2103
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2104
+ if (input.witnessIndex > removedIndex) {
2105
+ input.witnessIndex -= 1;
2186
2106
  }
2187
2107
  });
2188
2108
  }
@@ -2198,7 +2118,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2198
2118
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2199
2119
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2200
2120
  import { bn as bn8 } from "@fuel-ts/math";
2201
- import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2121
+ import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2202
2122
  import { concat as concat2 } from "@fuel-ts/utils";
2203
2123
  import { clone as clone2 } from "ramda";
2204
2124
  function hashTransaction(transactionRequest, chainId) {
@@ -2209,7 +2129,7 @@ function hashTransaction(transactionRequest, chainId) {
2209
2129
  transaction.inputs = transaction.inputs.map((input) => {
2210
2130
  const inputClone = clone2(input);
2211
2131
  switch (inputClone.type) {
2212
- case InputType3.Coin: {
2132
+ case InputType4.Coin: {
2213
2133
  inputClone.txPointer = {
2214
2134
  blockHeight: 0,
2215
2135
  txIndex: 0
@@ -2217,11 +2137,11 @@ function hashTransaction(transactionRequest, chainId) {
2217
2137
  inputClone.predicateGasUsed = bn8(0);
2218
2138
  return inputClone;
2219
2139
  }
2220
- case InputType3.Message: {
2140
+ case InputType4.Message: {
2221
2141
  inputClone.predicateGasUsed = bn8(0);
2222
2142
  return inputClone;
2223
2143
  }
2224
- case InputType3.Contract: {
2144
+ case InputType4.Contract: {
2225
2145
  inputClone.txPointer = {
2226
2146
  blockHeight: 0,
2227
2147
  txIndex: 0
@@ -2332,8 +2252,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2332
2252
  return {
2333
2253
  type: TransactionType3.Create,
2334
2254
  ...baseTransaction,
2255
+ bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2335
2256
  bytecodeWitnessIndex,
2336
- storageSlotsCount: bn9(storageSlots.length),
2257
+ storageSlotsCount: storageSlots.length,
2337
2258
  salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
2338
2259
  storageSlots
2339
2260
  };
@@ -2386,7 +2307,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2386
2307
  import { addressify as addressify2 } from "@fuel-ts/address";
2387
2308
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2388
2309
  import { bn as bn10 } from "@fuel-ts/math";
2389
- import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2310
+ import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2390
2311
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2391
2312
 
2392
2313
  // src/providers/transaction-request/scripts.ts
@@ -2456,8 +2377,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2456
2377
  type: TransactionType4.Script,
2457
2378
  scriptGasLimit: this.gasLimit,
2458
2379
  ...super.getBaseTransaction(),
2459
- scriptLength: bn10(script.length),
2460
- scriptDataLength: bn10(scriptData.length),
2380
+ scriptLength: script.length,
2381
+ scriptDataLength: scriptData.length,
2461
2382
  receiptsRoot: ZeroBytes327,
2462
2383
  script: hexlify10(script),
2463
2384
  scriptData: hexlify10(scriptData)
@@ -2470,7 +2391,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2470
2391
  */
2471
2392
  getContractInputs() {
2472
2393
  return this.inputs.filter(
2473
- (input) => input.type === InputType4.Contract
2394
+ (input) => input.type === InputType5.Contract
2474
2395
  );
2475
2396
  }
2476
2397
  /**
@@ -2521,7 +2442,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2521
2442
  }
2522
2443
  calculateMaxGas(chainInfo, minGas) {
2523
2444
  const { consensusParameters } = chainInfo;
2524
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2445
+ const { gasPerByte } = consensusParameters;
2525
2446
  const witnessesLength = this.toTransaction().witnesses.reduce(
2526
2447
  (acc, wit) => acc + wit.dataLength,
2527
2448
  0
@@ -2531,8 +2452,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2531
2452
  minGas,
2532
2453
  witnessesLength,
2533
2454
  witnessLimit: this.witnessLimit,
2534
- gasLimit: this.gasLimit,
2535
- maxGasPerTx
2455
+ gasLimit: this.gasLimit
2536
2456
  });
2537
2457
  }
2538
2458
  /**
@@ -2547,7 +2467,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2547
2467
  return this;
2548
2468
  }
2549
2469
  const inputIndex = super.pushInput({
2550
- type: InputType4.Contract,
2470
+ type: InputType5.Contract,
2551
2471
  contractId: contractAddress.toB256(),
2552
2472
  txPointer: "0x00000000000000000000000000000000"
2553
2473
  });
@@ -2589,7 +2509,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2589
2509
 
2590
2510
  // src/providers/transaction-request/utils.ts
2591
2511
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2592
- import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2512
+ import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2593
2513
  var transactionRequestify = (obj) => {
2594
2514
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2595
2515
  return obj;
@@ -2607,31 +2527,14 @@ var transactionRequestify = (obj) => {
2607
2527
  }
2608
2528
  }
2609
2529
  };
2610
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2611
- (acc, input) => {
2612
- if (input.type === InputType5.Coin && input.owner === owner) {
2613
- acc.utxos.push(input.id);
2614
- }
2615
- if (input.type === InputType5.Message && input.recipient === owner) {
2616
- acc.messages.push(input.nonce);
2617
- }
2618
- return acc;
2619
- },
2620
- {
2621
- utxos: [],
2622
- messages: []
2623
- }
2624
- );
2625
2530
 
2626
2531
  // src/providers/transaction-response/transaction-response.ts
2627
2532
  import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2628
- import { bn as bn15 } from "@fuel-ts/math";
2533
+ import { bn as bn14 } from "@fuel-ts/math";
2629
2534
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2630
2535
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2631
2536
 
2632
2537
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2633
- import { bn as bn14 } from "@fuel-ts/math";
2634
- import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2635
2538
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2636
2539
 
2637
2540
  // src/providers/transaction-summary/calculate-transaction-fee.ts
@@ -2640,10 +2543,9 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
2640
2543
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2641
2544
  var calculateTransactionFee = (params) => {
2642
2545
  const {
2643
- gasPrice,
2546
+ gasUsed,
2644
2547
  rawPayload,
2645
- tip,
2646
- consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2548
+ consensusParameters: { gasCosts, feeParams }
2647
2549
  } = params;
2648
2550
  const gasPerByte = bn11(feeParams.gasPerByte);
2649
2551
  const gasPriceFactor = bn11(feeParams.gasPriceFactor);
@@ -2653,7 +2555,8 @@ var calculateTransactionFee = (params) => {
2653
2555
  return {
2654
2556
  fee: bn11(0),
2655
2557
  minFee: bn11(0),
2656
- maxFee: bn11(0)
2558
+ maxFee: bn11(0),
2559
+ feeFromGasUsed: bn11(0)
2657
2560
  };
2658
2561
  }
2659
2562
  const { type, witnesses, inputs, policies } = transaction;
@@ -2685,6 +2588,7 @@ var calculateTransactionFee = (params) => {
2685
2588
  metadataGas,
2686
2589
  txBytesSize: transactionBytes.length
2687
2590
  });
2591
+ const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2688
2592
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2689
2593
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2690
2594
  const maxGas = getMaxGas({
@@ -2692,25 +2596,17 @@ var calculateTransactionFee = (params) => {
2692
2596
  minGas,
2693
2597
  witnessesLength,
2694
2598
  gasLimit,
2695
- witnessLimit,
2696
- maxGasPerTx
2697
- });
2698
- const minFee = calculateGasFee({
2699
- gasPrice,
2700
- gas: minGas,
2701
- priceFactor: gasPriceFactor,
2702
- tip
2703
- });
2704
- const maxFee = calculateGasFee({
2705
- gasPrice,
2706
- gas: maxGas,
2707
- priceFactor: gasPriceFactor,
2708
- tip
2599
+ witnessLimit
2709
2600
  });
2601
+ const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2602
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2603
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2604
+ const fee = minFee.add(feeFromGasUsed);
2710
2605
  return {
2606
+ fee,
2711
2607
  minFee,
2712
2608
  maxFee,
2713
- fee: maxFee
2609
+ feeFromGasUsed
2714
2610
  };
2715
2611
  };
2716
2612
 
@@ -3277,9 +3173,7 @@ function assembleTransactionSummary(params) {
3277
3173
  gqlTransactionStatus,
3278
3174
  abiMap = {},
3279
3175
  maxInputs,
3280
- gasCosts,
3281
- maxGasPerTx,
3282
- gasPrice
3176
+ gasCosts
3283
3177
  } = params;
3284
3178
  const gasUsed = getGasUsedFromReceipts(receipts);
3285
3179
  const rawPayload = hexlify11(transactionBytes);
@@ -3293,14 +3187,11 @@ function assembleTransactionSummary(params) {
3293
3187
  maxInputs
3294
3188
  });
3295
3189
  const typeName = getTransactionTypeName(transaction.type);
3296
- const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3297
3190
  const { fee } = calculateTransactionFee({
3298
- gasPrice,
3191
+ gasUsed,
3299
3192
  rawPayload,
3300
- tip,
3301
3193
  consensusParameters: {
3302
3194
  gasCosts,
3303
- maxGasPerTx,
3304
3195
  feeParams: {
3305
3196
  gasPerByte,
3306
3197
  gasPriceFactor
@@ -3360,7 +3251,7 @@ var TransactionResponse = class {
3360
3251
  /** Current provider */
3361
3252
  provider;
3362
3253
  /** Gas used on the transaction */
3363
- gasUsed = bn15(0);
3254
+ gasUsed = bn14(0);
3364
3255
  /** The graphql Transaction with receipts object. */
3365
3256
  gqlTransaction;
3366
3257
  abis;
@@ -3438,13 +3329,8 @@ var TransactionResponse = class {
3438
3329
  const decodedTransaction = this.decodeTransaction(
3439
3330
  transaction
3440
3331
  );
3441
- let txReceipts = [];
3442
- if (transaction?.status && "receipts" in transaction.status) {
3443
- txReceipts = transaction.status.receipts;
3444
- }
3445
- const receipts = txReceipts.map(processGqlReceipt) || [];
3446
- const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3447
- const gasPrice = await this.provider.getLatestGasPrice();
3332
+ const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3333
+ const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3448
3334
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3449
3335
  const transactionSummary = assembleTransactionSummary({
3450
3336
  id: this.id,
@@ -3456,9 +3342,7 @@ var TransactionResponse = class {
3456
3342
  gasPriceFactor,
3457
3343
  abiMap: contractsAbiMap,
3458
3344
  maxInputs,
3459
- gasCosts,
3460
- maxGasPerTx,
3461
- gasPrice
3345
+ gasCosts
3462
3346
  });
3463
3347
  return transactionSummary;
3464
3348
  }
@@ -3585,29 +3469,29 @@ var processGqlChain = (chain) => {
3585
3469
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3586
3470
  return {
3587
3471
  name,
3588
- baseChainHeight: bn16(daHeight),
3472
+ baseChainHeight: bn15(daHeight),
3589
3473
  consensusParameters: {
3590
- contractMaxSize: bn16(contractParams.contractMaxSize),
3591
- maxInputs: bn16(txParams.maxInputs),
3592
- maxOutputs: bn16(txParams.maxOutputs),
3593
- maxWitnesses: bn16(txParams.maxWitnesses),
3594
- maxGasPerTx: bn16(txParams.maxGasPerTx),
3595
- maxScriptLength: bn16(scriptParams.maxScriptLength),
3596
- maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
3597
- maxStorageSlots: bn16(contractParams.maxStorageSlots),
3598
- maxPredicateLength: bn16(predicateParams.maxPredicateLength),
3599
- maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
3600
- maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
3601
- gasPriceFactor: bn16(feeParams.gasPriceFactor),
3602
- gasPerByte: bn16(feeParams.gasPerByte),
3603
- maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
3604
- chainId: bn16(consensusParameters.chainId),
3474
+ contractMaxSize: bn15(contractParams.contractMaxSize),
3475
+ maxInputs: bn15(txParams.maxInputs),
3476
+ maxOutputs: bn15(txParams.maxOutputs),
3477
+ maxWitnesses: bn15(txParams.maxWitnesses),
3478
+ maxGasPerTx: bn15(txParams.maxGasPerTx),
3479
+ maxScriptLength: bn15(scriptParams.maxScriptLength),
3480
+ maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
3481
+ maxStorageSlots: bn15(contractParams.maxStorageSlots),
3482
+ maxPredicateLength: bn15(predicateParams.maxPredicateLength),
3483
+ maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
3484
+ maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
3485
+ gasPriceFactor: bn15(feeParams.gasPriceFactor),
3486
+ gasPerByte: bn15(feeParams.gasPerByte),
3487
+ maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3488
+ chainId: bn15(consensusParameters.chainId),
3605
3489
  gasCosts
3606
3490
  },
3607
3491
  gasCosts,
3608
3492
  latestBlock: {
3609
3493
  id: latestBlock.id,
3610
- height: bn16(latestBlock.height),
3494
+ height: bn15(latestBlock.header.height),
3611
3495
  time: latestBlock.header.time,
3612
3496
  transactions: latestBlock.transactions.map((i) => ({
3613
3497
  id: i.id
@@ -3701,8 +3585,10 @@ var _Provider = class {
3701
3585
  * Returns some helpful parameters related to gas fees.
3702
3586
  */
3703
3587
  getGasConfig() {
3588
+ const { minGasPrice } = this.getNode();
3704
3589
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3705
3590
  return {
3591
+ minGasPrice,
3706
3592
  maxGasPerTx,
3707
3593
  maxGasPerPredicate,
3708
3594
  gasPriceFactor,
@@ -3800,7 +3686,7 @@ var _Provider = class {
3800
3686
  */
3801
3687
  async getBlockNumber() {
3802
3688
  const { chain } = await this.operations.getChain();
3803
- return bn16(chain.latestBlock.height, 10);
3689
+ return bn15(chain.latestBlock.header.height, 10);
3804
3690
  }
3805
3691
  /**
3806
3692
  * Returns the chain information.
@@ -3810,11 +3696,13 @@ var _Provider = class {
3810
3696
  async fetchNode() {
3811
3697
  const { nodeInfo } = await this.operations.getNodeInfo();
3812
3698
  const processedNodeInfo = {
3813
- maxDepth: bn16(nodeInfo.maxDepth),
3814
- maxTx: bn16(nodeInfo.maxTx),
3699
+ maxDepth: bn15(nodeInfo.maxDepth),
3700
+ maxTx: bn15(nodeInfo.maxTx),
3701
+ minGasPrice: bn15(nodeInfo.minGasPrice),
3815
3702
  nodeVersion: nodeInfo.nodeVersion,
3816
3703
  utxoValidation: nodeInfo.utxoValidation,
3817
- vmBacktrace: nodeInfo.vmBacktrace
3704
+ vmBacktrace: nodeInfo.vmBacktrace,
3705
+ peers: nodeInfo.peers
3818
3706
  };
3819
3707
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3820
3708
  return processedNodeInfo;
@@ -3900,13 +3788,14 @@ var _Provider = class {
3900
3788
  return this.estimateTxDependencies(transactionRequest);
3901
3789
  }
3902
3790
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3903
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
3904
- encodedTransactions: encodedTransaction,
3791
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
3792
+ encodedTransaction,
3905
3793
  utxoValidation: utxoValidation || false
3906
3794
  });
3907
- const [{ receipts: rawReceipts, status }] = dryRunStatuses;
3908
- const receipts = rawReceipts.map(processGqlReceipt);
3909
- return { receipts, dryrunStatus: status };
3795
+ const receipts = gqlReceipts.map(processGqlReceipt);
3796
+ return {
3797
+ receipts
3798
+ };
3910
3799
  }
3911
3800
  /**
3912
3801
  * Verifies whether enough gas is available to complete transaction.
@@ -3932,7 +3821,7 @@ var _Provider = class {
3932
3821
  } = response;
3933
3822
  if (inputs) {
3934
3823
  inputs.forEach((input, index) => {
3935
- if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
3824
+ if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
3936
3825
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3937
3826
  }
3938
3827
  });
@@ -3945,6 +3834,9 @@ var _Provider = class {
3945
3834
  * If there are missing variable outputs,
3946
3835
  * `addVariableOutputs` is called on the transaction.
3947
3836
  *
3837
+ * @privateRemarks
3838
+ * TODO: Investigate support for missing contract IDs
3839
+ * TODO: Add support for missing output messages
3948
3840
  *
3949
3841
  * @param transactionRequest - The transaction request object.
3950
3842
  * @returns A promise.
@@ -3957,19 +3849,16 @@ var _Provider = class {
3957
3849
  missingContractIds: []
3958
3850
  };
3959
3851
  }
3852
+ await this.estimatePredicates(transactionRequest);
3960
3853
  let receipts = [];
3961
3854
  const missingContractIds = [];
3962
3855
  let outputVariables = 0;
3963
- let dryrunStatus;
3964
3856
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3965
- const {
3966
- dryRun: [{ receipts: rawReceipts, status }]
3967
- } = await this.operations.dryRun({
3968
- encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
3857
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
3858
+ encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
3969
3859
  utxoValidation: false
3970
3860
  });
3971
- receipts = rawReceipts.map(processGqlReceipt);
3972
- dryrunStatus = status;
3861
+ receipts = gqlReceipts.map(processGqlReceipt);
3973
3862
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3974
3863
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3975
3864
  if (hasMissingOutputs) {
@@ -3979,10 +3868,6 @@ var _Provider = class {
3979
3868
  transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
3980
3869
  missingContractIds.push(contractId);
3981
3870
  });
3982
- const { maxFee } = await this.estimateTxGasAndFee({
3983
- transactionRequest
3984
- });
3985
- transactionRequest.maxFee = maxFee;
3986
3871
  } else {
3987
3872
  break;
3988
3873
  }
@@ -3990,136 +3875,37 @@ var _Provider = class {
3990
3875
  return {
3991
3876
  receipts,
3992
3877
  outputVariables,
3993
- missingContractIds,
3994
- dryrunStatus
3878
+ missingContractIds
3995
3879
  };
3996
3880
  }
3997
- /**
3998
- * Dry runs multiple transactions and checks for missing dependencies in batches.
3999
- *
4000
- * Transactions are dry run in batches. After each dry run, transactions requiring
4001
- * further modifications are identified. The method iteratively updates these transactions
4002
- * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4003
- *
4004
- * @param transactionRequests - Array of transaction request objects.
4005
- * @returns A promise that resolves to an array of results for each transaction.
4006
- */
4007
- async estimateMultipleTxDependencies(transactionRequests) {
4008
- const results = transactionRequests.map(() => ({
4009
- receipts: [],
4010
- outputVariables: 0,
4011
- missingContractIds: [],
4012
- dryrunStatus: void 0
4013
- }));
4014
- const allRequests = clone3(transactionRequests);
4015
- const serializedTransactionsMap = /* @__PURE__ */ new Map();
4016
- allRequests.forEach((req, index) => {
4017
- if (req.type === TransactionType8.Script) {
4018
- serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
4019
- }
4020
- });
4021
- let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4022
- let attempt = 0;
4023
- while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4024
- const encodedTransactions = transactionsToProcess.map(
4025
- (index) => serializedTransactionsMap.get(index)
4026
- );
4027
- const dryRunResults = await this.operations.dryRun({
4028
- encodedTransactions,
4029
- utxoValidation: false
4030
- });
4031
- const nextRoundTransactions = [];
4032
- for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4033
- const requestIdx = transactionsToProcess[i];
4034
- const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4035
- const result = results[requestIdx];
4036
- result.receipts = rawReceipts.map(processGqlReceipt);
4037
- result.dryrunStatus = status;
4038
- const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4039
- result.receipts
4040
- );
4041
- const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4042
- const request = allRequests[requestIdx];
4043
- if (hasMissingOutputs && request?.type === TransactionType8.Script) {
4044
- result.outputVariables += missingOutputVariables.length;
4045
- request.addVariableOutputs(missingOutputVariables.length);
4046
- missingOutputContractIds.forEach(({ contractId }) => {
4047
- request.addContractInputAndOutput(Address2.fromString(contractId));
4048
- result.missingContractIds.push(contractId);
4049
- });
4050
- const { maxFee } = await this.estimateTxGasAndFee({
4051
- transactionRequest: request
4052
- });
4053
- request.maxFee = maxFee;
4054
- serializedTransactionsMap.set(requestIdx, hexlify12(request.toTransactionBytes()));
4055
- nextRoundTransactions.push(requestIdx);
4056
- }
4057
- }
4058
- transactionsToProcess = nextRoundTransactions;
4059
- attempt += 1;
4060
- }
4061
- return results;
4062
- }
4063
- async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4064
- if (estimateTxDependencies) {
4065
- return this.estimateMultipleTxDependencies(transactionRequests);
4066
- }
4067
- const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
4068
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4069
- encodedTransactions,
4070
- utxoValidation: utxoValidation || false
4071
- });
4072
- const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4073
- const receipts = rawReceipts.map(processGqlReceipt);
4074
- return { receipts, dryrunStatus: status };
4075
- });
4076
- return results;
4077
- }
4078
3881
  /**
4079
3882
  * Estimates the transaction gas and fee based on the provided transaction request.
4080
3883
  * @param transactionRequest - The transaction request object.
4081
3884
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4082
3885
  */
4083
- async estimateTxGasAndFee(params) {
3886
+ estimateTxGasAndFee(params) {
4084
3887
  const { transactionRequest } = params;
4085
- let { gasPrice } = params;
3888
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4086
3889
  const chainInfo = this.getChain();
4087
- const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
3890
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3891
+ transactionRequest.gasPrice = gasPrice;
4088
3892
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4089
- if (!gasPrice) {
4090
- gasPrice = await this.estimateGasPrice(10);
4091
- }
4092
- const minFee = calculateGasFee({
4093
- gasPrice: bn16(gasPrice),
4094
- gas: minGas,
4095
- priceFactor: gasPriceFactor,
4096
- tip: transactionRequest.tip
4097
- }).add(1);
4098
- let gasLimit = bn16(0);
3893
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4099
3894
  if (transactionRequest.type === TransactionType8.Script) {
4100
- gasLimit = transactionRequest.gasLimit;
4101
3895
  if (transactionRequest.gasLimit.eq(0)) {
4102
3896
  transactionRequest.gasLimit = minGas;
4103
3897
  transactionRequest.gasLimit = maxGasPerTx.sub(
4104
3898
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4105
3899
  );
4106
- gasLimit = transactionRequest.gasLimit;
4107
3900
  }
4108
3901
  }
4109
3902
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4110
- const maxFee = calculateGasFee({
4111
- gasPrice: bn16(gasPrice),
4112
- gas: maxGas,
4113
- priceFactor: gasPriceFactor,
4114
- tip: transactionRequest.tip
4115
- }).add(1);
3903
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4116
3904
  return {
4117
3905
  minGas,
4118
3906
  minFee,
4119
3907
  maxGas,
4120
- maxFee,
4121
- gasPrice,
4122
- gasLimit
3908
+ maxFee
4123
3909
  };
4124
3910
  }
4125
3911
  /**
@@ -4137,17 +3923,15 @@ var _Provider = class {
4137
3923
  if (estimateTxDependencies) {
4138
3924
  return this.estimateTxDependencies(transactionRequest);
4139
3925
  }
4140
- const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
4141
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4142
- encodedTransactions,
3926
+ const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3927
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
3928
+ encodedTransaction,
4143
3929
  utxoValidation: true
4144
3930
  });
4145
- const callResult = dryRunStatuses.map((dryRunStatus) => {
4146
- const { id, receipts, status } = dryRunStatus;
4147
- const processedReceipts = receipts.map(processGqlReceipt);
4148
- return { id, receipts: processedReceipts, status };
4149
- });
4150
- return { receipts: callResult[0].receipts };
3931
+ const receipts = gqlReceipts.map(processGqlReceipt);
3932
+ return {
3933
+ receipts
3934
+ };
4151
3935
  }
4152
3936
  /**
4153
3937
  * Returns a transaction cost to enable user
@@ -4164,79 +3948,77 @@ var _Provider = class {
4164
3948
  * @param tolerance - The tolerance to add on top of the gasUsed.
4165
3949
  * @returns A promise that resolves to the transaction cost object.
4166
3950
  */
4167
- async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3951
+ async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3952
+ estimateTxDependencies = true,
3953
+ estimatePredicates = true,
3954
+ resourcesOwner,
3955
+ signatureCallback
3956
+ } = {}) {
4168
3957
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3958
+ const { minGasPrice } = this.getGasConfig();
3959
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
4169
3960
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
4170
3961
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4171
- const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
3962
+ const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4172
3963
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4173
- txRequestClone.maxFee = bn16(0);
4174
3964
  if (isScriptTransaction) {
4175
- txRequestClone.gasLimit = bn16(0);
3965
+ txRequestClone.gasLimit = bn15(0);
4176
3966
  }
4177
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4178
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
3967
+ if (estimatePredicates) {
3968
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3969
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
3970
+ }
3971
+ await this.estimatePredicates(txRequestClone);
4179
3972
  }
4180
- const signedRequest = clone3(txRequestClone);
4181
- let addedSignatures = 0;
4182
3973
  if (signatureCallback && isScriptTransaction) {
4183
- const lengthBefore = signedRequest.witnesses.length;
4184
- await signatureCallback(signedRequest);
4185
- addedSignatures = signedRequest.witnesses.length - lengthBefore;
3974
+ await signatureCallback(txRequestClone);
4186
3975
  }
4187
- await this.estimatePredicates(signedRequest);
4188
- let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4189
- transactionRequest: signedRequest
3976
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3977
+ transactionRequest: txRequestClone
4190
3978
  });
4191
3979
  let receipts = [];
4192
3980
  let missingContractIds = [];
4193
3981
  let outputVariables = 0;
4194
- let gasUsed = bn16(0);
4195
- txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4196
- txRequestClone.maxFee = maxFee;
4197
- if (isScriptTransaction) {
4198
- txRequestClone.gasLimit = gasLimit;
4199
- if (signatureCallback) {
4200
- await signatureCallback(txRequestClone);
4201
- }
3982
+ let gasUsed = bn15(0);
3983
+ if (isScriptTransaction && estimateTxDependencies) {
3984
+ txRequestClone.gasPrice = bn15(0);
4202
3985
  const result = await this.estimateTxDependencies(txRequestClone);
4203
3986
  receipts = result.receipts;
4204
3987
  outputVariables = result.outputVariables;
4205
3988
  missingContractIds = result.missingContractIds;
4206
3989
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4207
3990
  txRequestClone.gasLimit = gasUsed;
4208
- ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4209
- transactionRequest: txRequestClone,
4210
- gasPrice
3991
+ txRequestClone.gasPrice = setGasPrice;
3992
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3993
+ transactionRequest: txRequestClone
4211
3994
  }));
4212
3995
  }
4213
3996
  return {
4214
3997
  requiredQuantities: allQuantities,
4215
3998
  receipts,
4216
3999
  gasUsed,
4217
- gasPrice,
4000
+ minGasPrice,
4001
+ gasPrice: setGasPrice,
4218
4002
  minGas,
4219
4003
  maxGas,
4220
4004
  minFee,
4221
4005
  maxFee,
4006
+ estimatedInputs: txRequestClone.inputs,
4222
4007
  outputVariables,
4223
- missingContractIds,
4224
- addedSignatures,
4225
- estimatedPredicates: txRequestClone.inputs
4008
+ missingContractIds
4226
4009
  };
4227
4010
  }
4228
- async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4011
+ async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4229
4012
  const ownerAddress = Address2.fromAddressOrString(owner);
4230
4013
  const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
4231
- const transactionCost = await this.getTransactionCost(transactionRequest, {
4232
- quantitiesToContract
4233
- });
4014
+ const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4234
4015
  transactionRequest.addResources(
4235
4016
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4236
4017
  );
4237
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4238
- quantitiesToContract
4239
- });
4018
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4019
+ transactionRequest,
4020
+ forwardingQuantities
4021
+ );
4240
4022
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4241
4023
  return {
4242
4024
  resources,
@@ -4258,10 +4040,11 @@ var _Provider = class {
4258
4040
  return coins.map((coin) => ({
4259
4041
  id: coin.utxoId,
4260
4042
  assetId: coin.assetId,
4261
- amount: bn16(coin.amount),
4043
+ amount: bn15(coin.amount),
4262
4044
  owner: Address2.fromAddressOrString(coin.owner),
4263
- blockCreated: bn16(coin.blockCreated),
4264
- txCreatedIdx: bn16(coin.txCreatedIdx)
4045
+ maturity: bn15(coin.maturity).toNumber(),
4046
+ blockCreated: bn15(coin.blockCreated),
4047
+ txCreatedIdx: bn15(coin.txCreatedIdx)
4265
4048
  }));
4266
4049
  }
4267
4050
  /**
@@ -4298,9 +4081,9 @@ var _Provider = class {
4298
4081
  switch (coin.__typename) {
4299
4082
  case "MessageCoin":
4300
4083
  return {
4301
- amount: bn16(coin.amount),
4084
+ amount: bn15(coin.amount),
4302
4085
  assetId: coin.assetId,
4303
- daHeight: bn16(coin.daHeight),
4086
+ daHeight: bn15(coin.daHeight),
4304
4087
  sender: Address2.fromAddressOrString(coin.sender),
4305
4088
  recipient: Address2.fromAddressOrString(coin.recipient),
4306
4089
  nonce: coin.nonce
@@ -4308,11 +4091,12 @@ var _Provider = class {
4308
4091
  case "Coin":
4309
4092
  return {
4310
4093
  id: coin.utxoId,
4311
- amount: bn16(coin.amount),
4094
+ amount: bn15(coin.amount),
4312
4095
  assetId: coin.assetId,
4313
4096
  owner: Address2.fromAddressOrString(coin.owner),
4314
- blockCreated: bn16(coin.blockCreated),
4315
- txCreatedIdx: bn16(coin.txCreatedIdx)
4097
+ maturity: bn15(coin.maturity).toNumber(),
4098
+ blockCreated: bn15(coin.blockCreated),
4099
+ txCreatedIdx: bn15(coin.txCreatedIdx)
4316
4100
  };
4317
4101
  default:
4318
4102
  return null;
@@ -4329,13 +4113,13 @@ var _Provider = class {
4329
4113
  async getBlock(idOrHeight) {
4330
4114
  let variables;
4331
4115
  if (typeof idOrHeight === "number") {
4332
- variables = { height: bn16(idOrHeight).toString(10) };
4116
+ variables = { height: bn15(idOrHeight).toString(10) };
4333
4117
  } else if (idOrHeight === "latest") {
4334
4118
  variables = { height: (await this.getBlockNumber()).toString(10) };
4335
4119
  } else if (idOrHeight.length === 66) {
4336
4120
  variables = { blockId: idOrHeight };
4337
4121
  } else {
4338
- variables = { blockId: bn16(idOrHeight).toString(10) };
4122
+ variables = { blockId: bn15(idOrHeight).toString(10) };
4339
4123
  }
4340
4124
  const { block } = await this.operations.getBlock(variables);
4341
4125
  if (!block) {
@@ -4343,7 +4127,7 @@ var _Provider = class {
4343
4127
  }
4344
4128
  return {
4345
4129
  id: block.id,
4346
- height: bn16(block.height),
4130
+ height: bn15(block.header.height),
4347
4131
  time: block.header.time,
4348
4132
  transactionIds: block.transactions.map((tx) => tx.id)
4349
4133
  };
@@ -4358,7 +4142,7 @@ var _Provider = class {
4358
4142
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4359
4143
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4360
4144
  id: block.id,
4361
- height: bn16(block.height),
4145
+ height: bn15(block.header.height),
4362
4146
  time: block.header.time,
4363
4147
  transactionIds: block.transactions.map((tx) => tx.id)
4364
4148
  }));
@@ -4373,7 +4157,7 @@ var _Provider = class {
4373
4157
  async getBlockWithTransactions(idOrHeight) {
4374
4158
  let variables;
4375
4159
  if (typeof idOrHeight === "number") {
4376
- variables = { blockHeight: bn16(idOrHeight).toString(10) };
4160
+ variables = { blockHeight: bn15(idOrHeight).toString(10) };
4377
4161
  } else if (idOrHeight === "latest") {
4378
4162
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4379
4163
  } else {
@@ -4385,7 +4169,7 @@ var _Provider = class {
4385
4169
  }
4386
4170
  return {
4387
4171
  id: block.id,
4388
- height: bn16(block.height, 10),
4172
+ height: bn15(block.header.height, 10),
4389
4173
  time: block.header.time,
4390
4174
  transactionIds: block.transactions.map((tx) => tx.id),
4391
4175
  transactions: block.transactions.map(
@@ -4434,7 +4218,7 @@ var _Provider = class {
4434
4218
  contract: Address2.fromAddressOrString(contractId).toB256(),
4435
4219
  asset: hexlify12(assetId)
4436
4220
  });
4437
- return bn16(contractBalance.amount, 10);
4221
+ return bn15(contractBalance.amount, 10);
4438
4222
  }
4439
4223
  /**
4440
4224
  * Returns the balance for the given owner for the given asset ID.
@@ -4448,7 +4232,7 @@ var _Provider = class {
4448
4232
  owner: Address2.fromAddressOrString(owner).toB256(),
4449
4233
  assetId: hexlify12(assetId)
4450
4234
  });
4451
- return bn16(balance.amount, 10);
4235
+ return bn15(balance.amount, 10);
4452
4236
  }
4453
4237
  /**
4454
4238
  * Returns balances for the given owner.
@@ -4466,7 +4250,7 @@ var _Provider = class {
4466
4250
  const balances = result.balances.edges.map((edge) => edge.node);
4467
4251
  return balances.map((balance) => ({
4468
4252
  assetId: balance.assetId,
4469
- amount: bn16(balance.amount)
4253
+ amount: bn15(balance.amount)
4470
4254
  }));
4471
4255
  }
4472
4256
  /**
@@ -4488,15 +4272,15 @@ var _Provider = class {
4488
4272
  sender: message.sender,
4489
4273
  recipient: message.recipient,
4490
4274
  nonce: message.nonce,
4491
- amount: bn16(message.amount),
4275
+ amount: bn15(message.amount),
4492
4276
  data: message.data
4493
4277
  }),
4494
4278
  sender: Address2.fromAddressOrString(message.sender),
4495
4279
  recipient: Address2.fromAddressOrString(message.recipient),
4496
4280
  nonce: message.nonce,
4497
- amount: bn16(message.amount),
4281
+ amount: bn15(message.amount),
4498
4282
  data: InputMessageCoder.decodeData(message.data),
4499
- daHeight: bn16(message.daHeight)
4283
+ daHeight: bn15(message.daHeight)
4500
4284
  }));
4501
4285
  }
4502
4286
  /**
@@ -4549,60 +4333,44 @@ var _Provider = class {
4549
4333
  } = result.messageProof;
4550
4334
  return {
4551
4335
  messageProof: {
4552
- proofIndex: bn16(messageProof.proofIndex),
4336
+ proofIndex: bn15(messageProof.proofIndex),
4553
4337
  proofSet: messageProof.proofSet
4554
4338
  },
4555
4339
  blockProof: {
4556
- proofIndex: bn16(blockProof.proofIndex),
4340
+ proofIndex: bn15(blockProof.proofIndex),
4557
4341
  proofSet: blockProof.proofSet
4558
4342
  },
4559
4343
  messageBlockHeader: {
4560
4344
  id: messageBlockHeader.id,
4561
- daHeight: bn16(messageBlockHeader.daHeight),
4562
- transactionsCount: bn16(messageBlockHeader.transactionsCount),
4345
+ daHeight: bn15(messageBlockHeader.daHeight),
4346
+ transactionsCount: bn15(messageBlockHeader.transactionsCount),
4563
4347
  transactionsRoot: messageBlockHeader.transactionsRoot,
4564
- height: bn16(messageBlockHeader.height),
4348
+ height: bn15(messageBlockHeader.height),
4565
4349
  prevRoot: messageBlockHeader.prevRoot,
4566
4350
  time: messageBlockHeader.time,
4567
4351
  applicationHash: messageBlockHeader.applicationHash,
4568
- messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
4569
- messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4570
- consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4571
- eventInboxRoot: messageBlockHeader.eventInboxRoot,
4572
- stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4352
+ messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4353
+ messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
4573
4354
  },
4574
4355
  commitBlockHeader: {
4575
4356
  id: commitBlockHeader.id,
4576
- daHeight: bn16(commitBlockHeader.daHeight),
4577
- transactionsCount: bn16(commitBlockHeader.transactionsCount),
4357
+ daHeight: bn15(commitBlockHeader.daHeight),
4358
+ transactionsCount: bn15(commitBlockHeader.transactionsCount),
4578
4359
  transactionsRoot: commitBlockHeader.transactionsRoot,
4579
- height: bn16(commitBlockHeader.height),
4360
+ height: bn15(commitBlockHeader.height),
4580
4361
  prevRoot: commitBlockHeader.prevRoot,
4581
4362
  time: commitBlockHeader.time,
4582
4363
  applicationHash: commitBlockHeader.applicationHash,
4583
- messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
4584
- messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4585
- consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4586
- eventInboxRoot: commitBlockHeader.eventInboxRoot,
4587
- stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4364
+ messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4365
+ messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
4588
4366
  },
4589
4367
  sender: Address2.fromAddressOrString(sender),
4590
4368
  recipient: Address2.fromAddressOrString(recipient),
4591
4369
  nonce,
4592
- amount: bn16(amount),
4370
+ amount: bn15(amount),
4593
4371
  data
4594
4372
  };
4595
4373
  }
4596
- async getLatestGasPrice() {
4597
- const { latestGasPrice } = await this.operations.getLatestGasPrice();
4598
- return bn16(latestGasPrice.gasPrice);
4599
- }
4600
- async estimateGasPrice(blockHorizon) {
4601
- const { estimateGasPrice } = await this.operations.estimateGasPrice({
4602
- blockHorizon: String(blockHorizon)
4603
- });
4604
- return bn16(estimateGasPrice.gasPrice);
4605
- }
4606
4374
  /**
4607
4375
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4608
4376
  *
@@ -4622,10 +4390,10 @@ var _Provider = class {
4622
4390
  */
4623
4391
  async produceBlocks(amount, startTime) {
4624
4392
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4625
- blocksToProduce: bn16(amount).toString(10),
4393
+ blocksToProduce: bn15(amount).toString(10),
4626
4394
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4627
4395
  });
4628
- return bn16(latestBlockHeight);
4396
+ return bn15(latestBlockHeight);
4629
4397
  }
4630
4398
  // eslint-disable-next-line @typescript-eslint/require-await
4631
4399
  async getTransactionResponse(transactionId) {
@@ -4649,7 +4417,7 @@ __publicField(Provider, "nodeInfoCache", {});
4649
4417
 
4650
4418
  // src/providers/transaction-summary/get-transaction-summary.ts
4651
4419
  import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4652
- import { bn as bn17 } from "@fuel-ts/math";
4420
+ import { bn as bn16 } from "@fuel-ts/math";
4653
4421
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4654
4422
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4655
4423
 
@@ -4895,30 +4663,37 @@ var Account = class extends AbstractAccount {
4895
4663
  * @param fee - The estimated transaction fee.
4896
4664
  * @returns A promise that resolves when the resources are added to the transaction.
4897
4665
  */
4898
- async fund(request, params) {
4899
- const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4900
- const txRequest = request;
4901
- const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4902
- amount: bn18(fee),
4666
+ async fund(request, coinQuantities, fee) {
4667
+ const updatedQuantities = addAmountToAsset({
4668
+ amount: bn17(fee),
4903
4669
  assetId: BaseAssetId3,
4904
- coinQuantities: requiredQuantities
4670
+ coinQuantities
4905
4671
  });
4906
4672
  const quantitiesDict = {};
4907
- requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4673
+ updatedQuantities.forEach(({ amount, assetId }) => {
4908
4674
  quantitiesDict[assetId] = {
4909
4675
  required: amount,
4910
- owned: bn18(0)
4676
+ owned: bn17(0)
4911
4677
  };
4912
4678
  });
4913
- txRequest.inputs.forEach((input) => {
4679
+ const cachedUtxos = [];
4680
+ const cachedMessages = [];
4681
+ const owner = this.address.toB256();
4682
+ request.inputs.forEach((input) => {
4914
4683
  const isResource = "amount" in input;
4915
- if (!isResource) {
4916
- return;
4917
- }
4918
- const isCoin2 = "owner" in input;
4919
- const assetId = isCoin2 ? String(input.assetId) : BaseAssetId3;
4920
- if (quantitiesDict[assetId]) {
4921
- quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
4684
+ if (isResource) {
4685
+ const isCoin2 = "owner" in input;
4686
+ if (isCoin2) {
4687
+ const assetId = String(input.assetId);
4688
+ if (input.owner === owner && quantitiesDict[assetId]) {
4689
+ const amount = bn17(input.amount);
4690
+ quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4691
+ cachedUtxos.push(input.id);
4692
+ }
4693
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4694
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4695
+ cachedMessages.push(input.nonce);
4696
+ }
4922
4697
  }
4923
4698
  });
4924
4699
  const missingQuantities = [];
@@ -4932,21 +4707,12 @@ var Account = class extends AbstractAccount {
4932
4707
  });
4933
4708
  const needsToBeFunded = missingQuantities.length;
4934
4709
  if (needsToBeFunded) {
4935
- const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
4936
- const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4937
- txRequest.addResources(resources);
4938
- }
4939
- txRequest.shiftPredicateData();
4940
- txRequest.updatePredicateGasUsed(estimatedPredicates);
4941
- const requestToReestimate = clone4(txRequest);
4942
- if (addedSignatures) {
4943
- Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
4944
- }
4945
- const { maxFee } = await this.provider.estimateTxGasAndFee({
4946
- transactionRequest: requestToReestimate
4947
- });
4948
- txRequest.maxFee = maxFee;
4949
- return txRequest;
4710
+ const resources = await this.getResourcesToSpend(missingQuantities, {
4711
+ messages: cachedMessages,
4712
+ utxos: cachedUtxos
4713
+ });
4714
+ request.addResources(resources);
4715
+ }
4950
4716
  }
4951
4717
  /**
4952
4718
  * A helper that creates a transfer transaction request and returns it.
@@ -4954,24 +4720,28 @@ var Account = class extends AbstractAccount {
4954
4720
  * @param destination - The address of the destination.
4955
4721
  * @param amount - The amount of coins to transfer.
4956
4722
  * @param assetId - The asset ID of the coins to transfer.
4957
- * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4723
+ * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4958
4724
  * @returns A promise that resolves to the prepared transaction request.
4959
4725
  */
4960
4726
  async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4961
- const request = new ScriptTransactionRequest(txParams);
4727
+ const { minGasPrice } = this.provider.getGasConfig();
4728
+ const params = { gasPrice: minGasPrice, ...txParams };
4729
+ const request = new ScriptTransactionRequest(params);
4962
4730
  request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4963
- const txCost = await this.provider.getTransactionCost(request, {
4731
+ const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4964
4732
  estimateTxDependencies: true,
4965
4733
  resourcesOwner: this
4966
4734
  });
4967
- this.validateGasLimitAndMaxFee({
4968
- gasUsed: txCost.gasUsed,
4969
- maxFee: txCost.maxFee,
4970
- txParams
4735
+ request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
4736
+ request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
4737
+ this.validateGas({
4738
+ gasUsed,
4739
+ gasPrice: request.gasPrice,
4740
+ gasLimit: request.gasLimit,
4741
+ minGasPrice
4971
4742
  });
4972
- request.gasLimit = txCost.gasUsed;
4973
- request.maxFee = txCost.maxFee;
4974
- await this.fund(request, txCost);
4743
+ await this.fund(request, requiredQuantities, maxFee);
4744
+ request.updatePredicateInputs(estimatedInputs);
4975
4745
  return request;
4976
4746
  }
4977
4747
  /**
@@ -4980,11 +4750,11 @@ var Account = class extends AbstractAccount {
4980
4750
  * @param destination - The address of the destination.
4981
4751
  * @param amount - The amount of coins to transfer.
4982
4752
  * @param assetId - The asset ID of the coins to transfer.
4983
- * @param txParams - The transaction parameters (gasLimit, maturity).
4753
+ * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4984
4754
  * @returns A promise that resolves to the transaction response.
4985
4755
  */
4986
4756
  async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4987
- if (bn18(amount).lte(0)) {
4757
+ if (bn17(amount).lte(0)) {
4988
4758
  throw new FuelError15(
4989
4759
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
4990
4760
  "Transfer amount must be a positive number."
@@ -5003,36 +4773,38 @@ var Account = class extends AbstractAccount {
5003
4773
  * @returns A promise that resolves to the transaction response.
5004
4774
  */
5005
4775
  async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5006
- if (bn18(amount).lte(0)) {
4776
+ if (bn17(amount).lte(0)) {
5007
4777
  throw new FuelError15(
5008
4778
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5009
4779
  "Transfer amount must be a positive number."
5010
4780
  );
5011
4781
  }
5012
4782
  const contractAddress = Address3.fromAddressOrString(contractId);
4783
+ const { minGasPrice } = this.provider.getGasConfig();
4784
+ const params = { gasPrice: minGasPrice, ...txParams };
5013
4785
  const { script, scriptData } = await assembleTransferToContractScript({
5014
4786
  hexlifiedContractId: contractAddress.toB256(),
5015
- amountToTransfer: bn18(amount),
4787
+ amountToTransfer: bn17(amount),
5016
4788
  assetId
5017
4789
  });
5018
4790
  const request = new ScriptTransactionRequest({
5019
- ...txParams,
4791
+ ...params,
5020
4792
  script,
5021
4793
  scriptData
5022
4794
  });
5023
4795
  request.addContractInputAndOutput(contractAddress);
5024
- const txCost = await this.provider.getTransactionCost(request, {
5025
- resourcesOwner: this,
5026
- quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
5027
- });
5028
- this.validateGasLimitAndMaxFee({
5029
- gasUsed: txCost.gasUsed,
5030
- maxFee: txCost.maxFee,
5031
- txParams
4796
+ const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4797
+ request,
4798
+ [{ amount: bn17(amount), assetId: String(assetId) }]
4799
+ );
4800
+ request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4801
+ this.validateGas({
4802
+ gasUsed,
4803
+ gasPrice: request.gasPrice,
4804
+ gasLimit: request.gasLimit,
4805
+ minGasPrice
5032
4806
  });
5033
- request.gasLimit = txCost.gasUsed;
5034
- request.maxFee = txCost.maxFee;
5035
- await this.fund(request, txCost);
4807
+ await this.fund(request, requiredQuantities, maxFee);
5036
4808
  return this.sendTransaction(request);
5037
4809
  }
5038
4810
  /**
@@ -5044,30 +4816,34 @@ var Account = class extends AbstractAccount {
5044
4816
  * @returns A promise that resolves to the transaction response.
5045
4817
  */
5046
4818
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4819
+ const { minGasPrice } = this.provider.getGasConfig();
5047
4820
  const recipientAddress = Address3.fromAddressOrString(recipient);
5048
4821
  const recipientDataArray = arrayify14(
5049
4822
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5050
4823
  );
5051
4824
  const amountDataArray = arrayify14(
5052
- "0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
4825
+ "0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
5053
4826
  );
5054
4827
  const script = new Uint8Array([
5055
4828
  ...arrayify14(withdrawScript.bytes),
5056
4829
  ...recipientDataArray,
5057
4830
  ...amountDataArray
5058
4831
  ]);
5059
- const params = { script, ...txParams };
4832
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5060
4833
  const request = new ScriptTransactionRequest(params);
5061
- const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
5062
- const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5063
- this.validateGasLimitAndMaxFee({
5064
- gasUsed: txCost.gasUsed,
5065
- maxFee: txCost.maxFee,
5066
- txParams
4834
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
4835
+ const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4836
+ request,
4837
+ forwardingQuantities
4838
+ );
4839
+ request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4840
+ this.validateGas({
4841
+ gasUsed,
4842
+ gasPrice: request.gasPrice,
4843
+ gasLimit: request.gasLimit,
4844
+ minGasPrice
5067
4845
  });
5068
- request.maxFee = txCost.maxFee;
5069
- request.gasLimit = txCost.gasUsed;
5070
- await this.fund(request, txCost);
4846
+ await this.fund(request, requiredQuantities, maxFee);
5071
4847
  return this.sendTransaction(request);
5072
4848
  }
5073
4849
  async signMessage(message) {
@@ -5125,21 +4901,22 @@ var Account = class extends AbstractAccount {
5125
4901
  }
5126
4902
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5127
4903
  }
5128
- validateGasLimitAndMaxFee({
5129
- txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
4904
+ validateGas({
5130
4905
  gasUsed,
5131
- maxFee
4906
+ gasPrice,
4907
+ gasLimit,
4908
+ minGasPrice
5132
4909
  }) {
5133
- if (isDefined(setGasLimit) && gasUsed.gt(setGasLimit)) {
4910
+ if (minGasPrice.gt(gasPrice)) {
5134
4911
  throw new FuelError15(
5135
- ErrorCode15.GAS_LIMIT_TOO_LOW,
5136
- `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
4912
+ ErrorCode15.GAS_PRICE_TOO_LOW,
4913
+ `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5137
4914
  );
5138
4915
  }
5139
- if (isDefined(setMaxFee) && maxFee.gt(setMaxFee)) {
4916
+ if (gasUsed.gt(gasLimit)) {
5140
4917
  throw new FuelError15(
5141
- ErrorCode15.MAX_FEE_TOO_LOW,
5142
- `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
4918
+ ErrorCode15.GAS_LIMIT_TOO_LOW,
4919
+ `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
5143
4920
  );
5144
4921
  }
5145
4922
  }
@@ -5427,7 +5204,7 @@ var BaseWalletUnlocked = class extends Account {
5427
5204
  * @param transactionRequestLike - The transaction request to send.
5428
5205
  * @returns A promise that resolves to the TransactionResponse object.
5429
5206
  */
5430
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5207
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5431
5208
  const transactionRequest = transactionRequestify(transactionRequestLike);
5432
5209
  if (estimateTxDependencies) {
5433
5210
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5468,7 +5245,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5468
5245
  // src/hdwallet/hdwallet.ts
5469
5246
  import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5470
5247
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5471
- import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5248
+ import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5472
5249
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5473
5250
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5474
5251
 
@@ -7934,7 +7711,7 @@ var HDWallet = class {
7934
7711
  const IR = bytes.slice(32);
7935
7712
  if (privateKey) {
7936
7713
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7937
- const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
7714
+ const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
7938
7715
  return new HDWallet({
7939
7716
  privateKey: ki,
7940
7717
  chainCode: IR,
@@ -8200,20 +7977,26 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8200
7977
 
8201
7978
  // src/test-utils/seedTestWallet.ts
8202
7979
  import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
8203
- var seedTestWallet = async (wallet, quantities) => {
7980
+ var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
7981
+ const toFundAccounts = Array.isArray(wallet) ? wallet : [wallet];
8204
7982
  const genesisWallet = new WalletUnlocked(
8205
7983
  process.env.GENESIS_SECRET || randomBytes5(32),
8206
- wallet.provider
7984
+ toFundAccounts[0].provider
8207
7985
  );
8208
- const request = new ScriptTransactionRequest();
8209
- quantities.forEach((quantity) => {
8210
- const { amount, assetId } = coinQuantityfy(quantity);
8211
- request.addCoinOutput(wallet.address, amount, assetId);
7986
+ const resources = await genesisWallet.getResourcesToSpend(quantities);
7987
+ const { minGasPrice } = genesisWallet.provider.getGasConfig();
7988
+ const request = new ScriptTransactionRequest({
7989
+ gasLimit: 1e4,
7990
+ gasPrice: minGasPrice
8212
7991
  });
8213
- const txCost = await genesisWallet.provider.getTransactionCost(request);
8214
- request.gasLimit = txCost.gasUsed;
8215
- request.maxFee = txCost.maxFee;
8216
- await genesisWallet.fund(request, txCost);
7992
+ request.addResources(resources);
7993
+ quantities.map(coinQuantityfy).forEach(
7994
+ ({ amount, assetId }) => toFundAccounts.forEach(({ address }) => {
7995
+ for (let i = 0; i < utxosAmount; i++) {
7996
+ request.addCoinOutput(address, amount.div(utxosAmount), assetId);
7997
+ }
7998
+ })
7999
+ );
8217
8000
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
8218
8001
  };
8219
8002
 
@@ -8227,10 +8010,9 @@ var generateTestWallet = async (provider, quantities) => {
8227
8010
  };
8228
8011
 
8229
8012
  // src/test-utils/launchNode.ts
8230
- import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
8231
8013
  import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8232
- import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
8233
- import { defaultChainConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
8014
+ import { toHex as toHex2 } from "@fuel-ts/math";
8015
+ import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
8234
8016
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
8235
8017
  import { spawn } from "child_process";
8236
8018
  import { randomUUID } from "crypto";
@@ -8282,12 +8064,12 @@ var launchNode = async ({
8282
8064
  // eslint-disable-next-line no-async-promise-executor
8283
8065
  new Promise(async (resolve, reject) => {
8284
8066
  const remainingArgs = extractRemainingArgs(args, [
8285
- "--snapshot",
8067
+ "--chain",
8286
8068
  "--consensus-key",
8287
8069
  "--db-type",
8288
8070
  "--poa-instant"
8289
8071
  ]);
8290
- const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
8072
+ const chainConfigPath = getFlagValueFromArgs(args, "--chain");
8291
8073
  const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || defaultConsensusKey;
8292
8074
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8293
8075
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
@@ -8306,54 +8088,36 @@ var launchNode = async ({
8306
8088
  let chainConfigPathToUse;
8307
8089
  const prefix = basePath || os.tmpdir();
8308
8090
  const suffix = basePath ? "" : randomUUID();
8309
- const tempDirPath = path.join(prefix, ".fuels", suffix, "chainConfigs");
8091
+ const tempDirPath = path.join(prefix, ".fuels", suffix);
8310
8092
  if (chainConfigPath) {
8311
8093
  chainConfigPathToUse = chainConfigPath;
8312
8094
  } else {
8313
8095
  if (!existsSync(tempDirPath)) {
8314
8096
  mkdirSync(tempDirPath, { recursive: true });
8315
8097
  }
8316
- let { stateConfigJson } = defaultChainConfigs;
8317
- const { chainConfigJson, metadataJson } = defaultChainConfigs;
8318
- stateConfigJson = {
8319
- ...stateConfigJson,
8320
- coins: [
8321
- ...stateConfigJson.coins.map((coin) => ({
8322
- ...coin,
8323
- amount: "18446744073709551615"
8324
- }))
8325
- ],
8326
- messages: stateConfigJson.messages.map((message) => ({
8327
- ...message,
8328
- amount: "18446744073709551615"
8329
- }))
8330
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8331
- };
8098
+ const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
8099
+ let chainConfig = defaultChainConfig;
8332
8100
  if (!process.env.GENESIS_SECRET) {
8333
8101
  const pk = Signer.generatePrivateKey();
8334
8102
  const signer = new Signer(pk);
8335
8103
  process.env.GENESIS_SECRET = hexlify18(pk);
8336
- stateConfigJson.coins.push({
8337
- tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
8338
- owner: signer.address.toHexString(),
8339
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8340
- amount: "18446744073709551615",
8341
- asset_id: BaseAssetId4,
8342
- output_index: 0,
8343
- tx_pointer_block_height: 0,
8344
- tx_pointer_tx_idx: 0
8345
- });
8104
+ chainConfig = {
8105
+ ...defaultChainConfig,
8106
+ initial_state: {
8107
+ ...defaultChainConfig.initial_state,
8108
+ coins: [
8109
+ ...defaultChainConfig.initial_state.coins,
8110
+ {
8111
+ owner: signer.address.toHexString(),
8112
+ amount: toHex2(1e9),
8113
+ asset_id: BaseAssetId4
8114
+ }
8115
+ ]
8116
+ }
8117
+ };
8346
8118
  }
8347
- let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8348
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8349
- fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8350
- const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
8351
- const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
8352
- const metadataWritePath = path.join(tempDirPath, "metadata.json");
8353
- writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8354
- writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8355
- writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8356
- chainConfigPathToUse = tempDirPath;
8119
+ writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
8120
+ chainConfigPathToUse = tempChainConfigFilePath;
8357
8121
  }
8358
8122
  const child = spawn(
8359
8123
  command,
@@ -8362,10 +8126,10 @@ var launchNode = async ({
8362
8126
  ["--ip", ipToUse],
8363
8127
  ["--port", portToUse],
8364
8128
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8365
- ["--min-gas-price", "1"],
8129
+ ["--min-gas-price", "0"],
8366
8130
  poaInstant ? ["--poa-instant", "true"] : [],
8367
8131
  ["--consensus-key", consensusKey],
8368
- ["--snapshot", chainConfigPathToUse],
8132
+ ["--chain", chainConfigPathToUse],
8369
8133
  "--vm-backtrace",
8370
8134
  "--utxo-validation",
8371
8135
  "--debug",
@@ -8424,14 +8188,51 @@ var launchNodeAndGetWallets = async ({
8424
8188
  walletCount = 10
8425
8189
  } = {}) => {
8426
8190
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8427
- const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8191
+ const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8428
8192
  const wallets = await generateWallets(walletCount, provider);
8429
8193
  const cleanup = () => {
8430
8194
  closeNode();
8431
8195
  };
8432
8196
  return { wallets, stop: cleanup, provider };
8433
8197
  };
8198
+
8199
+ // src/test-utils/transactionRequest.ts
8200
+ import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
8201
+ import { getRandomB256 } from "@fuel-ts/address";
8202
+ import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
8203
+ import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
8204
+ import { bn as bn19 } from "@fuel-ts/math";
8205
+ import { InputType as InputType8 } from "@fuel-ts/transactions";
8206
+ import { hexlify as hexlify19 } from "@fuel-ts/utils";
8207
+ var generateFakeRequestInputCoin = (partial = {}) => ({
8208
+ id: hexlify19(randomBytes6(UTXO_ID_LEN3)),
8209
+ type: InputType8.Coin,
8210
+ owner: getRandomB256(),
8211
+ amount: bn19(100),
8212
+ assetId: ZeroBytes329,
8213
+ txPointer: "0x00000000000000000000000000000000",
8214
+ witnessIndex: 0,
8215
+ ...partial
8216
+ });
8217
+ var generateFakeRequestInputMessage = (partial = {}) => ({
8218
+ nonce: getRandomB256(),
8219
+ type: InputType8.Message,
8220
+ sender: getRandomB256(),
8221
+ recipient: getRandomB256(),
8222
+ amount: bn19(100),
8223
+ witnessIndex: 0,
8224
+ ...partial
8225
+ });
8226
+ var generateFakeRequestInputContract = (partial = {}) => ({
8227
+ contractId: getRandomB256(),
8228
+ type: InputType8.Contract,
8229
+ txPointer: "0x00000000000000000000000000000000",
8230
+ ...partial
8231
+ });
8434
8232
  export {
8233
+ generateFakeRequestInputCoin,
8234
+ generateFakeRequestInputContract,
8235
+ generateFakeRequestInputMessage,
8435
8236
  generateTestWallet,
8436
8237
  killNode,
8437
8238
  launchNode,