@fuel-ts/account 0.0.0-rc-2152-20240425194419 → 0.0.0-rc-2021-20240425202957

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

Potentially problematic release.


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

Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +7 -6
  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 +1818 -696
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +796 -545
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +671 -421
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +12 -24
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +810 -359
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +1 -1
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +7 -1
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +46 -27
  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/input.d.ts +2 -2
  31. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  32. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/transaction-request.d.ts +8 -28
  34. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/utils.d.ts +3 -0
  36. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  37. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  38. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  39. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  40. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  43. package/dist/providers/utils/gas.d.ts +8 -2
  44. package/dist/providers/utils/gas.d.ts.map +1 -1
  45. package/dist/test-utils/launchNode.d.ts +1 -1
  46. package/dist/test-utils/launchNode.d.ts.map +1 -1
  47. package/dist/test-utils.global.js +2544 -1193
  48. package/dist/test-utils.global.js.map +1 -1
  49. package/dist/test-utils.js +782 -536
  50. package/dist/test-utils.js.map +1 -1
  51. package/dist/test-utils.mjs +669 -423
  52. package/dist/test-utils.mjs.map +1 -1
  53. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  54. package/package.json +16 -16
package/dist/index.mjs CHANGED
@@ -31,8 +31,9 @@ var __privateMethod = (obj, member, method) => {
31
31
  import { Address as Address3 } from "@fuel-ts/address";
32
32
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
33
33
  import { AbstractAccount } from "@fuel-ts/interfaces";
34
- import { bn as bn17 } from "@fuel-ts/math";
35
- import { arrayify as arrayify14 } from "@fuel-ts/utils";
34
+ import { bn as bn18 } from "@fuel-ts/math";
35
+ import { arrayify as arrayify14, isDefined } from "@fuel-ts/utils";
36
+ import { clone as clone4 } from "ramda";
36
37
 
37
38
  // src/providers/coin-quantity.ts
38
39
  import { bn } from "@fuel-ts/math";
@@ -40,24 +41,24 @@ import { hexlify } from "@fuel-ts/utils";
40
41
  var coinQuantityfy = (coinQuantityLike) => {
41
42
  let assetId;
42
43
  let amount;
43
- let max2;
44
+ let max;
44
45
  if (Array.isArray(coinQuantityLike)) {
45
46
  amount = coinQuantityLike[0];
46
47
  assetId = coinQuantityLike[1];
47
- max2 = coinQuantityLike[2] ?? void 0;
48
+ max = coinQuantityLike[2] ?? void 0;
48
49
  } else {
49
50
  amount = coinQuantityLike.amount;
50
51
  assetId = coinQuantityLike.assetId;
51
- max2 = coinQuantityLike.max ?? void 0;
52
+ max = coinQuantityLike.max ?? void 0;
52
53
  }
53
54
  const bnAmount = bn(amount);
54
55
  return {
55
56
  assetId: hexlify(assetId),
56
57
  amount: bnAmount.lt(1) ? bn(1) : bnAmount,
57
- max: max2 ? bn(max2) : void 0
58
+ max: max ? bn(max) : void 0
58
59
  };
59
60
  };
60
- var addAmountToAsset = (params) => {
61
+ var addAmountToCoinQuantities = (params) => {
61
62
  const { amount, assetId } = params;
62
63
  const coinQuantities = [...params.coinQuantities];
63
64
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -72,9 +73,9 @@ var addAmountToAsset = (params) => {
72
73
  // src/providers/provider.ts
73
74
  import { Address as Address2 } from "@fuel-ts/address";
74
75
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
75
- import { BN, bn as bn15, max } from "@fuel-ts/math";
76
+ import { BN, bn as bn16 } from "@fuel-ts/math";
76
77
  import {
77
- InputType as InputType6,
78
+ InputType as InputType7,
78
79
  TransactionType as TransactionType8,
79
80
  InputMessageCoder,
80
81
  TransactionCoder as TransactionCoder5
@@ -82,21 +83,26 @@ import {
82
83
  import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
83
84
  import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
84
85
  import { equalBytes } from "@noble/curves/abstract/utils";
86
+ import { Network } from "ethers";
85
87
  import { GraphQLClient } from "graphql-request";
86
88
  import { clone as clone3 } from "ramda";
87
89
 
88
90
  // src/providers/__generated__/operations.ts
89
91
  import gql from "graphql-tag";
92
+ var TransactionStatusSubscriptionFragmentFragmentDoc = gql`
93
+ fragment transactionStatusSubscriptionFragment on TransactionStatus {
94
+ type: __typename
95
+ ... on SqueezedOutStatus {
96
+ reason
97
+ }
98
+ }
99
+ `;
90
100
  var ReceiptFragmentFragmentDoc = gql`
91
101
  fragment receiptFragment on Receipt {
92
- contract {
93
- id
94
- }
102
+ id
95
103
  pc
96
104
  is
97
- to {
98
- id
99
- }
105
+ to
100
106
  toAddress
101
107
  amount
102
108
  assetId
@@ -134,10 +140,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
134
140
  id
135
141
  }
136
142
  time
143
+ receipts {
144
+ ...receiptFragment
145
+ }
137
146
  programState {
138
147
  returnType
139
148
  data
140
149
  }
150
+ receipts {
151
+ ...receiptFragment
152
+ }
141
153
  }
142
154
  ... on FailureStatus {
143
155
  block {
@@ -145,26 +157,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
145
157
  }
146
158
  time
147
159
  reason
160
+ receipts {
161
+ ...receiptFragment
162
+ }
148
163
  }
149
164
  ... on SqueezedOutStatus {
150
165
  reason
151
166
  }
152
167
  }
153
- `;
168
+ ${ReceiptFragmentFragmentDoc}`;
154
169
  var TransactionFragmentFragmentDoc = gql`
155
170
  fragment transactionFragment on Transaction {
156
171
  id
157
172
  rawPayload
158
- gasPrice
159
- receipts {
160
- ...receiptFragment
161
- }
162
173
  status {
163
174
  ...transactionStatusFragment
164
175
  }
165
176
  }
166
- ${ReceiptFragmentFragmentDoc}
167
- ${TransactionStatusFragmentFragmentDoc}`;
177
+ ${TransactionStatusFragmentFragmentDoc}`;
168
178
  var InputEstimatePredicatesFragmentFragmentDoc = gql`
169
179
  fragment inputEstimatePredicatesFragment on Input {
170
180
  ... on InputCoin {
@@ -182,6 +192,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
182
192
  }
183
193
  }
184
194
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
195
+ var DryRunFailureStatusFragmentFragmentDoc = gql`
196
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
197
+ reason
198
+ programState {
199
+ returnType
200
+ data
201
+ }
202
+ }
203
+ `;
204
+ var DryRunSuccessStatusFragmentFragmentDoc = gql`
205
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
206
+ programState {
207
+ returnType
208
+ data
209
+ }
210
+ }
211
+ `;
212
+ var DryRunTransactionStatusFragmentFragmentDoc = gql`
213
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
214
+ ... on DryRunFailureStatus {
215
+ ...dryRunFailureStatusFragment
216
+ }
217
+ ... on DryRunSuccessStatus {
218
+ ...dryRunSuccessStatusFragment
219
+ }
220
+ }
221
+ ${DryRunFailureStatusFragmentFragmentDoc}
222
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
223
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
224
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
225
+ id
226
+ status {
227
+ ...dryRunTransactionStatusFragment
228
+ }
229
+ receipts {
230
+ ...receiptFragment
231
+ }
232
+ }
233
+ ${DryRunTransactionStatusFragmentFragmentDoc}
234
+ ${ReceiptFragmentFragmentDoc}`;
185
235
  var CoinFragmentFragmentDoc = gql`
186
236
  fragment coinFragment on Coin {
187
237
  __typename
@@ -189,7 +239,6 @@ var CoinFragmentFragmentDoc = gql`
189
239
  owner
190
240
  amount
191
241
  assetId
192
- maturity
193
242
  blockCreated
194
243
  txCreatedIdx
195
244
  }
@@ -228,26 +277,32 @@ var MessageProofFragmentFragmentDoc = gql`
228
277
  messageBlockHeader {
229
278
  id
230
279
  daHeight
280
+ consensusParametersVersion
281
+ stateTransitionBytecodeVersion
231
282
  transactionsCount
283
+ messageReceiptCount
232
284
  transactionsRoot
285
+ messageOutboxRoot
286
+ eventInboxRoot
233
287
  height
234
288
  prevRoot
235
289
  time
236
290
  applicationHash
237
- messageReceiptRoot
238
- messageReceiptCount
239
291
  }
240
292
  commitBlockHeader {
241
293
  id
242
294
  daHeight
295
+ consensusParametersVersion
296
+ stateTransitionBytecodeVersion
243
297
  transactionsCount
298
+ messageReceiptCount
244
299
  transactionsRoot
300
+ messageOutboxRoot
301
+ eventInboxRoot
245
302
  height
246
303
  prevRoot
247
304
  time
248
305
  applicationHash
249
- messageReceiptRoot
250
- messageReceiptCount
251
306
  }
252
307
  sender
253
308
  recipient
@@ -266,8 +321,8 @@ var BalanceFragmentFragmentDoc = gql`
266
321
  var BlockFragmentFragmentDoc = gql`
267
322
  fragment blockFragment on Block {
268
323
  id
324
+ height
269
325
  header {
270
- height
271
326
  time
272
327
  }
273
328
  transactions {
@@ -277,6 +332,7 @@ var BlockFragmentFragmentDoc = gql`
277
332
  `;
278
333
  var TxParametersFragmentFragmentDoc = gql`
279
334
  fragment TxParametersFragment on TxParameters {
335
+ version
280
336
  maxInputs
281
337
  maxOutputs
282
338
  maxWitnesses
@@ -286,6 +342,7 @@ var TxParametersFragmentFragmentDoc = gql`
286
342
  `;
287
343
  var PredicateParametersFragmentFragmentDoc = gql`
288
344
  fragment PredicateParametersFragment on PredicateParameters {
345
+ version
289
346
  maxPredicateLength
290
347
  maxPredicateDataLength
291
348
  maxGasPerPredicate
@@ -294,18 +351,21 @@ var PredicateParametersFragmentFragmentDoc = gql`
294
351
  `;
295
352
  var ScriptParametersFragmentFragmentDoc = gql`
296
353
  fragment ScriptParametersFragment on ScriptParameters {
354
+ version
297
355
  maxScriptLength
298
356
  maxScriptDataLength
299
357
  }
300
358
  `;
301
359
  var ContractParametersFragmentFragmentDoc = gql`
302
360
  fragment ContractParametersFragment on ContractParameters {
361
+ version
303
362
  contractMaxSize
304
363
  maxStorageSlots
305
364
  }
306
365
  `;
307
366
  var FeeParametersFragmentFragmentDoc = gql`
308
367
  fragment FeeParametersFragment on FeeParameters {
368
+ version
309
369
  gasPriceFactor
310
370
  gasPerByte
311
371
  }
@@ -325,6 +385,7 @@ var DependentCostFragmentFragmentDoc = gql`
325
385
  `;
326
386
  var GasCostsFragmentFragmentDoc = gql`
327
387
  fragment GasCostsFragment on GasCosts {
388
+ version
328
389
  add
329
390
  addi
330
391
  aloc
@@ -337,7 +398,6 @@ var GasCostsFragmentFragmentDoc = gql`
337
398
  cb
338
399
  cfei
339
400
  cfsi
340
- croo
341
401
  div
342
402
  divi
343
403
  ecr1
@@ -420,6 +480,9 @@ var GasCostsFragmentFragmentDoc = gql`
420
480
  ccp {
421
481
  ...DependentCostFragment
422
482
  }
483
+ croo {
484
+ ...DependentCostFragment
485
+ }
423
486
  csiz {
424
487
  ...DependentCostFragment
425
488
  }
@@ -479,6 +542,7 @@ var GasCostsFragmentFragmentDoc = gql`
479
542
  ${DependentCostFragmentFragmentDoc}`;
480
543
  var ConsensusParametersFragmentFragmentDoc = gql`
481
544
  fragment consensusParametersFragment on ConsensusParameters {
545
+ version
482
546
  txParams {
483
547
  ...TxParametersFragment
484
548
  }
@@ -538,18 +602,9 @@ var NodeInfoFragmentFragmentDoc = gql`
538
602
  fragment nodeInfoFragment on NodeInfo {
539
603
  utxoValidation
540
604
  vmBacktrace
541
- minGasPrice
542
605
  maxTx
543
606
  maxDepth
544
607
  nodeVersion
545
- peers {
546
- id
547
- addresses
548
- clientVersion
549
- blockHeight
550
- lastHeartbeatMs
551
- appScore
552
- }
553
608
  }
554
609
  `;
555
610
  var GetVersionDocument = gql`
@@ -584,13 +639,9 @@ var GetTransactionWithReceiptsDocument = gql`
584
639
  query getTransactionWithReceipts($transactionId: TransactionId!) {
585
640
  transaction(id: $transactionId) {
586
641
  ...transactionFragment
587
- receipts {
588
- ...receiptFragment
589
- }
590
642
  }
591
643
  }
592
- ${TransactionFragmentFragmentDoc}
593
- ${ReceiptFragmentFragmentDoc}`;
644
+ ${TransactionFragmentFragmentDoc}`;
594
645
  var GetTransactionsDocument = gql`
595
646
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
596
647
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -718,6 +769,20 @@ var GetBalanceDocument = gql`
718
769
  }
719
770
  }
720
771
  ${BalanceFragmentFragmentDoc}`;
772
+ var GetLatestGasPriceDocument = gql`
773
+ query getLatestGasPrice {
774
+ latestGasPrice {
775
+ gasPrice
776
+ }
777
+ }
778
+ `;
779
+ var EstimateGasPriceDocument = gql`
780
+ query estimateGasPrice($blockHorizon: U32!) {
781
+ estimateGasPrice(blockHorizon: $blockHorizon) {
782
+ gasPrice
783
+ }
784
+ }
785
+ `;
721
786
  var GetBalancesDocument = gql`
722
787
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
723
788
  balances(
@@ -772,12 +837,12 @@ var GetMessageStatusDocument = gql`
772
837
  }
773
838
  `;
774
839
  var DryRunDocument = gql`
775
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
776
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
777
- ...receiptFragment
840
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
841
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
842
+ ...dryRunTransactionExecutionStatusFragment
778
843
  }
779
844
  }
780
- ${ReceiptFragmentFragmentDoc}`;
845
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
781
846
  var SubmitDocument = gql`
782
847
  mutation submit($encodedTransaction: HexString!) {
783
848
  submit(tx: $encodedTransaction) {
@@ -796,17 +861,17 @@ var ProduceBlocksDocument = gql`
796
861
  var SubmitAndAwaitDocument = gql`
797
862
  subscription submitAndAwait($encodedTransaction: HexString!) {
798
863
  submitAndAwait(tx: $encodedTransaction) {
799
- ...transactionStatusFragment
864
+ ...transactionStatusSubscriptionFragment
800
865
  }
801
866
  }
802
- ${TransactionStatusFragmentFragmentDoc}`;
867
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
803
868
  var StatusChangeDocument = gql`
804
869
  subscription statusChange($transactionId: TransactionId!) {
805
870
  statusChange(id: $transactionId) {
806
- ...transactionStatusFragment
871
+ ...transactionStatusSubscriptionFragment
807
872
  }
808
873
  }
809
- ${TransactionStatusFragmentFragmentDoc}`;
874
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
810
875
  function getSdk(requester) {
811
876
  return {
812
877
  getVersion(variables, options) {
@@ -860,6 +925,12 @@ function getSdk(requester) {
860
925
  getBalance(variables, options) {
861
926
  return requester(GetBalanceDocument, variables, options);
862
927
  },
928
+ getLatestGasPrice(variables, options) {
929
+ return requester(GetLatestGasPriceDocument, variables, options);
930
+ },
931
+ estimateGasPrice(variables, options) {
932
+ return requester(EstimateGasPriceDocument, variables, options);
933
+ },
863
934
  getBalances(variables, options) {
864
935
  return requester(GetBalancesDocument, variables, options);
865
936
  },
@@ -1053,10 +1124,9 @@ var inputify = (value) => {
1053
1124
  txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
1054
1125
  },
1055
1126
  witnessIndex: value.witnessIndex,
1056
- maturity: value.maturity ?? 0,
1057
1127
  predicateGasUsed: bn2(value.predicateGasUsed),
1058
- predicateLength: predicate.length,
1059
- predicateDataLength: predicateData.length,
1128
+ predicateLength: bn2(predicate.length),
1129
+ predicateDataLength: bn2(predicateData.length),
1060
1130
  predicate: hexlify3(predicate),
1061
1131
  predicateData: hexlify3(predicateData)
1062
1132
  };
@@ -1087,8 +1157,8 @@ var inputify = (value) => {
1087
1157
  nonce: hexlify3(value.nonce),
1088
1158
  witnessIndex: value.witnessIndex,
1089
1159
  predicateGasUsed: bn2(value.predicateGasUsed),
1090
- predicateLength: predicate.length,
1091
- predicateDataLength: predicateData.length,
1160
+ predicateLength: bn2(predicate.length),
1161
+ predicateDataLength: bn2(predicateData.length),
1092
1162
  predicate: hexlify3(predicate),
1093
1163
  predicateData: hexlify3(predicateData),
1094
1164
  data: hexlify3(data),
@@ -1218,8 +1288,8 @@ function assembleReceiptByType(receipt) {
1218
1288
  case "CALL" /* Call */: {
1219
1289
  const callReceipt = {
1220
1290
  type: ReceiptType.Call,
1221
- from: hexOrZero(receipt.contract?.id),
1222
- to: hexOrZero(receipt?.to?.id),
1291
+ from: hexOrZero(receipt.id || receipt.contractId),
1292
+ to: hexOrZero(receipt?.to),
1223
1293
  amount: bn4(receipt.amount),
1224
1294
  assetId: hexOrZero(receipt.assetId),
1225
1295
  gas: bn4(receipt.gas),
@@ -1233,7 +1303,7 @@ function assembleReceiptByType(receipt) {
1233
1303
  case "RETURN" /* Return */: {
1234
1304
  const returnReceipt = {
1235
1305
  type: ReceiptType.Return,
1236
- id: hexOrZero(receipt.contract?.id),
1306
+ id: hexOrZero(receipt.id || receipt.contractId),
1237
1307
  val: bn4(receipt.val),
1238
1308
  pc: bn4(receipt.pc),
1239
1309
  is: bn4(receipt.is)
@@ -1243,7 +1313,7 @@ function assembleReceiptByType(receipt) {
1243
1313
  case "RETURN_DATA" /* ReturnData */: {
1244
1314
  const returnDataReceipt = {
1245
1315
  type: ReceiptType.ReturnData,
1246
- id: hexOrZero(receipt.contract?.id),
1316
+ id: hexOrZero(receipt.id || receipt.contractId),
1247
1317
  ptr: bn4(receipt.ptr),
1248
1318
  len: bn4(receipt.len),
1249
1319
  digest: hexOrZero(receipt.digest),
@@ -1255,7 +1325,7 @@ function assembleReceiptByType(receipt) {
1255
1325
  case "PANIC" /* Panic */: {
1256
1326
  const panicReceipt = {
1257
1327
  type: ReceiptType.Panic,
1258
- id: hexOrZero(receipt.contract?.id),
1328
+ id: hexOrZero(receipt.id),
1259
1329
  reason: bn4(receipt.reason),
1260
1330
  pc: bn4(receipt.pc),
1261
1331
  is: bn4(receipt.is),
@@ -1266,7 +1336,7 @@ function assembleReceiptByType(receipt) {
1266
1336
  case "REVERT" /* Revert */: {
1267
1337
  const revertReceipt = {
1268
1338
  type: ReceiptType.Revert,
1269
- id: hexOrZero(receipt.contract?.id),
1339
+ id: hexOrZero(receipt.id || receipt.contractId),
1270
1340
  val: bn4(receipt.ra),
1271
1341
  pc: bn4(receipt.pc),
1272
1342
  is: bn4(receipt.is)
@@ -1276,7 +1346,7 @@ function assembleReceiptByType(receipt) {
1276
1346
  case "LOG" /* Log */: {
1277
1347
  const logReceipt = {
1278
1348
  type: ReceiptType.Log,
1279
- id: hexOrZero(receipt.contract?.id),
1349
+ id: hexOrZero(receipt.id || receipt.contractId),
1280
1350
  val0: bn4(receipt.ra),
1281
1351
  val1: bn4(receipt.rb),
1282
1352
  val2: bn4(receipt.rc),
@@ -1289,7 +1359,7 @@ function assembleReceiptByType(receipt) {
1289
1359
  case "LOG_DATA" /* LogData */: {
1290
1360
  const logDataReceipt = {
1291
1361
  type: ReceiptType.LogData,
1292
- id: hexOrZero(receipt.contract?.id),
1362
+ id: hexOrZero(receipt.id || receipt.contractId),
1293
1363
  val0: bn4(receipt.ra),
1294
1364
  val1: bn4(receipt.rb),
1295
1365
  ptr: bn4(receipt.ptr),
@@ -1303,8 +1373,8 @@ function assembleReceiptByType(receipt) {
1303
1373
  case "TRANSFER" /* Transfer */: {
1304
1374
  const transferReceipt = {
1305
1375
  type: ReceiptType.Transfer,
1306
- from: hexOrZero(receipt.contract?.id),
1307
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1376
+ from: hexOrZero(receipt.id || receipt.contractId),
1377
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1308
1378
  amount: bn4(receipt.amount),
1309
1379
  assetId: hexOrZero(receipt.assetId),
1310
1380
  pc: bn4(receipt.pc),
@@ -1315,8 +1385,8 @@ function assembleReceiptByType(receipt) {
1315
1385
  case "TRANSFER_OUT" /* TransferOut */: {
1316
1386
  const transferOutReceipt = {
1317
1387
  type: ReceiptType.TransferOut,
1318
- from: hexOrZero(receipt.contract?.id),
1319
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1388
+ from: hexOrZero(receipt.id || receipt.contractId),
1389
+ to: hexOrZero(receipt.toAddress || receipt.to),
1320
1390
  amount: bn4(receipt.amount),
1321
1391
  assetId: hexOrZero(receipt.assetId),
1322
1392
  pc: bn4(receipt.pc),
@@ -1359,7 +1429,7 @@ function assembleReceiptByType(receipt) {
1359
1429
  return receiptMessageOut;
1360
1430
  }
1361
1431
  case "MINT" /* Mint */: {
1362
- const contractId = hexOrZero(receipt.contract?.id);
1432
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1363
1433
  const subId = hexOrZero(receipt.subId);
1364
1434
  const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
1365
1435
  const mintReceipt = {
@@ -1374,7 +1444,7 @@ function assembleReceiptByType(receipt) {
1374
1444
  return mintReceipt;
1375
1445
  }
1376
1446
  case "BURN" /* Burn */: {
1377
- const contractId = hexOrZero(receipt.contract?.id);
1447
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1378
1448
  const subId = hexOrZero(receipt.subId);
1379
1449
  const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
1380
1450
  const burnReceipt = {
@@ -1459,7 +1529,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1459
1529
  import { bn as bn5 } from "@fuel-ts/math";
1460
1530
  import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
1461
1531
  import { arrayify as arrayify3 } from "@fuel-ts/utils";
1462
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1463
1532
  var getGasUsedFromReceipts = (receipts) => {
1464
1533
  const scriptResult = receipts.filter(
1465
1534
  (receipt) => receipt.type === ReceiptType2.ScriptResult
@@ -1480,18 +1549,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1480
1549
  }
1481
1550
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1482
1551
  const witnessCache = [];
1483
- const totalGas = inputs.reduce((total, input) => {
1552
+ const chargeableInputs = inputs.filter((input) => {
1553
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1554
+ if (isCoinOrMessage) {
1555
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1556
+ return true;
1557
+ }
1558
+ if (!witnessCache.includes(input.witnessIndex)) {
1559
+ witnessCache.push(input.witnessIndex);
1560
+ return true;
1561
+ }
1562
+ }
1563
+ return false;
1564
+ });
1565
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1566
+ const totalGas = chargeableInputs.reduce((total, input) => {
1484
1567
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1485
1568
  return total.add(
1486
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1569
+ vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1487
1570
  );
1488
1571
  }
1489
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1490
- witnessCache.push(input.witnessIndex);
1491
- return total.add(gasCosts.ecr1);
1492
- }
1493
- return total;
1494
- }, bn5());
1572
+ return total.add(gasCosts.ecr1);
1573
+ }, bn5(0));
1495
1574
  return totalGas;
1496
1575
  }
1497
1576
  function getMinGas(params) {
@@ -1503,12 +1582,20 @@ function getMinGas(params) {
1503
1582
  return minGas;
1504
1583
  }
1505
1584
  function getMaxGas(params) {
1506
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
1585
+ const {
1586
+ gasPerByte,
1587
+ witnessesLength,
1588
+ witnessLimit,
1589
+ minGas,
1590
+ gasLimit = bn5(0),
1591
+ maxGasPerTx
1592
+ } = params;
1507
1593
  let remainingAllowedWitnessGas = bn5(0);
1508
1594
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1509
1595
  remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1510
1596
  }
1511
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1597
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1598
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1512
1599
  }
1513
1600
  function calculateMetadataGasForTxCreate({
1514
1601
  gasCosts,
@@ -1530,6 +1617,10 @@ function calculateMetadataGasForTxScript({
1530
1617
  }) {
1531
1618
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1532
1619
  }
1620
+ var calculateGasFee = (params) => {
1621
+ const { gas, gasPrice, priceFactor, tip } = params;
1622
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1623
+ };
1533
1624
 
1534
1625
  // src/providers/utils/json.ts
1535
1626
  import { hexlify as hexlify5 } from "@fuel-ts/utils";
@@ -1686,7 +1777,7 @@ var witnessify = (value) => {
1686
1777
  // src/providers/transaction-request/transaction-request.ts
1687
1778
  var BaseTransactionRequest = class {
1688
1779
  /** Gas price for transaction */
1689
- gasPrice;
1780
+ tip;
1690
1781
  /** Block until which tx cannot be included */
1691
1782
  maturity;
1692
1783
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1705,7 +1796,7 @@ var BaseTransactionRequest = class {
1705
1796
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1706
1797
  */
1707
1798
  constructor({
1708
- gasPrice,
1799
+ tip,
1709
1800
  maturity,
1710
1801
  maxFee,
1711
1802
  witnessLimit,
@@ -1713,7 +1804,7 @@ var BaseTransactionRequest = class {
1713
1804
  outputs,
1714
1805
  witnesses
1715
1806
  } = {}) {
1716
- this.gasPrice = bn7(gasPrice);
1807
+ this.tip = bn7(tip);
1717
1808
  this.maturity = maturity ?? 0;
1718
1809
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1719
1810
  this.maxFee = maxFee ? bn7(maxFee) : void 0;
@@ -1724,9 +1815,9 @@ var BaseTransactionRequest = class {
1724
1815
  static getPolicyMeta(req) {
1725
1816
  let policyTypes = 0;
1726
1817
  const policies = [];
1727
- if (req.gasPrice) {
1728
- policyTypes += PolicyType.GasPrice;
1729
- policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
1818
+ if (req.tip) {
1819
+ policyTypes += PolicyType.Tip;
1820
+ policies.push({ data: req.tip, type: PolicyType.Tip });
1730
1821
  }
1731
1822
  if (req.witnessLimit) {
1732
1823
  policyTypes += PolicyType.WitnessLimit;
@@ -1910,13 +2001,11 @@ var BaseTransactionRequest = class {
1910
2001
  * assetId, if one it was not added yet.
1911
2002
  *
1912
2003
  * @param coin - Coin resource.
1913
- * @param predicate - Predicate bytes.
1914
- * @param predicateData - Predicate data bytes.
1915
2004
  */
1916
- addCoinInput(coin, predicate) {
2005
+ addCoinInput(coin) {
1917
2006
  const { assetId, owner, amount } = coin;
1918
2007
  let witnessIndex;
1919
- if (predicate) {
2008
+ if (coin.predicate) {
1920
2009
  witnessIndex = 0;
1921
2010
  } else {
1922
2011
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1931,8 +2020,7 @@ var BaseTransactionRequest = class {
1931
2020
  amount,
1932
2021
  assetId,
1933
2022
  txPointer: "0x00000000000000000000000000000000",
1934
- witnessIndex,
1935
- predicate: predicate?.bytes
2023
+ witnessIndex
1936
2024
  };
1937
2025
  this.pushInput(input);
1938
2026
  this.addChangeOutput(owner, assetId);
@@ -1942,12 +2030,11 @@ var BaseTransactionRequest = class {
1942
2030
  * asset against the message
1943
2031
  *
1944
2032
  * @param message - Message resource.
1945
- * @param predicate - Predicate bytes.
1946
2033
  */
1947
- addMessageInput(message, predicate) {
2034
+ addMessageInput(message) {
1948
2035
  const { recipient, sender, amount, assetId } = message;
1949
2036
  let witnessIndex;
1950
- if (predicate) {
2037
+ if (message.predicate) {
1951
2038
  witnessIndex = 0;
1952
2039
  } else {
1953
2040
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1961,8 +2048,7 @@ var BaseTransactionRequest = class {
1961
2048
  sender: sender.toB256(),
1962
2049
  recipient: recipient.toB256(),
1963
2050
  amount,
1964
- witnessIndex,
1965
- predicate: predicate?.bytes
2051
+ witnessIndex
1966
2052
  };
1967
2053
  this.pushInput(input);
1968
2054
  this.addChangeOutput(recipient, assetId);
@@ -1993,32 +2079,6 @@ var BaseTransactionRequest = class {
1993
2079
  resources.forEach((resource) => this.addResource(resource));
1994
2080
  return this;
1995
2081
  }
1996
- /**
1997
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1998
- * outputs from the related assetIds.
1999
- *
2000
- * @param resources - The resources to add.
2001
- * @returns This transaction.
2002
- */
2003
- addPredicateResource(resource, predicate) {
2004
- if (isCoin(resource)) {
2005
- this.addCoinInput(resource, predicate);
2006
- } else {
2007
- this.addMessageInput(resource, predicate);
2008
- }
2009
- return this;
2010
- }
2011
- /**
2012
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2013
- * from the related assetIds.
2014
- *
2015
- * @param resources - The resources to add.
2016
- * @returns This transaction.
2017
- */
2018
- addPredicateResources(resources, predicate) {
2019
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2020
- return this;
2021
- }
2022
2082
  /**
2023
2083
  * Adds a coin output to the transaction.
2024
2084
  *
@@ -2098,7 +2158,7 @@ var BaseTransactionRequest = class {
2098
2158
  }
2099
2159
  calculateMaxGas(chainInfo, minGas) {
2100
2160
  const { consensusParameters } = chainInfo;
2101
- const { gasPerByte } = consensusParameters;
2161
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2102
2162
  const witnessesLength = this.toTransaction().witnesses.reduce(
2103
2163
  (acc, wit) => acc + wit.dataLength,
2104
2164
  0
@@ -2107,7 +2167,8 @@ var BaseTransactionRequest = class {
2107
2167
  gasPerByte,
2108
2168
  minGas,
2109
2169
  witnessesLength,
2110
- witnessLimit: this.witnessLimit
2170
+ witnessLimit: this.witnessLimit,
2171
+ maxGasPerTx
2111
2172
  });
2112
2173
  }
2113
2174
  /**
@@ -2126,17 +2187,20 @@ var BaseTransactionRequest = class {
2126
2187
  });
2127
2188
  const updateAssetInput = (assetId, quantity) => {
2128
2189
  const assetInput = findAssetInput(assetId);
2190
+ let usedQuantity = quantity;
2191
+ if (assetId === baseAssetId) {
2192
+ usedQuantity = bn7("1000000000000000000");
2193
+ }
2129
2194
  if (assetInput && "assetId" in assetInput) {
2130
2195
  assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2131
- assetInput.amount = quantity;
2196
+ assetInput.amount = usedQuantity;
2132
2197
  } else {
2133
2198
  this.addResources([
2134
2199
  {
2135
2200
  id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2136
- amount: quantity,
2201
+ amount: usedQuantity,
2137
2202
  assetId,
2138
2203
  owner: resourcesOwner || Address.fromRandom(),
2139
- maturity: 0,
2140
2204
  blockCreated: bn7(1),
2141
2205
  txCreatedIdx: bn7(1)
2142
2206
  }
@@ -2168,7 +2232,7 @@ var BaseTransactionRequest = class {
2168
2232
  toJSON() {
2169
2233
  return normalizeJSON(this);
2170
2234
  }
2171
- updatePredicateInputs(inputs) {
2235
+ updatePredicateGasUsed(inputs) {
2172
2236
  this.inputs.forEach((i) => {
2173
2237
  let correspondingInput;
2174
2238
  switch (i.type) {
@@ -2190,6 +2254,15 @@ var BaseTransactionRequest = class {
2190
2254
  }
2191
2255
  });
2192
2256
  }
2257
+ shiftPredicateData() {
2258
+ this.inputs.forEach((input) => {
2259
+ if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
2260
+ input.predicateData = input.padPredicateData(
2261
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2262
+ );
2263
+ }
2264
+ });
2265
+ }
2193
2266
  };
2194
2267
 
2195
2268
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2331,9 +2404,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2331
2404
  return {
2332
2405
  type: TransactionType3.Create,
2333
2406
  ...baseTransaction,
2334
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2335
2407
  bytecodeWitnessIndex,
2336
- storageSlotsCount: storageSlots.length,
2408
+ storageSlotsCount: bn9(storageSlots.length),
2337
2409
  salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
2338
2410
  storageSlots
2339
2411
  };
@@ -2456,8 +2528,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2456
2528
  type: TransactionType4.Script,
2457
2529
  scriptGasLimit: this.gasLimit,
2458
2530
  ...super.getBaseTransaction(),
2459
- scriptLength: script.length,
2460
- scriptDataLength: scriptData.length,
2531
+ scriptLength: bn10(script.length),
2532
+ scriptDataLength: bn10(scriptData.length),
2461
2533
  receiptsRoot: ZeroBytes327,
2462
2534
  script: hexlify10(script),
2463
2535
  scriptData: hexlify10(scriptData)
@@ -2521,7 +2593,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2521
2593
  }
2522
2594
  calculateMaxGas(chainInfo, minGas) {
2523
2595
  const { consensusParameters } = chainInfo;
2524
- const { gasPerByte } = consensusParameters;
2596
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2525
2597
  const witnessesLength = this.toTransaction().witnesses.reduce(
2526
2598
  (acc, wit) => acc + wit.dataLength,
2527
2599
  0
@@ -2531,7 +2603,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2531
2603
  minGas,
2532
2604
  witnessesLength,
2533
2605
  witnessLimit: this.witnessLimit,
2534
- gasLimit: this.gasLimit
2606
+ gasLimit: this.gasLimit,
2607
+ maxGasPerTx
2535
2608
  });
2536
2609
  }
2537
2610
  /**
@@ -2588,7 +2661,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2588
2661
 
2589
2662
  // src/providers/transaction-request/utils.ts
2590
2663
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2591
- import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2664
+ import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2592
2665
  var transactionRequestify = (obj) => {
2593
2666
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2594
2667
  return obj;
@@ -2606,14 +2679,31 @@ var transactionRequestify = (obj) => {
2606
2679
  }
2607
2680
  }
2608
2681
  };
2682
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2683
+ (acc, input) => {
2684
+ if (input.type === InputType5.Coin && input.owner === owner) {
2685
+ acc.utxos.push(input.id);
2686
+ }
2687
+ if (input.type === InputType5.Message && input.recipient === owner) {
2688
+ acc.messages.push(input.nonce);
2689
+ }
2690
+ return acc;
2691
+ },
2692
+ {
2693
+ utxos: [],
2694
+ messages: []
2695
+ }
2696
+ );
2609
2697
 
2610
2698
  // src/providers/transaction-response/transaction-response.ts
2611
2699
  import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2612
- import { bn as bn14 } from "@fuel-ts/math";
2700
+ import { bn as bn15 } from "@fuel-ts/math";
2613
2701
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2614
2702
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2615
2703
 
2616
2704
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2705
+ import { bn as bn14 } from "@fuel-ts/math";
2706
+ import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2617
2707
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2618
2708
 
2619
2709
  // src/providers/transaction-summary/calculate-transaction-fee.ts
@@ -2622,9 +2712,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
2622
2712
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2623
2713
  var calculateTransactionFee = (params) => {
2624
2714
  const {
2625
- gasUsed,
2715
+ gasPrice,
2626
2716
  rawPayload,
2627
- consensusParameters: { gasCosts, feeParams }
2717
+ tip,
2718
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2628
2719
  } = params;
2629
2720
  const gasPerByte = bn11(feeParams.gasPerByte);
2630
2721
  const gasPriceFactor = bn11(feeParams.gasPriceFactor);
@@ -2634,8 +2725,7 @@ var calculateTransactionFee = (params) => {
2634
2725
  return {
2635
2726
  fee: bn11(0),
2636
2727
  minFee: bn11(0),
2637
- maxFee: bn11(0),
2638
- feeFromGasUsed: bn11(0)
2728
+ maxFee: bn11(0)
2639
2729
  };
2640
2730
  }
2641
2731
  const { type, witnesses, inputs, policies } = transaction;
@@ -2667,7 +2757,6 @@ var calculateTransactionFee = (params) => {
2667
2757
  metadataGas,
2668
2758
  txBytesSize: transactionBytes.length
2669
2759
  });
2670
- const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2671
2760
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2672
2761
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2673
2762
  const maxGas = getMaxGas({
@@ -2675,17 +2764,25 @@ var calculateTransactionFee = (params) => {
2675
2764
  minGas,
2676
2765
  witnessesLength,
2677
2766
  gasLimit,
2678
- witnessLimit
2767
+ witnessLimit,
2768
+ maxGasPerTx
2769
+ });
2770
+ const minFee = calculateGasFee({
2771
+ gasPrice,
2772
+ gas: minGas,
2773
+ priceFactor: gasPriceFactor,
2774
+ tip
2775
+ });
2776
+ const maxFee = calculateGasFee({
2777
+ gasPrice,
2778
+ gas: maxGas,
2779
+ priceFactor: gasPriceFactor,
2780
+ tip
2679
2781
  });
2680
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2681
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2682
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2683
- const fee = minFee.add(feeFromGasUsed);
2684
2782
  return {
2685
- fee,
2686
2783
  minFee,
2687
2784
  maxFee,
2688
- feeFromGasUsed
2785
+ fee: maxFee
2689
2786
  };
2690
2787
  };
2691
2788
 
@@ -2741,7 +2838,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2741
2838
 
2742
2839
  // src/providers/transaction-summary/input.ts
2743
2840
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2744
- import { InputType as InputType5 } from "@fuel-ts/transactions";
2841
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2745
2842
  function getInputsByTypes(inputs, types) {
2746
2843
  return inputs.filter((i) => types.includes(i.type));
2747
2844
  }
@@ -2749,16 +2846,16 @@ function getInputsByType(inputs, type) {
2749
2846
  return inputs.filter((i) => i.type === type);
2750
2847
  }
2751
2848
  function getInputsCoin(inputs) {
2752
- return getInputsByType(inputs, InputType5.Coin);
2849
+ return getInputsByType(inputs, InputType6.Coin);
2753
2850
  }
2754
2851
  function getInputsMessage(inputs) {
2755
- return getInputsByType(inputs, InputType5.Message);
2852
+ return getInputsByType(inputs, InputType6.Message);
2756
2853
  }
2757
2854
  function getInputsCoinAndMessage(inputs) {
2758
- return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2855
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2759
2856
  }
2760
2857
  function getInputsContract(inputs) {
2761
- return getInputsByType(inputs, InputType5.Contract);
2858
+ return getInputsByType(inputs, InputType6.Contract);
2762
2859
  }
2763
2860
  function getInputFromAssetId(inputs, assetId) {
2764
2861
  const coinInputs = getInputsCoin(inputs);
@@ -2777,7 +2874,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2777
2874
  if (!contractInput) {
2778
2875
  return void 0;
2779
2876
  }
2780
- if (contractInput.type !== InputType5.Contract) {
2877
+ if (contractInput.type !== InputType6.Contract) {
2781
2878
  throw new FuelError9(
2782
2879
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2783
2880
  `Contract input should be of type 'contract'.`
@@ -2786,10 +2883,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2786
2883
  return contractInput;
2787
2884
  }
2788
2885
  function getInputAccountAddress(input) {
2789
- if (input.type === InputType5.Coin) {
2886
+ if (input.type === InputType6.Coin) {
2790
2887
  return input.owner.toString();
2791
2888
  }
2792
- if (input.type === InputType5.Message) {
2889
+ if (input.type === InputType6.Message) {
2793
2890
  return input.recipient.toString();
2794
2891
  }
2795
2892
  return "";
@@ -3299,7 +3396,9 @@ function assembleTransactionSummary(params) {
3299
3396
  gqlTransactionStatus,
3300
3397
  abiMap = {},
3301
3398
  maxInputs,
3302
- gasCosts
3399
+ gasCosts,
3400
+ maxGasPerTx,
3401
+ gasPrice
3303
3402
  } = params;
3304
3403
  const gasUsed = getGasUsedFromReceipts(receipts);
3305
3404
  const rawPayload = hexlify11(transactionBytes);
@@ -3313,11 +3412,14 @@ function assembleTransactionSummary(params) {
3313
3412
  maxInputs
3314
3413
  });
3315
3414
  const typeName = getTransactionTypeName(transaction.type);
3415
+ const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3316
3416
  const { fee } = calculateTransactionFee({
3317
- gasUsed,
3417
+ gasPrice,
3318
3418
  rawPayload,
3419
+ tip,
3319
3420
  consensusParameters: {
3320
3421
  gasCosts,
3422
+ maxGasPerTx,
3321
3423
  feeParams: {
3322
3424
  gasPerByte,
3323
3425
  gasPriceFactor
@@ -3377,7 +3479,7 @@ var TransactionResponse = class {
3377
3479
  /** Current provider */
3378
3480
  provider;
3379
3481
  /** Gas used on the transaction */
3380
- gasUsed = bn14(0);
3482
+ gasUsed = bn15(0);
3381
3483
  /** The graphql Transaction with receipts object. */
3382
3484
  gqlTransaction;
3383
3485
  abis;
@@ -3455,8 +3557,13 @@ var TransactionResponse = class {
3455
3557
  const decodedTransaction = this.decodeTransaction(
3456
3558
  transaction
3457
3559
  );
3458
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3459
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3560
+ let txReceipts = [];
3561
+ if (transaction?.status && "receipts" in transaction.status) {
3562
+ txReceipts = transaction.status.receipts;
3563
+ }
3564
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3565
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3566
+ const gasPrice = await this.provider.getLatestGasPrice();
3460
3567
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3461
3568
  const transactionSummary = assembleTransactionSummary({
3462
3569
  id: this.id,
@@ -3468,7 +3575,9 @@ var TransactionResponse = class {
3468
3575
  gasPriceFactor,
3469
3576
  abiMap: contractsAbiMap,
3470
3577
  maxInputs,
3471
- gasCosts
3578
+ gasCosts,
3579
+ maxGasPerTx,
3580
+ gasPrice
3472
3581
  });
3473
3582
  return transactionSummary;
3474
3583
  }
@@ -3594,30 +3703,30 @@ var processGqlChain = (chain) => {
3594
3703
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3595
3704
  return {
3596
3705
  name,
3597
- baseChainHeight: bn15(daHeight),
3706
+ baseChainHeight: bn16(daHeight),
3598
3707
  consensusParameters: {
3599
- contractMaxSize: bn15(contractParams.contractMaxSize),
3600
- maxInputs: bn15(txParams.maxInputs),
3601
- maxOutputs: bn15(txParams.maxOutputs),
3602
- maxWitnesses: bn15(txParams.maxWitnesses),
3603
- maxGasPerTx: bn15(txParams.maxGasPerTx),
3604
- maxScriptLength: bn15(scriptParams.maxScriptLength),
3605
- maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
3606
- maxStorageSlots: bn15(contractParams.maxStorageSlots),
3607
- maxPredicateLength: bn15(predicateParams.maxPredicateLength),
3608
- maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
3609
- maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
3610
- gasPriceFactor: bn15(feeParams.gasPriceFactor),
3611
- gasPerByte: bn15(feeParams.gasPerByte),
3612
- maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3613
- chainId: bn15(consensusParameters.chainId),
3708
+ contractMaxSize: bn16(contractParams.contractMaxSize),
3709
+ maxInputs: bn16(txParams.maxInputs),
3710
+ maxOutputs: bn16(txParams.maxOutputs),
3711
+ maxWitnesses: bn16(txParams.maxWitnesses),
3712
+ maxGasPerTx: bn16(txParams.maxGasPerTx),
3713
+ maxScriptLength: bn16(scriptParams.maxScriptLength),
3714
+ maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
3715
+ maxStorageSlots: bn16(contractParams.maxStorageSlots),
3716
+ maxPredicateLength: bn16(predicateParams.maxPredicateLength),
3717
+ maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
3718
+ maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
3719
+ gasPriceFactor: bn16(feeParams.gasPriceFactor),
3720
+ gasPerByte: bn16(feeParams.gasPerByte),
3721
+ maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
3722
+ chainId: bn16(consensusParameters.chainId),
3614
3723
  baseAssetId: consensusParameters.baseAssetId,
3615
3724
  gasCosts
3616
3725
  },
3617
3726
  gasCosts,
3618
3727
  latestBlock: {
3619
3728
  id: latestBlock.id,
3620
- height: bn15(latestBlock.header.height),
3729
+ height: bn16(latestBlock.height),
3621
3730
  time: latestBlock.header.time,
3622
3731
  transactions: latestBlock.transactions.map((i) => ({
3623
3732
  id: i.id
@@ -3711,10 +3820,8 @@ var _Provider = class {
3711
3820
  * Returns some helpful parameters related to gas fees.
3712
3821
  */
3713
3822
  getGasConfig() {
3714
- const { minGasPrice } = this.getNode();
3715
3823
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3716
3824
  return {
3717
- minGasPrice,
3718
3825
  maxGasPerTx,
3719
3826
  maxGasPerPredicate,
3720
3827
  gasPriceFactor,
@@ -3790,6 +3897,21 @@ var _Provider = class {
3790
3897
  } = await this.operations.getVersion();
3791
3898
  return nodeVersion;
3792
3899
  }
3900
+ /**
3901
+ * @hidden
3902
+ *
3903
+ * Returns the network configuration of the connected Fuel node.
3904
+ *
3905
+ * @returns A promise that resolves to the network configuration object
3906
+ */
3907
+ async getNetwork() {
3908
+ const {
3909
+ name,
3910
+ consensusParameters: { chainId }
3911
+ } = await this.getChain();
3912
+ const network = new Network(name, chainId.toNumber());
3913
+ return Promise.resolve(network);
3914
+ }
3793
3915
  /**
3794
3916
  * Returns the block number.
3795
3917
  *
@@ -3797,7 +3919,7 @@ var _Provider = class {
3797
3919
  */
3798
3920
  async getBlockNumber() {
3799
3921
  const { chain } = await this.operations.getChain();
3800
- return bn15(chain.latestBlock.header.height, 10);
3922
+ return bn16(chain.latestBlock.height, 10);
3801
3923
  }
3802
3924
  /**
3803
3925
  * Returns the chain information.
@@ -3807,13 +3929,11 @@ var _Provider = class {
3807
3929
  async fetchNode() {
3808
3930
  const { nodeInfo } = await this.operations.getNodeInfo();
3809
3931
  const processedNodeInfo = {
3810
- maxDepth: bn15(nodeInfo.maxDepth),
3811
- maxTx: bn15(nodeInfo.maxTx),
3812
- minGasPrice: bn15(nodeInfo.minGasPrice),
3932
+ maxDepth: bn16(nodeInfo.maxDepth),
3933
+ maxTx: bn16(nodeInfo.maxTx),
3813
3934
  nodeVersion: nodeInfo.nodeVersion,
3814
3935
  utxoValidation: nodeInfo.utxoValidation,
3815
- vmBacktrace: nodeInfo.vmBacktrace,
3816
- peers: nodeInfo.peers
3936
+ vmBacktrace: nodeInfo.vmBacktrace
3817
3937
  };
3818
3938
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3819
3939
  return processedNodeInfo;
@@ -3910,14 +4030,13 @@ var _Provider = class {
3910
4030
  return this.estimateTxDependencies(transactionRequest);
3911
4031
  }
3912
4032
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3913
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3914
- encodedTransaction,
4033
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4034
+ encodedTransactions: encodedTransaction,
3915
4035
  utxoValidation: utxoValidation || false
3916
4036
  });
3917
- const receipts = gqlReceipts.map(processGqlReceipt);
3918
- return {
3919
- receipts
3920
- };
4037
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4038
+ const receipts = rawReceipts.map(processGqlReceipt);
4039
+ return { receipts, dryrunStatus: status };
3921
4040
  }
3922
4041
  /**
3923
4042
  * Verifies whether enough gas is available to complete transaction.
@@ -3943,7 +4062,7 @@ var _Provider = class {
3943
4062
  } = response;
3944
4063
  if (inputs) {
3945
4064
  inputs.forEach((input, index) => {
3946
- if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
4065
+ if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
3947
4066
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3948
4067
  }
3949
4068
  });
@@ -3956,9 +4075,6 @@ var _Provider = class {
3956
4075
  * If there are missing variable outputs,
3957
4076
  * `addVariableOutputs` is called on the transaction.
3958
4077
  *
3959
- * @privateRemarks
3960
- * TODO: Investigate support for missing contract IDs
3961
- * TODO: Add support for missing output messages
3962
4078
  *
3963
4079
  * @param transactionRequest - The transaction request object.
3964
4080
  * @returns A promise.
@@ -3971,16 +4087,19 @@ var _Provider = class {
3971
4087
  missingContractIds: []
3972
4088
  };
3973
4089
  }
3974
- await this.estimatePredicates(transactionRequest);
3975
4090
  let receipts = [];
3976
4091
  const missingContractIds = [];
3977
4092
  let outputVariables = 0;
4093
+ let dryrunStatus;
3978
4094
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3979
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3980
- encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
4095
+ const {
4096
+ dryRun: [{ receipts: rawReceipts, status }]
4097
+ } = await this.operations.dryRun({
4098
+ encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
3981
4099
  utxoValidation: false
3982
4100
  });
3983
- receipts = gqlReceipts.map(processGqlReceipt);
4101
+ receipts = rawReceipts.map(processGqlReceipt);
4102
+ dryrunStatus = status;
3984
4103
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3985
4104
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3986
4105
  if (hasMissingOutputs) {
@@ -3990,6 +4109,10 @@ var _Provider = class {
3990
4109
  transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
3991
4110
  missingContractIds.push(contractId);
3992
4111
  });
4112
+ const { maxFee } = await this.estimateTxGasAndFee({
4113
+ transactionRequest
4114
+ });
4115
+ transactionRequest.maxFee = maxFee;
3993
4116
  } else {
3994
4117
  break;
3995
4118
  }
@@ -3997,37 +4120,136 @@ var _Provider = class {
3997
4120
  return {
3998
4121
  receipts,
3999
4122
  outputVariables,
4000
- missingContractIds
4123
+ missingContractIds,
4124
+ dryrunStatus
4001
4125
  };
4002
4126
  }
4127
+ /**
4128
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4129
+ *
4130
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4131
+ * further modifications are identified. The method iteratively updates these transactions
4132
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4133
+ *
4134
+ * @param transactionRequests - Array of transaction request objects.
4135
+ * @returns A promise that resolves to an array of results for each transaction.
4136
+ */
4137
+ async estimateMultipleTxDependencies(transactionRequests) {
4138
+ const results = transactionRequests.map(() => ({
4139
+ receipts: [],
4140
+ outputVariables: 0,
4141
+ missingContractIds: [],
4142
+ dryrunStatus: void 0
4143
+ }));
4144
+ const allRequests = clone3(transactionRequests);
4145
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4146
+ allRequests.forEach((req, index) => {
4147
+ if (req.type === TransactionType8.Script) {
4148
+ serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
4149
+ }
4150
+ });
4151
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4152
+ let attempt = 0;
4153
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4154
+ const encodedTransactions = transactionsToProcess.map(
4155
+ (index) => serializedTransactionsMap.get(index)
4156
+ );
4157
+ const dryRunResults = await this.operations.dryRun({
4158
+ encodedTransactions,
4159
+ utxoValidation: false
4160
+ });
4161
+ const nextRoundTransactions = [];
4162
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4163
+ const requestIdx = transactionsToProcess[i];
4164
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4165
+ const result = results[requestIdx];
4166
+ result.receipts = rawReceipts.map(processGqlReceipt);
4167
+ result.dryrunStatus = status;
4168
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4169
+ result.receipts
4170
+ );
4171
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4172
+ const request = allRequests[requestIdx];
4173
+ if (hasMissingOutputs && request?.type === TransactionType8.Script) {
4174
+ result.outputVariables += missingOutputVariables.length;
4175
+ request.addVariableOutputs(missingOutputVariables.length);
4176
+ missingOutputContractIds.forEach(({ contractId }) => {
4177
+ request.addContractInputAndOutput(Address2.fromString(contractId));
4178
+ result.missingContractIds.push(contractId);
4179
+ });
4180
+ const { maxFee } = await this.estimateTxGasAndFee({
4181
+ transactionRequest: request
4182
+ });
4183
+ request.maxFee = maxFee;
4184
+ serializedTransactionsMap.set(requestIdx, hexlify12(request.toTransactionBytes()));
4185
+ nextRoundTransactions.push(requestIdx);
4186
+ }
4187
+ }
4188
+ transactionsToProcess = nextRoundTransactions;
4189
+ attempt += 1;
4190
+ }
4191
+ return results;
4192
+ }
4193
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4194
+ if (estimateTxDependencies) {
4195
+ return this.estimateMultipleTxDependencies(transactionRequests);
4196
+ }
4197
+ const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
4198
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4199
+ encodedTransactions,
4200
+ utxoValidation: utxoValidation || false
4201
+ });
4202
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4203
+ const receipts = rawReceipts.map(processGqlReceipt);
4204
+ return { receipts, dryrunStatus: status };
4205
+ });
4206
+ return results;
4207
+ }
4003
4208
  /**
4004
4209
  * Estimates the transaction gas and fee based on the provided transaction request.
4005
4210
  * @param transactionRequest - The transaction request object.
4006
4211
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4007
4212
  */
4008
- estimateTxGasAndFee(params) {
4213
+ async estimateTxGasAndFee(params) {
4009
4214
  const { transactionRequest } = params;
4010
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4215
+ let { gasPrice } = params;
4011
4216
  const chainInfo = this.getChain();
4012
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4013
- transactionRequest.gasPrice = gasPrice;
4217
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4014
4218
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4015
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4219
+ if (!gasPrice) {
4220
+ gasPrice = await this.estimateGasPrice(10);
4221
+ }
4222
+ const minFee = calculateGasFee({
4223
+ gasPrice: bn16(gasPrice),
4224
+ gas: minGas,
4225
+ priceFactor: gasPriceFactor,
4226
+ tip: transactionRequest.tip
4227
+ }).add(1);
4228
+ let gasLimit = bn16(0);
4016
4229
  if (transactionRequest.type === TransactionType8.Script) {
4230
+ gasLimit = transactionRequest.gasLimit;
4017
4231
  if (transactionRequest.gasLimit.eq(0)) {
4018
4232
  transactionRequest.gasLimit = minGas;
4019
4233
  transactionRequest.gasLimit = maxGasPerTx.sub(
4020
4234
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4021
4235
  );
4236
+ gasLimit = transactionRequest.gasLimit;
4022
4237
  }
4023
4238
  }
4024
4239
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4025
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4240
+ const maxFee = calculateGasFee({
4241
+ gasPrice: bn16(gasPrice),
4242
+ gas: maxGas,
4243
+ priceFactor: gasPriceFactor,
4244
+ tip: transactionRequest.tip
4245
+ }).add(1);
4026
4246
  return {
4027
4247
  minGas,
4028
4248
  minFee,
4029
4249
  maxGas,
4030
- maxFee
4250
+ maxFee,
4251
+ gasPrice,
4252
+ gasLimit
4031
4253
  };
4032
4254
  }
4033
4255
  /**
@@ -4045,15 +4267,17 @@ var _Provider = class {
4045
4267
  if (estimateTxDependencies) {
4046
4268
  return this.estimateTxDependencies(transactionRequest);
4047
4269
  }
4048
- const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
4049
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4050
- encodedTransaction,
4270
+ const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
4271
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4272
+ encodedTransactions,
4051
4273
  utxoValidation: true
4052
4274
  });
4053
- const receipts = gqlReceipts.map(processGqlReceipt);
4054
- return {
4055
- receipts
4056
- };
4275
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4276
+ const { id, receipts, status } = dryRunStatus;
4277
+ const processedReceipts = receipts.map(processGqlReceipt);
4278
+ return { id, receipts: processedReceipts, status };
4279
+ });
4280
+ return { receipts: callResult[0].receipts };
4057
4281
  }
4058
4282
  /**
4059
4283
  * Returns a transaction cost to enable user
@@ -4070,78 +4294,80 @@ var _Provider = class {
4070
4294
  * @param tolerance - The tolerance to add on top of the gasUsed.
4071
4295
  * @returns A promise that resolves to the transaction cost object.
4072
4296
  */
4073
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4074
- estimateTxDependencies = true,
4075
- estimatePredicates = true,
4076
- resourcesOwner,
4077
- signatureCallback
4078
- } = {}) {
4297
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4079
4298
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
4080
- const { minGasPrice } = this.getGasConfig();
4081
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
4082
4299
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
4083
4300
  const baseAssetId = this.getBaseAssetId();
4084
4301
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4085
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4302
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4086
4303
  txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4304
+ txRequestClone.maxFee = bn16(0);
4087
4305
  if (isScriptTransaction) {
4088
- txRequestClone.gasLimit = bn15(0);
4306
+ txRequestClone.gasLimit = bn16(0);
4089
4307
  }
4090
- if (estimatePredicates) {
4091
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4092
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4093
- }
4094
- await this.estimatePredicates(txRequestClone);
4308
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4309
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4095
4310
  }
4311
+ const signedRequest = clone3(txRequestClone);
4312
+ let addedSignatures = 0;
4096
4313
  if (signatureCallback && isScriptTransaction) {
4097
- await signatureCallback(txRequestClone);
4314
+ const lengthBefore = signedRequest.witnesses.length;
4315
+ await signatureCallback(signedRequest);
4316
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4098
4317
  }
4099
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4100
- transactionRequest: txRequestClone
4318
+ await this.estimatePredicates(signedRequest);
4319
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4320
+ transactionRequest: signedRequest
4101
4321
  });
4102
4322
  let receipts = [];
4103
4323
  let missingContractIds = [];
4104
4324
  let outputVariables = 0;
4105
- let gasUsed = bn15(0);
4106
- if (isScriptTransaction && estimateTxDependencies) {
4107
- txRequestClone.gasPrice = bn15(0);
4325
+ let gasUsed = bn16(0);
4326
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4327
+ txRequestClone.maxFee = maxFee;
4328
+ if (isScriptTransaction) {
4329
+ txRequestClone.gasLimit = gasLimit;
4330
+ if (signatureCallback) {
4331
+ await signatureCallback(txRequestClone);
4332
+ }
4108
4333
  const result = await this.estimateTxDependencies(txRequestClone);
4109
4334
  receipts = result.receipts;
4110
4335
  outputVariables = result.outputVariables;
4111
4336
  missingContractIds = result.missingContractIds;
4112
4337
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4113
4338
  txRequestClone.gasLimit = gasUsed;
4114
- txRequestClone.gasPrice = setGasPrice;
4115
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4116
- transactionRequest: txRequestClone
4339
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4340
+ transactionRequest: txRequestClone,
4341
+ gasPrice
4117
4342
  }));
4118
4343
  }
4119
4344
  return {
4120
4345
  requiredQuantities: allQuantities,
4121
4346
  receipts,
4122
4347
  gasUsed,
4123
- minGasPrice,
4124
- gasPrice: setGasPrice,
4348
+ gasPrice,
4125
4349
  minGas,
4126
4350
  maxGas,
4127
4351
  minFee,
4128
4352
  maxFee,
4129
- estimatedInputs: txRequestClone.inputs,
4130
4353
  outputVariables,
4131
- missingContractIds
4354
+ missingContractIds,
4355
+ addedSignatures,
4356
+ estimatedPredicates: txRequestClone.inputs
4132
4357
  };
4133
4358
  }
4134
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4359
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4135
4360
  const ownerAddress = Address2.fromAddressOrString(owner);
4136
4361
  const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
4137
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4362
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4363
+ quantitiesToContract
4364
+ });
4138
4365
  transactionRequest.addResources(
4139
4366
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4140
4367
  );
4141
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4142
- transactionRequest,
4143
- forwardingQuantities
4144
- );
4368
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4369
+ quantitiesToContract
4370
+ });
4145
4371
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4146
4372
  return {
4147
4373
  resources,
@@ -4163,11 +4389,10 @@ var _Provider = class {
4163
4389
  return coins.map((coin) => ({
4164
4390
  id: coin.utxoId,
4165
4391
  assetId: coin.assetId,
4166
- amount: bn15(coin.amount),
4392
+ amount: bn16(coin.amount),
4167
4393
  owner: Address2.fromAddressOrString(coin.owner),
4168
- maturity: bn15(coin.maturity).toNumber(),
4169
- blockCreated: bn15(coin.blockCreated),
4170
- txCreatedIdx: bn15(coin.txCreatedIdx)
4394
+ blockCreated: bn16(coin.blockCreated),
4395
+ txCreatedIdx: bn16(coin.txCreatedIdx)
4171
4396
  }));
4172
4397
  }
4173
4398
  /**
@@ -4204,9 +4429,9 @@ var _Provider = class {
4204
4429
  switch (coin.__typename) {
4205
4430
  case "MessageCoin":
4206
4431
  return {
4207
- amount: bn15(coin.amount),
4432
+ amount: bn16(coin.amount),
4208
4433
  assetId: coin.assetId,
4209
- daHeight: bn15(coin.daHeight),
4434
+ daHeight: bn16(coin.daHeight),
4210
4435
  sender: Address2.fromAddressOrString(coin.sender),
4211
4436
  recipient: Address2.fromAddressOrString(coin.recipient),
4212
4437
  nonce: coin.nonce
@@ -4214,12 +4439,11 @@ var _Provider = class {
4214
4439
  case "Coin":
4215
4440
  return {
4216
4441
  id: coin.utxoId,
4217
- amount: bn15(coin.amount),
4442
+ amount: bn16(coin.amount),
4218
4443
  assetId: coin.assetId,
4219
4444
  owner: Address2.fromAddressOrString(coin.owner),
4220
- maturity: bn15(coin.maturity).toNumber(),
4221
- blockCreated: bn15(coin.blockCreated),
4222
- txCreatedIdx: bn15(coin.txCreatedIdx)
4445
+ blockCreated: bn16(coin.blockCreated),
4446
+ txCreatedIdx: bn16(coin.txCreatedIdx)
4223
4447
  };
4224
4448
  default:
4225
4449
  return null;
@@ -4236,13 +4460,13 @@ var _Provider = class {
4236
4460
  async getBlock(idOrHeight) {
4237
4461
  let variables;
4238
4462
  if (typeof idOrHeight === "number") {
4239
- variables = { height: bn15(idOrHeight).toString(10) };
4463
+ variables = { height: bn16(idOrHeight).toString(10) };
4240
4464
  } else if (idOrHeight === "latest") {
4241
4465
  variables = { height: (await this.getBlockNumber()).toString(10) };
4242
4466
  } else if (idOrHeight.length === 66) {
4243
4467
  variables = { blockId: idOrHeight };
4244
4468
  } else {
4245
- variables = { blockId: bn15(idOrHeight).toString(10) };
4469
+ variables = { blockId: bn16(idOrHeight).toString(10) };
4246
4470
  }
4247
4471
  const { block } = await this.operations.getBlock(variables);
4248
4472
  if (!block) {
@@ -4250,7 +4474,7 @@ var _Provider = class {
4250
4474
  }
4251
4475
  return {
4252
4476
  id: block.id,
4253
- height: bn15(block.header.height),
4477
+ height: bn16(block.height),
4254
4478
  time: block.header.time,
4255
4479
  transactionIds: block.transactions.map((tx) => tx.id)
4256
4480
  };
@@ -4265,7 +4489,7 @@ var _Provider = class {
4265
4489
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4266
4490
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4267
4491
  id: block.id,
4268
- height: bn15(block.header.height),
4492
+ height: bn16(block.height),
4269
4493
  time: block.header.time,
4270
4494
  transactionIds: block.transactions.map((tx) => tx.id)
4271
4495
  }));
@@ -4280,7 +4504,7 @@ var _Provider = class {
4280
4504
  async getBlockWithTransactions(idOrHeight) {
4281
4505
  let variables;
4282
4506
  if (typeof idOrHeight === "number") {
4283
- variables = { blockHeight: bn15(idOrHeight).toString(10) };
4507
+ variables = { blockHeight: bn16(idOrHeight).toString(10) };
4284
4508
  } else if (idOrHeight === "latest") {
4285
4509
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4286
4510
  } else {
@@ -4292,7 +4516,7 @@ var _Provider = class {
4292
4516
  }
4293
4517
  return {
4294
4518
  id: block.id,
4295
- height: bn15(block.header.height, 10),
4519
+ height: bn16(block.height, 10),
4296
4520
  time: block.header.time,
4297
4521
  transactionIds: block.transactions.map((tx) => tx.id),
4298
4522
  transactions: block.transactions.map(
@@ -4341,7 +4565,7 @@ var _Provider = class {
4341
4565
  contract: Address2.fromAddressOrString(contractId).toB256(),
4342
4566
  asset: hexlify12(assetId)
4343
4567
  });
4344
- return bn15(contractBalance.amount, 10);
4568
+ return bn16(contractBalance.amount, 10);
4345
4569
  }
4346
4570
  /**
4347
4571
  * Returns the balance for the given owner for the given asset ID.
@@ -4355,7 +4579,7 @@ var _Provider = class {
4355
4579
  owner: Address2.fromAddressOrString(owner).toB256(),
4356
4580
  assetId: hexlify12(assetId)
4357
4581
  });
4358
- return bn15(balance.amount, 10);
4582
+ return bn16(balance.amount, 10);
4359
4583
  }
4360
4584
  /**
4361
4585
  * Returns balances for the given owner.
@@ -4373,7 +4597,7 @@ var _Provider = class {
4373
4597
  const balances = result.balances.edges.map((edge) => edge.node);
4374
4598
  return balances.map((balance) => ({
4375
4599
  assetId: balance.assetId,
4376
- amount: bn15(balance.amount)
4600
+ amount: bn16(balance.amount)
4377
4601
  }));
4378
4602
  }
4379
4603
  /**
@@ -4395,15 +4619,15 @@ var _Provider = class {
4395
4619
  sender: message.sender,
4396
4620
  recipient: message.recipient,
4397
4621
  nonce: message.nonce,
4398
- amount: bn15(message.amount),
4622
+ amount: bn16(message.amount),
4399
4623
  data: message.data
4400
4624
  }),
4401
4625
  sender: Address2.fromAddressOrString(message.sender),
4402
4626
  recipient: Address2.fromAddressOrString(message.recipient),
4403
4627
  nonce: message.nonce,
4404
- amount: bn15(message.amount),
4628
+ amount: bn16(message.amount),
4405
4629
  data: InputMessageCoder.decodeData(message.data),
4406
- daHeight: bn15(message.daHeight)
4630
+ daHeight: bn16(message.daHeight)
4407
4631
  }));
4408
4632
  }
4409
4633
  /**
@@ -4456,44 +4680,60 @@ var _Provider = class {
4456
4680
  } = result.messageProof;
4457
4681
  return {
4458
4682
  messageProof: {
4459
- proofIndex: bn15(messageProof.proofIndex),
4683
+ proofIndex: bn16(messageProof.proofIndex),
4460
4684
  proofSet: messageProof.proofSet
4461
4685
  },
4462
4686
  blockProof: {
4463
- proofIndex: bn15(blockProof.proofIndex),
4687
+ proofIndex: bn16(blockProof.proofIndex),
4464
4688
  proofSet: blockProof.proofSet
4465
4689
  },
4466
4690
  messageBlockHeader: {
4467
4691
  id: messageBlockHeader.id,
4468
- daHeight: bn15(messageBlockHeader.daHeight),
4469
- transactionsCount: bn15(messageBlockHeader.transactionsCount),
4692
+ daHeight: bn16(messageBlockHeader.daHeight),
4693
+ transactionsCount: bn16(messageBlockHeader.transactionsCount),
4470
4694
  transactionsRoot: messageBlockHeader.transactionsRoot,
4471
- height: bn15(messageBlockHeader.height),
4695
+ height: bn16(messageBlockHeader.height),
4472
4696
  prevRoot: messageBlockHeader.prevRoot,
4473
4697
  time: messageBlockHeader.time,
4474
4698
  applicationHash: messageBlockHeader.applicationHash,
4475
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4476
- messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
4699
+ messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
4700
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4701
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4702
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4703
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4477
4704
  },
4478
4705
  commitBlockHeader: {
4479
4706
  id: commitBlockHeader.id,
4480
- daHeight: bn15(commitBlockHeader.daHeight),
4481
- transactionsCount: bn15(commitBlockHeader.transactionsCount),
4707
+ daHeight: bn16(commitBlockHeader.daHeight),
4708
+ transactionsCount: bn16(commitBlockHeader.transactionsCount),
4482
4709
  transactionsRoot: commitBlockHeader.transactionsRoot,
4483
- height: bn15(commitBlockHeader.height),
4710
+ height: bn16(commitBlockHeader.height),
4484
4711
  prevRoot: commitBlockHeader.prevRoot,
4485
4712
  time: commitBlockHeader.time,
4486
4713
  applicationHash: commitBlockHeader.applicationHash,
4487
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4488
- messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
4714
+ messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
4715
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4716
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4717
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4718
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4489
4719
  },
4490
4720
  sender: Address2.fromAddressOrString(sender),
4491
4721
  recipient: Address2.fromAddressOrString(recipient),
4492
4722
  nonce,
4493
- amount: bn15(amount),
4723
+ amount: bn16(amount),
4494
4724
  data
4495
4725
  };
4496
4726
  }
4727
+ async getLatestGasPrice() {
4728
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4729
+ return bn16(latestGasPrice.gasPrice);
4730
+ }
4731
+ async estimateGasPrice(blockHorizon) {
4732
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4733
+ blockHorizon: String(blockHorizon)
4734
+ });
4735
+ return bn16(estimateGasPrice.gasPrice);
4736
+ }
4497
4737
  /**
4498
4738
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4499
4739
  *
@@ -4513,10 +4753,10 @@ var _Provider = class {
4513
4753
  */
4514
4754
  async produceBlocks(amount, startTime) {
4515
4755
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4516
- blocksToProduce: bn15(amount).toString(10),
4756
+ blocksToProduce: bn16(amount).toString(10),
4517
4757
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4518
4758
  });
4519
- return bn15(latestBlockHeight);
4759
+ return bn16(latestBlockHeight);
4520
4760
  }
4521
4761
  // eslint-disable-next-line @typescript-eslint/require-await
4522
4762
  async getTransactionResponse(transactionId) {
@@ -4530,7 +4770,7 @@ cacheInputs_fn = function(inputs) {
4530
4770
  return;
4531
4771
  }
4532
4772
  inputs.forEach((input) => {
4533
- if (input.type === InputType6.Coin) {
4773
+ if (input.type === InputType7.Coin) {
4534
4774
  this.cache?.set(input.id);
4535
4775
  }
4536
4776
  });
@@ -4540,7 +4780,7 @@ __publicField(Provider, "nodeInfoCache", {});
4540
4780
 
4541
4781
  // src/providers/transaction-summary/get-transaction-summary.ts
4542
4782
  import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4543
- import { bn as bn16 } from "@fuel-ts/math";
4783
+ import { bn as bn17 } from "@fuel-ts/math";
4544
4784
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4545
4785
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4546
4786
  async function getTransactionSummary(params) {
@@ -4558,21 +4798,28 @@ async function getTransactionSummary(params) {
4558
4798
  arrayify12(gqlTransaction.rawPayload),
4559
4799
  0
4560
4800
  );
4561
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4801
+ let txReceipts = [];
4802
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4803
+ txReceipts = gqlTransaction.status.receipts;
4804
+ }
4805
+ const receipts = txReceipts.map(processGqlReceipt);
4562
4806
  const {
4563
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4807
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4564
4808
  } = provider.getChain();
4809
+ const gasPrice = await provider.getLatestGasPrice();
4565
4810
  const transactionInfo = assembleTransactionSummary({
4566
4811
  id: gqlTransaction.id,
4567
4812
  receipts,
4568
4813
  transaction: decodedTransaction,
4569
4814
  transactionBytes: arrayify12(gqlTransaction.rawPayload),
4570
4815
  gqlTransactionStatus: gqlTransaction.status,
4571
- gasPerByte: bn16(gasPerByte),
4572
- gasPriceFactor: bn16(gasPriceFactor),
4816
+ gasPerByte: bn17(gasPerByte),
4817
+ gasPriceFactor: bn17(gasPriceFactor),
4573
4818
  abiMap,
4574
4819
  maxInputs,
4575
- gasCosts
4820
+ gasCosts,
4821
+ maxGasPerTx,
4822
+ gasPrice
4576
4823
  });
4577
4824
  return {
4578
4825
  gqlTransaction,
@@ -4582,10 +4829,11 @@ async function getTransactionSummary(params) {
4582
4829
  async function getTransactionSummaryFromRequest(params) {
4583
4830
  const { provider, transactionRequest, abiMap } = params;
4584
4831
  const { receipts } = await provider.call(transactionRequest);
4585
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4832
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4586
4833
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4587
4834
  const transaction = transactionRequest.toTransaction();
4588
4835
  const transactionBytes = transactionRequest.toTransactionBytes();
4836
+ const gasPrice = await provider.getLatestGasPrice();
4589
4837
  const transactionSummary = assembleTransactionSummary({
4590
4838
  receipts,
4591
4839
  transaction,
@@ -4594,7 +4842,9 @@ async function getTransactionSummaryFromRequest(params) {
4594
4842
  gasPerByte,
4595
4843
  gasPriceFactor,
4596
4844
  maxInputs,
4597
- gasCosts
4845
+ gasCosts,
4846
+ maxGasPerTx,
4847
+ gasPrice
4598
4848
  });
4599
4849
  return transactionSummary;
4600
4850
  }
@@ -4603,13 +4853,18 @@ async function getTransactionsSummaries(params) {
4603
4853
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4604
4854
  const { edges, pageInfo } = transactionsByOwner;
4605
4855
  const {
4606
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4856
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4607
4857
  } = provider.getChain();
4858
+ const gasPrice = await provider.getLatestGasPrice();
4608
4859
  const transactions = edges.map((edge) => {
4609
4860
  const { node: gqlTransaction } = edge;
4610
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4861
+ const { id, rawPayload, status } = gqlTransaction;
4611
4862
  const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
4612
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4863
+ let txReceipts = [];
4864
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4865
+ txReceipts = gqlTransaction.status.receipts;
4866
+ }
4867
+ const receipts = txReceipts.map(processGqlReceipt);
4613
4868
  const transactionSummary = assembleTransactionSummary({
4614
4869
  id,
4615
4870
  receipts,
@@ -4620,7 +4875,9 @@ async function getTransactionsSummaries(params) {
4620
4875
  gasPerByte,
4621
4876
  gasPriceFactor,
4622
4877
  maxInputs,
4623
- gasCosts
4878
+ gasCosts,
4879
+ maxGasPerTx,
4880
+ gasPrice
4624
4881
  });
4625
4882
  const output = {
4626
4883
  gqlTransaction,
@@ -4953,38 +5210,31 @@ var Account = class extends AbstractAccount {
4953
5210
  * @param fee - The estimated transaction fee.
4954
5211
  * @returns A promise that resolves when the resources are added to the transaction.
4955
5212
  */
4956
- async fund(request, coinQuantities, fee) {
5213
+ async fund(request, params) {
5214
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4957
5215
  const baseAssetId = this.provider.getBaseAssetId();
4958
- const updatedQuantities = addAmountToAsset({
4959
- amount: bn17(fee),
5216
+ const txRequest = request;
5217
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5218
+ amount: bn18(fee),
4960
5219
  assetId: baseAssetId,
4961
- coinQuantities
5220
+ coinQuantities: requiredQuantities
4962
5221
  });
4963
5222
  const quantitiesDict = {};
4964
- updatedQuantities.forEach(({ amount, assetId }) => {
5223
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4965
5224
  quantitiesDict[assetId] = {
4966
5225
  required: amount,
4967
- owned: bn17(0)
5226
+ owned: bn18(0)
4968
5227
  };
4969
5228
  });
4970
- const cachedUtxos = [];
4971
- const cachedMessages = [];
4972
- const owner = this.address.toB256();
4973
- request.inputs.forEach((input) => {
5229
+ txRequest.inputs.forEach((input) => {
4974
5230
  const isResource = "amount" in input;
4975
- if (isResource) {
4976
- const isCoin2 = "owner" in input;
4977
- if (isCoin2) {
4978
- const assetId = String(input.assetId);
4979
- if (input.owner === owner && quantitiesDict[assetId]) {
4980
- const amount = bn17(input.amount);
4981
- quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4982
- cachedUtxos.push(input.id);
4983
- }
4984
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4985
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4986
- cachedMessages.push(input.nonce);
4987
- }
5231
+ if (!isResource) {
5232
+ return;
5233
+ }
5234
+ const isCoin2 = "owner" in input;
5235
+ const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
5236
+ if (quantitiesDict[assetId]) {
5237
+ quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
4988
5238
  }
4989
5239
  });
4990
5240
  const missingQuantities = [];
@@ -4998,12 +5248,21 @@ var Account = class extends AbstractAccount {
4998
5248
  });
4999
5249
  const needsToBeFunded = missingQuantities.length;
5000
5250
  if (needsToBeFunded) {
5001
- const resources = await this.getResourcesToSpend(missingQuantities, {
5002
- messages: cachedMessages,
5003
- utxos: cachedUtxos
5004
- });
5005
- request.addResources(resources);
5006
- }
5251
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5252
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5253
+ txRequest.addResources(resources);
5254
+ }
5255
+ txRequest.shiftPredicateData();
5256
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5257
+ const requestToReestimate = clone4(txRequest);
5258
+ if (addedSignatures) {
5259
+ Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
5260
+ }
5261
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5262
+ transactionRequest: requestToReestimate
5263
+ });
5264
+ txRequest.maxFee = maxFee;
5265
+ return txRequest;
5007
5266
  }
5008
5267
  /**
5009
5268
  * A helper that creates a transfer transaction request and returns it.
@@ -5011,29 +5270,25 @@ var Account = class extends AbstractAccount {
5011
5270
  * @param destination - The address of the destination.
5012
5271
  * @param amount - The amount of coins to transfer.
5013
5272
  * @param assetId - The asset ID of the coins to transfer.
5014
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5273
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5015
5274
  * @returns A promise that resolves to the prepared transaction request.
5016
5275
  */
5017
5276
  async createTransfer(destination, amount, assetId, txParams = {}) {
5018
- const { minGasPrice } = this.provider.getGasConfig();
5277
+ const request = new ScriptTransactionRequest(txParams);
5019
5278
  const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5020
- const params = { gasPrice: minGasPrice, ...txParams };
5021
- const request = new ScriptTransactionRequest(params);
5022
5279
  request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
5023
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5280
+ const txCost = await this.provider.getTransactionCost(request, {
5024
5281
  estimateTxDependencies: true,
5025
5282
  resourcesOwner: this
5026
5283
  });
5027
- request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
5028
- request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
5029
- this.validateGas({
5030
- gasUsed,
5031
- gasPrice: request.gasPrice,
5032
- gasLimit: request.gasLimit,
5033
- minGasPrice
5284
+ this.validateGasLimitAndMaxFee({
5285
+ gasUsed: txCost.gasUsed,
5286
+ maxFee: txCost.maxFee,
5287
+ txParams
5034
5288
  });
5035
- await this.fund(request, requiredQuantities, maxFee);
5036
- request.updatePredicateInputs(estimatedInputs);
5289
+ request.gasLimit = txCost.gasUsed;
5290
+ request.maxFee = txCost.maxFee;
5291
+ await this.fund(request, txCost);
5037
5292
  return request;
5038
5293
  }
5039
5294
  /**
@@ -5042,11 +5297,11 @@ var Account = class extends AbstractAccount {
5042
5297
  * @param destination - The address of the destination.
5043
5298
  * @param amount - The amount of coins to transfer.
5044
5299
  * @param assetId - The asset ID of the coins to transfer.
5045
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5300
+ * @param txParams - The transaction parameters (gasLimit, maturity).
5046
5301
  * @returns A promise that resolves to the transaction response.
5047
5302
  */
5048
5303
  async transfer(destination, amount, assetId, txParams = {}) {
5049
- if (bn17(amount).lte(0)) {
5304
+ if (bn18(amount).lte(0)) {
5050
5305
  throw new FuelError15(
5051
5306
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5052
5307
  "Transfer amount must be a positive number."
@@ -5066,39 +5321,37 @@ var Account = class extends AbstractAccount {
5066
5321
  * @returns A promise that resolves to the transaction response.
5067
5322
  */
5068
5323
  async transferToContract(contractId, amount, assetId, txParams = {}) {
5069
- if (bn17(amount).lte(0)) {
5324
+ if (bn18(amount).lte(0)) {
5070
5325
  throw new FuelError15(
5071
5326
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5072
5327
  "Transfer amount must be a positive number."
5073
5328
  );
5074
5329
  }
5075
5330
  const contractAddress = Address3.fromAddressOrString(contractId);
5076
- const { minGasPrice } = this.provider.getGasConfig();
5077
5331
  const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5078
- const params = { gasPrice: minGasPrice, ...txParams };
5079
5332
  const { script, scriptData } = await assembleTransferToContractScript({
5080
5333
  hexlifiedContractId: contractAddress.toB256(),
5081
- amountToTransfer: bn17(amount),
5334
+ amountToTransfer: bn18(amount),
5082
5335
  assetId: assetIdToTransfer
5083
5336
  });
5084
5337
  const request = new ScriptTransactionRequest({
5085
- ...params,
5338
+ ...txParams,
5086
5339
  script,
5087
5340
  scriptData
5088
5341
  });
5089
5342
  request.addContractInputAndOutput(contractAddress);
5090
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5091
- request,
5092
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
5093
- );
5094
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5095
- this.validateGas({
5096
- gasUsed,
5097
- gasPrice: request.gasPrice,
5098
- gasLimit: request.gasLimit,
5099
- minGasPrice
5343
+ const txCost = await this.provider.getTransactionCost(request, {
5344
+ resourcesOwner: this,
5345
+ quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetIdToTransfer) }]
5346
+ });
5347
+ this.validateGasLimitAndMaxFee({
5348
+ gasUsed: txCost.gasUsed,
5349
+ maxFee: txCost.maxFee,
5350
+ txParams
5100
5351
  });
5101
- await this.fund(request, requiredQuantities, maxFee);
5352
+ request.gasLimit = txCost.gasUsed;
5353
+ request.maxFee = txCost.maxFee;
5354
+ await this.fund(request, txCost);
5102
5355
  return this.sendTransaction(request);
5103
5356
  }
5104
5357
  /**
@@ -5110,39 +5363,31 @@ var Account = class extends AbstractAccount {
5110
5363
  * @returns A promise that resolves to the transaction response.
5111
5364
  */
5112
5365
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5113
- const { minGasPrice } = this.provider.getGasConfig();
5114
- const baseAssetId = this.provider.getBaseAssetId();
5115
5366
  const recipientAddress = Address3.fromAddressOrString(recipient);
5116
5367
  const recipientDataArray = arrayify14(
5117
5368
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5118
5369
  );
5119
5370
  const amountDataArray = arrayify14(
5120
- "0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
5371
+ "0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
5121
5372
  );
5122
5373
  const script = new Uint8Array([
5123
5374
  ...arrayify14(withdrawScript.bytes),
5124
5375
  ...recipientDataArray,
5125
5376
  ...amountDataArray
5126
5377
  ]);
5127
- const params = {
5128
- script,
5129
- gasPrice: minGasPrice,
5130
- ...txParams
5131
- };
5378
+ const params = { script, ...txParams };
5379
+ const baseAssetId = this.provider.getBaseAssetId();
5132
5380
  const request = new ScriptTransactionRequest(params);
5133
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
5134
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5135
- request,
5136
- forwardingQuantities
5137
- );
5138
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5139
- this.validateGas({
5140
- gasUsed,
5141
- gasPrice: request.gasPrice,
5142
- gasLimit: request.gasLimit,
5143
- minGasPrice
5381
+ const quantitiesToContract = [{ amount: bn18(amount), assetId: baseAssetId }];
5382
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5383
+ this.validateGasLimitAndMaxFee({
5384
+ gasUsed: txCost.gasUsed,
5385
+ maxFee: txCost.maxFee,
5386
+ txParams
5144
5387
  });
5145
- await this.fund(request, requiredQuantities, maxFee);
5388
+ request.maxFee = txCost.maxFee;
5389
+ request.gasLimit = txCost.gasUsed;
5390
+ await this.fund(request, txCost);
5146
5391
  return this.sendTransaction(request);
5147
5392
  }
5148
5393
  async signMessage(message) {
@@ -5200,22 +5445,21 @@ var Account = class extends AbstractAccount {
5200
5445
  }
5201
5446
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5202
5447
  }
5203
- validateGas({
5448
+ validateGasLimitAndMaxFee({
5449
+ txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
5204
5450
  gasUsed,
5205
- gasPrice,
5206
- gasLimit,
5207
- minGasPrice
5451
+ maxFee
5208
5452
  }) {
5209
- if (minGasPrice.gt(gasPrice)) {
5453
+ if (isDefined(setGasLimit) && gasUsed.gt(setGasLimit)) {
5210
5454
  throw new FuelError15(
5211
- ErrorCode15.GAS_PRICE_TOO_LOW,
5212
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5455
+ ErrorCode15.GAS_LIMIT_TOO_LOW,
5456
+ `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5213
5457
  );
5214
5458
  }
5215
- if (gasUsed.gt(gasLimit)) {
5459
+ if (isDefined(setMaxFee) && maxFee.gt(setMaxFee)) {
5216
5460
  throw new FuelError15(
5217
- ErrorCode15.GAS_LIMIT_TOO_LOW,
5218
- `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
5461
+ ErrorCode15.MAX_FEE_TOO_LOW,
5462
+ `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
5219
5463
  );
5220
5464
  }
5221
5465
  }
@@ -5507,7 +5751,7 @@ var BaseWalletUnlocked = class extends Account {
5507
5751
  * @param transactionRequestLike - The transaction request to send.
5508
5752
  * @returns A promise that resolves to the TransactionResponse object.
5509
5753
  */
5510
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5754
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5511
5755
  const transactionRequest = transactionRequestify(transactionRequestLike);
5512
5756
  if (estimateTxDependencies) {
5513
5757
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5548,7 +5792,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5548
5792
  // src/hdwallet/hdwallet.ts
5549
5793
  import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5550
5794
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5551
- import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5795
+ import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5552
5796
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5553
5797
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5554
5798
 
@@ -8020,7 +8264,7 @@ var HDWallet = class {
8020
8264
  const IR = bytes.slice(32);
8021
8265
  if (privateKey) {
8022
8266
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8023
- const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
8267
+ const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
8024
8268
  return new HDWallet({
8025
8269
  privateKey: ki,
8026
8270
  chainCode: IR,
@@ -8708,7 +8952,7 @@ import {
8708
8952
  } from "@fuel-ts/abi-coder";
8709
8953
  import { Address as Address9 } from "@fuel-ts/address";
8710
8954
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8711
- import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8955
+ import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
8712
8956
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8713
8957
 
8714
8958
  // src/predicate/utils/getPredicateRoot.ts
@@ -8768,36 +9012,22 @@ var Predicate = class extends Account {
8768
9012
  const request = transactionRequestify(transactionRequestLike);
8769
9013
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8770
9014
  request.inputs?.forEach((input) => {
8771
- if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
8772
- input.predicate = this.bytes;
8773
- input.predicateData = this.getPredicateData(policies.length);
9015
+ if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
9016
+ input.predicate = hexlify19(this.bytes);
9017
+ input.predicateData = hexlify19(this.getPredicateData(policies.length));
8774
9018
  }
8775
9019
  });
8776
9020
  return request;
8777
9021
  }
8778
- /**
8779
- * A helper that creates a transfer transaction request and returns it.
8780
- *
8781
- * @param destination - The address of the destination.
8782
- * @param amount - The amount of coins to transfer.
8783
- * @param assetId - The asset ID of the coins to transfer.
8784
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8785
- * @returns A promise that resolves to the prepared transaction request.
8786
- */
8787
- async createTransfer(destination, amount, assetId, txParams = {}) {
8788
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8789
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8790
- return this.populateTransactionPredicateData(request);
8791
- }
8792
9022
  /**
8793
9023
  * Sends a transaction with the populated predicate data.
8794
9024
  *
8795
9025
  * @param transactionRequestLike - The transaction request-like object.
8796
9026
  * @returns A promise that resolves to the transaction response.
8797
9027
  */
8798
- sendTransaction(transactionRequestLike, options) {
8799
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8800
- return super.sendTransaction(transactionRequest, options);
9028
+ sendTransaction(transactionRequestLike) {
9029
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9030
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8801
9031
  }
8802
9032
  /**
8803
9033
  * Simulates a transaction with the populated predicate data.
@@ -8806,8 +9036,8 @@ var Predicate = class extends Account {
8806
9036
  * @returns A promise that resolves to the call result.
8807
9037
  */
8808
9038
  simulateTransaction(transactionRequestLike) {
8809
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8810
- return super.simulateTransaction(transactionRequest);
9039
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9040
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8811
9041
  }
8812
9042
  getPredicateData(policiesLength) {
8813
9043
  if (!this.predicateData.length) {
@@ -8853,6 +9083,25 @@ var Predicate = class extends Account {
8853
9083
  predicateInterface: abiInterface
8854
9084
  };
8855
9085
  }
9086
+ /**
9087
+ * Retrieves resources satisfying the spend query for the account.
9088
+ *
9089
+ * @param quantities - IDs of coins to exclude.
9090
+ * @param excludedIds - IDs of resources to be excluded from the query.
9091
+ * @returns A promise that resolves to an array of Resources.
9092
+ */
9093
+ async getResourcesToSpend(quantities, excludedIds) {
9094
+ const resources = await this.provider.getResourcesToSpend(
9095
+ this.address,
9096
+ quantities,
9097
+ excludedIds
9098
+ );
9099
+ return resources.map((resource) => ({
9100
+ ...resource,
9101
+ predicate: hexlify19(this.bytes),
9102
+ padPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
9103
+ }));
9104
+ }
8856
9105
  /**
8857
9106
  * Sets the configurable constants for the predicate.
8858
9107
  *
@@ -9601,7 +9850,7 @@ export {
9601
9850
  WalletLocked,
9602
9851
  WalletManager,
9603
9852
  WalletUnlocked,
9604
- addAmountToAsset,
9853
+ addAmountToCoinQuantities,
9605
9854
  addOperation,
9606
9855
  assemblePanicError,
9607
9856
  assembleReceiptByType,
@@ -9610,9 +9859,10 @@ export {
9610
9859
  assets,
9611
9860
  buildBlockExplorerUrl,
9612
9861
  cacheFor,
9862
+ cacheTxInputsFromOwner,
9863
+ calculateGasFee,
9613
9864
  calculateMetadataGasForTxCreate,
9614
9865
  calculateMetadataGasForTxScript,
9615
- calculatePriceWithFactor,
9616
9866
  calculateTransactionFee,
9617
9867
  coinQuantityfy,
9618
9868
  deferPromise,