@fuel-ts/account 0.0.0-rc-2037-20240418195040 → 0.0.0-rc-2021-20240418195117

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

Potentially problematic release.


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

Files changed (66) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +5 -4
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +1 -1
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +1 -1
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +1 -1
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +797 -596
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +825 -633
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +648 -451
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +11 -18
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +906 -324
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +1 -1
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +2 -1
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +6 -1
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +37 -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/index.d.ts +0 -1
  31. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  32. package/dist/providers/transaction-request/input.d.ts +2 -2
  33. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  34. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/transaction-request.d.ts +6 -7
  36. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  37. package/dist/providers/transaction-request/utils.d.ts +3 -0
  38. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  39. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  40. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  41. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  43. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  44. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  45. package/dist/providers/utils/gas.d.ts +8 -2
  46. package/dist/providers/utils/gas.d.ts.map +1 -1
  47. package/dist/test-utils/index.d.ts +0 -1
  48. package/dist/test-utils/index.d.ts.map +1 -1
  49. package/dist/test-utils/launchNode.d.ts.map +1 -1
  50. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  51. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  52. package/dist/test-utils.global.js +1547 -1085
  53. package/dist/test-utils.global.js.map +1 -1
  54. package/dist/test-utils.js +804 -608
  55. package/dist/test-utils.js.map +1 -1
  56. package/dist/test-utils.mjs +641 -442
  57. package/dist/test-utils.mjs.map +1 -1
  58. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  59. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  60. package/package.json +16 -16
  61. package/dist/providers/transaction-request/helpers.d.ts +0 -10
  62. package/dist/providers/transaction-request/helpers.d.ts.map +0 -1
  63. package/dist/test-utils/resources.d.ts +0 -4
  64. package/dist/test-utils/resources.d.ts.map +0 -1
  65. package/dist/test-utils/transactionRequest.d.ts +0 -5
  66. package/dist/test-utils/transactionRequest.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -32,8 +32,9 @@ import { Address as Address3 } from "@fuel-ts/address";
32
32
  import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
33
33
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
34
34
  import { AbstractAccount } from "@fuel-ts/interfaces";
35
- import { bn as bn17 } from "@fuel-ts/math";
35
+ import { bn as bn18 } from "@fuel-ts/math";
36
36
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
37
+ import { clone as clone4 } from "ramda";
37
38
 
38
39
  // src/providers/coin-quantity.ts
39
40
  import { BaseAssetId } from "@fuel-ts/address/configs";
@@ -42,24 +43,24 @@ import { hexlify } from "@fuel-ts/utils";
42
43
  var coinQuantityfy = (coinQuantityLike) => {
43
44
  let assetId;
44
45
  let amount;
45
- let max2;
46
+ let max;
46
47
  if (Array.isArray(coinQuantityLike)) {
47
48
  amount = coinQuantityLike[0];
48
49
  assetId = coinQuantityLike[1] ?? BaseAssetId;
49
- max2 = coinQuantityLike[2] ?? void 0;
50
+ max = coinQuantityLike[2] ?? void 0;
50
51
  } else {
51
52
  amount = coinQuantityLike.amount;
52
53
  assetId = coinQuantityLike.assetId ?? BaseAssetId;
53
- max2 = coinQuantityLike.max ?? void 0;
54
+ max = coinQuantityLike.max ?? void 0;
54
55
  }
55
56
  const bnAmount = bn(amount);
56
57
  return {
57
58
  assetId: hexlify(assetId),
58
59
  amount: bnAmount.lt(1) ? bn(1) : bnAmount,
59
- max: max2 ? bn(max2) : void 0
60
+ max: max ? bn(max) : void 0
60
61
  };
61
62
  };
62
- var addAmountToAsset = (params) => {
63
+ var addAmountToCoinQuantities = (params) => {
63
64
  const { amount, assetId } = params;
64
65
  const coinQuantities = [...params.coinQuantities];
65
66
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -74,7 +75,7 @@ var addAmountToAsset = (params) => {
74
75
  // src/providers/provider.ts
75
76
  import { Address as Address2 } from "@fuel-ts/address";
76
77
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
77
- import { BN, bn as bn15, max } from "@fuel-ts/math";
78
+ import { BN, bn as bn16 } from "@fuel-ts/math";
78
79
  import {
79
80
  InputType as InputType7,
80
81
  TransactionType as TransactionType8,
@@ -92,14 +93,10 @@ import { clone as clone3 } from "ramda";
92
93
  import gql from "graphql-tag";
93
94
  var ReceiptFragmentFragmentDoc = gql`
94
95
  fragment receiptFragment on Receipt {
95
- contract {
96
- id
97
- }
96
+ id
98
97
  pc
99
98
  is
100
- to {
101
- id
102
- }
99
+ to
103
100
  toAddress
104
101
  amount
105
102
  assetId
@@ -137,10 +134,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
137
134
  id
138
135
  }
139
136
  time
137
+ receipts {
138
+ ...receiptFragment
139
+ }
140
140
  programState {
141
141
  returnType
142
142
  data
143
143
  }
144
+ receipts {
145
+ ...receiptFragment
146
+ }
144
147
  }
145
148
  ... on FailureStatus {
146
149
  block {
@@ -148,26 +151,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
148
151
  }
149
152
  time
150
153
  reason
154
+ receipts {
155
+ ...receiptFragment
156
+ }
151
157
  }
152
158
  ... on SqueezedOutStatus {
153
159
  reason
154
160
  }
155
161
  }
156
- `;
162
+ ${ReceiptFragmentFragmentDoc}`;
157
163
  var TransactionFragmentFragmentDoc = gql`
158
164
  fragment transactionFragment on Transaction {
159
165
  id
160
166
  rawPayload
161
- gasPrice
162
- receipts {
163
- ...receiptFragment
164
- }
165
167
  status {
166
168
  ...transactionStatusFragment
167
169
  }
168
170
  }
169
- ${ReceiptFragmentFragmentDoc}
170
- ${TransactionStatusFragmentFragmentDoc}`;
171
+ ${TransactionStatusFragmentFragmentDoc}`;
171
172
  var InputEstimatePredicatesFragmentFragmentDoc = gql`
172
173
  fragment inputEstimatePredicatesFragment on Input {
173
174
  ... on InputCoin {
@@ -185,6 +186,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
185
186
  }
186
187
  }
187
188
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
189
+ var DryRunFailureStatusFragmentFragmentDoc = gql`
190
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
191
+ reason
192
+ programState {
193
+ returnType
194
+ data
195
+ }
196
+ }
197
+ `;
198
+ var DryRunSuccessStatusFragmentFragmentDoc = gql`
199
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
200
+ programState {
201
+ returnType
202
+ data
203
+ }
204
+ }
205
+ `;
206
+ var DryRunTransactionStatusFragmentFragmentDoc = gql`
207
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
208
+ ... on DryRunFailureStatus {
209
+ ...dryRunFailureStatusFragment
210
+ }
211
+ ... on DryRunSuccessStatus {
212
+ ...dryRunSuccessStatusFragment
213
+ }
214
+ }
215
+ ${DryRunFailureStatusFragmentFragmentDoc}
216
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
217
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
218
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
219
+ id
220
+ status {
221
+ ...dryRunTransactionStatusFragment
222
+ }
223
+ receipts {
224
+ ...receiptFragment
225
+ }
226
+ }
227
+ ${DryRunTransactionStatusFragmentFragmentDoc}
228
+ ${ReceiptFragmentFragmentDoc}`;
188
229
  var CoinFragmentFragmentDoc = gql`
