@fuel-ts/account 0.0.0-rc-2130-20240422142413 → 0.0.0-rc-2021-20240422173414

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 (55) 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/hdwallet/hdwallet.d.ts.map +1 -1
  12. package/dist/index.global.js +3380 -1998
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +786 -518
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +663 -396
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/mnemonic/mnemonic.d.ts.map +1 -1
  19. package/dist/predicate/predicate.d.ts +10 -2
  20. package/dist/predicate/predicate.d.ts.map +1 -1
  21. package/dist/providers/__generated__/operations.d.ts +906 -324
  22. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  23. package/dist/providers/coin-quantity.d.ts +1 -1
  24. package/dist/providers/coin-quantity.d.ts.map +1 -1
  25. package/dist/providers/coin.d.ts +4 -2
  26. package/dist/providers/coin.d.ts.map +1 -1
  27. package/dist/providers/message.d.ts +7 -1
  28. package/dist/providers/message.d.ts.map +1 -1
  29. package/dist/providers/provider.d.ts +46 -27
  30. package/dist/providers/provider.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/create-transaction-request.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 +8 -25
  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/launchNode.d.ts.map +1 -1
  48. package/dist/test-utils.global.js +4111 -2491
  49. package/dist/test-utils.global.js.map +1 -1
  50. package/dist/test-utils.js +765 -515
  51. package/dist/test-utils.js.map +1 -1
  52. package/dist/test-utils.mjs +655 -405
  53. package/dist/test-utils.mjs.map +1 -1
  54. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  55. package/package.json +17 -16
package/dist/index.mjs CHANGED
@@ -32,8 +32,9 @@ import { Address as Address3 } from "@fuel-ts/address";
32
32
  import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
33
33
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
34
34
  import { AbstractAccount } from "@fuel-ts/interfaces";
35
- import { bn as bn17 } from "@fuel-ts/math";
35
+ import { bn as bn18 } from "@fuel-ts/math";
36
36
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
37
+ import { clone as clone4 } from "ramda";
37
38
 
38
39
  // src/providers/coin-quantity.ts
39
40
  import { BaseAssetId } from "@fuel-ts/address/configs";
@@ -42,24 +43,24 @@ import { hexlify } from "@fuel-ts/utils";
42
43
  var coinQuantityfy = (coinQuantityLike) => {
43
44
  let assetId;
44
45
  let amount;
45
- let max2;
46
+ let max;
46
47
  if (Array.isArray(coinQuantityLike)) {
47
48
  amount = coinQuantityLike[0];
48
49
  assetId = coinQuantityLike[1] ?? BaseAssetId;
49
- max2 = coinQuantityLike[2] ?? void 0;
50
+ max = coinQuantityLike[2] ?? void 0;
50
51
  } else {
51
52
  amount = coinQuantityLike.amount;
52
53
  assetId = coinQuantityLike.assetId ?? BaseAssetId;
53
- max2 = coinQuantityLike.max ?? void 0;
54
+ max = coinQuantityLike.max ?? void 0;
54
55
  }
55
56
  const bnAmount = bn(amount);
56
57
  return {
57
58
  assetId: hexlify(assetId),
58
59
  amount: bnAmount.lt(1) ? bn(1) : bnAmount,
59
- max: max2 ? bn(max2) : void 0
60
+ max: max ? bn(max) : void 0
60
61
  };
61
62
  };
