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