189
230
  fragment coinFragment on Coin {
190
231
  __typename
@@ -192,7 +233,6 @@ var CoinFragmentFragmentDoc = gql`
192
233
  owner
193
234
  amount
194
235
  assetId
195
- maturity
196
236
  blockCreated
197
237
  txCreatedIdx
198
238
  }
@@ -231,26 +271,32 @@ var MessageProofFragmentFragmentDoc = gql`
231
271
  messageBlockHeader {
232
272
  id
233
273
  daHeight
274
+ consensusParametersVersion
275
+ stateTransitionBytecodeVersion
234
276
  transactionsCount
277
+ messageReceiptCount
235
278
  transactionsRoot
279
+ messageOutboxRoot
280
+ eventInboxRoot
236
281
  height
237
282
  prevRoot
238
283
  time
239
284
  applicationHash
240
- messageReceiptRoot
241
- messageReceiptCount
242
285
  }
243
286
  commitBlockHeader {
244
287
  id
245
288
  daHeight
289
+ consensusParametersVersion
290
+ stateTransitionBytecodeVersion
246
291
  transactionsCount
292
+ messageReceiptCount
247
293
  transactionsRoot
294
+ messageOutboxRoot
295
+ eventInboxRoot
248
296
  height
249
297
  prevRoot
250
298
  time
251
299
  applicationHash
252
- messageReceiptRoot
253
- messageReceiptCount
254
300
  }
255
301
  sender
256
302
  recipient
@@ -269,8 +315,8 @@ var BalanceFragmentFragmentDoc = gql`
269
315
  var BlockFragmentFragmentDoc = gql`
270
316
  fragment blockFragment on Block {
271
317
  id
318
+ height
272
319
  header {
273
- height
274
320
  time
275
321
  }
276
322
  transactions {
@@ -328,6 +374,11 @@ var DependentCostFragmentFragmentDoc = gql`
328
374
  `;
329
375
  var GasCostsFragmentFragmentDoc = gql`
330
376
  fragment GasCostsFragment on GasCosts {
377
+ version {
378
+ ... on Version {
379
+ value
380
+ }
381
+ }
331
382
  add
332
383
  addi
333
384
  aloc
@@ -340,7 +391,6 @@ var GasCostsFragmentFragmentDoc = gql`
340
391
  cb
341
392
  cfei
342
393
  cfsi
343
- croo
344
394
  div
345
395
  divi
346
396
  ecr1
@@ -423,6 +473,9 @@ var GasCostsFragmentFragmentDoc = gql`
423
473
  ccp {
424
474
  ...DependentCostFragment
425
475
  }
476
+ croo {
477
+ ...DependentCostFragment
478
+ }
426
479
  csiz {
427
480
  ...DependentCostFragment
428
481
  }
@@ -482,6 +535,11 @@ var GasCostsFragmentFragmentDoc = gql`
482
535
  ${DependentCostFragmentFragmentDoc}`;
483
536
  var ConsensusParametersFragmentFragmentDoc = gql`
484
537
  fragment consensusParametersFragment on ConsensusParameters {
538
+ version {
539
+ ... on Version {
540
+ value
541
+ }
542
+ }
485
543
  txParams {
486
544
  ...TxParametersFragment
487
545
  }
@@ -541,18 +599,9 @@ var NodeInfoFragmentFragmentDoc = gql`
541
599
  fragment nodeInfoFragment on NodeInfo {
542
600
  utxoValidation
543
601
  vmBacktrace
544
- minGasPrice
545
602
  maxTx
546
603
  maxDepth
547
604
  nodeVersion
548
- peers {
549
- id
550
- addresses
551
- clientVersion
552
- blockHeight
553
- lastHeartbeatMs
554
- appScore
555
- }
556
605
  }
557
606
  `;
558
607
  var GetVersionDocument = gql`
@@ -587,13 +636,9 @@ var GetTransactionWithReceiptsDocument = gql`
587
636
  query getTransactionWithReceipts($transactionId: TransactionId!) {
588
637
  transaction(id: $transactionId) {
589
638
  ...transactionFragment
590
- receipts {
591
- ...receiptFragment
592
- }
593
639
  }
594
640
  }
595
- ${TransactionFragmentFragmentDoc}
596
- ${ReceiptFragmentFragmentDoc}`;
641
+ ${TransactionFragmentFragmentDoc}`;
597
642
  var GetTransactionsDocument = gql`
598
643
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
599
644
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -721,6 +766,20 @@ var GetBalanceDocument = gql`
721
766
  }
722
767
  }
723
768
  ${BalanceFragmentFragmentDoc}`;
769
+ var GetLatestGasPriceDocument = gql`
770
+ query getLatestGasPrice {
771
+ latestGasPrice {
772
+ gasPrice
773
+ }
774
+ }
775
+ `;
776
+ var EstimateGasPriceDocument = gql`
777
+ query estimateGasPrice($blockHorizon: U32!) {
778
+ estimateGasPrice(blockHorizon: $blockHorizon) {
779
+ gasPrice
780
+ }
781
+ }
782
+ `;
724
783
  var GetBalancesDocument = gql`
725
784
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
726
785
  balances(
@@ -775,12 +834,12 @@ var GetMessageStatusDocument = gql`
775
834
  }
776
835
  `;
777
836
  var DryRunDocument = gql`
778
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
779
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
780
- ...receiptFragment
837
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
838
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
839
+ ...dryRunTransactionExecutionStatusFragment
781
840
  }
782
841
  }
783
- ${ReceiptFragmentFragmentDoc}`;
842
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
784
843
  var SubmitDocument = gql`
785
844
  mutation submit($encodedTransaction: HexString!) {
786
845
  submit(tx: $encodedTransaction) {
@@ -863,6 +922,12 @@ function getSdk(requester) {
863
922
  getBalance(variables, options) {
864
923
  return requester(GetBalanceDocument, variables, options);
865
924
  },
925
+ getLatestGasPrice(variables, options) {
926
+ return requester(GetLatestGasPriceDocument, variables, options);
927
+ },
928
+ estimateGasPrice(variables, options) {
929
+ return requester(EstimateGasPriceDocument, variables, options);
930
+ },
866
931
  getBalances(variables, options) {
867
932
  return requester(GetBalancesDocument, variables, options);
868
933
  },
@@ -1056,10 +1121,9 @@ var inputify = (value) => {
1056
1121
  txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
1057
1122
  },
1058
1123
  witnessIndex: value.witnessIndex,
1059
- maturity: value.maturity ?? 0,
1060
1124
  predicateGasUsed: bn2(value.predicateGasUsed),
1061
- predicateLength: predicate.length,
1062
- predicateDataLength: predicateData.length,
1125
+ predicateLength: bn2(predicate.length),
1126
+ predicateDataLength: bn2(predicateData.length),
1063
1127
  predicate: hexlify3(predicate),
1064
1128
  predicateData: hexlify3(predicateData)
1065
1129
  };
@@ -1090,8 +1154,8 @@ var inputify = (value) => {
1090
1154
  nonce: hexlify3(value.nonce),
1091
1155
  witnessIndex: value.witnessIndex,
1092
1156
  predicateGasUsed: bn2(value.predicateGasUsed),
1093
- predicateLength: predicate.length,
1094
- predicateDataLength: predicateData.length,
1157
+ predicateLength: bn2(predicate.length),
1158
+ predicateDataLength: bn2(predicateData.length),
1095
1159
  predicate: hexlify3(predicate),
1096
1160
  predicateData: hexlify3(predicateData),
1097
1161
  data: hexlify3(data),
@@ -1173,7 +1237,7 @@ import { bn as bn7 } from "@fuel-ts/math";
1173
1237
  import {
1174
1238
  PolicyType,
1175
1239
  TransactionCoder,
1176
- InputType as InputType3,
1240
+ InputType as InputType2,
1177
1241
  OutputType as OutputType2,
1178
1242
  TransactionType
1179
1243
  } from "@fuel-ts/transactions";
@@ -1221,8 +1285,8 @@ function assembleReceiptByType(receipt) {
1221
1285
  case "CALL" /* Call */: {
1222
1286
  const callReceipt = {
1223
1287
  type: ReceiptType.Call,
1224
- from: hexOrZero(receipt.contract?.id),
1225
- to: hexOrZero(receipt?.to?.id),
1288
+ from: hexOrZero(receipt.id || receipt.contractId),
1289
+ to: hexOrZero(receipt?.to),
1226
1290
  amount: bn4(receipt.amount),
1227
1291
  assetId: hexOrZero(receipt.assetId),
1228
1292
  gas: bn4(receipt.gas),
@@ -1236,7 +1300,7 @@ function assembleReceiptByType(receipt) {
1236
1300
  case "RETURN" /* Return */: {
1237
1301
  const returnReceipt = {
1238
1302
  type: ReceiptType.Return,
1239
- id: hexOrZero(receipt.contract?.id),
1303
+ id: hexOrZero(receipt.id || receipt.contractId),
1240
1304
  val: bn4(receipt.val),
1241
1305
  pc: bn4(receipt.pc),
1242
1306
  is: bn4(receipt.is)
@@ -1246,7 +1310,7 @@ function assembleReceiptByType(receipt) {
1246
1310
  case "RETURN_DATA" /* ReturnData */: {
1247
1311
  const returnDataReceipt = {
1248
1312
  type: ReceiptType.ReturnData,
1249
- id: hexOrZero(receipt.contract?.id),
1313
+ id: hexOrZero(receipt.id || receipt.contractId),
1250
1314
  ptr: bn4(receipt.ptr),
1251
1315
  len: bn4(receipt.len),
1252
1316
  digest: hexOrZero(receipt.digest),
@@ -1258,7 +1322,7 @@ function assembleReceiptByType(receipt) {
1258
1322
  case "PANIC" /* Panic */: {
1259
1323
  const panicReceipt = {
1260
1324
  type: ReceiptType.Panic,
1261
- id: hexOrZero(receipt.contract?.id),
1325
+ id: hexOrZero(receipt.id),
1262
1326
  reason: bn4(receipt.reason),
1263
1327
  pc: bn4(receipt.pc),
1264
1328
  is: bn4(receipt.is),
@@ -1269,7 +1333,7 @@ function assembleReceiptByType(receipt) {
1269
1333
  case "REVERT" /* Revert */: {
1270
1334
  const revertReceipt = {
1271
1335
  type: ReceiptType.Revert,
1272
- id: hexOrZero(receipt.contract?.id),
1336
+ id: hexOrZero(receipt.id || receipt.contractId),
1273
1337
  val: bn4(receipt.ra),
1274
1338
  pc: bn4(receipt.pc),
1275
1339
  is: bn4(receipt.is)
@@ -1279,7 +1343,7 @@ function assembleReceiptByType(receipt) {
1279
1343
  case "LOG" /* Log */: {
1280
1344
  const logReceipt = {
1281
1345
  type: ReceiptType.Log,
1282
- id: hexOrZero(receipt.contract?.id),
1346
+ id: hexOrZero(receipt.id || receipt.contractId),
1283
1347
  val0: bn4(receipt.ra),
1284
1348
  val1: bn4(receipt.rb),
1285
1349
  val2: bn4(receipt.rc),
@@ -1292,7 +1356,7 @@ function assembleReceiptByType(receipt) {
1292
1356
  case "LOG_DATA" /* LogData */: {
1293
1357
  const logDataReceipt = {
1294
1358
  type: ReceiptType.LogData,
1295
- id: hexOrZero(receipt.contract?.id),
1359
+ id: hexOrZero(receipt.id || receipt.contractId),
1296
1360
  val0: bn4(receipt.ra),
1297
1361
  val1: bn4(receipt.rb),
1298
1362
  ptr: bn4(receipt.ptr),
@@ -1306,8 +1370,8 @@ function assembleReceiptByType(receipt) {
1306
1370
  case "TRANSFER" /* Transfer */: {
1307
1371
  const transferReceipt = {
1308
1372
  type: ReceiptType.Transfer,
1309
- from: hexOrZero(receipt.contract?.id),
1310
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1373
+ from: hexOrZero(receipt.id || receipt.contractId),
1374
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1311
1375
  amount: bn4(receipt.amount),
1312
1376
  assetId: hexOrZero(receipt.assetId),
1313
1377
  pc: bn4(receipt.pc),
@@ -1318,8 +1382,8 @@ function assembleReceiptByType(receipt) {
1318
1382
  case "TRANSFER_OUT" /* TransferOut */: {
1319
1383
  const transferOutReceipt = {
1320
1384
  type: ReceiptType.TransferOut,
1321
- from: hexOrZero(receipt.contract?.id),
1322
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1385
+ from: hexOrZero(receipt.id || receipt.contractId),
1386
+ to: hexOrZero(receipt.toAddress || receipt.to),
1323
1387
  amount: bn4(receipt.amount),
1324
1388
  assetId: hexOrZero(receipt.assetId),
1325
1389
  pc: bn4(receipt.pc),
@@ -1362,7 +1426,7 @@ function assembleReceiptByType(receipt) {
1362
1426
  return receiptMessageOut;
1363
1427
  }
1364
1428
  case "MINT" /* Mint */: {
1365
- const contractId = hexOrZero(receipt.contract?.id);
1429
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1366
1430
  const subId = hexOrZero(receipt.subId);
1367
1431
  const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
1368
1432
  const mintReceipt = {
@@ -1377,7 +1441,7 @@ function assembleReceiptByType(receipt) {
1377
1441
  return mintReceipt;
1378
1442
  }
1379
1443
  case "BURN" /* Burn */: {
1380
- const contractId = hexOrZero(receipt.contract?.id);
1444
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1381
1445
  const subId = hexOrZero(receipt.subId);
1382
1446
  const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
1383
1447
  const burnReceipt = {
@@ -1462,7 +1526,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1462
1526
  import { bn as bn5 } from "@fuel-ts/math";
1463
1527
  import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
1464
1528
  import { arrayify as arrayify3 } from "@fuel-ts/utils";
1465
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1466
1529
  var getGasUsedFromReceipts = (receipts) => {
1467
1530
  const scriptResult = receipts.filter(
1468
1531
  (receipt) => receipt.type === ReceiptType2.ScriptResult
@@ -1483,18 +1546,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1483
1546
  }
1484
1547
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1485
1548
  const witnessCache = [];
1486
- const totalGas = inputs.reduce((total, input) => {
1549
+ const chargeableInputs = inputs.filter((input) => {
1550
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1551
+ if (isCoinOrMessage) {
1552
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1553
+ return true;
1554
+ }
1555
+ if (!witnessCache.includes(input.witnessIndex)) {
1556
+ witnessCache.push(input.witnessIndex);
1557
+ return true;
1558
+ }
1559
+ }
1560
+ return false;
1561
+ });
1562
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1563
+ const totalGas = chargeableInputs.reduce((total, input) => {
1487
1564
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1488
1565
  return total.add(
1489
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1566
+ vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1490
1567
  );
1491
1568
  }
1492
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1493
- witnessCache.push(input.witnessIndex);
1494
- return total.add(gasCosts.ecr1);
1495
- }
1496
- return total;
1497
- }, bn5());
1569
+ return total.add(gasCosts.ecr1);
1570
+ }, bn5(0));
1498
1571
  return totalGas;
1499
1572
  }
1500
1573
  function getMinGas(params) {
@@ -1506,12 +1579,20 @@ function getMinGas(params) {
1506
1579
  return minGas;
1507
1580
  }
1508
1581
  function getMaxGas(params) {
1509
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
1582
+ const {
1583
+ gasPerByte,
1584
+ witnessesLength,
1585
+ witnessLimit,
1586
+ minGas,
1587
+ gasLimit = bn5(0),
1588
+ maxGasPerTx
1589
+ } = params;
1510
1590
  let remainingAllowedWitnessGas = bn5(0);
1511
1591
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1512
1592
  remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1513
1593
  }
1514
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1594
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1595
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1515
1596
  }
1516
1597
  function calculateMetadataGasForTxCreate({
1517
1598
  gasCosts,
@@ -1533,6 +1614,10 @@ function calculateMetadataGasForTxScript({
1533
1614
  }) {
1534
1615
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1535
1616
  }
1617
+ var calculateGasFee = (params) => {
1618
+ const { gas, gasPrice, priceFactor, tip } = params;
1619
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1620
+ };
1536
1621
 
1537
1622
  // src/providers/utils/json.ts
1538
1623
  import { hexlify as hexlify5 } from "@fuel-ts/utils";
@@ -1676,28 +1761,6 @@ var NoWitnessByOwnerError = class extends Error {
1676
1761
  name = "NoWitnessByOwnerError";
1677
1762
  };
1678
1763
 
1679
- // src/providers/transaction-request/helpers.ts
1680
- import { InputType as InputType2 } from "@fuel-ts/transactions";
1681
- var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1682
- var isRequestInputMessage = (input) => input.type === InputType2.Message;
1683
- var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1684
- var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
1685
- var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1686
- var cacheResources = (resources) => resources.reduce(
1687
- (cache2, resource) => {
1688
- if (isCoin(resource)) {
1689
- cache2.utxos.push(resource.id);
1690
- } else {
1691
- cache2.messages.push(resource.nonce);
1692
- }
1693
- return cache2;
1694
- },
1695
- {
1696
- utxos: [],
1697
- messages: []
1698
- }
1699
- );
1700
-
1701
1764
  // src/providers/transaction-request/witness.ts
1702
1765
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1703
1766
  var witnessify = (value) => {
@@ -1711,7 +1774,7 @@ var witnessify = (value) => {
1711
1774
  // src/providers/transaction-request/transaction-request.ts
1712
1775
  var BaseTransactionRequest = class {
1713
1776
  /** Gas price for transaction */
1714
- gasPrice;
1777
+ tip;
1715
1778
  /** Block until which tx cannot be included */
1716
1779
  maturity;
1717
1780
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1730,7 +1793,7 @@ var BaseTransactionRequest = class {
1730
1793
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1731
1794
  */
1732
1795
  constructor({
1733
- gasPrice,
1796
+ tip,
1734
1797
  maturity,
1735
1798
  maxFee,
1736
1799
  witnessLimit,
@@ -1738,7 +1801,7 @@ var BaseTransactionRequest = class {
1738
1801
  outputs,
1739
1802
  witnesses
1740
1803
  } = {}) {
1741
- this.gasPrice = bn7(gasPrice);
1804
+ this.tip = bn7(tip);
1742
1805
  this.maturity = maturity ?? 0;
1743
1806
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1744
1807
  this.maxFee = maxFee ? bn7(maxFee) : void 0;
@@ -1749,9 +1812,9 @@ var BaseTransactionRequest = class {
1749
1812
  static getPolicyMeta(req) {
1750
1813
  let policyTypes = 0;
1751
1814
  const policies = [];
1752
- if (req.gasPrice) {
1753
- policyTypes += PolicyType.GasPrice;
1754
- policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
1815
+ if (req.tip) {
1816
+ policyTypes += PolicyType.Tip;
1817
+ policies.push({ data: req.tip, type: PolicyType.Tip });
1755
1818
  }
1756
1819
  if (req.witnessLimit) {
1757
1820
  policyTypes += PolicyType.WitnessLimit;
@@ -1888,7 +1951,7 @@ var BaseTransactionRequest = class {
1888
1951
  */
1889
1952
  getCoinInputs() {
1890
1953
  return this.inputs.filter(
1891
- (input) => input.type === InputType3.Coin
1954
+ (input) => input.type === InputType2.Coin
1892
1955
  );
1893
1956
  }
1894
1957
  /**
@@ -1920,9 +1983,9 @@ var BaseTransactionRequest = class {
1920
1983
  const ownerAddress = addressify(owner);
1921
1984
  const found = this.inputs.find((input) => {
1922
1985
  switch (input.type) {
1923
- case InputType3.Coin:
1986
+ case InputType2.Coin:
1924
1987
  return hexlify7(input.owner) === ownerAddress.toB256();
1925
- case InputType3.Message:
1988
+ case InputType2.Message:
1926
1989
  return hexlify7(input.recipient) === ownerAddress.toB256();
1927
1990
  default:
1928
1991
  return false;
@@ -1939,9 +2002,9 @@ var BaseTransactionRequest = class {
1939
2002
  * @param predicateData - Predicate data bytes.
1940
2003
  */
1941
2004
  addCoinInput(coin) {
1942
- const { assetId, owner, amount, id, predicate } = coin;
2005
+ const { assetId, owner, amount } = coin;
1943
2006
  let witnessIndex;
1944
- if (predicate) {
2007
+ if (coin.predicate) {
1945
2008
  witnessIndex = 0;
1946
2009
  } else {
1947
2010
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1950,14 +2013,13 @@ var BaseTransactionRequest = class {
1950
2013
  }
1951
2014
  }
1952
2015
  const input = {
1953
- id,
1954
- type: InputType3.Coin,
2016
+ ...coin,
2017
+ type: InputType2.Coin,
1955
2018
  owner: owner.toB256(),
1956
2019
  amount,
1957
2020
  assetId,
1958
2021
  txPointer: "0x00000000000000000000000000000000",
1959
- witnessIndex,
1960
- predicate
2022
+ witnessIndex
1961
2023
  };
1962
2024
  this.pushInput(input);
1963
2025
  this.addChangeOutput(owner, assetId);
@@ -1971,10 +2033,10 @@ var BaseTransactionRequest = class {
1971
2033
  * @param predicateData - Predicate data bytes.
1972
2034
  */
1973
2035
  addMessageInput(message) {
1974
- const { recipient, sender, amount, predicate, nonce } = message;
2036
+ const { recipient, sender, amount } = message;
1975
2037
  const assetId = BaseAssetId2;
1976
2038
  let witnessIndex;
1977
- if (predicate) {
2039
+ if (message.predicate) {
1978
2040
  witnessIndex = 0;
1979
2041
  } else {
1980
2042
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1983,13 +2045,12 @@ var BaseTransactionRequest = class {
1983
2045
  }
1984
2046
  }
1985
2047
  const input = {
1986
- nonce,
1987
- type: InputType3.Message,
2048
+ ...message,
2049
+ type: InputType2.Message,
1988
2050
  sender: sender.toB256(),
1989
2051
  recipient: recipient.toB256(),
1990
2052
  amount,
1991
- witnessIndex,
1992
- predicate
2053
+ witnessIndex
1993
2054
  };
1994
2055
  this.pushInput(input);
1995
2056
  this.addChangeOutput(recipient, assetId);
@@ -2099,7 +2160,7 @@ var BaseTransactionRequest = class {
2099
2160
  }
2100
2161
  calculateMaxGas(chainInfo, minGas) {
2101
2162
  const { consensusParameters } = chainInfo;
2102
- const { gasPerByte } = consensusParameters;
2163
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2103
2164
  const witnessesLength = this.toTransaction().witnesses.reduce(
2104
2165
  (acc, wit) => acc + wit.dataLength,
2105
2166
  0
@@ -2108,7 +2169,8 @@ var BaseTransactionRequest = class {
2108
2169
  gasPerByte,
2109
2170
  minGas,
2110
2171
  witnessesLength,
2111
- witnessLimit: this.witnessLimit
2172
+ witnessLimit: this.witnessLimit,
2173
+ maxGasPerTx
2112
2174
  });
2113
2175
  }
2114
2176
  /**
@@ -2126,17 +2188,20 @@ var BaseTransactionRequest = class {
2126
2188
  });
2127
2189
  const updateAssetInput = (assetId, quantity) => {
2128
2190
  const assetInput = findAssetInput(assetId);
2191
+ let usedQuantity = quantity;
2192
+ if (assetId === BaseAssetId2) {
2193
+ usedQuantity = bn7("1000000000000000000");
2194
+ }
2129
2195
  if (assetInput && "assetId" in assetInput) {
2130
2196
  assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2131
- assetInput.amount = quantity;
2197
+ assetInput.amount = usedQuantity;
2132
2198
  } else {
2133
2199
  this.addResources([
2134
2200
  {
2135
2201
  id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2136
- amount: quantity,
2202
+ amount: usedQuantity,
2137
2203
  assetId,
2138
2204
  owner: resourcesOwner || Address.fromRandom(),
2139
- maturity: 0,
2140
2205
  blockCreated: bn7(1),
2141
2206
  txCreatedIdx: bn7(1)
2142
2207
  }
@@ -2168,20 +2233,16 @@ var BaseTransactionRequest = class {
2168
2233
  toJSON() {
2169
2234
  return normalizeJSON(this);
2170
2235
  }
2171
- removeWitness(index) {
2172
- this.witnesses.splice(index, 1);
2173
- this.adjustWitnessIndexes(index);
2174
- }
2175
- updatePredicateInputs(inputs) {
2236
+ updatePredicateGasUsed(inputs) {
2176
2237
  this.inputs.forEach((i) => {
2177
2238
  let correspondingInput;
2178
2239
  switch (i.type) {
2179
- case InputType3.Coin:
2180
- correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2240
+ case InputType2.Coin:
2241
+ correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2181
2242
  break;
2182
- case InputType3.Message:
2243
+ case InputType2.Message:
2183
2244
  correspondingInput = inputs.find(
2184
- (x) => x.type === InputType3.Message && x.sender === i.sender
2245
+ (x) => x.type === InputType2.Message && x.sender === i.sender
2185
2246
  );
2186
2247
  break;
2187
2248
  default:
@@ -2194,10 +2255,12 @@ var BaseTransactionRequest = class {
2194
2255
  }
2195
2256
  });
2196
2257
  }
2197
- adjustWitnessIndexes(removedIndex) {
2198
- this.inputs.filter(isRequestInputResource).forEach((input) => {
2199
- if (input.witnessIndex > removedIndex) {
2200
- input.witnessIndex -= 1;
2258
+ shiftPredicateData() {
2259
+ this.inputs.forEach((input) => {
2260
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2261
+ input.predicateData = input.paddPredicateData(
2262
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2263
+ );
2201
2264
  }
2202
2265
  });
2203
2266
  }
@@ -2213,7 +2276,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2213
2276
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2214
2277
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2215
2278
  import { bn as bn8 } from "@fuel-ts/math";
2216
- import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2279
+ import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2217
2280
  import { concat as concat2 } from "@fuel-ts/utils";
2218
2281
  import { clone as clone2 } from "ramda";
2219
2282
  function hashTransaction(transactionRequest, chainId) {
@@ -2224,7 +2287,7 @@ function hashTransaction(transactionRequest, chainId) {
2224
2287
  transaction.inputs = transaction.inputs.map((input) => {
2225
2288
  const inputClone = clone2(input);
2226
2289
  switch (inputClone.type) {
2227
- case InputType4.Coin: {
2290
+ case InputType3.Coin: {
2228
2291
  inputClone.txPointer = {
2229
2292
  blockHeight: 0,
2230
2293
  txIndex: 0
@@ -2232,11 +2295,11 @@ function hashTransaction(transactionRequest, chainId) {
2232
2295
  inputClone.predicateGasUsed = bn8(0);
2233
2296
  return inputClone;
2234
2297
  }
2235
- case InputType4.Message: {
2298
+ case InputType3.Message: {
2236
2299
  inputClone.predicateGasUsed = bn8(0);
2237
2300
  return inputClone;
2238
2301
  }
2239
- case InputType4.Contract: {
2302
+ case InputType3.Contract: {
2240
2303
  inputClone.txPointer = {
2241
2304
  blockHeight: 0,
2242
2305
  txIndex: 0
@@ -2347,9 +2410,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2347
2410
  return {
2348
2411
  type: TransactionType3.Create,
2349
2412
  ...baseTransaction,
2350
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2351
2413
  bytecodeWitnessIndex,
2352
- storageSlotsCount: storageSlots.length,
2414
+ storageSlotsCount: bn9(storageSlots.length),
2353
2415
  salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
2354
2416
  storageSlots
2355
2417
  };
@@ -2402,7 +2464,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2402
2464
  import { addressify as addressify2 } from "@fuel-ts/address";
2403
2465
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2404
2466
  import { bn as bn10 } from "@fuel-ts/math";
2405
- import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2467
+ import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2406
2468
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2407
2469
 
2408
2470
  // src/providers/transaction-request/scripts.ts
@@ -2472,8 +2534,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2472
2534
  type: TransactionType4.Script,
2473
2535
  scriptGasLimit: this.gasLimit,
2474
2536
  ...super.getBaseTransaction(),
2475
- scriptLength: script.length,
2476
- scriptDataLength: scriptData.length,
2537
+ scriptLength: bn10(script.length),
2538
+ scriptDataLength: bn10(scriptData.length),
2477
2539
  receiptsRoot: ZeroBytes327,
2478
2540
  script: hexlify10(script),
2479
2541
  scriptData: hexlify10(scriptData)
@@ -2486,7 +2548,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2486
2548
  */
2487
2549
  getContractInputs() {
2488
2550
  return this.inputs.filter(
2489
- (input) => input.type === InputType5.Contract
2551
+ (input) => input.type === InputType4.Contract
2490
2552
  );
2491
2553
  }
2492
2554
  /**
@@ -2537,7 +2599,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2537
2599
  }
2538
2600
  calculateMaxGas(chainInfo, minGas) {
2539
2601
  const { consensusParameters } = chainInfo;
2540
- const { gasPerByte } = consensusParameters;
2602
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2541
2603
  const witnessesLength = this.toTransaction().witnesses.reduce(
2542
2604
  (acc, wit) => acc + wit.dataLength,
2543
2605
  0
@@ -2547,7 +2609,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2547
2609
  minGas,
2548
2610
  witnessesLength,
2549
2611
  witnessLimit: this.witnessLimit,
2550
- gasLimit: this.gasLimit
2612
+ gasLimit: this.gasLimit,
2613
+ maxGasPerTx
2551
2614
  });
2552
2615
  }
2553
2616
  /**
@@ -2562,7 +2625,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2562
2625
  return this;
2563
2626
  }
2564
2627
  const inputIndex = super.pushInput({
2565
- type: InputType5.Contract,
2628
+ type: InputType4.Contract,
2566
2629
  contractId: contractAddress.toB256(),
2567
2630
  txPointer: "0x00000000000000000000000000000000"
2568
2631
  });
@@ -2604,7 +2667,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2604
2667
 
2605
2668
  // src/providers/transaction-request/utils.ts
2606
2669
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2607
- import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2670
+ import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2608
2671
  var transactionRequestify = (obj) => {
2609
2672
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2610
2673
  return obj;
@@ -2622,14 +2685,31 @@ var transactionRequestify = (obj) => {
2622
2685
  }
2623
2686
  }
2624
2687
  };
2688
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2689
+ (acc, input) => {
2690
+ if (input.type === InputType5.Coin && input.owner === owner) {
2691
+ acc.utxos.push(input.id);
2692
+ }
2693
+ if (input.type === InputType5.Message && input.recipient === owner) {
2694
+ acc.messages.push(input.nonce);
2695
+ }
2696
+ return acc;
2697
+ },
2698
+ {
2699
+ utxos: [],
2700
+ messages: []
2701
+ }
2702
+ );
2625
2703
 
2626
2704
  // src/providers/transaction-response/transaction-response.ts
2627
2705
  import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2628
- import { bn as bn14 } from "@fuel-ts/math";
2706
+ import { bn as bn15 } from "@fuel-ts/math";
2629
2707
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2630
2708
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2631
2709
 
2632
2710
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2711
+ import { bn as bn14 } from "@fuel-ts/math";
2712
+ import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2633
2713
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2634
2714
 
2635
2715
  // src/providers/transaction-summary/calculate-transaction-fee.ts
@@ -2638,9 +2718,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
2638
2718
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2639
2719
  var calculateTransactionFee = (params) => {
2640
2720
  const {
2641
- gasUsed,
2721
+ gasPrice,
2642
2722
  rawPayload,
2643
- consensusParameters: { gasCosts, feeParams }
2723
+ tip,
2724
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2644
2725
  } = params;
2645
2726
  const gasPerByte = bn11(feeParams.gasPerByte);
2646
2727
  const gasPriceFactor = bn11(feeParams.gasPriceFactor);
@@ -2650,8 +2731,7 @@ var calculateTransactionFee = (params) => {
2650
2731
  return {
2651
2732
  fee: bn11(0),
2652
2733
  minFee: bn11(0),
2653
- maxFee: bn11(0),
2654
- feeFromGasUsed: bn11(0)
2734
+ maxFee: bn11(0)
2655
2735
  };
2656
2736
  }
2657
2737
  const { type, witnesses, inputs, policies } = transaction;
@@ -2683,7 +2763,6 @@ var calculateTransactionFee = (params) => {
2683
2763
  metadataGas,
2684
2764
  txBytesSize: transactionBytes.length
2685
2765
  });
2686
- const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2687
2766
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2688
2767
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2689
2768
  const maxGas = getMaxGas({
@@ -2691,17 +2770,25 @@ var calculateTransactionFee = (params) => {
2691
2770
  minGas,
2692
2771
  witnessesLength,
2693
2772
  gasLimit,
2694
- witnessLimit
2773
+ witnessLimit,
2774
+ maxGasPerTx
2775
+ });
2776
+ const minFee = calculateGasFee({
2777
+ gasPrice,
2778
+ gas: minGas,
2779
+ priceFactor: gasPriceFactor,
2780
+ tip
2781
+ });
2782
+ const maxFee = calculateGasFee({
2783
+ gasPrice,
2784
+ gas: maxGas,
2785
+ priceFactor: gasPriceFactor,
2786
+ tip
2695
2787
  });
2696
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2697
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2698
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2699
- const fee = minFee.add(feeFromGasUsed);
2700
2788
  return {
2701
- fee,
2702
2789
  minFee,
2703
2790
  maxFee,
2704
- feeFromGasUsed
2791
+ fee: maxFee
2705
2792
  };
2706
2793
  };
2707
2794
 
@@ -3315,7 +3402,9 @@ function assembleTransactionSummary(params) {
3315
3402
  gqlTransactionStatus,
3316
3403
  abiMap = {},
3317
3404
  maxInputs,
3318
- gasCosts
3405
+ gasCosts,
3406
+ maxGasPerTx,
3407
+ gasPrice
3319
3408
  } = params;
3320
3409
  const gasUsed = getGasUsedFromReceipts(receipts);
3321
3410
  const rawPayload = hexlify11(transactionBytes);
@@ -3329,11 +3418,14 @@ function assembleTransactionSummary(params) {
3329
3418
  maxInputs
3330
3419
  });
3331
3420
  const typeName = getTransactionTypeName(transaction.type);
3421
+ const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3332
3422
  const { fee } = calculateTransactionFee({
3333
- gasUsed,
3423
+ gasPrice,
3334
3424
  rawPayload,
3425
+ tip,
3335
3426
  consensusParameters: {
3336
3427
  gasCosts,
3428
+ maxGasPerTx,
3337
3429
  feeParams: {
3338
3430
  gasPerByte,
3339
3431
  gasPriceFactor
@@ -3393,7 +3485,7 @@ var TransactionResponse = class {
3393
3485
  /** Current provider */
3394
3486
  provider;
3395
3487
  /** Gas used on the transaction */
3396
- gasUsed = bn14(0);
3488
+ gasUsed = bn15(0);
3397
3489
  /** The graphql Transaction with receipts object. */
3398
3490
  gqlTransaction;
3399
3491
  abis;
@@ -3471,8 +3563,13 @@ var TransactionResponse = class {
3471
3563
  const decodedTransaction = this.decodeTransaction(
3472
3564
  transaction
3473
3565
  );
3474
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3475
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3566
+ let txReceipts = [];
3567
+ if (transaction?.status && "receipts" in transaction.status) {
3568
+ txReceipts = transaction.status.receipts;
3569
+ }
3570
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3571
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3572
+ const gasPrice = await this.provider.getLatestGasPrice();
3476
3573
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3477
3574
  const transactionSummary = assembleTransactionSummary({
3478
3575
  id: this.id,
@@ -3484,7 +3581,9 @@ var TransactionResponse = class {
3484
3581
  gasPriceFactor,
3485
3582
  abiMap: contractsAbiMap,
3486
3583
  maxInputs,
3487
- gasCosts
3584
+ gasCosts,
3585
+ maxGasPerTx,
3586
+ gasPrice
3488
3587
  });
3489
3588
  return transactionSummary;
3490
3589
  }
@@ -3611,29 +3710,29 @@ var processGqlChain = (chain) => {
3611
3710
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3612
3711
  return {
3613
3712
  name,
3614
- baseChainHeight: bn15(daHeight),
3713
+ baseChainHeight: bn16(daHeight),
3615
3714
  consensusParameters: {
3616
- contractMaxSize: bn15(contractParams.contractMaxSize),
3617
- maxInputs: bn15(txParams.maxInputs),
3618
- maxOutputs: bn15(txParams.maxOutputs),
3619
- maxWitnesses: bn15(txParams.maxWitnesses),
3620
- maxGasPerTx: bn15(txParams.maxGasPerTx),
3621
- maxScriptLength: bn15(scriptParams.maxScriptLength),
3622
- maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
3623
- maxStorageSlots: bn15(contractParams.maxStorageSlots),
3624
- maxPredicateLength: bn15(predicateParams.maxPredicateLength),
3625
- maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
3626
- maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
3627
- gasPriceFactor: bn15(feeParams.gasPriceFactor),
3628
- gasPerByte: bn15(feeParams.gasPerByte),
3629
- maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3630
- chainId: bn15(consensusParameters.chainId),
3715
+ contractMaxSize: bn16(contractParams.contractMaxSize),
3716
+ maxInputs: bn16(txParams.maxInputs),
3717
+ maxOutputs: bn16(txParams.maxOutputs),
3718
+ maxWitnesses: bn16(txParams.maxWitnesses),
3719
+ maxGasPerTx: bn16(txParams.maxGasPerTx),
3720
+ maxScriptLength: bn16(scriptParams.maxScriptLength),
3721
+ maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
3722
+ maxStorageSlots: bn16(contractParams.maxStorageSlots),
3723
+ maxPredicateLength: bn16(predicateParams.maxPredicateLength),
3724
+ maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
3725
+ maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
3726
+ gasPriceFactor: bn16(feeParams.gasPriceFactor),
3727
+ gasPerByte: bn16(feeParams.gasPerByte),
3728
+ maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
3729
+ chainId: bn16(consensusParameters.chainId),
3631
3730
  gasCosts
3632
3731
  },
3633
3732
  gasCosts,
3634
3733
  latestBlock: {
3635
3734
  id: latestBlock.id,
3636
- height: bn15(latestBlock.header.height),
3735
+ height: bn16(latestBlock.height),
3637
3736
  time: latestBlock.header.time,
3638
3737
  transactions: latestBlock.transactions.map((i) => ({
3639
3738
  id: i.id
@@ -3727,10 +3826,8 @@ var _Provider = class {
3727
3826
  * Returns some helpful parameters related to gas fees.
3728
3827
  */
3729
3828
  getGasConfig() {
3730
- const { minGasPrice } = this.getNode();
3731
3829
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3732
3830
  return {
3733
- minGasPrice,
3734
3831
  maxGasPerTx,
3735
3832
  maxGasPerPredicate,
3736
3833
  gasPriceFactor,
@@ -3828,7 +3925,7 @@ var _Provider = class {
3828
3925
  */
3829
3926
  async getBlockNumber() {
3830
3927
  const { chain } = await this.operations.getChain();
3831
- return bn15(chain.latestBlock.header.height, 10);
3928
+ return bn16(chain.latestBlock.height, 10);
3832
3929
  }
3833
3930
  /**
3834
3931
  * Returns the chain information.
@@ -3838,13 +3935,11 @@ var _Provider = class {
3838
3935
  async fetchNode() {
3839
3936
  const { nodeInfo } = await this.operations.getNodeInfo();
3840
3937
  const processedNodeInfo = {
3841
- maxDepth: bn15(nodeInfo.maxDepth),
3842
- maxTx: bn15(nodeInfo.maxTx),
3843
- minGasPrice: bn15(nodeInfo.minGasPrice),
3938
+ maxDepth: bn16(nodeInfo.maxDepth),
3939
+ maxTx: bn16(nodeInfo.maxTx),
3844
3940
  nodeVersion: nodeInfo.nodeVersion,
3845
3941
  utxoValidation: nodeInfo.utxoValidation,
3846
- vmBacktrace: nodeInfo.vmBacktrace,
3847
- peers: nodeInfo.peers
3942
+ vmBacktrace: nodeInfo.vmBacktrace
3848
3943
  };
3849
3944
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3850
3945
  return processedNodeInfo;
@@ -3930,14 +4025,13 @@ var _Provider = class {
3930
4025
  return this.estimateTxDependencies(transactionRequest);
3931
4026
  }
3932
4027
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3933
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3934
- encodedTransaction,
4028
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4029
+ encodedTransactions: encodedTransaction,
3935
4030
  utxoValidation: utxoValidation || false
3936
4031
  });
3937
- const receipts = gqlReceipts.map(processGqlReceipt);
3938
- return {
3939
- receipts
3940
- };
4032
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4033
+ const receipts = rawReceipts.map(processGqlReceipt);
4034
+ return { receipts, dryrunStatus: status };
3941
4035
  }
3942
4036
  /**
3943
4037
  * Verifies whether enough gas is available to complete transaction.
@@ -3963,7 +4057,7 @@ var _Provider = class {
3963
4057
  } = response;
3964
4058
  if (inputs) {
3965
4059
  inputs.forEach((input, index) => {
3966
- if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
4060
+ if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
3967
4061
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3968
4062
  }
3969
4063
  });
@@ -3976,9 +4070,6 @@ var _Provider = class {
3976
4070
  * If there are missing variable outputs,
3977
4071
  * `addVariableOutputs` is called on the transaction.
3978
4072
  *
3979
- * @privateRemarks
3980
- * TODO: Investigate support for missing contract IDs
3981
- * TODO: Add support for missing output messages
3982
4073
  *
3983
4074
  * @param transactionRequest - The transaction request object.
3984
4075
  * @returns A promise.
@@ -3991,16 +4082,19 @@ var _Provider = class {
3991
4082
  missingContractIds: []
3992
4083
  };
3993
4084
  }
3994
- await this.estimatePredicates(transactionRequest);
3995
4085
  let receipts = [];
3996
4086
  const missingContractIds = [];
3997
4087
  let outputVariables = 0;
4088
+ let dryrunStatus;
3998
4089
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3999
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4000
- encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
4090
+ const {
4091
+ dryRun: [{ receipts: rawReceipts, status }]
4092
+ } = await this.operations.dryRun({
4093
+ encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
4001
4094
  utxoValidation: false
4002
4095
  });
4003
- receipts = gqlReceipts.map(processGqlReceipt);
4096
+ receipts = rawReceipts.map(processGqlReceipt);
4097
+ dryrunStatus = status;
4004
4098
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4005
4099
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4006
4100
  if (hasMissingOutputs) {
@@ -4010,6 +4104,10 @@ var _Provider = class {
4010
4104
  transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
4011
4105
  missingContractIds.push(contractId);
4012
4106
  });
4107
+ const { maxFee } = await this.estimateTxGasAndFee({
4108
+ transactionRequest
4109
+ });
4110
+ transactionRequest.maxFee = maxFee;
4013
4111
  } else {
4014
4112
  break;
4015
4113
  }
@@ -4017,37 +4115,139 @@ var _Provider = class {
4017
4115
  return {
4018
4116
  receipts,
4019
4117
  outputVariables,
4020
- missingContractIds
4118
+ missingContractIds,
4119
+ dryrunStatus
4021
4120
  };
4022
4121
  }
4122
+ /**
4123
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4124
+ *
4125
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4126
+ * further modifications are identified. The method iteratively updates these transactions
4127
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4128
+ *
4129
+ * @param transactionRequests - Array of transaction request objects.
4130
+ * @returns A promise that resolves to an array of results for each transaction.
4131
+ */
4132
+ async estimateMultipleTxDependencies(transactionRequests) {
4133
+ const results = transactionRequests.map(() => ({
4134
+ receipts: [],
4135
+ outputVariables: 0,
4136
+ missingContractIds: [],
4137
+ dryrunStatus: void 0
4138
+ }));
4139
+ const allRequests = clone3(transactionRequests);
4140
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4141
+ allRequests.forEach((req, index) => {
4142
+ if (req.type === TransactionType8.Script) {
4143
+ serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
4144
+ }
4145
+ });
4146
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4147
+ let attempt = 0;
4148
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4149
+ const encodedTransactions = transactionsToProcess.map(
4150
+ (index) => serializedTransactionsMap.get(index)
4151
+ );
4152
+ const dryRunResults = await this.operations.dryRun({
4153
+ encodedTransactions,
4154
+ utxoValidation: false
4155
+ });
4156
+ const nextRoundTransactions = [];
4157
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4158
+ const currentResultIndex = transactionsToProcess[i];
4159
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4160
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4161
+ results[currentResultIndex].dryrunStatus = status;
4162
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4163
+ results[currentResultIndex].receipts
4164
+ );
4165
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4166
+ const requestToProcess = allRequests[currentResultIndex];
4167
+ if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
4168
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4169
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4170
+ missingOutputContractIds.forEach(({ contractId }) => {
4171
+ requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
4172
+ results[currentResultIndex].missingContractIds.push(contractId);
4173
+ });
4174
+ const { maxFee } = await this.estimateTxGasAndFee({
4175
+ transactionRequest: requestToProcess
4176
+ });
4177
+ requestToProcess.maxFee = maxFee;
4178
+ serializedTransactionsMap.set(
4179
+ currentResultIndex,
4180
+ hexlify12(requestToProcess.toTransactionBytes())
4181
+ );
4182
+ nextRoundTransactions.push(currentResultIndex);
4183
+ allRequests[currentResultIndex] = requestToProcess;
4184
+ }
4185
+ }
4186
+ transactionsToProcess = nextRoundTransactions;
4187
+ attempt += 1;
4188
+ }
4189
+ return results;
4190
+ }
4191
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4192
+ if (estimateTxDependencies) {
4193
+ return this.estimateMultipleTxDependencies(transactionRequests);
4194
+ }
4195
+ const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
4196
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4197
+ encodedTransactions,
4198
+ utxoValidation: utxoValidation || false
4199
+ });
4200
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4201
+ const receipts = rawReceipts.map(processGqlReceipt);
4202
+ return { receipts, dryrunStatus: status };
4203
+ });
4204
+ return results;
4205
+ }
4023
4206
  /**
4024
4207
  * Estimates the transaction gas and fee based on the provided transaction request.
4025
4208
  * @param transactionRequest - The transaction request object.
4026
4209
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4027
4210
  */
4028
- estimateTxGasAndFee(params) {
4211
+ async estimateTxGasAndFee(params) {
4029
4212
  const { transactionRequest } = params;
4030
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4213
+ let { gasPrice } = params;
4031
4214
  const chainInfo = this.getChain();
4032
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4033
- transactionRequest.gasPrice = gasPrice;
4215
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4034
4216
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4035
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4217
+ if (!gasPrice) {
4218
+ gasPrice = await this.estimateGasPrice(10);
4219
+ }
4220
+ const minFee = calculateGasFee({
4221
+ gasPrice: bn16(gasPrice),
4222
+ gas: minGas,
4223
+ priceFactor: gasPriceFactor,
4224
+ tip: transactionRequest.tip
4225
+ }).add(1);
4226
+ let gasLimit = bn16(0);
4036
4227
  if (transactionRequest.type === TransactionType8.Script) {
4228
+ gasLimit = transactionRequest.gasLimit;
4037
4229
  if (transactionRequest.gasLimit.eq(0)) {
4038
4230
  transactionRequest.gasLimit = minGas;
4039
4231
  transactionRequest.gasLimit = maxGasPerTx.sub(
4040
4232
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4041
4233
  );
4234
+ gasLimit = transactionRequest.gasLimit;
4042
4235
  }
4043
4236
  }
4044
4237
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4045
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4238
+ const maxFee = calculateGasFee({
4239
+ gasPrice: bn16(gasPrice),
4240
+ gas: maxGas,
4241
+ priceFactor: gasPriceFactor,
4242
+ tip: transactionRequest.tip
4243
+ }).add(1);
4046
4244
  return {
4047
4245
  minGas,
4048
4246
  minFee,
4049
4247
  maxGas,
4050
- maxFee
4248
+ maxFee,
4249
+ gasPrice,
4250
+ gasLimit
4051
4251
  };
4052
4252
  }
4053
4253
  /**
@@ -4065,15 +4265,17 @@ var _Provider = class {
4065
4265
  if (estimateTxDependencies) {
4066
4266
  return this.estimateTxDependencies(transactionRequest);
4067
4267
  }
4068
- const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
4069
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4070
- encodedTransaction,
4268
+ const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
4269
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4270
+ encodedTransactions,
4071
4271
  utxoValidation: true
4072
4272
  });
4073
- const receipts = gqlReceipts.map(processGqlReceipt);
4074
- return {
4075
- receipts
4076
- };
4273
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4274
+ const { id, receipts, status } = dryRunStatus;
4275
+ const processedReceipts = receipts.map(processGqlReceipt);
4276
+ return { id, receipts: processedReceipts, status };
4277
+ });
4278
+ return { receipts: callResult[0].receipts };
4077
4279
  }
4078
4280
  /**
4079
4281
  * Returns a transaction cost to enable user
@@ -4090,77 +4292,79 @@ var _Provider = class {
4090
4292
  * @param tolerance - The tolerance to add on top of the gasUsed.
4091
4293
  * @returns A promise that resolves to the transaction cost object.
4092
4294
  */
4093
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4094
- estimateTxDependencies = true,
4095
- estimatePredicates = true,
4096
- resourcesOwner,
4097
- signatureCallback
4098
- } = {}) {
4295
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4099
4296
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
4100
- const { minGasPrice } = this.getGasConfig();
4101
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
4102
4297
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
4103
4298
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4104
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4299
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4105
4300
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4301
+ txRequestClone.maxFee = bn16(0);
4106
4302
  if (isScriptTransaction) {
4107
- txRequestClone.gasLimit = bn15(0);
4303
+ txRequestClone.gasLimit = bn16(0);
4108
4304
  }
4109
- if (estimatePredicates) {
4110
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4111
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4112
- }
4113
- await this.estimatePredicates(txRequestClone);
4305
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4306
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4114
4307
  }
4308
+ const signedRequest = clone3(txRequestClone);
4309
+ let addedSignatures = 0;
4115
4310
  if (signatureCallback && isScriptTransaction) {
4116
- await signatureCallback(txRequestClone);
4311
+ const lengthBefore = signedRequest.witnesses.length;
4312
+ await signatureCallback(signedRequest);
4313
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4117
4314
  }
4118
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4119
- transactionRequest: txRequestClone
4315
+ await this.estimatePredicates(signedRequest);
4316
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4317
+ transactionRequest: signedRequest
4120
4318
  });
4121
4319
  let receipts = [];
4122
4320
  let missingContractIds = [];
4123
4321
  let outputVariables = 0;
4124
- let gasUsed = bn15(0);
4125
- if (isScriptTransaction && estimateTxDependencies) {
4126
- txRequestClone.gasPrice = bn15(0);
4322
+ let gasUsed = bn16(0);
4323
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4324
+ txRequestClone.maxFee = maxFee;
4325
+ if (isScriptTransaction) {
4326
+ txRequestClone.gasLimit = gasLimit;
4327
+ if (signatureCallback) {
4328
+ await signatureCallback(txRequestClone);
4329
+ }
4127
4330
  const result = await this.estimateTxDependencies(txRequestClone);
4128
4331
  receipts = result.receipts;
4129
4332
  outputVariables = result.outputVariables;
4130
4333
  missingContractIds = result.missingContractIds;
4131
4334
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4132
4335
  txRequestClone.gasLimit = gasUsed;
4133
- txRequestClone.gasPrice = setGasPrice;
4134
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4135
- transactionRequest: txRequestClone
4336
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4337
+ transactionRequest: txRequestClone,
4338
+ gasPrice
4136
4339
  }));
4137
4340
  }
4138
4341
  return {
4139
4342
  requiredQuantities: allQuantities,
4140
4343
  receipts,
4141
4344
  gasUsed,
4142
- minGasPrice,
4143
- gasPrice: setGasPrice,
4345
+ gasPrice,
4144
4346
  minGas,
4145
4347
  maxGas,
4146
4348
  minFee,
4147
4349
  maxFee,
4148
- estimatedInputs: txRequestClone.inputs,
4149
4350
  outputVariables,
4150
- missingContractIds
4351
+ missingContractIds,
4352
+ addedSignatures,
4353
+ estimatedPredicates: txRequestClone.inputs
4151
4354
  };
4152
4355
  }
4153
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4356
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4154
4357
  const ownerAddress = Address2.fromAddressOrString(owner);
4155
4358
  const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
4156
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4359
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4360
+ quantitiesToContract
4361
+ });
4157
4362
  transactionRequest.addResources(
4158
4363
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4159
4364
  );
4160
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4161
- transactionRequest,
4162
- forwardingQuantities
4163
- );
4365
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4366
+ quantitiesToContract
4367
+ });
4164
4368
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4165
4369
  return {
4166
4370
  resources,
@@ -4182,11 +4386,10 @@ var _Provider = class {
4182
4386
  return coins.map((coin) => ({
4183
4387
  id: coin.utxoId,
4184
4388
  assetId: coin.assetId,
4185
- amount: bn15(coin.amount),
4389
+ amount: bn16(coin.amount),
4186
4390
  owner: Address2.fromAddressOrString(coin.owner),
4187
- maturity: bn15(coin.maturity).toNumber(),
4188
- blockCreated: bn15(coin.blockCreated),
4189
- txCreatedIdx: bn15(coin.txCreatedIdx)
4391
+ blockCreated: bn16(coin.blockCreated),
4392
+ txCreatedIdx: bn16(coin.txCreatedIdx)
4190
4393
  }));
4191
4394
  }
4192
4395
  /**
@@ -4223,9 +4426,9 @@ var _Provider = class {
4223
4426
  switch (coin.__typename) {
4224
4427
  case "MessageCoin":
4225
4428
  return {
4226
- amount: bn15(coin.amount),
4429
+ amount: bn16(coin.amount),
4227
4430
  assetId: coin.assetId,
4228
- daHeight: bn15(coin.daHeight),
4431
+ daHeight: bn16(coin.daHeight),
4229
4432
  sender: Address2.fromAddressOrString(coin.sender),
4230
4433
  recipient: Address2.fromAddressOrString(coin.recipient),
4231
4434
  nonce: coin.nonce
@@ -4233,12 +4436,11 @@ var _Provider = class {
4233
4436
  case "Coin":
4234
4437
  return {
4235
4438
  id: coin.utxoId,
4236
- amount: bn15(coin.amount),
4439
+ amount: bn16(coin.amount),
4237
4440
  assetId: coin.assetId,
4238
4441
  owner: Address2.fromAddressOrString(coin.owner),
4239
- maturity: bn15(coin.maturity).toNumber(),
4240
- blockCreated: bn15(coin.blockCreated),
4241
- txCreatedIdx: bn15(coin.txCreatedIdx)
4442
+ blockCreated: bn16(coin.blockCreated),
4443
+ txCreatedIdx: bn16(coin.txCreatedIdx)
4242
4444
  };
4243
4445
  default:
4244
4446
  return null;
@@ -4255,13 +4457,13 @@ var _Provider = class {
4255
4457
  async getBlock(idOrHeight) {
4256
4458
  let variables;
4257
4459
  if (typeof idOrHeight === "number") {
4258
- variables = { height: bn15(idOrHeight).toString(10) };
4460
+ variables = { height: bn16(idOrHeight).toString(10) };
4259
4461
  } else if (idOrHeight === "latest") {
4260
4462
  variables = { height: (await this.getBlockNumber()).toString(10) };
4261
4463
  } else if (idOrHeight.length === 66) {
4262
4464
  variables = { blockId: idOrHeight };
4263
4465
  } else {
4264
- variables = { blockId: bn15(idOrHeight).toString(10) };
4466
+ variables = { blockId: bn16(idOrHeight).toString(10) };
4265
4467
  }
4266
4468
  const { block } = await this.operations.getBlock(variables);
4267
4469
  if (!block) {
@@ -4269,7 +4471,7 @@ var _Provider = class {
4269
4471
  }
4270
4472
  return {
4271
4473
  id: block.id,
4272
- height: bn15(block.header.height),
4474
+ height: bn16(block.height),
4273
4475
  time: block.header.time,
4274
4476
  transactionIds: block.transactions.map((tx) => tx.id)
4275
4477
  };
@@ -4284,7 +4486,7 @@ var _Provider = class {
4284
4486
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4285
4487
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4286
4488
  id: block.id,
4287
- height: bn15(block.header.height),
4489
+ height: bn16(block.height),
4288
4490
  time: block.header.time,
4289
4491
  transactionIds: block.transactions.map((tx) => tx.id)
4290
4492
  }));
@@ -4299,7 +4501,7 @@ var _Provider = class {
4299
4501
  async getBlockWithTransactions(idOrHeight) {
4300
4502
  let variables;
4301
4503
  if (typeof idOrHeight === "number") {
4302
- variables = { blockHeight: bn15(idOrHeight).toString(10) };
4504
+ variables = { blockHeight: bn16(idOrHeight).toString(10) };
4303
4505
  } else if (idOrHeight === "latest") {
4304
4506
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4305
4507
  } else {
@@ -4311,7 +4513,7 @@ var _Provider = class {
4311
4513
  }
4312
4514
  return {
4313
4515
  id: block.id,
4314
- height: bn15(block.header.height, 10),
4516
+ height: bn16(block.height, 10),
4315
4517
  time: block.header.time,
4316
4518
  transactionIds: block.transactions.map((tx) => tx.id),
4317
4519
  transactions: block.transactions.map(
@@ -4360,7 +4562,7 @@ var _Provider = class {
4360
4562
  contract: Address2.fromAddressOrString(contractId).toB256(),
4361
4563
  asset: hexlify12(assetId)
4362
4564
  });
4363
- return bn15(contractBalance.amount, 10);
4565
+ return bn16(contractBalance.amount, 10);
4364
4566
  }
4365
4567
  /**
4366
4568
  * Returns the balance for the given owner for the given asset ID.
@@ -4374,7 +4576,7 @@ var _Provider = class {
4374
4576
  owner: Address2.fromAddressOrString(owner).toB256(),
4375
4577
  assetId: hexlify12(assetId)
4376
4578
  });
4377
- return bn15(balance.amount, 10);
4579
+ return bn16(balance.amount, 10);
4378
4580
  }
4379
4581
  /**
4380
4582
  * Returns balances for the given owner.
@@ -4392,7 +4594,7 @@ var _Provider = class {
4392
4594
  const balances = result.balances.edges.map((edge) => edge.node);
4393
4595
  return balances.map((balance) => ({
4394
4596
  assetId: balance.assetId,
4395
- amount: bn15(balance.amount)
4597
+ amount: bn16(balance.amount)
4396
4598
  }));
4397
4599
  }
4398
4600
  /**
@@ -4414,15 +4616,15 @@ var _Provider = class {
4414
4616
  sender: message.sender,
4415
4617
  recipient: message.recipient,
4416
4618
  nonce: message.nonce,
4417
- amount: bn15(message.amount),
4619
+ amount: bn16(message.amount),
4418
4620
  data: message.data
4419
4621
  }),
4420
4622
  sender: Address2.fromAddressOrString(message.sender),
4421
4623
  recipient: Address2.fromAddressOrString(message.recipient),
4422
4624
  nonce: message.nonce,
4423
- amount: bn15(message.amount),
4625
+ amount: bn16(message.amount),
4424
4626
  data: InputMessageCoder.decodeData(message.data),
4425
- daHeight: bn15(message.daHeight)
4627
+ daHeight: bn16(message.daHeight)
4426
4628
  }));
4427
4629
  }
4428
4630
  /**
@@ -4475,44 +4677,60 @@ var _Provider = class {
4475
4677
  } = result.messageProof;
4476
4678
  return {
4477
4679
  messageProof: {
4478
- proofIndex: bn15(messageProof.proofIndex),
4680
+ proofIndex: bn16(messageProof.proofIndex),
4479
4681
  proofSet: messageProof.proofSet
4480
4682
  },
4481
4683
  blockProof: {
4482
- proofIndex: bn15(blockProof.proofIndex),
4684
+ proofIndex: bn16(blockProof.proofIndex),
4483
4685
  proofSet: blockProof.proofSet
4484
4686
  },
4485
4687
  messageBlockHeader: {
4486
4688
  id: messageBlockHeader.id,
4487
- daHeight: bn15(messageBlockHeader.daHeight),
4488
- transactionsCount: bn15(messageBlockHeader.transactionsCount),
4689
+ daHeight: bn16(messageBlockHeader.daHeight),
4690
+ transactionsCount: bn16(messageBlockHeader.transactionsCount),
4489
4691
  transactionsRoot: messageBlockHeader.transactionsRoot,
4490
- height: bn15(messageBlockHeader.height),
4692
+ height: bn16(messageBlockHeader.height),
4491
4693
  prevRoot: messageBlockHeader.prevRoot,
4492
4694
  time: messageBlockHeader.time,
4493
4695
  applicationHash: messageBlockHeader.applicationHash,
4494
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4495
- messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
4696
+ messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
4697
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4698
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4699
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4700
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4496
4701
  },
4497
4702
  commitBlockHeader: {
4498
4703
  id: commitBlockHeader.id,
4499
- daHeight: bn15(commitBlockHeader.daHeight),
4500
- transactionsCount: bn15(commitBlockHeader.transactionsCount),
4704
+ daHeight: bn16(commitBlockHeader.daHeight),
4705
+ transactionsCount: bn16(commitBlockHeader.transactionsCount),
4501
4706
  transactionsRoot: commitBlockHeader.transactionsRoot,
4502
- height: bn15(commitBlockHeader.height),
4707
+ height: bn16(commitBlockHeader.height),
4503
4708
  prevRoot: commitBlockHeader.prevRoot,
4504
4709
  time: commitBlockHeader.time,
4505
4710
  applicationHash: commitBlockHeader.applicationHash,
4506
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4507
- messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
4711
+ messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
4712
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4713
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4714
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4715
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4508
4716
  },
4509
4717
  sender: Address2.fromAddressOrString(sender),
4510
4718
  recipient: Address2.fromAddressOrString(recipient),
4511
4719
  nonce,
4512
- amount: bn15(amount),
4720
+ amount: bn16(amount),
4513
4721
  data
4514
4722
  };
4515
4723
  }
4724
+ async getLatestGasPrice() {
4725
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4726
+ return bn16(latestGasPrice.gasPrice);
4727
+ }
4728
+ async estimateGasPrice(blockHorizon) {
4729
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4730
+ blockHorizon: String(blockHorizon)
4731
+ });
4732
+ return bn16(estimateGasPrice.gasPrice);
4733
+ }
4516
4734
  /**
4517
4735
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4518
4736
  *
@@ -4532,10 +4750,10 @@ var _Provider = class {
4532
4750
  */
4533
4751
  async produceBlocks(amount, startTime) {
4534
4752
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4535
- blocksToProduce: bn15(amount).toString(10),
4753
+ blocksToProduce: bn16(amount).toString(10),
4536
4754
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4537
4755
  });
4538
- return bn15(latestBlockHeight);
4756
+ return bn16(latestBlockHeight);
4539
4757
  }
4540
4758
  // eslint-disable-next-line @typescript-eslint/require-await
4541
4759
  async getTransactionResponse(transactionId) {
@@ -4559,7 +4777,7 @@ __publicField(Provider, "nodeInfoCache", {});
4559
4777
 
4560
4778
  // src/providers/transaction-summary/get-transaction-summary.ts
4561
4779
  import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4562
- import { bn as bn16 } from "@fuel-ts/math";
4780
+ import { bn as bn17 } from "@fuel-ts/math";
4563
4781
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4564
4782
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4565
4783
  async function getTransactionSummary(params) {
@@ -4577,21 +4795,28 @@ async function getTransactionSummary(params) {
4577
4795
  arrayify12(gqlTransaction.rawPayload),
4578
4796
  0
4579
4797
  );
4580
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4798
+ let txReceipts = [];
4799
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4800
+ txReceipts = gqlTransaction.status.receipts;
4801
+ }
4802
+ const receipts = txReceipts.map(processGqlReceipt);
4581
4803
  const {
4582
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4804
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4583
4805
  } = provider.getChain();
4806
+ const gasPrice = await provider.getLatestGasPrice();
4584
4807
  const transactionInfo = assembleTransactionSummary({
4585
4808
  id: gqlTransaction.id,
4586
4809
  receipts,
4587
4810
  transaction: decodedTransaction,
4588
4811
  transactionBytes: arrayify12(gqlTransaction.rawPayload),
4589
4812
  gqlTransactionStatus: gqlTransaction.status,
4590
- gasPerByte: bn16(gasPerByte),
4591
- gasPriceFactor: bn16(gasPriceFactor),
4813
+ gasPerByte: bn17(gasPerByte),
4814
+ gasPriceFactor: bn17(gasPriceFactor),
4592
4815
  abiMap,
4593
4816
  maxInputs,
4594
- gasCosts
4817
+ gasCosts,
4818
+ maxGasPerTx,
4819
+ gasPrice
4595
4820
  });
4596
4821
  return {
4597
4822
  gqlTransaction,
@@ -4601,10 +4826,11 @@ async function getTransactionSummary(params) {
4601
4826
  async function getTransactionSummaryFromRequest(params) {
4602
4827
  const { provider, transactionRequest, abiMap } = params;
4603
4828
  const { receipts } = await provider.call(transactionRequest);
4604
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4829
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4605
4830
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4606
4831
  const transaction = transactionRequest.toTransaction();
4607
4832
  const transactionBytes = transactionRequest.toTransactionBytes();
4833
+ const gasPrice = await provider.getLatestGasPrice();
4608
4834
  const transactionSummary = assembleTransactionSummary({
4609
4835
  receipts,
4610
4836
  transaction,
@@ -4613,7 +4839,9 @@ async function getTransactionSummaryFromRequest(params) {
4613
4839
  gasPerByte,
4614
4840
  gasPriceFactor,
4615
4841
  maxInputs,
4616
- gasCosts
4842
+ gasCosts,
4843
+ maxGasPerTx,
4844
+ gasPrice
4617
4845
  });
4618
4846
  return transactionSummary;
4619
4847
  }
@@ -4622,13 +4850,18 @@ async function getTransactionsSummaries(params) {
4622
4850
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4623
4851
  const { edges, pageInfo } = transactionsByOwner;
4624
4852
  const {
4625
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4853
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4626
4854
  } = provider.getChain();
4855
+ const gasPrice = await provider.getLatestGasPrice();
4627
4856
  const transactions = edges.map((edge) => {
4628
4857
  const { node: gqlTransaction } = edge;
4629
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4858
+ const { id, rawPayload, status } = gqlTransaction;
4630
4859
  const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
4631
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4860
+ let txReceipts = [];
4861
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4862
+ txReceipts = gqlTransaction.status.receipts;
4863
+ }
4864
+ const receipts = txReceipts.map(processGqlReceipt);
4632
4865
  const transactionSummary = assembleTransactionSummary({
4633
4866
  id,
4634
4867
  receipts,
@@ -4639,7 +4872,9 @@ async function getTransactionsSummaries(params) {
4639
4872
  gasPerByte,
4640
4873
  gasPriceFactor,
4641
4874
  maxInputs,
4642
- gasCosts
4875
+ gasCosts,
4876
+ maxGasPerTx,
4877
+ gasPrice
4643
4878
  });
4644
4879
  const output = {
4645
4880
  gqlTransaction,
@@ -4971,36 +5206,33 @@ var Account = class extends AbstractAccount {
4971
5206
  * @param fee - The estimated transaction fee.
4972
5207
  * @returns A promise that resolves when the resources are added to the transaction.
4973
5208
  */
4974
- async fund(request, coinQuantities, fee) {
4975
- const updatedQuantities = addAmountToAsset({
4976
- amount: bn17(fee),
5209
+ async fund(request, params) {
5210
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5211
+ const txRequest = request;
5212
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5213
+ amount: bn18(fee),
4977
5214
  assetId: BaseAssetId3,
4978
- coinQuantities
5215
+ coinQuantities: requiredQuantities
4979
5216
  });
4980
5217
  const quantitiesDict = {};
4981
- updatedQuantities.forEach(({ amount, assetId }) => {
5218
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4982
5219
  quantitiesDict[assetId] = {
4983
5220
  required: amount,
4984
- owned: bn17(0)
5221
+ owned: bn18(0)
4985
5222
  };
4986
5223
  });
4987
- const cachedUtxos = [];
4988
- const cachedMessages = [];
4989
- const owner = this.address.toB256();
4990
- request.inputs.forEach((input) => {
5224
+ txRequest.inputs.forEach((input) => {
4991
5225
  const isResource = "amount" in input;
4992
5226
  if (isResource) {
4993
5227
  const isCoin2 = "owner" in input;
4994
5228
  if (isCoin2) {
4995
5229
  const assetId = String(input.assetId);
4996
- if (input.owner === owner && quantitiesDict[assetId]) {
4997
- const amount = bn17(input.amount);
5230
+ if (quantitiesDict[assetId]) {
5231
+ const amount = bn18(input.amount);
4998
5232
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4999
- cachedUtxos.push(input.id);
5000
5233
  }
5001
- } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
5234
+ } else if (input.amount && quantitiesDict[BaseAssetId3]) {
5002
5235
  quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
5003
- cachedMessages.push(input.nonce);
5004
5236
  }
5005
5237
  }
5006
5238
  });
@@ -5015,12 +5247,23 @@ var Account = class extends AbstractAccount {
5015
5247
  });
5016
5248
  const needsToBeFunded = missingQuantities.length;
5017
5249
  if (needsToBeFunded) {
5018
- const resources = await this.getResourcesToSpend(missingQuantities, {
5019
- messages: cachedMessages,
5020
- utxos: cachedUtxos
5021
- });
5022
- request.addResources(resources);
5250
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5251
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5252
+ txRequest.addResources(resources);
5253
+ }
5254
+ txRequest.shiftPredicateData();
5255
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5256
+ const requestToBeReEstimate = clone4(txRequest);
5257
+ if (addedSignatures) {
5258
+ Array.from({ length: addedSignatures }).forEach(
5259
+ () => requestToBeReEstimate.addEmptyWitness()
5260
+ );
5023
5261
  }
5262
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5263
+ transactionRequest: requestToBeReEstimate
5264
+ });
5265
+ txRequest.maxFee = maxFee;
5266
+ return txRequest;
5024
5267
  }
5025
5268
  /**
5026
5269
  * A helper that creates a transfer transaction request and returns it.
@@ -5028,28 +5271,25 @@ var Account = class extends AbstractAccount {
5028
5271
  * @param destination - The address of the destination.
5029
5272
  * @param amount - The amount of coins to transfer.
5030
5273
  * @param assetId - The asset ID of the coins to transfer.
5031
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5274
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5032
5275
  * @returns A promise that resolves to the prepared transaction request.
5033
5276
  */
5034
5277
  async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5035
- const { minGasPrice } = this.provider.getGasConfig();
5036
- const params = { gasPrice: minGasPrice, ...txParams };
5037
- const request = new ScriptTransactionRequest(params);
5278
+ const request = new ScriptTransactionRequest(txParams);
5038
5279
  request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
5039
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5280
+ const txCost = await this.provider.getTransactionCost(request, {
5040
5281
  estimateTxDependencies: true,
5041
5282
  resourcesOwner: this
5042
5283
  });
5043
- request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
5044
- request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
5045
- this.validateGas({
5046
- gasUsed,
5047
- gasPrice: request.gasPrice,
5048
- gasLimit: request.gasLimit,
5049
- minGasPrice
5050
- });
5051
- await this.fund(request, requiredQuantities, maxFee);
5052
- request.updatePredicateInputs(estimatedInputs);
5284
+ if ("gasLimit" in txParams) {
5285
+ this.validateGas({
5286
+ gasUsed: txCost.gasUsed,
5287
+ gasLimit: request.gasLimit
5288
+ });
5289
+ }
5290
+ request.gasLimit = txCost.gasUsed;
5291
+ request.maxFee = txCost.maxFee;
5292
+ await this.fund(request, txCost);
5053
5293
  return request;
5054
5294
  }
5055
5295
  /**
@@ -5062,7 +5302,7 @@ var Account = class extends AbstractAccount {
5062
5302
  * @returns A promise that resolves to the transaction response.
5063
5303
  */
5064
5304
  async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5065
- if (bn17(amount).lte(0)) {
5305
+ if (bn18(amount).lte(0)) {
5066
5306
  throw new FuelError15(
5067
5307
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5068
5308
  "Transfer amount must be a positive number."
@@ -5081,38 +5321,37 @@ var Account = class extends AbstractAccount {
5081
5321
  * @returns A promise that resolves to the transaction response.
5082
5322
  */
5083
5323
  async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5084
- if (bn17(amount).lte(0)) {
5324
+ if (bn18(amount).lte(0)) {
5085
5325
  throw new FuelError15(
5086
5326
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5087
5327
  "Transfer amount must be a positive number."
5088
5328
  );
5089
5329
  }
5090
5330
  const contractAddress = Address3.fromAddressOrString(contractId);
5091
- const { minGasPrice } = this.provider.getGasConfig();
5092
- const params = { gasPrice: minGasPrice, ...txParams };
5093
5331
  const { script, scriptData } = await assembleTransferToContractScript({
5094
5332
  hexlifiedContractId: contractAddress.toB256(),
5095
- amountToTransfer: bn17(amount),
5333
+ amountToTransfer: bn18(amount),
5096
5334
  assetId
5097
5335
  });
5098
5336
  const request = new ScriptTransactionRequest({
5099
- ...params,
5337
+ ...txParams,
5100
5338
  script,
5101
5339
  scriptData
5102
5340
  });
5103
5341
  request.addContractInputAndOutput(contractAddress);
5104
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5105
- request,
5106
- [{ amount: bn17(amount), assetId: String(assetId) }]
5107
- );
5108
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5109
- this.validateGas({
5110
- gasUsed,
5111
- gasPrice: request.gasPrice,
5112
- gasLimit: request.gasLimit,
5113
- minGasPrice
5342
+ const txCost = await this.provider.getTransactionCost(request, {
5343
+ resourcesOwner: this,
5344
+ quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
5114
5345
  });
5115
- await this.fund(request, requiredQuantities, maxFee);
5346
+ if (txParams.gasLimit) {
5347
+ this.validateGas({
5348
+ gasUsed: txCost.gasUsed,
5349
+ gasLimit: request.gasLimit
5350
+ });
5351
+ }
5352
+ request.gasLimit = txCost.gasUsed;
5353
+ request.maxFee = txCost.maxFee;
5354
+ await this.fund(request, txCost);
5116
5355
  return this.sendTransaction(request);
5117
5356
  }
5118
5357
  /**
@@ -5124,34 +5363,31 @@ var Account = class extends AbstractAccount {
5124
5363
  * @returns A promise that resolves to the transaction response.
5125
5364
  */
5126
5365
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5127
- const { minGasPrice } = this.provider.getGasConfig();
5128
5366
  const recipientAddress = Address3.fromAddressOrString(recipient);
5129
5367
  const recipientDataArray = arrayify14(
5130
5368
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5131
5369
  );
5132
5370
  const amountDataArray = arrayify14(
5133
- "0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
5371
+ "0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
5134
5372
  );
5135
5373
  const script = new Uint8Array([
5136
5374
  ...arrayify14(withdrawScript.bytes),
5137
5375
  ...recipientDataArray,
5138
5376
  ...amountDataArray
5139
5377
  ]);
5140
- const params = { script, gasPrice: minGasPrice, ...txParams };
5378
+ const params = { script, ...txParams };
5141
5379
  const request = new ScriptTransactionRequest(params);
5142
- const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
5143
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5144
- request,
5145
- forwardingQuantities
5146
- );
5147
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5148
- this.validateGas({
5149
- gasUsed,
5150
- gasPrice: request.gasPrice,
5151
- gasLimit: request.gasLimit,
5152
- minGasPrice
5153
- });
5154
- await this.fund(request, requiredQuantities, maxFee);
5380
+ const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
5381
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5382
+ if (txParams.gasLimit) {
5383
+ this.validateGas({
5384
+ gasUsed: txCost.gasUsed,
5385
+ gasLimit: request.gasLimit
5386
+ });
5387
+ }
5388
+ request.maxFee = txCost.maxFee;
5389
+ request.gasLimit = txCost.gasUsed;
5390
+ await this.fund(request, txCost);
5155
5391
  return this.sendTransaction(request);
5156
5392
  }
5157
5393
  async signMessage(message) {
@@ -5209,18 +5445,7 @@ var Account = class extends AbstractAccount {
5209
5445
  }
5210
5446
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5211
5447
  }
5212
- validateGas({
5213
- gasUsed,
5214
- gasPrice,
5215
- gasLimit,
5216
- minGasPrice
5217
- }) {
5218
- if (minGasPrice.gt(gasPrice)) {
5219
- throw new FuelError15(
5220
- ErrorCode15.GAS_PRICE_TOO_LOW,
5221
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5222
- );
5223
- }
5448
+ validateGas({ gasUsed, gasLimit }) {
5224
5449
  if (gasUsed.gt(gasLimit)) {
5225
5450
  throw new FuelError15(
5226
5451
  ErrorCode15.GAS_LIMIT_TOO_LOW,
@@ -5516,7 +5741,7 @@ var BaseWalletUnlocked = class extends Account {
5516
5741
  * @param transactionRequestLike - The transaction request to send.
5517
5742
  * @returns A promise that resolves to the TransactionResponse object.
5518
5743
  */
5519
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5744
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5520
5745
  const transactionRequest = transactionRequestify(transactionRequestLike);
5521
5746
  if (estimateTxDependencies) {
5522
5747
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5557,7 +5782,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5557
5782
  // src/hdwallet/hdwallet.ts
5558
5783
  import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5559
5784
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5560
- import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5785
+ import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5561
5786
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5562
5787
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5563
5788
 
@@ -8029,7 +8254,7 @@ var HDWallet = class {
8029
8254
  const IR = bytes.slice(32);
8030
8255
  if (privateKey) {
8031
8256
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8032
- const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
8257
+ const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
8033
8258
  return new HDWallet({
8034
8259
  privateKey: ki,
8035
8260
  chainCode: IR,
@@ -8718,7 +8943,7 @@ import {
8718
8943
  import { Address as Address9 } from "@fuel-ts/address";
8719
8944
  import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8720
8945
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8721
- import { ByteArrayCoder } from "@fuel-ts/transactions";
8946
+ import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
8722
8947
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8723
8948
 
8724
8949
  // src/predicate/utils/getPredicateRoot.ts
@@ -8777,15 +9002,10 @@ var Predicate = class extends Account {
8777
9002
  populateTransactionPredicateData(transactionRequestLike) {
8778
9003
  const request = transactionRequestify(transactionRequestLike);
8779
9004
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8780
- const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
8781
- if (placeholderIndex !== -1) {
8782
- request.removeWitness(placeholderIndex);
8783
- }
8784
- request.inputs.filter(isRequestInputResource).forEach((input) => {
8785
- if (isRequestInputResourceFromOwner(input, this.address)) {
8786
- input.predicate = this.bytes;
8787
- input.predicateData = this.getPredicateData(policies.length);
8788
- input.witnessIndex = 0;
9005
+ request.inputs?.forEach((input) => {
9006
+ if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
9007
+ input.predicate = hexlify19(this.bytes);
9008
+ input.predicateData = hexlify19(this.getPredicateData(policies.length));
8789
9009
  }
8790
9010
  });
8791
9011
  return request;
@@ -8800,8 +9020,7 @@ var Predicate = class extends Account {
8800
9020
  * @returns A promise that resolves to the prepared transaction request.
8801
9021
  */
8802
9022
  async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8803
- const request = await super.createTransfer(destination, amount, assetId, txParams);
8804
- return this.populateTransactionPredicateData(request);
9023
+ return super.createTransfer(destination, amount, assetId, txParams);
8805
9024
  }
8806
9025
  /**
8807
9026
  * Sends a transaction with the populated predicate data.
@@ -8809,9 +9028,9 @@ var Predicate = class extends Account {
8809
9028
  * @param transactionRequestLike - The transaction request-like object.
8810
9029
  * @returns A promise that resolves to the transaction response.
8811
9030
  */
8812
- sendTransaction(transactionRequestLike, options) {
8813
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8814
- return super.sendTransaction(transactionRequest, options);
9031
+ sendTransaction(transactionRequestLike) {
9032
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9033
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8815
9034
  }
8816
9035
  /**
8817
9036
  * Simulates a transaction with the populated predicate data.
@@ -8820,22 +9039,8 @@ var Predicate = class extends Account {
8820
9039
  * @returns A promise that resolves to the call result.
8821
9040
  */
8822
9041
  simulateTransaction(transactionRequestLike) {
8823
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8824
- return super.simulateTransaction(transactionRequest);
8825
- }
8826
- /**
8827
- * Retrieves resources satisfying the spend query for the account.
8828
- *
8829
- * @param quantities - Coins to retrieve.
8830
- * @param excludedIds - IDs of resources to be excluded from the query.
8831
- * @returns A promise that resolves to an array of Resources.
8832
- */
8833
- async getResourcesToSpend(quantities, excludedIds) {
8834
- const resources = await super.getResourcesToSpend(quantities, excludedIds);
8835
- return resources.map((resource) => ({
8836
- ...resource,
8837
- predicate: hexlify19(this.bytes)
8838
- }));
9042
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9043
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8839
9044
  }
8840
9045
  getPredicateData(policiesLength) {
8841
9046
  if (!this.predicateData.length) {
@@ -8881,6 +9086,25 @@ var Predicate = class extends Account {
8881
9086
  predicateInterface: abiInterface
8882
9087
  };
8883
9088
  }
9089
+ /**
9090
+ * Retrieves resources satisfying the spend query for the account.
9091
+ *
9092
+ * @param quantities - IDs of coins to exclude.
9093
+ * @param excludedIds - IDs of resources to be excluded from the query.
9094
+ * @returns A promise that resolves to an array of Resources.
9095
+ */
9096
+ async getResourcesToSpend(quantities, excludedIds) {
9097
+ const resources = await this.provider.getResourcesToSpend(
9098
+ this.address,
9099
+ quantities,
9100
+ excludedIds
9101
+ );
9102
+ return resources.map((resource) => ({
9103
+ ...resource,
9104
+ predicate: hexlify19(this.bytes),
9105
+ paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
9106
+ }));
9107
+ }
8884
9108
  /**
8885
9109
  * Sets the configurable constants for the predicate.
8886
9110
  *
@@ -8916,28 +9140,6 @@ var Predicate = class extends Account {
8916
9140
  }
8917
9141
  return mutatedBytes;
8918
9142
  }
8919
- /**
8920
- * Returns the index of the witness placeholder that was added to this predicate.
8921
- * If no witness placeholder was added, it returns -1.
8922
- * @param request - The transaction request.
8923
- * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
8924
- */
8925
- getIndexFromPlaceholderWitness(request) {
8926
- const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
8927
- let index = -1;
8928
- const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
8929
- if (hasEmptyPredicateInputs) {
8930
- index = hasEmptyPredicateInputs.witnessIndex;
8931
- const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
8932
- if (!allInputsAreEmpty) {
8933
- const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
8934
- if (wasFilledInputAddedFirst) {
8935
- index = -1;
8936
- }
8937
- }
8938
- }
8939
- return index;
8940
- }
8941
9143
  };
8942
9144
 
8943
9145
  // src/connectors/fuel.ts
@@ -9651,7 +9853,7 @@ export {
9651
9853
  WalletLocked,
9652
9854
  WalletManager,
9653
9855
  WalletUnlocked,
9654
- addAmountToAsset,
9856
+ addAmountToCoinQuantities,
9655
9857
  addOperation,
9656
9858
  assemblePanicError,
9657
9859
  assembleReceiptByType,
@@ -9660,10 +9862,10 @@ export {
9660
9862
  assets,
9661
9863
  buildBlockExplorerUrl,
9662
9864
  cacheFor,
9663
- cacheResources,
9865
+ cacheTxInputsFromOwner,
9866
+ calculateGasFee,
9664
9867
  calculateMetadataGasForTxCreate,
9665
9868
  calculateMetadataGasForTxScript,
9666
- calculatePriceWithFactor,
9667
9869
  calculateTransactionFee,
9668
9870
  coinQuantityfy,
9669
9871
  deferPromise,
@@ -9707,7 +9909,6 @@ export {
9707
9909
  getReceiptsMessageOut,
9708
9910
  getReceiptsTransferOut,
9709
9911
  getReceiptsWithMissingData,
9710
- getRequestInputResourceOwner,
9711
9912
  getTransactionStatusName,
9712
9913
  getTransactionSummary,
9713
9914
  getTransactionSummaryFromRequest,
@@ -9721,10 +9922,6 @@ export {
9721
9922
  isMessage,
9722
9923
  isRawCoin,
9723
9924
  isRawMessage,
9724
- isRequestInputCoin,
9725
- isRequestInputMessage,
9726
- isRequestInputResource,
9727
- isRequestInputResourceFromOwner,
9728
9925
  isType,
9729
9926
  isTypeCreate,
9730
9927
  isTypeMint,