62
- var addAmountToAsset = (params) => {
63
+ var addAmountToCoinQuantities = (params) => {
63
64
  const { amount, assetId } = params;
64
65
  const coinQuantities = [...params.coinQuantities];
65
66
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -74,9 +75,9 @@ var addAmountToAsset = (params) => {
74
75
  // src/providers/provider.ts
75
76
  import { Address as Address2 } from "@fuel-ts/address";
76
77
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
77
- import { BN, bn as bn15, max } from "@fuel-ts/math";
78
+ import { BN, bn as bn16 } from "@fuel-ts/math";
78
79
  import {
79
- InputType as InputType6,
80
+ InputType as InputType7,
80
81
  TransactionType as TransactionType8,
81
82
  InputMessageCoder,
82
83
  TransactionCoder as TransactionCoder5
@@ -84,6 +85,7 @@ import {
84
85
  import { arrayify as arrayify11, hexlify as hexlify12, DateTime as DateTime2 } from "@fuel-ts/utils";
85
86
  import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
86
87
  import { equalBytes } from "@noble/curves/abstract/utils";
88
+ import { Network } from "ethers";
87
89
  import { GraphQLClient } from "graphql-request";
88
90
  import { clone as clone3 } from "ramda";
89
91
 
@@ -91,14 +93,10 @@ import { clone as clone3 } from "ramda";
91
93
  import gql from "graphql-tag";
92
94
  var ReceiptFragmentFragmentDoc = gql`
93
95
  fragment receiptFragment on Receipt {
94
- contract {
95
- id
96
- }
96
+ id
97
97
  pc
98
98
  is
99
- to {
100
- id
101
- }
99
+ to
102
100
  toAddress
103
101
  amount
104
102
  assetId
@@ -136,10 +134,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
136
134
  id
137
135
  }
138
136
  time
137
+ receipts {
138
+ ...receiptFragment
139
+ }
139
140
  programState {
140
141
  returnType
141
142
  data
142
143
  }
144
+ receipts {
145
+ ...receiptFragment
146
+ }
143
147
  }
144
148
  ... on FailureStatus {
145
149
  block {
@@ -147,26 +151,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
147
151
  }
148
152
  time
149
153
  reason
154
+ receipts {
155
+ ...receiptFragment
156
+ }
150
157
  }
151
158
  ... on SqueezedOutStatus {
152
159
  reason
153
160
  }
154
161
  }
155
- `;
162
+ ${ReceiptFragmentFragmentDoc}`;
156
163
  var TransactionFragmentFragmentDoc = gql`
157
164
  fragment transactionFragment on Transaction {
158
165
  id
159
166
  rawPayload
160
- gasPrice
161
- receipts {
162
- ...receiptFragment
163
- }
164
167
  status {
165
168
  ...transactionStatusFragment
166
169
  }
167
170
  }
168
- ${ReceiptFragmentFragmentDoc}
169
- ${TransactionStatusFragmentFragmentDoc}`;
171
+ ${TransactionStatusFragmentFragmentDoc}`;
170
172
  var InputEstimatePredicatesFragmentFragmentDoc = gql`
171
173
  fragment inputEstimatePredicatesFragment on Input {
172
174
  ... on InputCoin {
@@ -184,6 +186,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
184
186
  }
185
187
  }
186
188
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
189
+ var DryRunFailureStatusFragmentFragmentDoc = gql`
190
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
191
+ reason
192
+ programState {
193
+ returnType
194
+ data
195
+ }
196
+ }
197
+ `;
198
+ var DryRunSuccessStatusFragmentFragmentDoc = gql`
199
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
200
+ programState {
201
+ returnType
202
+ data
203
+ }
204
+ }
205
+ `;
206
+ var DryRunTransactionStatusFragmentFragmentDoc = gql`
207
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
208
+ ... on DryRunFailureStatus {
209
+ ...dryRunFailureStatusFragment
210
+ }
211
+ ... on DryRunSuccessStatus {
212
+ ...dryRunSuccessStatusFragment
213
+ }
214
+ }
215
+ ${DryRunFailureStatusFragmentFragmentDoc}
216
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
217
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
218
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
219
+ id
220
+ status {
221
+ ...dryRunTransactionStatusFragment
222
+ }
223
+ receipts {
224
+ ...receiptFragment
225
+ }
226
+ }
227
+ ${DryRunTransactionStatusFragmentFragmentDoc}
228
+ ${ReceiptFragmentFragmentDoc}`;
187
229
  var CoinFragmentFragmentDoc = gql`
188
230
  fragment coinFragment on Coin {
189
231
  __typename
@@ -191,7 +233,6 @@ var CoinFragmentFragmentDoc = gql`
191
233
  owner
192
234
  amount
193
235
  assetId
194
- maturity
195
236
  blockCreated
196
237
  txCreatedIdx
197
238
  }
@@ -230,26 +271,32 @@ var MessageProofFragmentFragmentDoc = gql`
230
271
  messageBlockHeader {
231
272
  id
232
273
  daHeight
274
+ consensusParametersVersion
275
+ stateTransitionBytecodeVersion
233
276
  transactionsCount
277
+ messageReceiptCount
234
278
  transactionsRoot
279
+ messageOutboxRoot
280
+ eventInboxRoot
235
281
  height
236
282
  prevRoot
237
283
  time
238
284
  applicationHash
239
- messageReceiptRoot
240
- messageReceiptCount
241
285
  }
242
286
  commitBlockHeader {
243
287
  id
244
288
  daHeight
289
+ consensusParametersVersion
290
+ stateTransitionBytecodeVersion
245
291
  transactionsCount
292
+ messageReceiptCount
246
293
  transactionsRoot
294
+ messageOutboxRoot
295
+ eventInboxRoot
247
296
  height
248
297
  prevRoot
249
298
  time
250
299
  applicationHash
251
- messageReceiptRoot
252
- messageReceiptCount
253
300
  }
254
301
  sender
255
302
  recipient
@@ -268,8 +315,8 @@ var BalanceFragmentFragmentDoc = gql`
268
315
  var BlockFragmentFragmentDoc = gql`
269
316
  fragment blockFragment on Block {
270
317
  id
318
+ height
271
319
  header {
272
- height
273
320
  time
274
321
  }
275
322
  transactions {
@@ -327,6 +374,11 @@ var DependentCostFragmentFragmentDoc = gql`
327
374
  `;
328
375
  var GasCostsFragmentFragmentDoc = gql`
329
376
  fragment GasCostsFragment on GasCosts {
377
+ version {
378
+ ... on Version {
379
+ value
380
+ }
381
+ }
330
382
  add
331
383
  addi
332
384
  aloc
@@ -339,7 +391,6 @@ var GasCostsFragmentFragmentDoc = gql`
339
391
  cb
340
392
  cfei
341
393
  cfsi
342
- croo
343
394
  div
344
395
  divi
345
396
  ecr1
@@ -422,6 +473,9 @@ var GasCostsFragmentFragmentDoc = gql`
422
473
  ccp {
423
474
  ...DependentCostFragment
424
475
  }
476
+ croo {
477
+ ...DependentCostFragment
478
+ }
425
479
  csiz {
426
480
  ...DependentCostFragment
427
481
  }
@@ -481,6 +535,11 @@ var GasCostsFragmentFragmentDoc = gql`
481
535
  ${DependentCostFragmentFragmentDoc}`;
482
536
  var ConsensusParametersFragmentFragmentDoc = gql`
483
537
  fragment consensusParametersFragment on ConsensusParameters {
538
+ version {
539
+ ... on Version {
540
+ value
541
+ }
542
+ }
484
543
  txParams {
485
544
  ...TxParametersFragment
486
545
  }
@@ -540,18 +599,9 @@ var NodeInfoFragmentFragmentDoc = gql`
540
599
  fragment nodeInfoFragment on NodeInfo {
541
600
  utxoValidation
542
601
  vmBacktrace
543
- minGasPrice
544
602
  maxTx
545
603
  maxDepth
546
604
  nodeVersion
547
- peers {
548
- id
549
- addresses
550
- clientVersion
551
- blockHeight
552
- lastHeartbeatMs
553
- appScore
554
- }
555
605
  }
556
606
  `;
557
607
  var GetVersionDocument = gql`
@@ -586,13 +636,9 @@ var GetTransactionWithReceiptsDocument = gql`
586
636
  query getTransactionWithReceipts($transactionId: TransactionId!) {
587
637
  transaction(id: $transactionId) {
588
638
  ...transactionFragment
589
- receipts {
590
- ...receiptFragment
591
- }
592
639
  }
593
640
  }
594
- ${TransactionFragmentFragmentDoc}
595
- ${ReceiptFragmentFragmentDoc}`;
641
+ ${TransactionFragmentFragmentDoc}`;
596
642
  var GetTransactionsDocument = gql`
597
643
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
598
644
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -720,6 +766,20 @@ var GetBalanceDocument = gql`
720
766
  }
721
767
  }
722
768
  ${BalanceFragmentFragmentDoc}`;
769
+ var GetLatestGasPriceDocument = gql`
770
+ query getLatestGasPrice {
771
+ latestGasPrice {
772
+ gasPrice
773
+ }
774
+ }
775
+ `;
776
+ var EstimateGasPriceDocument = gql`
777
+ query estimateGasPrice($blockHorizon: U32!) {
778
+ estimateGasPrice(blockHorizon: $blockHorizon) {
779
+ gasPrice
780
+ }
781
+ }
782
+ `;
723
783
  var GetBalancesDocument = gql`
724
784
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
725
785
  balances(
@@ -774,12 +834,12 @@ var GetMessageStatusDocument = gql`
774
834
  }
775
835
  `;
776
836
  var DryRunDocument = gql`
777
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
778
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
779
- ...receiptFragment
837
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
838
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
839
+ ...dryRunTransactionExecutionStatusFragment
780
840
  }
781
841
  }
782
- ${ReceiptFragmentFragmentDoc}`;
842
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
783
843
  var SubmitDocument = gql`
784
844
  mutation submit($encodedTransaction: HexString!) {
785
845
  submit(tx: $encodedTransaction) {
@@ -862,6 +922,12 @@ function getSdk(requester) {
862
922
  getBalance(variables, options) {
863
923
  return requester(GetBalanceDocument, variables, options);
864
924
  },
925
+ getLatestGasPrice(variables, options) {
926
+ return requester(GetLatestGasPriceDocument, variables, options);
927
+ },
928
+ estimateGasPrice(variables, options) {
929
+ return requester(EstimateGasPriceDocument, variables, options);
930
+ },
865
931
  getBalances(variables, options) {
866
932
  return requester(GetBalancesDocument, variables, options);
867
933
  },
@@ -1055,10 +1121,9 @@ var inputify = (value) => {
1055
1121
  txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
1056
1122
  },
1057
1123
  witnessIndex: value.witnessIndex,
1058
- maturity: value.maturity ?? 0,
1059
1124
  predicateGasUsed: bn2(value.predicateGasUsed),
1060
- predicateLength: predicate.length,
1061
- predicateDataLength: predicateData.length,
1125
+ predicateLength: bn2(predicate.length),
1126
+ predicateDataLength: bn2(predicateData.length),
1062
1127
  predicate: hexlify3(predicate),
1063
1128
  predicateData: hexlify3(predicateData)
1064
1129
  };
@@ -1089,8 +1154,8 @@ var inputify = (value) => {
1089
1154
  nonce: hexlify3(value.nonce),
1090
1155
  witnessIndex: value.witnessIndex,
1091
1156
  predicateGasUsed: bn2(value.predicateGasUsed),
1092
- predicateLength: predicate.length,
1093
- predicateDataLength: predicateData.length,
1157
+ predicateLength: bn2(predicate.length),
1158
+ predicateDataLength: bn2(predicateData.length),
1094
1159
  predicate: hexlify3(predicate),
1095
1160
  predicateData: hexlify3(predicateData),
1096
1161
  data: hexlify3(data),
@@ -1220,8 +1285,8 @@ function assembleReceiptByType(receipt) {
1220
1285
  case "CALL" /* Call */: {
1221
1286
  const callReceipt = {
1222
1287
  type: ReceiptType.Call,
1223
- from: hexOrZero(receipt.contract?.id),
1224
- to: hexOrZero(receipt?.to?.id),
1288
+ from: hexOrZero(receipt.id || receipt.contractId),
1289
+ to: hexOrZero(receipt?.to),
1225
1290
  amount: bn4(receipt.amount),
1226
1291
  assetId: hexOrZero(receipt.assetId),
1227
1292
  gas: bn4(receipt.gas),
@@ -1235,7 +1300,7 @@ function assembleReceiptByType(receipt) {
1235
1300
  case "RETURN" /* Return */: {
1236
1301
  const returnReceipt = {
1237
1302
  type: ReceiptType.Return,
1238
- id: hexOrZero(receipt.contract?.id),
1303
+ id: hexOrZero(receipt.id || receipt.contractId),
1239
1304
  val: bn4(receipt.val),
1240
1305
  pc: bn4(receipt.pc),
1241
1306
  is: bn4(receipt.is)
@@ -1245,7 +1310,7 @@ function assembleReceiptByType(receipt) {
1245
1310
  case "RETURN_DATA" /* ReturnData */: {
1246
1311
  const returnDataReceipt = {
1247
1312
  type: ReceiptType.ReturnData,
1248
- id: hexOrZero(receipt.contract?.id),
1313
+ id: hexOrZero(receipt.id || receipt.contractId),
1249
1314
  ptr: bn4(receipt.ptr),
1250
1315
  len: bn4(receipt.len),
1251
1316
  digest: hexOrZero(receipt.digest),
@@ -1257,7 +1322,7 @@ function assembleReceiptByType(receipt) {
1257
1322
  case "PANIC" /* Panic */: {
1258
1323
  const panicReceipt = {
1259
1324
  type: ReceiptType.Panic,
1260
- id: hexOrZero(receipt.contract?.id),
1325
+ id: hexOrZero(receipt.id),
1261
1326
  reason: bn4(receipt.reason),
1262
1327
  pc: bn4(receipt.pc),
1263
1328
  is: bn4(receipt.is),
@@ -1268,7 +1333,7 @@ function assembleReceiptByType(receipt) {
1268
1333
  case "REVERT" /* Revert */: {
1269
1334
  const revertReceipt = {
1270
1335
  type: ReceiptType.Revert,
1271
- id: hexOrZero(receipt.contract?.id),
1336
+ id: hexOrZero(receipt.id || receipt.contractId),
1272
1337
  val: bn4(receipt.ra),
1273
1338
  pc: bn4(receipt.pc),
1274
1339
  is: bn4(receipt.is)
@@ -1278,7 +1343,7 @@ function assembleReceiptByType(receipt) {
1278
1343
  case "LOG" /* Log */: {
1279
1344
  const logReceipt = {
1280
1345
  type: ReceiptType.Log,
1281
- id: hexOrZero(receipt.contract?.id),
1346
+ id: hexOrZero(receipt.id || receipt.contractId),
1282
1347
  val0: bn4(receipt.ra),
1283
1348
  val1: bn4(receipt.rb),
1284
1349
  val2: bn4(receipt.rc),
@@ -1291,7 +1356,7 @@ function assembleReceiptByType(receipt) {
1291
1356
  case "LOG_DATA" /* LogData */: {
1292
1357
  const logDataReceipt = {
1293
1358
  type: ReceiptType.LogData,
1294
- id: hexOrZero(receipt.contract?.id),
1359
+ id: hexOrZero(receipt.id || receipt.contractId),
1295
1360
  val0: bn4(receipt.ra),
1296
1361
  val1: bn4(receipt.rb),
1297
1362
  ptr: bn4(receipt.ptr),
@@ -1305,8 +1370,8 @@ function assembleReceiptByType(receipt) {
1305
1370
  case "TRANSFER" /* Transfer */: {
1306
1371
  const transferReceipt = {
1307
1372
  type: ReceiptType.Transfer,
1308
- from: hexOrZero(receipt.contract?.id),
1309
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1373
+ from: hexOrZero(receipt.id || receipt.contractId),
1374
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1310
1375
  amount: bn4(receipt.amount),
1311
1376
  assetId: hexOrZero(receipt.assetId),
1312
1377
  pc: bn4(receipt.pc),
@@ -1317,8 +1382,8 @@ function assembleReceiptByType(receipt) {
1317
1382
  case "TRANSFER_OUT" /* TransferOut */: {
1318
1383
  const transferOutReceipt = {
1319
1384
  type: ReceiptType.TransferOut,
1320
- from: hexOrZero(receipt.contract?.id),
1321
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1385
+ from: hexOrZero(receipt.id || receipt.contractId),
1386
+ to: hexOrZero(receipt.toAddress || receipt.to),
1322
1387
  amount: bn4(receipt.amount),
1323
1388
  assetId: hexOrZero(receipt.assetId),
1324
1389
  pc: bn4(receipt.pc),
@@ -1361,7 +1426,7 @@ function assembleReceiptByType(receipt) {
1361
1426
  return receiptMessageOut;
1362
1427
  }
1363
1428
  case "MINT" /* Mint */: {
1364
- const contractId = hexOrZero(receipt.contract?.id);
1429
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1365
1430
  const subId = hexOrZero(receipt.subId);
1366
1431
  const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
1367
1432
  const mintReceipt = {
@@ -1376,7 +1441,7 @@ function assembleReceiptByType(receipt) {
1376
1441
  return mintReceipt;
1377
1442
  }
1378
1443
  case "BURN" /* Burn */: {
1379
- const contractId = hexOrZero(receipt.contract?.id);
1444
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1380
1445
  const subId = hexOrZero(receipt.subId);
1381
1446
  const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
1382
1447
  const burnReceipt = {
@@ -1461,7 +1526,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1461
1526
  import { bn as bn5 } from "@fuel-ts/math";
1462
1527
  import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
1463
1528
  import { arrayify as arrayify3 } from "@fuel-ts/utils";
1464
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1465
1529
  var getGasUsedFromReceipts = (receipts) => {
1466
1530
  const scriptResult = receipts.filter(
1467
1531
  (receipt) => receipt.type === ReceiptType2.ScriptResult
@@ -1482,18 +1546,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1482
1546
  }
1483
1547
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1484
1548
  const witnessCache = [];
1485
- const totalGas = inputs.reduce((total, input) => {
1549
+ const chargeableInputs = inputs.filter((input) => {
1550
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1551
+ if (isCoinOrMessage) {
1552
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1553
+ return true;
1554
+ }
1555
+ if (!witnessCache.includes(input.witnessIndex)) {
1556
+ witnessCache.push(input.witnessIndex);
1557
+ return true;
1558
+ }
1559
+ }
1560
+ return false;
1561
+ });
1562
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1563
+ const totalGas = chargeableInputs.reduce((total, input) => {
1486
1564
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1487
1565
  return total.add(
1488
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1566
+ vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1489
1567
  );
1490
1568
  }
1491
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1492
- witnessCache.push(input.witnessIndex);
1493
- return total.add(gasCosts.ecr1);
1494
- }
1495
- return total;
1496
- }, bn5());
1569
+ return total.add(gasCosts.ecr1);
1570
+ }, bn5(0));
1497
1571
  return totalGas;
1498
1572
  }
1499
1573
  function getMinGas(params) {
@@ -1505,12 +1579,20 @@ function getMinGas(params) {
1505
1579
  return minGas;
1506
1580
  }
1507
1581
  function getMaxGas(params) {
1508
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
1582
+ const {
1583
+ gasPerByte,
1584
+ witnessesLength,
1585
+ witnessLimit,
1586
+ minGas,
1587
+ gasLimit = bn5(0),
1588
+ maxGasPerTx
1589
+ } = params;
1509
1590
  let remainingAllowedWitnessGas = bn5(0);
1510
1591
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1511
1592
  remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1512
1593
  }
1513
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1594
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1595
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1514
1596
  }
1515
1597
  function calculateMetadataGasForTxCreate({
1516
1598
  gasCosts,
@@ -1532,6 +1614,10 @@ function calculateMetadataGasForTxScript({
1532
1614
  }) {
1533
1615
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1534
1616
  }
1617
+ var calculateGasFee = (params) => {
1618
+ const { gas, gasPrice, priceFactor, tip } = params;
1619
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1620
+ };
1535
1621
 
1536
1622
  // src/providers/utils/json.ts
1537
1623
  import { hexlify as hexlify5 } from "@fuel-ts/utils";
@@ -1688,7 +1774,7 @@ var witnessify = (value) => {
1688
1774
  // src/providers/transaction-request/transaction-request.ts
1689
1775
  var BaseTransactionRequest = class {
1690
1776
  /** Gas price for transaction */
1691
- gasPrice;
1777
+ tip;
1692
1778
  /** Block until which tx cannot be included */
1693
1779
  maturity;
1694
1780
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1707,7 +1793,7 @@ var BaseTransactionRequest = class {
1707
1793
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1708
1794
  */
1709
1795
  constructor({
1710
- gasPrice,
1796
+ tip,
1711
1797
  maturity,
1712
1798
  maxFee,
1713
1799
  witnessLimit,
@@ -1715,7 +1801,7 @@ var BaseTransactionRequest = class {
1715
1801
  outputs,
1716
1802
  witnesses
1717
1803
  } = {}) {
1718
- this.gasPrice = bn7(gasPrice);
1804
+ this.tip = bn7(tip);
1719
1805
  this.maturity = maturity ?? 0;
1720
1806
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1721
1807
  this.maxFee = maxFee ? bn7(maxFee) : void 0;
@@ -1726,9 +1812,9 @@ var BaseTransactionRequest = class {
1726
1812
  static getPolicyMeta(req) {
1727
1813
  let policyTypes = 0;
1728
1814
  const policies = [];
1729
- if (req.gasPrice) {
1730
- policyTypes += PolicyType.GasPrice;
1731
- policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
1815
+ if (req.tip) {
1816
+ policyTypes += PolicyType.Tip;
1817
+ policies.push({ data: req.tip, type: PolicyType.Tip });
1732
1818
  }
1733
1819
  if (req.witnessLimit) {
1734
1820
  policyTypes += PolicyType.WitnessLimit;
@@ -1915,10 +2001,10 @@ var BaseTransactionRequest = class {
1915
2001
  * @param predicate - Predicate bytes.
1916
2002
  * @param predicateData - Predicate data bytes.
1917
2003
  */
1918
- addCoinInput(coin, predicate) {
2004
+ addCoinInput(coin) {
1919
2005
  const { assetId, owner, amount } = coin;
1920
2006
  let witnessIndex;
1921
- if (predicate) {
2007
+ if (coin.predicate) {
1922
2008
  witnessIndex = 0;
1923
2009
  } else {
1924
2010
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1933,8 +2019,7 @@ var BaseTransactionRequest = class {
1933
2019
  amount,
1934
2020
  assetId,
1935
2021
  txPointer: "0x00000000000000000000000000000000",
1936
- witnessIndex,
1937
- predicate: predicate?.bytes
2022
+ witnessIndex
1938
2023
  };
1939
2024
  this.pushInput(input);
1940
2025
  this.addChangeOutput(owner, assetId);
@@ -1947,11 +2032,11 @@ var BaseTransactionRequest = class {
1947
2032
  * @param predicate - Predicate bytes.
1948
2033
  * @param predicateData - Predicate data bytes.
1949
2034
  */
1950
- addMessageInput(message, predicate) {
2035
+ addMessageInput(message) {
1951
2036
  const { recipient, sender, amount } = message;
1952
2037
  const assetId = BaseAssetId2;
1953
2038
  let witnessIndex;
1954
- if (predicate) {
2039
+ if (message.predicate) {
1955
2040
  witnessIndex = 0;
1956
2041
  } else {
1957
2042
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1965,8 +2050,7 @@ var BaseTransactionRequest = class {
1965
2050
  sender: sender.toB256(),
1966
2051
  recipient: recipient.toB256(),
1967
2052
  amount,
1968
- witnessIndex,
1969
- predicate: predicate?.bytes
2053
+ witnessIndex
1970
2054
  };
1971
2055
  this.pushInput(input);
1972
2056
  this.addChangeOutput(recipient, assetId);
@@ -1997,32 +2081,6 @@ var BaseTransactionRequest = class {
1997
2081
  resources.forEach((resource) => this.addResource(resource));
1998
2082
  return this;
1999
2083
  }
2000
- /**
2001
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2002
- * outputs from the related assetIds.
2003
- *
2004
- * @param resources - The resources to add.
2005
- * @returns This transaction.
2006
- */
2007
- addPredicateResource(resource, predicate) {
2008
- if (isCoin(resource)) {
2009
- this.addCoinInput(resource, predicate);
2010
- } else {
2011
- this.addMessageInput(resource, predicate);
2012
- }
2013
- return this;
2014
- }
2015
- /**
2016
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2017
- * from the related assetIds.
2018
- *
2019
- * @param resources - The resources to add.
2020
- * @returns This transaction.
2021
- */
2022
- addPredicateResources(resources, predicate) {
2023
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2024
- return this;
2025
- }
2026
2084
  /**
2027
2085
  * Adds a coin output to the transaction.
2028
2086
  *
@@ -2102,7 +2160,7 @@ var BaseTransactionRequest = class {
2102
2160
  }
2103
2161
  calculateMaxGas(chainInfo, minGas) {
2104
2162
  const { consensusParameters } = chainInfo;
2105
- const { gasPerByte } = consensusParameters;
2163
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2106
2164
  const witnessesLength = this.toTransaction().witnesses.reduce(
2107
2165
  (acc, wit) => acc + wit.dataLength,
2108
2166
  0
@@ -2111,7 +2169,8 @@ var BaseTransactionRequest = class {
2111
2169
  gasPerByte,
2112
2170
  minGas,
2113
2171
  witnessesLength,
2114
- witnessLimit: this.witnessLimit
2172
+ witnessLimit: this.witnessLimit,
2173
+ maxGasPerTx
2115
2174
  });
2116
2175
  }
2117
2176
  /**
@@ -2129,17 +2188,20 @@ var BaseTransactionRequest = class {
2129
2188
  });
2130
2189
  const updateAssetInput = (assetId, quantity) => {
2131
2190
  const assetInput = findAssetInput(assetId);
2191
+ let usedQuantity = quantity;
2192
+ if (assetId === BaseAssetId2) {
2193
+ usedQuantity = bn7("1000000000000000000");
2194
+ }
2132
2195
  if (assetInput && "assetId" in assetInput) {
2133
2196
  assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2134
- assetInput.amount = quantity;
2197
+ assetInput.amount = usedQuantity;
2135
2198
  } else {
2136
2199
  this.addResources([
2137
2200
  {
2138
2201
  id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2139
- amount: quantity,
2202
+ amount: usedQuantity,
2140
2203
  assetId,
2141
2204
  owner: resourcesOwner || Address.fromRandom(),
2142
- maturity: 0,
2143
2205
  blockCreated: bn7(1),
2144
2206
  txCreatedIdx: bn7(1)
2145
2207
  }
@@ -2171,7 +2233,7 @@ var BaseTransactionRequest = class {
2171
2233
  toJSON() {
2172
2234
  return normalizeJSON(this);
2173
2235
  }
2174
- updatePredicateInputs(inputs) {
2236
+ updatePredicateGasUsed(inputs) {
2175
2237
  this.inputs.forEach((i) => {
2176
2238
  let correspondingInput;
2177
2239
  switch (i.type) {
@@ -2193,6 +2255,15 @@ var BaseTransactionRequest = class {
2193
2255
  }
2194
2256
  });
2195
2257
  }
2258
+ shiftPredicateData() {
2259
+ this.inputs.forEach((input) => {
2260
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2261
+ input.predicateData = input.paddPredicateData(
2262
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2263
+ );
2264
+ }
2265
+ });
2266
+ }
2196
2267
  };
2197
2268
 
2198
2269
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2339,9 +2410,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2339
2410
  return {
2340
2411
  type: TransactionType3.Create,
2341
2412
  ...baseTransaction,
2342
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2343
2413
  bytecodeWitnessIndex,
2344
- storageSlotsCount: storageSlots.length,
2414
+ storageSlotsCount: bn9(storageSlots.length),
2345
2415
  salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
2346
2416
  storageSlots
2347
2417
  };
@@ -2464,8 +2534,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2464
2534
  type: TransactionType4.Script,
2465
2535
  scriptGasLimit: this.gasLimit,
2466
2536
  ...super.getBaseTransaction(),
2467
- scriptLength: script.length,
2468
- scriptDataLength: scriptData.length,
2537
+ scriptLength: bn10(script.length),
2538
+ scriptDataLength: bn10(scriptData.length),
2469
2539
  receiptsRoot: ZeroBytes327,
2470
2540
  script: hexlify10(script),
2471
2541
  scriptData: hexlify10(scriptData)
@@ -2529,7 +2599,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2529
2599
  }
2530
2600
  calculateMaxGas(chainInfo, minGas) {
2531
2601
  const { consensusParameters } = chainInfo;
2532
- const { gasPerByte } = consensusParameters;
2602
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2533
2603
  const witnessesLength = this.toTransaction().witnesses.reduce(
2534
2604
  (acc, wit) => acc + wit.dataLength,
2535
2605
  0
@@ -2539,7 +2609,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2539
2609
  minGas,
2540
2610
  witnessesLength,
2541
2611
  witnessLimit: this.witnessLimit,
2542
- gasLimit: this.gasLimit
2612
+ gasLimit: this.gasLimit,
2613
+ maxGasPerTx
2543
2614
  });
2544
2615
  }
2545
2616
  /**
@@ -2596,7 +2667,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2596
2667
 
2597
2668
  // src/providers/transaction-request/utils.ts
2598
2669
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2599
- import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2670
+ import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2600
2671
  var transactionRequestify = (obj) => {
2601
2672
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2602
2673
  return obj;
@@ -2614,14 +2685,31 @@ var transactionRequestify = (obj) => {
2614
2685
  }
2615
2686
  }
2616
2687
  };
2688
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2689
+ (acc, input) => {
2690
+ if (input.type === InputType5.Coin && input.owner === owner) {
2691
+ acc.utxos.push(input.id);
2692
+ }
2693
+ if (input.type === InputType5.Message && input.recipient === owner) {
2694
+ acc.messages.push(input.nonce);
2695
+ }
2696
+ return acc;
2697
+ },
2698
+ {
2699
+ utxos: [],
2700
+ messages: []
2701
+ }
2702
+ );
2617
2703
 
2618
2704
  // src/providers/transaction-response/transaction-response.ts
2619
2705
  import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2620
- import { bn as bn14 } from "@fuel-ts/math";
2706
+ import { bn as bn15 } from "@fuel-ts/math";
2621
2707
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2622
2708
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2623
2709
 
2624
2710
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2711
+ import { bn as bn14 } from "@fuel-ts/math";
2712
+ import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2625
2713
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2626
2714
 
2627
2715
  // src/providers/transaction-summary/calculate-transaction-fee.ts
@@ -2630,9 +2718,10 @@ import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, Trans
2630
2718
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2631
2719
  var calculateTransactionFee = (params) => {
2632
2720
  const {
2633
- gasUsed,
2721
+ gasPrice,
2634
2722
  rawPayload,
2635
- consensusParameters: { gasCosts, feeParams }
2723
+ tip,
2724
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2636
2725
  } = params;
2637
2726
  const gasPerByte = bn11(feeParams.gasPerByte);
2638
2727
  const gasPriceFactor = bn11(feeParams.gasPriceFactor);
@@ -2642,8 +2731,7 @@ var calculateTransactionFee = (params) => {
2642
2731
  return {
2643
2732
  fee: bn11(0),
2644
2733
  minFee: bn11(0),
2645
- maxFee: bn11(0),
2646
- feeFromGasUsed: bn11(0)
2734
+ maxFee: bn11(0)
2647
2735
  };
2648
2736
  }
2649
2737
  const { type, witnesses, inputs, policies } = transaction;
@@ -2675,7 +2763,6 @@ var calculateTransactionFee = (params) => {
2675
2763
  metadataGas,
2676
2764
  txBytesSize: transactionBytes.length
2677
2765
  });
2678
- const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2679
2766
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2680
2767
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2681
2768
  const maxGas = getMaxGas({
@@ -2683,17 +2770,25 @@ var calculateTransactionFee = (params) => {
2683
2770
  minGas,
2684
2771
  witnessesLength,
2685
2772
  gasLimit,
2686
- witnessLimit
2773
+ witnessLimit,
2774
+ maxGasPerTx
2775
+ });
2776
+ const minFee = calculateGasFee({
2777
+ gasPrice,
2778
+ gas: minGas,
2779
+ priceFactor: gasPriceFactor,
2780
+ tip
2781
+ });
2782
+ const maxFee = calculateGasFee({
2783
+ gasPrice,
2784
+ gas: maxGas,
2785
+ priceFactor: gasPriceFactor,
2786
+ tip
2687
2787
  });
2688
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2689
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2690
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2691
- const fee = minFee.add(feeFromGasUsed);
2692
2788
  return {
2693
- fee,
2694
2789
  minFee,
2695
2790
  maxFee,
2696
- feeFromGasUsed
2791
+ fee: maxFee
2697
2792
  };
2698
2793
  };
2699
2794
 
@@ -2749,7 +2844,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2749
2844
 
2750
2845
  // src/providers/transaction-summary/input.ts
2751
2846
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2752
- import { InputType as InputType5 } from "@fuel-ts/transactions";
2847
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2753
2848
  function getInputsByTypes(inputs, types) {
2754
2849
  return inputs.filter((i) => types.includes(i.type));
2755
2850
  }
@@ -2757,16 +2852,16 @@ function getInputsByType(inputs, type) {
2757
2852
  return inputs.filter((i) => i.type === type);
2758
2853
  }
2759
2854
  function getInputsCoin(inputs) {
2760
- return getInputsByType(inputs, InputType5.Coin);
2855
+ return getInputsByType(inputs, InputType6.Coin);
2761
2856
  }
2762
2857
  function getInputsMessage(inputs) {
2763
- return getInputsByType(inputs, InputType5.Message);
2858
+ return getInputsByType(inputs, InputType6.Message);
2764
2859
  }
2765
2860
  function getInputsCoinAndMessage(inputs) {
2766
- return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2861
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2767
2862
  }
2768
2863
  function getInputsContract(inputs) {
2769
- return getInputsByType(inputs, InputType5.Contract);
2864
+ return getInputsByType(inputs, InputType6.Contract);
2770
2865
  }
2771
2866
  function getInputFromAssetId(inputs, assetId) {
2772
2867
  const coinInputs = getInputsCoin(inputs);
@@ -2785,7 +2880,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2785
2880
  if (!contractInput) {
2786
2881
  return void 0;
2787
2882
  }
2788
- if (contractInput.type !== InputType5.Contract) {
2883
+ if (contractInput.type !== InputType6.Contract) {
2789
2884
  throw new FuelError9(
2790
2885
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2791
2886
  `Contract input should be of type 'contract'.`
@@ -2794,10 +2889,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2794
2889
  return contractInput;
2795
2890
  }
2796
2891
  function getInputAccountAddress(input) {
2797
- if (input.type === InputType5.Coin) {
2892
+ if (input.type === InputType6.Coin) {
2798
2893
  return input.owner.toString();
2799
2894
  }
2800
- if (input.type === InputType5.Message) {
2895
+ if (input.type === InputType6.Message) {
2801
2896
  return input.recipient.toString();
2802
2897
  }
2803
2898
  return "";
@@ -3307,7 +3402,9 @@ function assembleTransactionSummary(params) {
3307
3402
  gqlTransactionStatus,
3308
3403
  abiMap = {},
3309
3404
  maxInputs,
3310
- gasCosts
3405
+ gasCosts,
3406
+ maxGasPerTx,
3407
+ gasPrice
3311
3408
  } = params;
3312
3409
  const gasUsed = getGasUsedFromReceipts(receipts);
3313
3410
  const rawPayload = hexlify11(transactionBytes);
@@ -3321,11 +3418,14 @@ function assembleTransactionSummary(params) {
3321
3418
  maxInputs
3322
3419
  });
3323
3420
  const typeName = getTransactionTypeName(transaction.type);
3421
+ const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3324
3422
  const { fee } = calculateTransactionFee({
3325
- gasUsed,
3423
+ gasPrice,
3326
3424
  rawPayload,
3425
+ tip,
3327
3426
  consensusParameters: {
3328
3427
  gasCosts,
3428
+ maxGasPerTx,
3329
3429
  feeParams: {
3330
3430
  gasPerByte,
3331
3431
  gasPriceFactor
@@ -3385,7 +3485,7 @@ var TransactionResponse = class {
3385
3485
  /** Current provider */
3386
3486
  provider;
3387
3487
  /** Gas used on the transaction */
3388
- gasUsed = bn14(0);
3488
+ gasUsed = bn15(0);
3389
3489
  /** The graphql Transaction with receipts object. */
3390
3490
  gqlTransaction;
3391
3491
  abis;
@@ -3463,8 +3563,13 @@ var TransactionResponse = class {
3463
3563
  const decodedTransaction = this.decodeTransaction(
3464
3564
  transaction
3465
3565
  );
3466
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3467
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3566
+ let txReceipts = [];
3567
+ if (transaction?.status && "receipts" in transaction.status) {
3568
+ txReceipts = transaction.status.receipts;
3569
+ }
3570
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3571
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3572
+ const gasPrice = await this.provider.getLatestGasPrice();
3468
3573
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3469
3574
  const transactionSummary = assembleTransactionSummary({
3470
3575
  id: this.id,
@@ -3476,7 +3581,9 @@ var TransactionResponse = class {
3476
3581
  gasPriceFactor,
3477
3582
  abiMap: contractsAbiMap,
3478
3583
  maxInputs,
3479
- gasCosts
3584
+ gasCosts,
3585
+ maxGasPerTx,
3586
+ gasPrice
3480
3587
  });
3481
3588
  return transactionSummary;
3482
3589
  }
@@ -3603,29 +3710,29 @@ var processGqlChain = (chain) => {
3603
3710
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3604
3711
  return {
3605
3712
  name,
3606
- baseChainHeight: bn15(daHeight),
3713
+ baseChainHeight: bn16(daHeight),
3607
3714
  consensusParameters: {
3608
- contractMaxSize: bn15(contractParams.contractMaxSize),
3609
- maxInputs: bn15(txParams.maxInputs),
3610
- maxOutputs: bn15(txParams.maxOutputs),
3611
- maxWitnesses: bn15(txParams.maxWitnesses),
3612
- maxGasPerTx: bn15(txParams.maxGasPerTx),
3613
- maxScriptLength: bn15(scriptParams.maxScriptLength),
3614
- maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
3615
- maxStorageSlots: bn15(contractParams.maxStorageSlots),
3616
- maxPredicateLength: bn15(predicateParams.maxPredicateLength),
3617
- maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
3618
- maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
3619
- gasPriceFactor: bn15(feeParams.gasPriceFactor),
3620
- gasPerByte: bn15(feeParams.gasPerByte),
3621
- maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3622
- chainId: bn15(consensusParameters.chainId),
3715
+ contractMaxSize: bn16(contractParams.contractMaxSize),
3716
+ maxInputs: bn16(txParams.maxInputs),
3717
+ maxOutputs: bn16(txParams.maxOutputs),
3718
+ maxWitnesses: bn16(txParams.maxWitnesses),
3719
+ maxGasPerTx: bn16(txParams.maxGasPerTx),
3720
+ maxScriptLength: bn16(scriptParams.maxScriptLength),
3721
+ maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
3722
+ maxStorageSlots: bn16(contractParams.maxStorageSlots),
3723
+ maxPredicateLength: bn16(predicateParams.maxPredicateLength),
3724
+ maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
3725
+ maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
3726
+ gasPriceFactor: bn16(feeParams.gasPriceFactor),
3727
+ gasPerByte: bn16(feeParams.gasPerByte),
3728
+ maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
3729
+ chainId: bn16(consensusParameters.chainId),
3623
3730
  gasCosts
3624
3731
  },
3625
3732
  gasCosts,
3626
3733
  latestBlock: {
3627
3734
  id: latestBlock.id,
3628
- height: bn15(latestBlock.header.height),
3735
+ height: bn16(latestBlock.height),
3629
3736
  time: latestBlock.header.time,
3630
3737
  transactions: latestBlock.transactions.map((i) => ({
3631
3738
  id: i.id
@@ -3719,10 +3826,8 @@ var _Provider = class {
3719
3826
  * Returns some helpful parameters related to gas fees.
3720
3827
  */
3721
3828
  getGasConfig() {
3722
- const { minGasPrice } = this.getNode();
3723
3829
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3724
3830
  return {
3725
- minGasPrice,
3726
3831
  maxGasPerTx,
3727
3832
  maxGasPerPredicate,
3728
3833
  gasPriceFactor,
@@ -3798,6 +3903,21 @@ var _Provider = class {
3798
3903
  } = await this.operations.getVersion();
3799
3904
  return nodeVersion;
3800
3905
  }
3906
+ /**
3907
+ * @hidden
3908
+ *
3909
+ * Returns the network configuration of the connected Fuel node.
3910
+ *
3911
+ * @returns A promise that resolves to the network configuration object
3912
+ */
3913
+ async getNetwork() {
3914
+ const {
3915
+ name,
3916
+ consensusParameters: { chainId }
3917
+ } = await this.getChain();
3918
+ const network = new Network(name, chainId.toNumber());
3919
+ return Promise.resolve(network);
3920
+ }
3801
3921
  /**
3802
3922
  * Returns the block number.
3803
3923
  *
@@ -3805,7 +3925,7 @@ var _Provider = class {
3805
3925
  */
3806
3926
  async getBlockNumber() {
3807
3927
  const { chain } = await this.operations.getChain();
3808
- return bn15(chain.latestBlock.header.height, 10);
3928
+ return bn16(chain.latestBlock.height, 10);
3809
3929
  }
3810
3930
  /**
3811
3931
  * Returns the chain information.
@@ -3815,13 +3935,11 @@ var _Provider = class {
3815
3935
  async fetchNode() {
3816
3936
  const { nodeInfo } = await this.operations.getNodeInfo();
3817
3937
  const processedNodeInfo = {
3818
- maxDepth: bn15(nodeInfo.maxDepth),
3819
- maxTx: bn15(nodeInfo.maxTx),
3820
- minGasPrice: bn15(nodeInfo.minGasPrice),
3938
+ maxDepth: bn16(nodeInfo.maxDepth),
3939
+ maxTx: bn16(nodeInfo.maxTx),
3821
3940
  nodeVersion: nodeInfo.nodeVersion,
3822
3941
  utxoValidation: nodeInfo.utxoValidation,
3823
- vmBacktrace: nodeInfo.vmBacktrace,
3824
- peers: nodeInfo.peers
3942
+ vmBacktrace: nodeInfo.vmBacktrace
3825
3943
  };
3826
3944
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3827
3945
  return processedNodeInfo;
@@ -3907,14 +4025,13 @@ var _Provider = class {
3907
4025
  return this.estimateTxDependencies(transactionRequest);
3908
4026
  }
3909
4027
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3910
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3911
- encodedTransaction,
4028
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4029
+ encodedTransactions: encodedTransaction,
3912
4030
  utxoValidation: utxoValidation || false
3913
4031
  });
3914
- const receipts = gqlReceipts.map(processGqlReceipt);
3915
- return {
3916
- receipts
3917
- };
4032
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4033
+ const receipts = rawReceipts.map(processGqlReceipt);
4034
+ return { receipts, dryrunStatus: status };
3918
4035
  }
3919
4036
  /**
3920
4037
  * Verifies whether enough gas is available to complete transaction.
@@ -3940,7 +4057,7 @@ var _Provider = class {
3940
4057
  } = response;
3941
4058
  if (inputs) {
3942
4059
  inputs.forEach((input, index) => {
3943
- if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
4060
+ if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
3944
4061
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3945
4062
  }
3946
4063
  });
@@ -3953,9 +4070,6 @@ var _Provider = class {
3953
4070
  * If there are missing variable outputs,
3954
4071
  * `addVariableOutputs` is called on the transaction.
3955
4072
  *
3956
- * @privateRemarks
3957
- * TODO: Investigate support for missing contract IDs
3958
- * TODO: Add support for missing output messages
3959
4073
  *
3960
4074
  * @param transactionRequest - The transaction request object.
3961
4075
  * @returns A promise.
@@ -3968,16 +4082,19 @@ var _Provider = class {
3968
4082
  missingContractIds: []
3969
4083
  };
3970
4084
  }
3971
- await this.estimatePredicates(transactionRequest);
3972
4085
  let receipts = [];
3973
4086
  const missingContractIds = [];
3974
4087
  let outputVariables = 0;
4088
+ let dryrunStatus;
3975
4089
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3976
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3977
- encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
4090
+ const {
4091
+ dryRun: [{ receipts: rawReceipts, status }]
4092
+ } = await this.operations.dryRun({
4093
+ encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
3978
4094
  utxoValidation: false
3979
4095
  });
3980
- receipts = gqlReceipts.map(processGqlReceipt);
4096
+ receipts = rawReceipts.map(processGqlReceipt);
4097
+ dryrunStatus = status;
3981
4098
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3982
4099
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3983
4100
  if (hasMissingOutputs) {
@@ -3987,6 +4104,10 @@ var _Provider = class {
3987
4104
  transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
3988
4105
  missingContractIds.push(contractId);
3989
4106
  });
4107
+ const { maxFee } = await this.estimateTxGasAndFee({
4108
+ transactionRequest
4109
+ });
4110
+ transactionRequest.maxFee = maxFee;
3990
4111
  } else {
3991
4112
  break;
3992
4113
  }
@@ -3994,37 +4115,139 @@ var _Provider = class {
3994
4115
  return {
3995
4116
  receipts,
3996
4117
  outputVariables,
3997
- missingContractIds
4118
+ missingContractIds,
4119
+ dryrunStatus
3998
4120
  };
3999
4121
  }
4122
+ /**
4123
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4124
+ *
4125
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4126
+ * further modifications are identified. The method iteratively updates these transactions
4127
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4128
+ *
4129
+ * @param transactionRequests - Array of transaction request objects.
4130
+ * @returns A promise that resolves to an array of results for each transaction.
4131
+ */
4132
+ async estimateMultipleTxDependencies(transactionRequests) {
4133
+ const results = transactionRequests.map(() => ({
4134
+ receipts: [],
4135
+ outputVariables: 0,
4136
+ missingContractIds: [],
4137
+ dryrunStatus: void 0
4138
+ }));
4139
+ const allRequests = clone3(transactionRequests);
4140
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4141
+ allRequests.forEach((req, index) => {
4142
+ if (req.type === TransactionType8.Script) {
4143
+ serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
4144
+ }
4145
+ });
4146
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4147
+ let attempt = 0;
4148
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4149
+ const encodedTransactions = transactionsToProcess.map(
4150
+ (index) => serializedTransactionsMap.get(index)
4151
+ );
4152
+ const dryRunResults = await this.operations.dryRun({
4153
+ encodedTransactions,
4154
+ utxoValidation: false
4155
+ });
4156
+ const nextRoundTransactions = [];
4157
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4158
+ const currentResultIndex = transactionsToProcess[i];
4159
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4160
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4161
+ results[currentResultIndex].dryrunStatus = status;
4162
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4163
+ results[currentResultIndex].receipts
4164
+ );
4165
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4166
+ const requestToProcess = allRequests[currentResultIndex];
4167
+ if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
4168
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4169
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4170
+ missingOutputContractIds.forEach(({ contractId }) => {
4171
+ requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
4172
+ results[currentResultIndex].missingContractIds.push(contractId);
4173
+ });
4174
+ const { maxFee } = await this.estimateTxGasAndFee({
4175
+ transactionRequest: requestToProcess
4176
+ });
4177
+ requestToProcess.maxFee = maxFee;
4178
+ serializedTransactionsMap.set(
4179
+ currentResultIndex,
4180
+ hexlify12(requestToProcess.toTransactionBytes())
4181
+ );
4182
+ nextRoundTransactions.push(currentResultIndex);
4183
+ allRequests[currentResultIndex] = requestToProcess;
4184
+ }
4185
+ }
4186
+ transactionsToProcess = nextRoundTransactions;
4187
+ attempt += 1;
4188
+ }
4189
+ return results;
4190
+ }
4191
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4192
+ if (estimateTxDependencies) {
4193
+ return this.estimateMultipleTxDependencies(transactionRequests);
4194
+ }
4195
+ const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
4196
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4197
+ encodedTransactions,
4198
+ utxoValidation: utxoValidation || false
4199
+ });
4200
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4201
+ const receipts = rawReceipts.map(processGqlReceipt);
4202
+ return { receipts, dryrunStatus: status };
4203
+ });
4204
+ return results;
4205
+ }
4000
4206
  /**
4001
4207
  * Estimates the transaction gas and fee based on the provided transaction request.
4002
4208
  * @param transactionRequest - The transaction request object.
4003
4209
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4004
4210
  */
4005
- estimateTxGasAndFee(params) {
4211
+ async estimateTxGasAndFee(params) {
4006
4212
  const { transactionRequest } = params;
4007
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4213
+ let { gasPrice } = params;
4008
4214
  const chainInfo = this.getChain();
4009
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4010
- transactionRequest.gasPrice = gasPrice;
4215
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4011
4216
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4012
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4217
+ if (!gasPrice) {
4218
+ gasPrice = await this.estimateGasPrice(10);
4219
+ }
4220
+ const minFee = calculateGasFee({
4221
+ gasPrice: bn16(gasPrice),
4222
+ gas: minGas,
4223
+ priceFactor: gasPriceFactor,
4224
+ tip: transactionRequest.tip
4225
+ }).add(1);
4226
+ let gasLimit = bn16(0);
4013
4227
  if (transactionRequest.type === TransactionType8.Script) {
4228
+ gasLimit = transactionRequest.gasLimit;
4014
4229
  if (transactionRequest.gasLimit.eq(0)) {
4015
4230
  transactionRequest.gasLimit = minGas;
4016
4231
  transactionRequest.gasLimit = maxGasPerTx.sub(
4017
4232
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4018
4233
  );
4234
+ gasLimit = transactionRequest.gasLimit;
4019
4235
  }
4020
4236
  }
4021
4237
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4022
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4238
+ const maxFee = calculateGasFee({
4239
+ gasPrice: bn16(gasPrice),
4240
+ gas: maxGas,
4241
+ priceFactor: gasPriceFactor,
4242
+ tip: transactionRequest.tip
4243
+ }).add(1);
4023
4244
  return {
4024
4245
  minGas,
4025
4246
  minFee,
4026
4247
  maxGas,
4027
- maxFee
4248
+ maxFee,
4249
+ gasPrice,
4250
+ gasLimit
4028
4251
  };
4029
4252
  }
4030
4253
  /**
@@ -4042,15 +4265,17 @@ var _Provider = class {
4042
4265
  if (estimateTxDependencies) {
4043
4266
  return this.estimateTxDependencies(transactionRequest);
4044
4267
  }
4045
- const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
4046
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4047
- encodedTransaction,
4268
+ const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
4269
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4270
+ encodedTransactions,
4048
4271
  utxoValidation: true
4049
4272
  });
4050
- const receipts = gqlReceipts.map(processGqlReceipt);
4051
- return {
4052
- receipts
4053
- };
4273
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4274
+ const { id, receipts, status } = dryRunStatus;
4275
+ const processedReceipts = receipts.map(processGqlReceipt);
4276
+ return { id, receipts: processedReceipts, status };
4277
+ });
4278
+ return { receipts: callResult[0].receipts };
4054
4279
  }
4055
4280
  /**
4056
4281
  * Returns a transaction cost to enable user
@@ -4067,77 +4292,79 @@ var _Provider = class {
4067
4292
  * @param tolerance - The tolerance to add on top of the gasUsed.
4068
4293
  * @returns A promise that resolves to the transaction cost object.
4069
4294
  */
4070
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4071
- estimateTxDependencies = true,
4072
- estimatePredicates = true,
4073
- resourcesOwner,
4074
- signatureCallback
4075
- } = {}) {
4295
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4076
4296
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
4077
- const { minGasPrice } = this.getGasConfig();
4078
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
4079
4297
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
4080
4298
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4081
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4299
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4082
4300
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4301
+ txRequestClone.maxFee = bn16(0);
4083
4302
  if (isScriptTransaction) {
4084
- txRequestClone.gasLimit = bn15(0);
4303
+ txRequestClone.gasLimit = bn16(0);
4085
4304
  }
4086
- if (estimatePredicates) {
4087
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4088
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4089
- }
4090
- await this.estimatePredicates(txRequestClone);
4305
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4306
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4091
4307
  }
4308
+ const signedRequest = clone3(txRequestClone);
4309
+ let addedSignatures = 0;
4092
4310
  if (signatureCallback && isScriptTransaction) {
4093
- await signatureCallback(txRequestClone);
4311
+ const lengthBefore = signedRequest.witnesses.length;
4312
+ await signatureCallback(signedRequest);
4313
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4094
4314
  }
4095
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4096
- transactionRequest: txRequestClone
4315
+ await this.estimatePredicates(signedRequest);
4316
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4317
+ transactionRequest: signedRequest
4097
4318
  });
4098
4319
  let receipts = [];
4099
4320
  let missingContractIds = [];
4100
4321
  let outputVariables = 0;
4101
- let gasUsed = bn15(0);
4102
- if (isScriptTransaction && estimateTxDependencies) {
4103
- txRequestClone.gasPrice = bn15(0);
4322
+ let gasUsed = bn16(0);
4323
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4324
+ txRequestClone.maxFee = maxFee;
4325
+ if (isScriptTransaction) {
4326
+ txRequestClone.gasLimit = gasLimit;
4327
+ if (signatureCallback) {
4328
+ await signatureCallback(txRequestClone);
4329
+ }
4104
4330
  const result = await this.estimateTxDependencies(txRequestClone);
4105
4331
  receipts = result.receipts;
4106
4332
  outputVariables = result.outputVariables;
4107
4333
  missingContractIds = result.missingContractIds;
4108
4334
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4109
4335
  txRequestClone.gasLimit = gasUsed;
4110
- txRequestClone.gasPrice = setGasPrice;
4111
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4112
- transactionRequest: txRequestClone
4336
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4337
+ transactionRequest: txRequestClone,
4338
+ gasPrice
4113
4339
  }));
4114
4340
  }
4115
4341
  return {
4116
4342
  requiredQuantities: allQuantities,
4117
4343
  receipts,
4118
4344
  gasUsed,
4119
- minGasPrice,
4120
- gasPrice: setGasPrice,
4345
+ gasPrice,
4121
4346
  minGas,
4122
4347
  maxGas,
4123
4348
  minFee,
4124
4349
  maxFee,
4125
- estimatedInputs: txRequestClone.inputs,
4126
4350
  outputVariables,
4127
- missingContractIds
4351
+ missingContractIds,
4352
+ addedSignatures,
4353
+ estimatedPredicates: txRequestClone.inputs
4128
4354
  };
4129
4355
  }
4130
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4356
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4131
4357
  const ownerAddress = Address2.fromAddressOrString(owner);
4132
4358
  const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
4133
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4359
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4360
+ quantitiesToContract
4361
+ });
4134
4362
  transactionRequest.addResources(
4135
4363
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4136
4364
  );
4137
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4138
- transactionRequest,
4139
- forwardingQuantities
4140
- );
4365
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4366
+ quantitiesToContract
4367
+ });
4141
4368
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4142
4369
  return {
4143
4370
  resources,
@@ -4159,11 +4386,10 @@ var _Provider = class {
4159
4386
  return coins.map((coin) => ({
4160
4387
  id: coin.utxoId,
4161
4388
  assetId: coin.assetId,
4162
- amount: bn15(coin.amount),
4389
+ amount: bn16(coin.amount),
4163
4390
  owner: Address2.fromAddressOrString(coin.owner),
4164
- maturity: bn15(coin.maturity).toNumber(),
4165
- blockCreated: bn15(coin.blockCreated),
4166
- txCreatedIdx: bn15(coin.txCreatedIdx)
4391
+ blockCreated: bn16(coin.blockCreated),
4392
+ txCreatedIdx: bn16(coin.txCreatedIdx)
4167
4393
  }));
4168
4394
  }
4169
4395
  /**
@@ -4200,9 +4426,9 @@ var _Provider = class {
4200
4426
  switch (coin.__typename) {
4201
4427
  case "MessageCoin":
4202
4428
  return {
4203
- amount: bn15(coin.amount),
4429
+ amount: bn16(coin.amount),
4204
4430
  assetId: coin.assetId,
4205
- daHeight: bn15(coin.daHeight),
4431
+ daHeight: bn16(coin.daHeight),
4206
4432
  sender: Address2.fromAddressOrString(coin.sender),
4207
4433
  recipient: Address2.fromAddressOrString(coin.recipient),
4208
4434
  nonce: coin.nonce
@@ -4210,12 +4436,11 @@ var _Provider = class {
4210
4436
  case "Coin":
4211
4437
  return {
4212
4438
  id: coin.utxoId,
4213
- amount: bn15(coin.amount),
4439
+ amount: bn16(coin.amount),
4214
4440
  assetId: coin.assetId,
4215
4441
  owner: Address2.fromAddressOrString(coin.owner),
4216
- maturity: bn15(coin.maturity).toNumber(),
4217
- blockCreated: bn15(coin.blockCreated),
4218
- txCreatedIdx: bn15(coin.txCreatedIdx)
4442
+ blockCreated: bn16(coin.blockCreated),
4443
+ txCreatedIdx: bn16(coin.txCreatedIdx)
4219
4444
  };
4220
4445
  default:
4221
4446
  return null;
@@ -4232,13 +4457,13 @@ var _Provider = class {
4232
4457
  async getBlock(idOrHeight) {
4233
4458
  let variables;
4234
4459
  if (typeof idOrHeight === "number") {
4235
- variables = { height: bn15(idOrHeight).toString(10) };
4460
+ variables = { height: bn16(idOrHeight).toString(10) };
4236
4461
  } else if (idOrHeight === "latest") {
4237
4462
  variables = { height: (await this.getBlockNumber()).toString(10) };
4238
4463
  } else if (idOrHeight.length === 66) {
4239
4464
  variables = { blockId: idOrHeight };
4240
4465
  } else {
4241
- variables = { blockId: bn15(idOrHeight).toString(10) };
4466
+ variables = { blockId: bn16(idOrHeight).toString(10) };
4242
4467
  }
4243
4468
  const { block } = await this.operations.getBlock(variables);
4244
4469
  if (!block) {
@@ -4246,7 +4471,7 @@ var _Provider = class {
4246
4471
  }
4247
4472
  return {
4248
4473
  id: block.id,
4249
- height: bn15(block.header.height),
4474
+ height: bn16(block.height),
4250
4475
  time: block.header.time,
4251
4476
  transactionIds: block.transactions.map((tx) => tx.id)
4252
4477
  };
@@ -4261,7 +4486,7 @@ var _Provider = class {
4261
4486
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4262
4487
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4263
4488
  id: block.id,
4264
- height: bn15(block.header.height),
4489
+ height: bn16(block.height),
4265
4490
  time: block.header.time,
4266
4491
  transactionIds: block.transactions.map((tx) => tx.id)
4267
4492
  }));
@@ -4276,7 +4501,7 @@ var _Provider = class {
4276
4501
  async getBlockWithTransactions(idOrHeight) {
4277
4502
  let variables;
4278
4503
  if (typeof idOrHeight === "number") {
4279
- variables = { blockHeight: bn15(idOrHeight).toString(10) };
4504
+ variables = { blockHeight: bn16(idOrHeight).toString(10) };
4280
4505
  } else if (idOrHeight === "latest") {
4281
4506
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4282
4507
  } else {
@@ -4288,7 +4513,7 @@ var _Provider = class {
4288
4513
  }
4289
4514
  return {
4290
4515
  id: block.id,
4291
- height: bn15(block.header.height, 10),
4516
+ height: bn16(block.height, 10),
4292
4517
  time: block.header.time,
4293
4518
  transactionIds: block.transactions.map((tx) => tx.id),
4294
4519
  transactions: block.transactions.map(
@@ -4337,7 +4562,7 @@ var _Provider = class {
4337
4562
  contract: Address2.fromAddressOrString(contractId).toB256(),
4338
4563
  asset: hexlify12(assetId)
4339
4564
  });
4340
- return bn15(contractBalance.amount, 10);
4565
+ return bn16(contractBalance.amount, 10);
4341
4566
  }
4342
4567
  /**
4343
4568
  * Returns the balance for the given owner for the given asset ID.
@@ -4351,7 +4576,7 @@ var _Provider = class {
4351
4576
  owner: Address2.fromAddressOrString(owner).toB256(),
4352
4577
  assetId: hexlify12(assetId)
4353
4578
  });
4354
- return bn15(balance.amount, 10);
4579
+ return bn16(balance.amount, 10);
4355
4580
  }
4356
4581
  /**
4357
4582
  * Returns balances for the given owner.
@@ -4369,7 +4594,7 @@ var _Provider = class {
4369
4594
  const balances = result.balances.edges.map((edge) => edge.node);
4370
4595
  return balances.map((balance) => ({
4371
4596
  assetId: balance.assetId,
4372
- amount: bn15(balance.amount)
4597
+ amount: bn16(balance.amount)
4373
4598
  }));
4374
4599
  }
4375
4600
  /**
@@ -4391,15 +4616,15 @@ var _Provider = class {
4391
4616
  sender: message.sender,
4392
4617
  recipient: message.recipient,
4393
4618
  nonce: message.nonce,
4394
- amount: bn15(message.amount),
4619
+ amount: bn16(message.amount),
4395
4620
  data: message.data
4396
4621
  }),
4397
4622
  sender: Address2.fromAddressOrString(message.sender),
4398
4623
  recipient: Address2.fromAddressOrString(message.recipient),
4399
4624
  nonce: message.nonce,
4400
- amount: bn15(message.amount),
4625
+ amount: bn16(message.amount),
4401
4626
  data: InputMessageCoder.decodeData(message.data),
4402
- daHeight: bn15(message.daHeight)
4627
+ daHeight: bn16(message.daHeight)
4403
4628
  }));
4404
4629
  }
4405
4630
  /**
@@ -4452,44 +4677,60 @@ var _Provider = class {
4452
4677
  } = result.messageProof;
4453
4678
  return {
4454
4679
  messageProof: {
4455
- proofIndex: bn15(messageProof.proofIndex),
4680
+ proofIndex: bn16(messageProof.proofIndex),
4456
4681
  proofSet: messageProof.proofSet
4457
4682
  },
4458
4683
  blockProof: {
4459
- proofIndex: bn15(blockProof.proofIndex),
4684
+ proofIndex: bn16(blockProof.proofIndex),
4460
4685
  proofSet: blockProof.proofSet
4461
4686
  },
4462
4687
  messageBlockHeader: {
4463
4688
  id: messageBlockHeader.id,
4464
- daHeight: bn15(messageBlockHeader.daHeight),
4465
- transactionsCount: bn15(messageBlockHeader.transactionsCount),
4689
+ daHeight: bn16(messageBlockHeader.daHeight),
4690
+ transactionsCount: bn16(messageBlockHeader.transactionsCount),
4466
4691
  transactionsRoot: messageBlockHeader.transactionsRoot,
4467
- height: bn15(messageBlockHeader.height),
4692
+ height: bn16(messageBlockHeader.height),
4468
4693
  prevRoot: messageBlockHeader.prevRoot,
4469
4694
  time: messageBlockHeader.time,
4470
4695
  applicationHash: messageBlockHeader.applicationHash,
4471
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4472
- messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
4696
+ messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
4697
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4698
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4699
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4700
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4473
4701
  },
4474
4702
  commitBlockHeader: {
4475
4703
  id: commitBlockHeader.id,
4476
- daHeight: bn15(commitBlockHeader.daHeight),
4477
- transactionsCount: bn15(commitBlockHeader.transactionsCount),
4704
+ daHeight: bn16(commitBlockHeader.daHeight),
4705
+ transactionsCount: bn16(commitBlockHeader.transactionsCount),
4478
4706
  transactionsRoot: commitBlockHeader.transactionsRoot,
4479
- height: bn15(commitBlockHeader.height),
4707
+ height: bn16(commitBlockHeader.height),
4480
4708
  prevRoot: commitBlockHeader.prevRoot,
4481
4709
  time: commitBlockHeader.time,
4482
4710
  applicationHash: commitBlockHeader.applicationHash,
4483
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4484
- messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
4711
+ messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
4712
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4713
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4714
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4715
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4485
4716
  },
4486
4717
  sender: Address2.fromAddressOrString(sender),
4487
4718
  recipient: Address2.fromAddressOrString(recipient),
4488
4719
  nonce,
4489
- amount: bn15(amount),
4720
+ amount: bn16(amount),
4490
4721
  data
4491
4722
  };
4492
4723
  }
4724
+ async getLatestGasPrice() {
4725
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4726
+ return bn16(latestGasPrice.gasPrice);
4727
+ }
4728
+ async estimateGasPrice(blockHorizon) {
4729
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4730
+ blockHorizon: String(blockHorizon)
4731
+ });
4732
+ return bn16(estimateGasPrice.gasPrice);
4733
+ }
4493
4734
  /**
4494
4735
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4495
4736
  *
@@ -4509,10 +4750,10 @@ var _Provider = class {
4509
4750
  */
4510
4751
  async produceBlocks(amount, startTime) {
4511
4752
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4512
- blocksToProduce: bn15(amount).toString(10),
4753
+ blocksToProduce: bn16(amount).toString(10),
4513
4754
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4514
4755
  });
4515
- return bn15(latestBlockHeight);
4756
+ return bn16(latestBlockHeight);
4516
4757
  }
4517
4758
  // eslint-disable-next-line @typescript-eslint/require-await
4518
4759
  async getTransactionResponse(transactionId) {
@@ -4526,7 +4767,7 @@ cacheInputs_fn = function(inputs) {
4526
4767
  return;
4527
4768
  }
4528
4769
  inputs.forEach((input) => {
4529
- if (input.type === InputType6.Coin) {
4770
+ if (input.type === InputType7.Coin) {
4530
4771
  this.cache?.set(input.id);
4531
4772
  }
4532
4773
  });
@@ -4536,7 +4777,7 @@ __publicField(Provider, "nodeInfoCache", {});
4536
4777
 
4537
4778
  // src/providers/transaction-summary/get-transaction-summary.ts
4538
4779
  import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4539
- import { bn as bn16 } from "@fuel-ts/math";
4780
+ import { bn as bn17 } from "@fuel-ts/math";
4540
4781
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4541
4782
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4542
4783
  async function getTransactionSummary(params) {
@@ -4554,21 +4795,28 @@ async function getTransactionSummary(params) {
4554
4795
  arrayify12(gqlTransaction.rawPayload),
4555
4796
  0
4556
4797
  );
4557
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4798
+ let txReceipts = [];
4799
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4800
+ txReceipts = gqlTransaction.status.receipts;
4801
+ }
4802
+ const receipts = txReceipts.map(processGqlReceipt);
4558
4803
  const {
4559
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4804
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4560
4805
  } = provider.getChain();
4806
+ const gasPrice = await provider.getLatestGasPrice();
4561
4807
  const transactionInfo = assembleTransactionSummary({
4562
4808
  id: gqlTransaction.id,
4563
4809
  receipts,
4564
4810
  transaction: decodedTransaction,
4565
4811
  transactionBytes: arrayify12(gqlTransaction.rawPayload),
4566
4812
  gqlTransactionStatus: gqlTransaction.status,
4567
- gasPerByte: bn16(gasPerByte),
4568
- gasPriceFactor: bn16(gasPriceFactor),
4813
+ gasPerByte: bn17(gasPerByte),
4814
+ gasPriceFactor: bn17(gasPriceFactor),
4569
4815
  abiMap,
4570
4816
  maxInputs,
4571
- gasCosts
4817
+ gasCosts,
4818
+ maxGasPerTx,
4819
+ gasPrice
4572
4820
  });
4573
4821
  return {
4574
4822
  gqlTransaction,
@@ -4578,10 +4826,11 @@ async function getTransactionSummary(params) {
4578
4826
  async function getTransactionSummaryFromRequest(params) {
4579
4827
  const { provider, transactionRequest, abiMap } = params;
4580
4828
  const { receipts } = await provider.call(transactionRequest);
4581
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4829
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4582
4830
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4583
4831
  const transaction = transactionRequest.toTransaction();
4584
4832
  const transactionBytes = transactionRequest.toTransactionBytes();
4833
+ const gasPrice = await provider.getLatestGasPrice();
4585
4834
  const transactionSummary = assembleTransactionSummary({
4586
4835
  receipts,
4587
4836
  transaction,
@@ -4590,7 +4839,9 @@ async function getTransactionSummaryFromRequest(params) {
4590
4839
  gasPerByte,
4591
4840
  gasPriceFactor,
4592
4841
  maxInputs,
4593
- gasCosts
4842
+ gasCosts,
4843
+ maxGasPerTx,
4844
+ gasPrice
4594
4845
  });
4595
4846
  return transactionSummary;
4596
4847
  }
@@ -4599,13 +4850,18 @@ async function getTransactionsSummaries(params) {
4599
4850
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4600
4851
  const { edges, pageInfo } = transactionsByOwner;
4601
4852
  const {
4602
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4853
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4603
4854
  } = provider.getChain();
4855
+ const gasPrice = await provider.getLatestGasPrice();
4604
4856
  const transactions = edges.map((edge) => {
4605
4857
  const { node: gqlTransaction } = edge;
4606
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4858
+ const { id, rawPayload, status } = gqlTransaction;
4607
4859
  const [decodedTransaction] = new TransactionCoder6().decode(arrayify12(rawPayload), 0);
4608
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4860
+ let txReceipts = [];
4861
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4862
+ txReceipts = gqlTransaction.status.receipts;
4863
+ }
4864
+ const receipts = txReceipts.map(processGqlReceipt);
4609
4865
  const transactionSummary = assembleTransactionSummary({
4610
4866
  id,
4611
4867
  receipts,
@@ -4616,7 +4872,9 @@ async function getTransactionsSummaries(params) {
4616
4872
  gasPerByte,
4617
4873
  gasPriceFactor,
4618
4874
  maxInputs,
4619
- gasCosts
4875
+ gasCosts,
4876
+ maxGasPerTx,
4877
+ gasPrice
4620
4878
  });
4621
4879
  const output = {
4622
4880
  gqlTransaction,
@@ -4948,36 +5206,33 @@ var Account = class extends AbstractAccount {
4948
5206
  * @param fee - The estimated transaction fee.
4949
5207
  * @returns A promise that resolves when the resources are added to the transaction.
4950
5208
  */
4951
- async fund(request, coinQuantities, fee) {
4952
- const updatedQuantities = addAmountToAsset({
4953
- amount: bn17(fee),
5209
+ async fund(request, params) {
5210
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5211
+ const txRequest = request;
5212
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5213
+ amount: bn18(fee),
4954
5214
  assetId: BaseAssetId3,
4955
- coinQuantities
5215
+ coinQuantities: requiredQuantities
4956
5216
  });
4957
5217
  const quantitiesDict = {};
4958
- updatedQuantities.forEach(({ amount, assetId }) => {
5218
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4959
5219
  quantitiesDict[assetId] = {
4960
5220
  required: amount,
4961
- owned: bn17(0)
5221
+ owned: bn18(0)
4962
5222
  };
4963
5223
  });
4964
- const cachedUtxos = [];
4965
- const cachedMessages = [];
4966
- const owner = this.address.toB256();
4967
- request.inputs.forEach((input) => {
5224
+ txRequest.inputs.forEach((input) => {
4968
5225
  const isResource = "amount" in input;
4969
5226
  if (isResource) {
4970
5227
  const isCoin2 = "owner" in input;
4971
5228
  if (isCoin2) {
4972
5229
  const assetId = String(input.assetId);
4973
- if (input.owner === owner && quantitiesDict[assetId]) {
4974
- const amount = bn17(input.amount);
5230
+ if (quantitiesDict[assetId]) {
5231
+ const amount = bn18(input.amount);
4975
5232
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4976
- cachedUtxos.push(input.id);
4977
5233
  }
4978
- } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
5234
+ } else if (input.amount && quantitiesDict[BaseAssetId3]) {
4979
5235
  quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4980
- cachedMessages.push(input.nonce);
4981
5236
  }
4982
5237
  }
4983
5238
  });
@@ -4992,12 +5247,23 @@ var Account = class extends AbstractAccount {
4992
5247
  });
4993
5248
  const needsToBeFunded = missingQuantities.length;
4994
5249
  if (needsToBeFunded) {
4995
- const resources = await this.getResourcesToSpend(missingQuantities, {
4996
- messages: cachedMessages,
4997
- utxos: cachedUtxos
4998
- });
4999
- request.addResources(resources);
5250
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5251
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5252
+ txRequest.addResources(resources);
5253
+ }
5254
+ txRequest.shiftPredicateData();
5255
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5256
+ const requestToBeReEstimate = clone4(txRequest);
5257
+ if (addedSignatures) {
5258
+ Array.from({ length: addedSignatures }).forEach(
5259
+ () => requestToBeReEstimate.addEmptyWitness()
5260
+ );
5000
5261
  }
5262
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5263
+ transactionRequest: requestToBeReEstimate
5264
+ });
5265
+ txRequest.maxFee = maxFee;
5266
+ return txRequest;
5001
5267
  }
5002
5268
  /**
5003
5269
  * A helper that creates a transfer transaction request and returns it.
@@ -5005,28 +5271,25 @@ var Account = class extends AbstractAccount {
5005
5271
  * @param destination - The address of the destination.
5006
5272
  * @param amount - The amount of coins to transfer.
5007
5273
  * @param assetId - The asset ID of the coins to transfer.
5008
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5274
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5009
5275
  * @returns A promise that resolves to the prepared transaction request.
5010
5276
  */
5011
5277
  async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5012
- const { minGasPrice } = this.provider.getGasConfig();
5013
- const params = { gasPrice: minGasPrice, ...txParams };
5014
- const request = new ScriptTransactionRequest(params);
5278
+ const request = new ScriptTransactionRequest(txParams);
5015
5279
  request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
5016
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5280
+ const txCost = await this.provider.getTransactionCost(request, {
5017
5281
  estimateTxDependencies: true,
5018
5282
  resourcesOwner: this
5019
5283
  });
5020
- request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
5021
- request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
5022
- this.validateGas({
5023
- gasUsed,
5024
- gasPrice: request.gasPrice,
5025
- gasLimit: request.gasLimit,
5026
- minGasPrice
5027
- });
5028
- await this.fund(request, requiredQuantities, maxFee);
5029
- request.updatePredicateInputs(estimatedInputs);
5284
+ if ("gasLimit" in txParams) {
5285
+ this.validateGas({
5286
+ gasUsed: txCost.gasUsed,
5287
+ gasLimit: request.gasLimit
5288
+ });
5289
+ }
5290
+ request.gasLimit = txCost.gasUsed;
5291
+ request.maxFee = txCost.maxFee;
5292
+ await this.fund(request, txCost);
5030
5293
  return request;
5031
5294
  }
5032
5295
  /**
@@ -5039,7 +5302,7 @@ var Account = class extends AbstractAccount {
5039
5302
  * @returns A promise that resolves to the transaction response.
5040
5303
  */
5041
5304
  async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5042
- if (bn17(amount).lte(0)) {
5305
+ if (bn18(amount).lte(0)) {
5043
5306
  throw new FuelError15(
5044
5307
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5045
5308
  "Transfer amount must be a positive number."
@@ -5058,38 +5321,37 @@ var Account = class extends AbstractAccount {
5058
5321
  * @returns A promise that resolves to the transaction response.
5059
5322
  */
5060
5323
  async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5061
- if (bn17(amount).lte(0)) {
5324
+ if (bn18(amount).lte(0)) {
5062
5325
  throw new FuelError15(
5063
5326
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5064
5327
  "Transfer amount must be a positive number."
5065
5328
  );
5066
5329
  }
5067
5330
  const contractAddress = Address3.fromAddressOrString(contractId);
5068
- const { minGasPrice } = this.provider.getGasConfig();
5069
- const params = { gasPrice: minGasPrice, ...txParams };
5070
5331
  const { script, scriptData } = await assembleTransferToContractScript({
5071
5332
  hexlifiedContractId: contractAddress.toB256(),
5072
- amountToTransfer: bn17(amount),
5333
+ amountToTransfer: bn18(amount),
5073
5334
  assetId
5074
5335
  });
5075
5336
  const request = new ScriptTransactionRequest({
5076
- ...params,
5337
+ ...txParams,
5077
5338
  script,
5078
5339
  scriptData
5079
5340
  });
5080
5341
  request.addContractInputAndOutput(contractAddress);
5081
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5082
- request,
5083
- [{ amount: bn17(amount), assetId: String(assetId) }]
5084
- );
5085
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5086
- this.validateGas({
5087
- gasUsed,
5088
- gasPrice: request.gasPrice,
5089
- gasLimit: request.gasLimit,
5090
- minGasPrice
5342
+ const txCost = await this.provider.getTransactionCost(request, {
5343
+ resourcesOwner: this,
5344
+ quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
5091
5345
  });
5092
- await this.fund(request, requiredQuantities, maxFee);
5346
+ if (txParams.gasLimit) {
5347
+ this.validateGas({
5348
+ gasUsed: txCost.gasUsed,
5349
+ gasLimit: request.gasLimit
5350
+ });
5351
+ }
5352
+ request.gasLimit = txCost.gasUsed;
5353
+ request.maxFee = txCost.maxFee;
5354
+ await this.fund(request, txCost);
5093
5355
  return this.sendTransaction(request);
5094
5356
  }
5095
5357
  /**
@@ -5101,34 +5363,31 @@ var Account = class extends AbstractAccount {
5101
5363
  * @returns A promise that resolves to the transaction response.
5102
5364
  */
5103
5365
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5104
- const { minGasPrice } = this.provider.getGasConfig();
5105
5366
  const recipientAddress = Address3.fromAddressOrString(recipient);
5106
5367
  const recipientDataArray = arrayify14(
5107
5368
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5108
5369
  );
5109
5370
  const amountDataArray = arrayify14(
5110
- "0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
5371
+ "0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
5111
5372
  );
5112
5373
  const script = new Uint8Array([
5113
5374
  ...arrayify14(withdrawScript.bytes),
5114
5375
  ...recipientDataArray,
5115
5376
  ...amountDataArray
5116
5377
  ]);
5117
- const params = { script, gasPrice: minGasPrice, ...txParams };
5378
+ const params = { script, ...txParams };
5118
5379
  const request = new ScriptTransactionRequest(params);
5119
- const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
5120
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5121
- request,
5122
- forwardingQuantities
5123
- );
5124
- request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5125
- this.validateGas({
5126
- gasUsed,
5127
- gasPrice: request.gasPrice,
5128
- gasLimit: request.gasLimit,
5129
- minGasPrice
5130
- });
5131
- await this.fund(request, requiredQuantities, maxFee);
5380
+ const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
5381
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5382
+ if (txParams.gasLimit) {
5383
+ this.validateGas({
5384
+ gasUsed: txCost.gasUsed,
5385
+ gasLimit: request.gasLimit
5386
+ });
5387
+ }
5388
+ request.maxFee = txCost.maxFee;
5389
+ request.gasLimit = txCost.gasUsed;
5390
+ await this.fund(request, txCost);
5132
5391
  return this.sendTransaction(request);
5133
5392
  }
5134
5393
  async signMessage(message) {
@@ -5186,18 +5445,7 @@ var Account = class extends AbstractAccount {
5186
5445
  }
5187
5446
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5188
5447
  }
5189
- validateGas({
5190
- gasUsed,
5191
- gasPrice,
5192
- gasLimit,
5193
- minGasPrice
5194
- }) {
5195
- if (minGasPrice.gt(gasPrice)) {
5196
- throw new FuelError15(
5197
- ErrorCode15.GAS_PRICE_TOO_LOW,
5198
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5199
- );
5200
- }
5448
+ validateGas({ gasUsed, gasLimit }) {
5201
5449
  if (gasUsed.gt(gasLimit)) {
5202
5450
  throw new FuelError15(
5203
5451
  ErrorCode15.GAS_LIMIT_TOO_LOW,
@@ -5493,7 +5741,7 @@ var BaseWalletUnlocked = class extends Account {
5493
5741
  * @param transactionRequestLike - The transaction request to send.
5494
5742
  * @returns A promise that resolves to the TransactionResponse object.
5495
5743
  */
5496
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5744
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5497
5745
  const transactionRequest = transactionRequestify(transactionRequestLike);
5498
5746
  if (estimateTxDependencies) {
5499
5747
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5532,17 +5780,18 @@ var BaseWalletUnlocked = class extends Account {
5532
5780
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5533
5781
 
5534
5782
  // src/hdwallet/hdwallet.ts
5535
- import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
5536
5783
  import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5537
5784
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5538
- import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5539
- import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
5785
+ import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5786
+ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5787
+ import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5540
5788
 
5541
5789
  // src/mnemonic/mnemonic.ts
5542
- import { randomBytes as randomBytes4, pbkdf2, computeHmac } from "@fuel-ts/crypto";
5790
+ import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5543
5791
  import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5544
5792
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5545
- import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4, dataSlice, encodeBase58 } from "@fuel-ts/utils";
5793
+ import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
5794
+ import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
5546
5795
 
5547
5796
  // src/wordlists/words/english.ts
5548
5797
  var english = [
@@ -8005,7 +8254,7 @@ var HDWallet = class {
8005
8254
  const IR = bytes.slice(32);
8006
8255
  if (privateKey) {
8007
8256
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8008
- const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
8257
+ const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
8009
8258
  return new HDWallet({
8010
8259
  privateKey: ki,
8011
8260
  chainCode: IR,
@@ -8071,8 +8320,7 @@ var HDWallet = class {
8071
8320
  });
8072
8321
  }
8073
8322
  static fromExtendedKey(extendedKey) {
8074
- let decoded = toHex(decodeBase58(extendedKey));
8075
- decoded = `${decoded.substring(0, 2)}0${decoded.substring(2)}`;
8323
+ const decoded = toBeHex(decodeBase58(extendedKey));
8076
8324
  const bytes = arrayify18(decoded);
8077
8325
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8078
8326
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
@@ -8695,7 +8943,7 @@ import {
8695
8943
  import { Address as Address9 } from "@fuel-ts/address";
8696
8944
  import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8697
8945
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8698
- import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8946
+ import { ByteArrayCoder, InputType as InputType8 } from "@fuel-ts/transactions";
8699
8947
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8700
8948
 
8701
8949
  // src/predicate/utils/getPredicateRoot.ts
@@ -8755,9 +9003,9 @@ var Predicate = class extends Account {
8755
9003
  const request = transactionRequestify(transactionRequestLike);
8756
9004
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8757
9005
  request.inputs?.forEach((input) => {
8758
- if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
8759
- input.predicate = this.bytes;
8760
- input.predicateData = this.getPredicateData(policies.length);
9006
+ if (input.type === InputType8.Coin && hexlify19(input.owner) === this.address.toB256()) {
9007
+ input.predicate = hexlify19(this.bytes);
9008
+ input.predicateData = hexlify19(this.getPredicateData(policies.length));
8761
9009
  }
8762
9010
  });
8763
9011
  return request;
@@ -8772,8 +9020,7 @@ var Predicate = class extends Account {
8772
9020
  * @returns A promise that resolves to the prepared transaction request.
8773
9021
  */
8774
9022
  async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8775
- const request = await super.createTransfer(destination, amount, assetId, txParams);
8776
- return this.populateTransactionPredicateData(request);
9023
+ return super.createTransfer(destination, amount, assetId, txParams);
8777
9024
  }
8778
9025
  /**
8779
9026
  * Sends a transaction with the populated predicate data.
@@ -8781,9 +9028,9 @@ var Predicate = class extends Account {
8781
9028
  * @param transactionRequestLike - The transaction request-like object.
8782
9029
  * @returns A promise that resolves to the transaction response.
8783
9030
  */
8784
- sendTransaction(transactionRequestLike, options) {
8785
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8786
- return super.sendTransaction(transactionRequest, options);
9031
+ sendTransaction(transactionRequestLike) {
9032
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9033
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8787
9034
  }
8788
9035
  /**
8789
9036
  * Simulates a transaction with the populated predicate data.
@@ -8792,8 +9039,8 @@ var Predicate = class extends Account {
8792
9039
  * @returns A promise that resolves to the call result.
8793
9040
  */
8794
9041
  simulateTransaction(transactionRequestLike) {
8795
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8796
- return super.simulateTransaction(transactionRequest);
9042
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9043
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8797
9044
  }
8798
9045
  getPredicateData(policiesLength) {
8799
9046
  if (!this.predicateData.length) {
@@ -8839,6 +9086,25 @@ var Predicate = class extends Account {
8839
9086
  predicateInterface: abiInterface
8840
9087
  };
8841
9088
  }
9089
+ /**
9090
+ * Retrieves resources satisfying the spend query for the account.
9091
+ *
9092
+ * @param quantities - IDs of coins to exclude.
9093
+ * @param excludedIds - IDs of resources to be excluded from the query.
9094
+ * @returns A promise that resolves to an array of Resources.
9095
+ */
9096
+ async getResourcesToSpend(quantities, excludedIds) {
9097
+ const resources = await this.provider.getResourcesToSpend(
9098
+ this.address,
9099
+ quantities,
9100
+ excludedIds
9101
+ );
9102
+ return resources.map((resource) => ({
9103
+ ...resource,
9104
+ predicate: hexlify19(this.bytes),
9105
+ paddPredicateData: (policiesLength) => hexlify19(this.getPredicateData(policiesLength))
9106
+ }));
9107
+ }
8842
9108
  /**
8843
9109
  * Sets the configurable constants for the predicate.
8844
9110
  *
@@ -9587,7 +9853,7 @@ export {
9587
9853
  WalletLocked,
9588
9854
  WalletManager,
9589
9855
  WalletUnlocked,
9590
- addAmountToAsset,
9856
+ addAmountToCoinQuantities,
9591
9857
  addOperation,
9592
9858
  assemblePanicError,
9593
9859
  assembleReceiptByType,
@@ -9596,9 +9862,10 @@ export {
9596
9862
  assets,
9597
9863
  buildBlockExplorerUrl,
9598
9864
  cacheFor,
9865
+ cacheTxInputsFromOwner,
9866
+ calculateGasFee,
9599
9867
  calculateMetadataGasForTxCreate,
9600
9868
  calculateMetadataGasForTxScript,
9601
- calculatePriceWithFactor,
9602
9869
  calculateTransactionFee,
9603
9870
  coinQuantityfy,
9604
9871
  deferPromise,