@fuel-ts/account 0.0.0-rc-1976-20240404073406 → 0.0.0-rc-1764-20240404125616

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 (57) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +5 -4
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +1 -1
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +1 -1
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +1 -1
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +912 -544
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +1032 -714
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +909 -587
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +10 -2
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +822 -303
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +3 -3
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  26. package/dist/providers/message.d.ts +3 -0
  27. package/dist/providers/message.d.ts.map +1 -1
  28. package/dist/providers/provider.d.ts +44 -31
  29. package/dist/providers/provider.d.ts.map +1 -1
  30. package/dist/providers/transaction-request/input.d.ts +2 -2
  31. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  32. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
  34. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/utils.d.ts +3 -0
  36. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  37. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  38. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  39. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  40. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  43. package/dist/providers/utils/extract-tx-error.d.ts +36 -0
  44. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
  45. package/dist/providers/utils/gas.d.ts +8 -2
  46. package/dist/providers/utils/gas.d.ts.map +1 -1
  47. package/dist/providers/utils/index.d.ts +1 -0
  48. package/dist/providers/utils/index.d.ts.map +1 -1
  49. package/dist/test-utils/launchNode.d.ts.map +1 -1
  50. package/dist/test-utils.global.js +871 -540
  51. package/dist/test-utils.global.js.map +1 -1
  52. package/dist/test-utils.js +944 -671
  53. package/dist/test-utils.js.map +1 -1
  54. package/dist/test-utils.mjs +832 -551
  55. package/dist/test-utils.mjs.map +1 -1
  56. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  57. package/package.json +17 -17
@@ -24,35 +24,38 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
24
24
 
25
25
  // src/account.ts
26
26
  import { Address as Address3 } from "@fuel-ts/address";
27
- import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
27
+ import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
28
+ import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
28
29
  import { AbstractAccount } from "@fuel-ts/interfaces";
29
- import { bn as bn16 } from "@fuel-ts/math";
30
+ import { bn as bn18 } from "@fuel-ts/math";
30
31
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
32
+ import { clone as clone4 } from "ramda";
31
33
 
32
34
  // src/providers/coin-quantity.ts
35
+ import { BaseAssetId } from "@fuel-ts/address/configs";
33
36
  import { bn } from "@fuel-ts/math";
34
37
  import { hexlify } from "@fuel-ts/utils";
35
38
  var coinQuantityfy = (coinQuantityLike) => {
36
39
  let assetId;
37
40
  let amount;
38
- let max2;
41
+ let max;
39
42
  if (Array.isArray(coinQuantityLike)) {
40
43
  amount = coinQuantityLike[0];
41
- assetId = coinQuantityLike[1];
42
- max2 = coinQuantityLike[2];
44
+ assetId = coinQuantityLike[1] ?? BaseAssetId;
45
+ max = coinQuantityLike[2] ?? void 0;
43
46
  } else {
44
47
  amount = coinQuantityLike.amount;
45
- assetId = coinQuantityLike.assetId;
46
- max2 = coinQuantityLike.max ?? void 0;
48
+ assetId = coinQuantityLike.assetId ?? BaseAssetId;
49
+ max = coinQuantityLike.max ?? void 0;
47
50
  }
48
51
  const bnAmount = bn(amount);
49
52
  return {
50
53
  assetId: hexlify(assetId),
51
54
  amount: bnAmount.lt(1) ? bn(1) : bnAmount,
52
- max: max2 ? bn(max2) : void 0
55
+ max: max ? bn(max) : void 0
53
56
  };
54
57
  };
55
- var addAmountToAsset = (params) => {
58
+ var addAmountToCoinQuantities = (params) => {
56
59
  const { amount, assetId } = params;
57
60
  const coinQuantities = [...params.coinQuantities];
58
61
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -66,10 +69,10 @@ var addAmountToAsset = (params) => {
66
69
 
67
70
  // src/providers/provider.ts
68
71
  import { Address as Address2 } from "@fuel-ts/address";
69
- import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
70
- import { BN, bn as bn14, max } from "@fuel-ts/math";
72
+ import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
73
+ import { BN, bn as bn16 } from "@fuel-ts/math";
71
74
  import {
72
- InputType as InputType6,
75
+ InputType as InputType7,
73
76
  TransactionType as TransactionType8,
74
77
  InputMessageCoder,
75
78
  TransactionCoder as TransactionCoder5
@@ -85,14 +88,10 @@ import { clone as clone3 } from "ramda";
85
88
  import gql from "graphql-tag";
86
89
  var ReceiptFragmentFragmentDoc = gql`
87
90
  fragment receiptFragment on Receipt {
88
- contract {
89
- id
90
- }
91
+ id
91
92
  pc
92
93
  is
93
- to {
94
- id
95
- }
94
+ to
96
95
  toAddress
97
96
  amount
98
97
  assetId
@@ -130,10 +129,16 @@ var TransactionStatusFragmentFragmentDoc = gql`
130
129
  id
131
130
  }
132
131
  time
132
+ receipts {
133
+ ...receiptFragment
134
+ }
133
135
  programState {
134
136
  returnType
135
137
  data
136
138
  }
139
+ receipts {
140
+ ...receiptFragment
141
+ }
137
142
  }
138
143
  ... on FailureStatus {
139
144
  block {
@@ -141,26 +146,24 @@ var TransactionStatusFragmentFragmentDoc = gql`
141
146
  }
142
147
  time
143
148
  reason
149
+ receipts {
150
+ ...receiptFragment
151
+ }
144
152
  }
145
153
  ... on SqueezedOutStatus {
146
154
  reason
147
155
  }
148
156
  }
149
- `;
157
+ ${ReceiptFragmentFragmentDoc}`;
150
158
  var TransactionFragmentFragmentDoc = gql`
151
159
  fragment transactionFragment on Transaction {
152
160
  id
153
161
  rawPayload
154
- gasPrice
155
- receipts {
156
- ...receiptFragment
157
- }
158
162
  status {
159
163
  ...transactionStatusFragment
160
164
  }
161
165
  }
162
- ${ReceiptFragmentFragmentDoc}
163
- ${TransactionStatusFragmentFragmentDoc}`;
166
+ ${TransactionStatusFragmentFragmentDoc}`;
164
167
  var InputEstimatePredicatesFragmentFragmentDoc = gql`
165
168
  fragment inputEstimatePredicatesFragment on Input {
166
169
  ... on InputCoin {
@@ -178,6 +181,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = gql`
178
181
  }
179
182
  }
180
183
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
184
+ var DryRunFailureStatusFragmentFragmentDoc = gql`
185
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
186
+ reason
187
+ programState {
188
+ returnType
189
+ data
190
+ }
191
+ }
192
+ `;
193
+ var DryRunSuccessStatusFragmentFragmentDoc = gql`
194
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
195
+ programState {
196
+ returnType
197
+ data
198
+ }
199
+ }
200
+ `;
201
+ var DryRunTransactionStatusFragmentFragmentDoc = gql`
202
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
203
+ ... on DryRunFailureStatus {
204
+ ...dryRunFailureStatusFragment
205
+ }
206
+ ... on DryRunSuccessStatus {
207
+ ...dryRunSuccessStatusFragment
208
+ }
209
+ }
210
+ ${DryRunFailureStatusFragmentFragmentDoc}
211
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
212
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = gql`
213
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
214
+ id
215
+ status {
216
+ ...dryRunTransactionStatusFragment
217
+ }
218
+ receipts {
219
+ ...receiptFragment
220
+ }
221
+ }
222
+ ${DryRunTransactionStatusFragmentFragmentDoc}
223
+ ${ReceiptFragmentFragmentDoc}`;
181
224
  var CoinFragmentFragmentDoc = gql`
182
225
  fragment coinFragment on Coin {
183
226
  __typename
@@ -185,7 +228,6 @@ var CoinFragmentFragmentDoc = gql`
185
228
  owner
186
229
  amount
187
230
  assetId
188
- maturity
189
231
  blockCreated
190
232
  txCreatedIdx
191
233
  }
@@ -262,8 +304,8 @@ var BalanceFragmentFragmentDoc = gql`
262
304
  var BlockFragmentFragmentDoc = gql`
263
305
  fragment blockFragment on Block {
264
306
  id
307
+ height
265
308
  header {
266
- height
267
309
  time
268
310
  }
269
311
  transactions {
@@ -333,7 +375,6 @@ var GasCostsFragmentFragmentDoc = gql`
333
375
  cb
334
376
  cfei
335
377
  cfsi
336
- croo
337
378
  div
338
379
  divi
339
380
  ecr1
@@ -416,6 +457,9 @@ var GasCostsFragmentFragmentDoc = gql`
416
457
  ccp {
417
458
  ...DependentCostFragment
418
459
  }
460
+ croo {
461
+ ...DependentCostFragment
462
+ }
419
463
  csiz {
420
464
  ...DependentCostFragment
421
465
  }
@@ -538,14 +582,6 @@ var NodeInfoFragmentFragmentDoc = gql`
538
582
  maxTx
539
583
  maxDepth
540
584
  nodeVersion
541
- peers {
542
- id
543
- addresses
544
- clientVersion
545
- blockHeight
546
- lastHeartbeatMs
547
- appScore
548
- }
549
585
  }
550
586
  `;
551
587
  var GetVersionDocument = gql`
@@ -580,13 +616,9 @@ var GetTransactionWithReceiptsDocument = gql`
580
616
  query getTransactionWithReceipts($transactionId: TransactionId!) {
581
617
  transaction(id: $transactionId) {
582
618
  ...transactionFragment
583
- receipts {
584
- ...receiptFragment
585
- }
586
619
  }
587
620
  }
588
- ${TransactionFragmentFragmentDoc}
589
- ${ReceiptFragmentFragmentDoc}`;
621
+ ${TransactionFragmentFragmentDoc}`;
590
622
  var GetTransactionsDocument = gql`
591
623
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
592
624
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -714,6 +746,20 @@ var GetBalanceDocument = gql`
714
746
  }
715
747
  }
716
748
  ${BalanceFragmentFragmentDoc}`;
749
+ var GetLatestGasPriceDocument = gql`
750
+ query getLatestGasPrice {
751
+ latestGasPrice {
752
+ gasPrice
753
+ }
754
+ }
755
+ `;
756
+ var EstimateGasPriceDocument = gql`
757
+ query estimateGasPrice($blockHorizon: U32!) {
758
+ estimateGasPrice(blockHorizon: $blockHorizon) {
759
+ gasPrice
760
+ }
761
+ }
762
+ `;
717
763
  var GetBalancesDocument = gql`
718
764
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
719
765
  balances(
@@ -768,12 +814,12 @@ var GetMessageStatusDocument = gql`
768
814
  }
769
815
  `;
770
816
  var DryRunDocument = gql`
771
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
772
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
773
- ...receiptFragment
817
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
818
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
819
+ ...dryRunTransactionExecutionStatusFragment
774
820
  }
775
821
  }
776
- ${ReceiptFragmentFragmentDoc}`;
822
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
777
823
  var SubmitDocument = gql`
778
824
  mutation submit($encodedTransaction: HexString!) {
779
825
  submit(tx: $encodedTransaction) {
@@ -856,6 +902,12 @@ function getSdk(requester) {
856
902
  getBalance(variables, options) {
857
903
  return requester(GetBalanceDocument, variables, options);
858
904
  },
905
+ getLatestGasPrice(variables, options) {
906
+ return requester(GetLatestGasPriceDocument, variables, options);
907
+ },
908
+ estimateGasPrice(variables, options) {
909
+ return requester(EstimateGasPriceDocument, variables, options);
910
+ },
859
911
  getBalances(variables, options) {
860
912
  return requester(GetBalancesDocument, variables, options);
861
913
  },
@@ -1039,7 +1091,6 @@ var inputify = (value) => {
1039
1091
  txIndex: toNumber(arrayify(value.txPointer).slice(8, 16))
1040
1092
  },
1041
1093
  witnessIndex: value.witnessIndex,
1042
- maturity: value.maturity ?? 0,
1043
1094
  predicateGasUsed: bn2(value.predicateGasUsed),
1044
1095
  predicateLength: predicate.length,
1045
1096
  predicateDataLength: predicateData.length,
@@ -1149,8 +1200,8 @@ var outputify = (value) => {
1149
1200
 
1150
1201
  // src/providers/transaction-request/transaction-request.ts
1151
1202
  import { Address, addressify } from "@fuel-ts/address";
1152
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1153
- import { bn as bn6 } from "@fuel-ts/math";
1203
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1204
+ import { bn as bn7 } from "@fuel-ts/math";
1154
1205
  import {
1155
1206
  PolicyType,
1156
1207
  TransactionCoder,
@@ -1159,6 +1210,7 @@ import {
1159
1210
  TransactionType
1160
1211
  } from "@fuel-ts/transactions";
1161
1212
  import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
1213
+ import { randomBytes } from "ethers";
1162
1214
 
1163
1215
  // src/providers/resource.ts
1164
1216
  var isCoin = (resource) => "id" in resource;
@@ -1199,8 +1251,8 @@ function assembleReceiptByType(receipt) {
1199
1251
  case "CALL" /* Call */: {
1200
1252
  const callReceipt = {
1201
1253
  type: ReceiptType.Call,
1202
- from: hexOrZero(receipt.contract?.id),
1203
- to: hexOrZero(receipt?.to?.id),
1254
+ from: hexOrZero(receipt.id || receipt.contractId),
1255
+ to: hexOrZero(receipt?.to),
1204
1256
  amount: bn4(receipt.amount),
1205
1257
  assetId: hexOrZero(receipt.assetId),
1206
1258
  gas: bn4(receipt.gas),
@@ -1214,7 +1266,7 @@ function assembleReceiptByType(receipt) {
1214
1266
  case "RETURN" /* Return */: {
1215
1267
  const returnReceipt = {
1216
1268
  type: ReceiptType.Return,
1217
- id: hexOrZero(receipt.contract?.id),
1269
+ id: hexOrZero(receipt.id || receipt.contractId),
1218
1270
  val: bn4(receipt.val),
1219
1271
  pc: bn4(receipt.pc),
1220
1272
  is: bn4(receipt.is)
@@ -1224,7 +1276,7 @@ function assembleReceiptByType(receipt) {
1224
1276
  case "RETURN_DATA" /* ReturnData */: {
1225
1277
  const returnDataReceipt = {
1226
1278
  type: ReceiptType.ReturnData,
1227
- id: hexOrZero(receipt.contract?.id),
1279
+ id: hexOrZero(receipt.id || receipt.contractId),
1228
1280
  ptr: bn4(receipt.ptr),
1229
1281
  len: bn4(receipt.len),
1230
1282
  digest: hexOrZero(receipt.digest),
@@ -1236,7 +1288,7 @@ function assembleReceiptByType(receipt) {
1236
1288
  case "PANIC" /* Panic */: {
1237
1289
  const panicReceipt = {
1238
1290
  type: ReceiptType.Panic,
1239
- id: hexOrZero(receipt.contract?.id),
1291
+ id: hexOrZero(receipt.id),
1240
1292
  reason: bn4(receipt.reason),
1241
1293
  pc: bn4(receipt.pc),
1242
1294
  is: bn4(receipt.is),
@@ -1247,7 +1299,7 @@ function assembleReceiptByType(receipt) {
1247
1299
  case "REVERT" /* Revert */: {
1248
1300
  const revertReceipt = {
1249
1301
  type: ReceiptType.Revert,
1250
- id: hexOrZero(receipt.contract?.id),
1302
+ id: hexOrZero(receipt.id || receipt.contractId),
1251
1303
  val: bn4(receipt.ra),
1252
1304
  pc: bn4(receipt.pc),
1253
1305
  is: bn4(receipt.is)
@@ -1257,7 +1309,7 @@ function assembleReceiptByType(receipt) {
1257
1309
  case "LOG" /* Log */: {
1258
1310
  const logReceipt = {
1259
1311
  type: ReceiptType.Log,
1260
- id: hexOrZero(receipt.contract?.id),
1312
+ id: hexOrZero(receipt.id || receipt.contractId),
1261
1313
  val0: bn4(receipt.ra),
1262
1314
  val1: bn4(receipt.rb),
1263
1315
  val2: bn4(receipt.rc),
@@ -1270,7 +1322,7 @@ function assembleReceiptByType(receipt) {
1270
1322
  case "LOG_DATA" /* LogData */: {
1271
1323
  const logDataReceipt = {
1272
1324
  type: ReceiptType.LogData,
1273
- id: hexOrZero(receipt.contract?.id),
1325
+ id: hexOrZero(receipt.id || receipt.contractId),
1274
1326
  val0: bn4(receipt.ra),
1275
1327
  val1: bn4(receipt.rb),
1276
1328
  ptr: bn4(receipt.ptr),
@@ -1284,8 +1336,8 @@ function assembleReceiptByType(receipt) {
1284
1336
  case "TRANSFER" /* Transfer */: {
1285
1337
  const transferReceipt = {
1286
1338
  type: ReceiptType.Transfer,
1287
- from: hexOrZero(receipt.contract?.id),
1288
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1339
+ from: hexOrZero(receipt.id || receipt.contractId),
1340
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1289
1341
  amount: bn4(receipt.amount),
1290
1342
  assetId: hexOrZero(receipt.assetId),
1291
1343
  pc: bn4(receipt.pc),
@@ -1296,8 +1348,8 @@ function assembleReceiptByType(receipt) {
1296
1348
  case "TRANSFER_OUT" /* TransferOut */: {
1297
1349
  const transferOutReceipt = {
1298
1350
  type: ReceiptType.TransferOut,
1299
- from: hexOrZero(receipt.contract?.id),
1300
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1351
+ from: hexOrZero(receipt.id || receipt.contractId),
1352
+ to: hexOrZero(receipt.toAddress || receipt.to),
1301
1353
  amount: bn4(receipt.amount),
1302
1354
  assetId: hexOrZero(receipt.assetId),
1303
1355
  pc: bn4(receipt.pc),
@@ -1340,7 +1392,7 @@ function assembleReceiptByType(receipt) {
1340
1392
  return receiptMessageOut;
1341
1393
  }
1342
1394
  case "MINT" /* Mint */: {
1343
- const contractId = hexOrZero(receipt.contract?.id);
1395
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1344
1396
  const subId = hexOrZero(receipt.subId);
1345
1397
  const assetId = ReceiptMintCoder.getAssetId(contractId, subId);
1346
1398
  const mintReceipt = {
@@ -1355,7 +1407,7 @@ function assembleReceiptByType(receipt) {
1355
1407
  return mintReceipt;
1356
1408
  }
1357
1409
  case "BURN" /* Burn */: {
1358
- const contractId = hexOrZero(receipt.contract?.id);
1410
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1359
1411
  const subId = hexOrZero(receipt.subId);
1360
1412
  const assetId = ReceiptBurnCoder.getAssetId(contractId, subId);
1361
1413
  const burnReceipt = {
@@ -1381,7 +1433,6 @@ import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/error
1381
1433
  import { bn as bn5 } from "@fuel-ts/math";
1382
1434
  import { ReceiptType as ReceiptType2 } from "@fuel-ts/transactions";
1383
1435
  import { arrayify as arrayify3 } from "@fuel-ts/utils";
1384
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => bn5(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1385
1436
  var getGasUsedFromReceipts = (receipts) => {
1386
1437
  const scriptResult = receipts.filter(
1387
1438
  (receipt) => receipt.type === ReceiptType2.ScriptResult
@@ -1402,18 +1453,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1402
1453
  }
1403
1454
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1404
1455
  const witnessCache = [];
1405
- const totalGas = inputs.reduce((total, input) => {
1456
+ const chargeableInputs = inputs.filter((input) => {
1457
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1458
+ if (isCoinOrMessage) {
1459
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1460
+ return true;
1461
+ }
1462
+ if (!witnessCache.includes(input.witnessIndex)) {
1463
+ witnessCache.push(input.witnessIndex);
1464
+ return true;
1465
+ }
1466
+ }
1467
+ return false;
1468
+ });
1469
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1470
+ const totalGas = chargeableInputs.reduce((total, input) => {
1406
1471
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1407
1472
  return total.add(
1408
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1473
+ vmInitializationCost.add(resolveGasDependentCosts(arrayify3(input.predicate).length, gasCosts.contractRoot)).add(bn5(input.predicateGasUsed))
1409
1474
  );
1410
1475
  }
1411
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1412
- witnessCache.push(input.witnessIndex);
1413
- return total.add(gasCosts.ecr1);
1414
- }
1415
- return total;
1416
- }, bn5());
1476
+ return total.add(gasCosts.ecr1);
1477
+ }, bn5(0));
1417
1478
  return totalGas;
1418
1479
  }
1419
1480
  function getMinGas(params) {
@@ -1425,12 +1486,20 @@ function getMinGas(params) {
1425
1486
  return minGas;
1426
1487
  }
1427
1488
  function getMaxGas(params) {
1428
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = bn5(0) } = params;
1489
+ const {
1490
+ gasPerByte,
1491
+ witnessesLength,
1492
+ witnessLimit,
1493
+ minGas,
1494
+ gasLimit = bn5(0),
1495
+ maxGasPerTx
1496
+ } = params;
1429
1497
  let remainingAllowedWitnessGas = bn5(0);
1430
1498
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1431
1499
  remainingAllowedWitnessGas = bn5(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1432
1500
  }
1433
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1501
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1502
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1434
1503
  }
1435
1504
  function calculateMetadataGasForTxCreate({
1436
1505
  gasCosts,
@@ -1452,6 +1521,10 @@ function calculateMetadataGasForTxScript({
1452
1521
  }) {
1453
1522
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1454
1523
  }
1524
+ var calculateGasFee = (params) => {
1525
+ const { gas, gasPrice, priceFactor, tip } = params;
1526
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1527
+ };
1455
1528
 
1456
1529
  // src/providers/utils/json.ts
1457
1530
  import { hexlify as hexlify5 } from "@fuel-ts/utils";
@@ -1493,6 +1566,86 @@ function sleep(time) {
1493
1566
  });
1494
1567
  }
1495
1568
 
1569
+ // src/providers/utils/extract-tx-error.ts
1570
+ import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
1571
+ import { bn as bn6 } from "@fuel-ts/math";
1572
+ import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
1573
+ import {
1574
+ FAILED_REQUIRE_SIGNAL,
1575
+ FAILED_ASSERT_EQ_SIGNAL,
1576
+ FAILED_ASSERT_NE_SIGNAL,
1577
+ FAILED_ASSERT_SIGNAL,
1578
+ FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
1579
+ PANIC_REASONS,
1580
+ PANIC_DOC_URL
1581
+ } from "@fuel-ts/transactions/configs";
1582
+ var assemblePanicError = (status) => {
1583
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1584
+ const reason = status.reason;
1585
+ if (PANIC_REASONS.includes(status.reason)) {
1586
+ errorMessage = `${errorMessage}
1587
+
1588
+ You can read more about this error at:
1589
+
1590
+ ${PANIC_DOC_URL}#variant.${status.reason}`;
1591
+ }
1592
+ return { errorMessage, reason };
1593
+ };
1594
+ var stringify = (obj) => JSON.stringify(obj, null, 2);
1595
+ var assembleRevertError = (receipts, logs) => {
1596
+ let errorMessage = "The transaction reverted with an unknown reason.";
1597
+ const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
1598
+ let reason = "";
1599
+ if (revertReceipt) {
1600
+ const reasonHex = bn6(revertReceipt.val).toHex();
1601
+ switch (reasonHex) {
1602
+ case FAILED_REQUIRE_SIGNAL: {
1603
+ reason = "require";
1604
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1605
+ break;
1606
+ }
1607
+ case FAILED_ASSERT_EQ_SIGNAL: {
1608
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1609
+ reason = "assert_eq";
1610
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1611
+ break;
1612
+ }
1613
+ case FAILED_ASSERT_NE_SIGNAL: {
1614
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1615
+ reason = "assert_ne";
1616
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1617
+ break;
1618
+ }
1619
+ case FAILED_ASSERT_SIGNAL:
1620
+ reason = "assert";
1621
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1622
+ break;
1623
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
1624
+ reason = "MissingOutputChange";
1625
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1626
+ break;
1627
+ default:
1628
+ reason = "unknown";
1629
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
1630
+ }
1631
+ }
1632
+ return { errorMessage, reason };
1633
+ };
1634
+ var extractTxError = (params) => {
1635
+ const { receipts, status, logs } = params;
1636
+ const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
1637
+ const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
1638
+ const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
1639
+ const metadata = {
1640
+ logs,
1641
+ receipts,
1642
+ panic: isPanic,
1643
+ revert: isRevert,
1644
+ reason
1645
+ };
1646
+ return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
1647
+ };
1648
+
1496
1649
  // src/providers/transaction-request/errors.ts
1497
1650
  var NoWitnessAtIndexError = class extends Error {
1498
1651
  constructor(index) {
@@ -1516,7 +1669,7 @@ var witnessify = (value) => {
1516
1669
  // src/providers/transaction-request/transaction-request.ts
1517
1670
  var BaseTransactionRequest = class {
1518
1671
  /** Gas price for transaction */
1519
- gasPrice;
1672
+ tip;
1520
1673
  /** Block until which tx cannot be included */
1521
1674
  maturity;
1522
1675
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1529,38 +1682,34 @@ var BaseTransactionRequest = class {
1529
1682
  outputs = [];
1530
1683
  /** List of witnesses */
1531
1684
  witnesses = [];
1532
- /** Base asset ID - should be fetched from the chain */
1533
- baseAssetId = ZeroBytes324;
1534
1685
  /**
1535
1686
  * Constructor for initializing a base transaction request.
1536
1687
  *
1537
1688
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1538
1689
  */
1539
1690
  constructor({
1540
- gasPrice,
1691
+ tip,
1541
1692
  maturity,
1542
1693
  maxFee,
1543
1694
  witnessLimit,
1544
1695
  inputs,
1545
1696
  outputs,
1546
- witnesses,
1547
- baseAssetId
1697
+ witnesses
1548
1698
  } = {}) {
1549
- this.gasPrice = bn6(gasPrice);
1699
+ this.tip = bn7(tip);
1550
1700
  this.maturity = maturity ?? 0;
1551
- this.witnessLimit = witnessLimit ? bn6(witnessLimit) : void 0;
1552
- this.maxFee = maxFee ? bn6(maxFee) : void 0;
1701
+ this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1702
+ this.maxFee = maxFee ? bn7(maxFee) : void 0;
1553
1703
  this.inputs = inputs ?? [];
1554
1704
  this.outputs = outputs ?? [];
1555
1705
  this.witnesses = witnesses ?? [];
1556
- this.baseAssetId = baseAssetId ?? ZeroBytes324;
1557
1706
  }
1558
1707
  static getPolicyMeta(req) {
1559
1708
  let policyTypes = 0;
1560
1709
  const policies = [];
1561
- if (req.gasPrice) {
1562
- policyTypes += PolicyType.GasPrice;
1563
- policies.push({ data: req.gasPrice, type: PolicyType.GasPrice });
1710
+ if (req.tip) {
1711
+ policyTypes += PolicyType.Tip;
1712
+ policies.push({ data: req.tip, type: PolicyType.Tip });
1564
1713
  }
1565
1714
  if (req.witnessLimit) {
1566
1715
  policyTypes += PolicyType.WitnessLimit;
@@ -1747,10 +1896,10 @@ var BaseTransactionRequest = class {
1747
1896
  * @param predicate - Predicate bytes.
1748
1897
  * @param predicateData - Predicate data bytes.
1749
1898
  */
1750
- addCoinInput(coin, predicate) {
1899
+ addCoinInput(coin) {
1751
1900
  const { assetId, owner, amount } = coin;
1752
1901
  let witnessIndex;
1753
- if (predicate) {
1902
+ if (coin.predicate) {
1754
1903
  witnessIndex = 0;
1755
1904
  } else {
1756
1905
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1765,9 +1914,7 @@ var BaseTransactionRequest = class {
1765
1914
  amount,
1766
1915
  assetId,
1767
1916
  txPointer: "0x00000000000000000000000000000000",
1768
- witnessIndex,
1769
- predicate: predicate?.bytes,
1770
- predicateData: predicate?.predicateDataBytes
1917
+ witnessIndex
1771
1918
  };
1772
1919
  this.pushInput(input);
1773
1920
  this.addChangeOutput(owner, assetId);
@@ -1778,11 +1925,13 @@ var BaseTransactionRequest = class {
1778
1925
  *
1779
1926
  * @param message - Message resource.
1780
1927
  * @param predicate - Predicate bytes.
1928
+ * @param predicateData - Predicate data bytes.
1781
1929
  */
1782
- addMessageInput(message, predicate) {
1930
+ addMessageInput(message) {
1783
1931
  const { recipient, sender, amount } = message;
1932
+ const assetId = BaseAssetId2;
1784
1933
  let witnessIndex;
1785
- if (predicate) {
1934
+ if (message.predicate) {
1786
1935
  witnessIndex = 0;
1787
1936
  } else {
1788
1937
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1796,12 +1945,10 @@ var BaseTransactionRequest = class {
1796
1945
  sender: sender.toB256(),
1797
1946
  recipient: recipient.toB256(),
1798
1947
  amount,
1799
- witnessIndex,
1800
- predicate: predicate?.bytes,
1801
- predicateData: predicate?.predicateDataBytes
1948
+ witnessIndex
1802
1949
  };
1803
1950
  this.pushInput(input);
1804
- this.addChangeOutput(recipient, this.baseAssetId);
1951
+ this.addChangeOutput(recipient, assetId);
1805
1952
  }
1806
1953
  /**
1807
1954
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1829,32 +1976,6 @@ var BaseTransactionRequest = class {
1829
1976
  resources.forEach((resource) => this.addResource(resource));
1830
1977
  return this;
1831
1978
  }
1832
- /**
1833
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1834
- * outputs from the related assetIds.
1835
- *
1836
- * @param resources - The resources to add.
1837
- * @returns This transaction.
1838
- */
1839
- addPredicateResource(resource, predicate) {
1840
- if (isCoin(resource)) {
1841
- this.addCoinInput(resource, predicate);
1842
- } else {
1843
- this.addMessageInput(resource, predicate);
1844
- }
1845
- return this;
1846
- }
1847
- /**
1848
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
1849
- * from the related assetIds.
1850
- *
1851
- * @param resources - The resources to add.
1852
- * @returns This transaction.
1853
- */
1854
- addPredicateResources(resources, predicate) {
1855
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1856
- return this;
1857
- }
1858
1979
  /**
1859
1980
  * Adds a coin output to the transaction.
1860
1981
  *
@@ -1862,12 +1983,12 @@ var BaseTransactionRequest = class {
1862
1983
  * @param amount - Amount of coin.
1863
1984
  * @param assetId - Asset ID of coin.
1864
1985
  */
1865
- addCoinOutput(to, amount, assetId) {
1986
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
1866
1987
  this.pushOutput({
1867
1988
  type: OutputType2.Coin,
1868
1989
  to: addressify(to).toB256(),
1869
1990
  amount,
1870
- assetId: assetId ?? this.baseAssetId
1991
+ assetId
1871
1992
  });
1872
1993
  return this;
1873
1994
  }
@@ -1894,7 +2015,7 @@ var BaseTransactionRequest = class {
1894
2015
  * @param to - Address of the owner.
1895
2016
  * @param assetId - Asset ID of coin.
1896
2017
  */
1897
- addChangeOutput(to, assetId) {
2018
+ addChangeOutput(to, assetId = BaseAssetId2) {
1898
2019
  const changeOutput = this.getChangeOutputs().find(
1899
2020
  (output) => hexlify7(output.assetId) === assetId
1900
2021
  );
@@ -1902,7 +2023,7 @@ var BaseTransactionRequest = class {
1902
2023
  this.pushOutput({
1903
2024
  type: OutputType2.Change,
1904
2025
  to: addressify(to).toB256(),
1905
- assetId: assetId ?? this.baseAssetId
2026
+ assetId
1906
2027
  });
1907
2028
  }
1908
2029
  }
@@ -1934,7 +2055,7 @@ var BaseTransactionRequest = class {
1934
2055
  }
1935
2056
  calculateMaxGas(chainInfo, minGas) {
1936
2057
  const { consensusParameters } = chainInfo;
1937
- const { gasPerByte } = consensusParameters;
2058
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
1938
2059
  const witnessesLength = this.toTransaction().witnesses.reduce(
1939
2060
  (acc, wit) => acc + wit.dataLength,
1940
2061
  0
@@ -1943,7 +2064,8 @@ var BaseTransactionRequest = class {
1943
2064
  gasPerByte,
1944
2065
  minGas,
1945
2066
  witnessesLength,
1946
- witnessLimit: this.witnessLimit
2067
+ witnessLimit: this.witnessLimit,
2068
+ maxGasPerTx
1947
2069
  });
1948
2070
  }
1949
2071
  /**
@@ -1953,12 +2075,6 @@ var BaseTransactionRequest = class {
1953
2075
  * @param quantities - CoinQuantity Array.
1954
2076
  */
1955
2077
  fundWithFakeUtxos(quantities, resourcesOwner) {
1956
- let idCounter = 0;
1957
- const generateId = () => {
1958
- const counterString = String(idCounter++);
1959
- const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
1960
- return id;
1961
- };
1962
2078
  const findAssetInput = (assetId) => this.inputs.find((input) => {
1963
2079
  if ("assetId" in input) {
1964
2080
  return input.assetId === assetId;
@@ -1967,24 +2083,27 @@ var BaseTransactionRequest = class {
1967
2083
  });
1968
2084
  const updateAssetInput = (assetId, quantity) => {
1969
2085
  const assetInput = findAssetInput(assetId);
2086
+ let usedQuantity = quantity;
2087
+ if (assetId === BaseAssetId2) {
2088
+ usedQuantity = bn7("1000000000000000000");
2089
+ }
1970
2090
  if (assetInput && "assetId" in assetInput) {
1971
- assetInput.id = generateId();
1972
- assetInput.amount = quantity;
2091
+ assetInput.id = hexlify7(randomBytes(33));
2092
+ assetInput.amount = usedQuantity;
1973
2093
  } else {
1974
2094
  this.addResources([
1975
2095
  {
1976
- id: generateId(),
1977
- amount: quantity,
2096
+ id: hexlify7(randomBytes(33)),
2097
+ amount: usedQuantity,
1978
2098
  assetId,
1979
2099
  owner: resourcesOwner || Address.fromRandom(),
1980
- maturity: 0,
1981
- blockCreated: bn6(1),
1982
- txCreatedIdx: bn6(1)
2100
+ blockCreated: bn7(1),
2101
+ txCreatedIdx: bn7(1)
1983
2102
  }
1984
2103
  ]);
1985
2104
  }
1986
2105
  };
1987
- updateAssetInput(this.baseAssetId, bn6(1e11));
2106
+ updateAssetInput(BaseAssetId2, bn7(1e11));
1988
2107
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
1989
2108
  }
1990
2109
  /**
@@ -1995,7 +2114,7 @@ var BaseTransactionRequest = class {
1995
2114
  */
1996
2115
  getCoinOutputsQuantities() {
1997
2116
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
1998
- amount: bn6(amount),
2117
+ amount: bn7(amount),
1999
2118
  assetId: assetId.toString()
2000
2119
  }));
2001
2120
  return coinsQuantities;
@@ -2009,7 +2128,7 @@ var BaseTransactionRequest = class {
2009
2128
  toJSON() {
2010
2129
  return normalizeJSON(this);
2011
2130
  }
2012
- updatePredicateInputs(inputs) {
2131
+ updatePredicateGasUsed(inputs) {
2013
2132
  this.inputs.forEach((i) => {
2014
2133
  let correspondingInput;
2015
2134
  switch (i.type) {
@@ -2024,25 +2143,34 @@ var BaseTransactionRequest = class {
2024
2143
  default:
2025
2144
  return;
2026
2145
  }
2027
- if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
2146
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
2028
2147
  i.predicate = correspondingInput.predicate;
2029
2148
  i.predicateData = correspondingInput.predicateData;
2030
2149
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
2031
2150
  }
2032
2151
  });
2033
2152
  }
2153
+ shiftPredicateData() {
2154
+ this.inputs.forEach((input) => {
2155
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2156
+ input.predicateData = input.paddPredicateData(
2157
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2158
+ );
2159
+ }
2160
+ });
2161
+ }
2034
2162
  };
2035
2163
 
2036
2164
  // src/providers/transaction-request/create-transaction-request.ts
2037
2165
  import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
2038
- import { bn as bn8 } from "@fuel-ts/math";
2166
+ import { bn as bn9 } from "@fuel-ts/math";
2039
2167
  import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
2040
2168
  import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2041
2169
 
2042
2170
  // src/providers/transaction-request/hash-transaction.ts
2043
2171
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2044
2172
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2045
- import { bn as bn7 } from "@fuel-ts/math";
2173
+ import { bn as bn8 } from "@fuel-ts/math";
2046
2174
  import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2047
2175
  import { concat as concat2 } from "@fuel-ts/utils";
2048
2176
  import { clone as clone2 } from "ramda";
@@ -2059,11 +2187,11 @@ function hashTransaction(transactionRequest, chainId) {
2059
2187
  blockHeight: 0,
2060
2188
  txIndex: 0
2061
2189
  };
2062
- inputClone.predicateGasUsed = bn7(0);
2190
+ inputClone.predicateGasUsed = bn8(0);
2063
2191
  return inputClone;
2064
2192
  }
2065
2193
  case InputType3.Message: {
2066
- inputClone.predicateGasUsed = bn7(0);
2194
+ inputClone.predicateGasUsed = bn8(0);
2067
2195
  return inputClone;
2068
2196
  }
2069
2197
  case InputType3.Contract: {
@@ -2090,12 +2218,12 @@ function hashTransaction(transactionRequest, chainId) {
2090
2218
  return outputClone;
2091
2219
  }
2092
2220
  case OutputType3.Change: {
2093
- outputClone.amount = bn7(0);
2221
+ outputClone.amount = bn8(0);
2094
2222
  return outputClone;
2095
2223
  }
2096
2224
  case OutputType3.Variable: {
2097
2225
  outputClone.to = ZeroBytes325;
2098
- outputClone.amount = bn7(0);
2226
+ outputClone.amount = bn8(0);
2099
2227
  outputClone.assetId = ZeroBytes325;
2100
2228
  return outputClone;
2101
2229
  }
@@ -2219,7 +2347,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2219
2347
  }
2220
2348
  metadataGas(gasCosts) {
2221
2349
  return calculateMetadataGasForTxCreate({
2222
- contractBytesSize: bn8(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2350
+ contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2223
2351
  gasCosts,
2224
2352
  stateRootSize: this.storageSlots.length,
2225
2353
  txBytesSize: this.byteSize()
@@ -2231,7 +2359,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2231
2359
  import { Interface } from "@fuel-ts/abi-coder";
2232
2360
  import { addressify as addressify2 } from "@fuel-ts/address";
2233
2361
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2234
- import { bn as bn9 } from "@fuel-ts/math";
2362
+ import { bn as bn10 } from "@fuel-ts/math";
2235
2363
  import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2236
2364
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2237
2365
 
@@ -2285,7 +2413,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2285
2413
  */
2286
2414
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2287
2415
  super(rest);
2288
- this.gasLimit = bn9(gasLimit);
2416
+ this.gasLimit = bn10(gasLimit);
2289
2417
  this.script = arrayify8(script ?? returnZeroScript.bytes);
2290
2418
  this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
2291
2419
  this.abis = rest.abis;
@@ -2367,7 +2495,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2367
2495
  }
2368
2496
  calculateMaxGas(chainInfo, minGas) {
2369
2497
  const { consensusParameters } = chainInfo;
2370
- const { gasPerByte } = consensusParameters;
2498
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2371
2499
  const witnessesLength = this.toTransaction().witnesses.reduce(
2372
2500
  (acc, wit) => acc + wit.dataLength,
2373
2501
  0
@@ -2377,7 +2505,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2377
2505
  minGas,
2378
2506
  witnessesLength,
2379
2507
  witnessLimit: this.witnessLimit,
2380
- gasLimit: this.gasLimit
2508
+ gasLimit: this.gasLimit,
2509
+ maxGasPerTx
2381
2510
  });
2382
2511
  }
2383
2512
  /**
@@ -2433,8 +2562,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2433
2562
  };
2434
2563
 
2435
2564
  // src/providers/transaction-request/utils.ts
2436
- import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
2437
- import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2565
+ import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2566
+ import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2438
2567
  var transactionRequestify = (obj) => {
2439
2568
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2440
2569
  return obj;
@@ -2448,48 +2577,65 @@ var transactionRequestify = (obj) => {
2448
2577
  return CreateTransactionRequest.from(obj);
2449
2578
  }
2450
2579
  default: {
2451
- throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2580
+ throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2452
2581
  }
2453
2582
  }
2454
2583
  };
2584
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2585
+ (acc, input) => {
2586
+ if (input.type === InputType5.Coin && input.owner === owner) {
2587
+ acc.utxos.push(input.id);
2588
+ }
2589
+ if (input.type === InputType5.Message && input.recipient === owner) {
2590
+ acc.messages.push(input.nonce);
2591
+ }
2592
+ return acc;
2593
+ },
2594
+ {
2595
+ utxos: [],
2596
+ messages: []
2597
+ }
2598
+ );
2455
2599
 
2456
2600
  // src/providers/transaction-response/transaction-response.ts
2457
- import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
2458
- import { bn as bn13 } from "@fuel-ts/math";
2601
+ import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2602
+ import { bn as bn15 } from "@fuel-ts/math";
2459
2603
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2460
2604
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2461
2605
 
2462
2606
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2607
+ import { bn as bn14 } from "@fuel-ts/math";
2608
+ import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2463
2609
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2464
2610
 
2465
2611
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2466
- import { bn as bn10 } from "@fuel-ts/math";
2612
+ import { bn as bn11 } from "@fuel-ts/math";
2467
2613
  import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
2468
2614
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2469
2615
  var calculateTransactionFee = (params) => {
2470
2616
  const {
2471
- gasUsed,
2617
+ gasPrice,
2472
2618
  rawPayload,
2473
- consensusParameters: { gasCosts, feeParams }
2619
+ tip,
2620
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2474
2621
  } = params;
2475
- const gasPerByte = bn10(feeParams.gasPerByte);
2476
- const gasPriceFactor = bn10(feeParams.gasPriceFactor);
2622
+ const gasPerByte = bn11(feeParams.gasPerByte);
2623
+ const gasPriceFactor = bn11(feeParams.gasPriceFactor);
2477
2624
  const transactionBytes = arrayify9(rawPayload);
2478
2625
  const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
2479
2626
  if (transaction.type === TransactionType6.Mint) {
2480
2627
  return {
2481
- fee: bn10(0),
2482
- minFee: bn10(0),
2483
- maxFee: bn10(0),
2484
- feeFromGasUsed: bn10(0)
2628
+ fee: bn11(0),
2629
+ minFee: bn11(0),
2630
+ maxFee: bn11(0)
2485
2631
  };
2486
2632
  }
2487
2633
  const { type, witnesses, inputs, policies } = transaction;
2488
- let metadataGas = bn10(0);
2489
- let gasLimit = bn10(0);
2634
+ let metadataGas = bn11(0);
2635
+ let gasLimit = bn11(0);
2490
2636
  if (type === TransactionType6.Create) {
2491
2637
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2492
- const contractBytesSize = bn10(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2638
+ const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2493
2639
  metadataGas = calculateMetadataGasForTxCreate({
2494
2640
  contractBytesSize,
2495
2641
  gasCosts,
@@ -2508,12 +2654,11 @@ var calculateTransactionFee = (params) => {
2508
2654
  }
2509
2655
  const minGas = getMinGas({
2510
2656
  gasCosts,
2511
- gasPerByte: bn10(gasPerByte),
2657
+ gasPerByte: bn11(gasPerByte),
2512
2658
  inputs,
2513
2659
  metadataGas,
2514
2660
  txBytesSize: transactionBytes.length
2515
2661
  });
2516
- const gasPrice = bn10(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2517
2662
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2518
2663
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2519
2664
  const maxGas = getMaxGas({
@@ -2521,29 +2666,37 @@ var calculateTransactionFee = (params) => {
2521
2666
  minGas,
2522
2667
  witnessesLength,
2523
2668
  gasLimit,
2524
- witnessLimit
2669
+ witnessLimit,
2670
+ maxGasPerTx
2671
+ });
2672
+ const minFee = calculateGasFee({
2673
+ gasPrice,
2674
+ gas: minGas,
2675
+ priceFactor: gasPriceFactor,
2676
+ tip
2677
+ });
2678
+ const maxFee = calculateGasFee({
2679
+ gasPrice,
2680
+ gas: maxGas,
2681
+ priceFactor: gasPriceFactor,
2682
+ tip
2525
2683
  });
2526
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2527
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2528
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2529
- const fee = minFee.add(feeFromGasUsed);
2530
2684
  return {
2531
- fee,
2532
2685
  minFee,
2533
2686
  maxFee,
2534
- feeFromGasUsed
2687
+ fee: maxFee
2535
2688
  };
2536
2689
  };
2537
2690
 
2538
2691
  // src/providers/transaction-summary/operations.ts
2539
2692
  import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
2540
- import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2541
- import { bn as bn12 } from "@fuel-ts/math";
2542
- import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
2693
+ import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
2694
+ import { bn as bn13 } from "@fuel-ts/math";
2695
+ import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
2543
2696
 
2544
2697
  // src/providers/transaction-summary/call.ts
2545
2698
  import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
2546
- import { bn as bn11 } from "@fuel-ts/math";
2699
+ import { bn as bn12 } from "@fuel-ts/math";
2547
2700
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2548
2701
  const abiInterface = new Interface2(abi);
2549
2702
  const callFunctionSelector = receipt.param1.toHex(8);
@@ -2552,7 +2705,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2552
2705
  let encodedArgs;
2553
2706
  if (functionFragment.isInputDataPointer) {
2554
2707
  if (rawPayload) {
2555
- const argsOffset = bn11(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2708
+ const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2556
2709
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2557
2710
  }
2558
2711
  } else {
@@ -2586,8 +2739,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2586
2739
  };
2587
2740
 
2588
2741
  // src/providers/transaction-summary/input.ts
2589
- import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2590
- import { InputType as InputType5 } from "@fuel-ts/transactions";
2742
+ import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2743
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2591
2744
  function getInputsByTypes(inputs, types) {
2592
2745
  return inputs.filter((i) => types.includes(i.type));
2593
2746
  }
@@ -2595,16 +2748,16 @@ function getInputsByType(inputs, type) {
2595
2748
  return inputs.filter((i) => i.type === type);
2596
2749
  }
2597
2750
  function getInputsCoin(inputs) {
2598
- return getInputsByType(inputs, InputType5.Coin);
2751
+ return getInputsByType(inputs, InputType6.Coin);
2599
2752
  }
2600
2753
  function getInputsMessage(inputs) {
2601
- return getInputsByType(inputs, InputType5.Message);
2754
+ return getInputsByType(inputs, InputType6.Message);
2602
2755
  }
2603
2756
  function getInputsCoinAndMessage(inputs) {
2604
- return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2757
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2605
2758
  }
2606
2759
  function getInputsContract(inputs) {
2607
- return getInputsByType(inputs, InputType5.Contract);
2760
+ return getInputsByType(inputs, InputType6.Contract);
2608
2761
  }
2609
2762
  function getInputFromAssetId(inputs, assetId) {
2610
2763
  const coinInputs = getInputsCoin(inputs);
@@ -2623,19 +2776,19 @@ function getInputContractFromIndex(inputs, inputIndex) {
2623
2776
  if (!contractInput) {
2624
2777
  return void 0;
2625
2778
  }
2626
- if (contractInput.type !== InputType5.Contract) {
2627
- throw new FuelError8(
2628
- ErrorCode8.INVALID_TRANSACTION_INPUT,
2779
+ if (contractInput.type !== InputType6.Contract) {
2780
+ throw new FuelError9(
2781
+ ErrorCode9.INVALID_TRANSACTION_INPUT,
2629
2782
  `Contract input should be of type 'contract'.`
2630
2783
  );
2631
2784
  }
2632
2785
  return contractInput;
2633
2786
  }
2634
2787
  function getInputAccountAddress(input) {
2635
- if (input.type === InputType5.Coin) {
2788
+ if (input.type === InputType6.Coin) {
2636
2789
  return input.owner.toString();
2637
2790
  }
2638
- if (input.type === InputType5.Message) {
2791
+ if (input.type === InputType6.Message) {
2639
2792
  return input.recipient.toString();
2640
2793
  }
2641
2794
  return "";
@@ -2672,8 +2825,8 @@ function getTransactionTypeName(transactionType) {
2672
2825
  case TransactionType7.Script:
2673
2826
  return "Script" /* Script */;
2674
2827
  default:
2675
- throw new FuelError9(
2676
- ErrorCode9.INVALID_TRANSACTION_TYPE,
2828
+ throw new FuelError10(
2829
+ ErrorCode10.INVALID_TRANSACTION_TYPE,
2677
2830
  `Invalid transaction type: ${transactionType}.`
2678
2831
  );
2679
2832
  }
@@ -2692,10 +2845,10 @@ function isTypeScript(transactionType) {
2692
2845
  return isType(transactionType, "Script" /* Script */);
2693
2846
  }
2694
2847
  function getReceiptsCall(receipts) {
2695
- return getReceiptsByType(receipts, ReceiptType3.Call);
2848
+ return getReceiptsByType(receipts, ReceiptType4.Call);
2696
2849
  }
2697
2850
  function getReceiptsMessageOut(receipts) {
2698
- return getReceiptsByType(receipts, ReceiptType3.MessageOut);
2851
+ return getReceiptsByType(receipts, ReceiptType4.MessageOut);
2699
2852
  }
2700
2853
  var mergeAssets = (op1, op2) => {
2701
2854
  const assets1 = op1.assetsSent || [];
@@ -2708,7 +2861,7 @@ var mergeAssets = (op1, op2) => {
2708
2861
  if (!matchingAsset) {
2709
2862
  return asset1;
2710
2863
  }
2711
- const mergedAmount = bn12(asset1.amount).add(matchingAsset.amount);
2864
+ const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
2712
2865
  return { ...asset1, amount: mergedAmount };
2713
2866
  });
2714
2867
  return mergedAssets.concat(filteredAssets);
@@ -2891,11 +3044,11 @@ function getTransferOperations({
2891
3044
  });
2892
3045
  const transferReceipts = getReceiptsByType(
2893
3046
  receipts,
2894
- ReceiptType3.Transfer
3047
+ ReceiptType4.Transfer
2895
3048
  );
2896
3049
  const transferOutReceipts = getReceiptsByType(
2897
3050
  receipts,
2898
- ReceiptType3.TransferOut
3051
+ ReceiptType4.TransferOut
2899
3052
  );
2900
3053
  [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
2901
3054
  const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
@@ -2980,17 +3133,17 @@ function getOperations({
2980
3133
  }
2981
3134
 
2982
3135
  // src/providers/transaction-summary/receipt.ts
2983
- import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
3136
+ import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
2984
3137
  var processGqlReceipt = (gqlReceipt) => {
2985
3138
  const receipt = assembleReceiptByType(gqlReceipt);
2986
3139
  switch (receipt.type) {
2987
- case ReceiptType4.ReturnData: {
3140
+ case ReceiptType5.ReturnData: {
2988
3141
  return {
2989
3142
  ...receipt,
2990
3143
  data: gqlReceipt.data || "0x"
2991
3144
  };
2992
3145
  }
2993
- case ReceiptType4.LogData: {
3146
+ case ReceiptType5.LogData: {
2994
3147
  return {
2995
3148
  ...receipt,
2996
3149
  data: gqlReceipt.data || "0x"
@@ -3003,7 +3156,7 @@ var processGqlReceipt = (gqlReceipt) => {
3003
3156
  var extractMintedAssetsFromReceipts = (receipts) => {
3004
3157
  const mintedAssets = [];
3005
3158
  receipts.forEach((receipt) => {
3006
- if (receipt.type === ReceiptType4.Mint) {
3159
+ if (receipt.type === ReceiptType5.Mint) {
3007
3160
  mintedAssets.push({
3008
3161
  subId: receipt.subId,
3009
3162
  contractId: receipt.contractId,
@@ -3017,7 +3170,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
3017
3170
  var extractBurnedAssetsFromReceipts = (receipts) => {
3018
3171
  const burnedAssets = [];
3019
3172
  receipts.forEach((receipt) => {
3020
- if (receipt.type === ReceiptType4.Burn) {
3173
+ if (receipt.type === ReceiptType5.Burn) {
3021
3174
  burnedAssets.push({
3022
3175
  subId: receipt.subId,
3023
3176
  contractId: receipt.contractId,
@@ -3030,7 +3183,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3030
3183
  };
3031
3184
 
3032
3185
  // src/providers/transaction-summary/status.ts
3033
- import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
3186
+ import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
3034
3187
  var getTransactionStatusName = (gqlStatus) => {
3035
3188
  switch (gqlStatus) {
3036
3189
  case "FailureStatus":
@@ -3042,8 +3195,8 @@ var getTransactionStatusName = (gqlStatus) => {
3042
3195
  case "SqueezedOutStatus":
3043
3196
  return "squeezedout" /* squeezedout */;
3044
3197
  default:
3045
- throw new FuelError10(
3046
- ErrorCode10.INVALID_TRANSACTION_STATUS,
3198
+ throw new FuelError11(
3199
+ ErrorCode11.INVALID_TRANSACTION_STATUS,
3047
3200
  `Invalid transaction status: ${gqlStatus}.`
3048
3201
  );
3049
3202
  }
@@ -3098,7 +3251,9 @@ function assembleTransactionSummary(params) {
3098
3251
  gqlTransactionStatus,
3099
3252
  abiMap = {},
3100
3253
  maxInputs,
3101
- gasCosts
3254
+ gasCosts,
3255
+ maxGasPerTx,
3256
+ gasPrice
3102
3257
  } = params;
3103
3258
  const gasUsed = getGasUsedFromReceipts(receipts);
3104
3259
  const rawPayload = hexlify11(transactionBytes);
@@ -3112,11 +3267,14 @@ function assembleTransactionSummary(params) {
3112
3267
  maxInputs
3113
3268
  });
3114
3269
  const typeName = getTransactionTypeName(transaction.type);
3270
+ const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3115
3271
  const { fee } = calculateTransactionFee({
3116
- gasUsed,
3272
+ gasPrice,
3117
3273
  rawPayload,
3274
+ tip,
3118
3275
  consensusParameters: {
3119
3276
  gasCosts,
3277
+ maxGasPerTx,
3120
3278
  feeParams: {
3121
3279
  gasPerByte,
3122
3280
  gasPriceFactor
@@ -3156,12 +3314,12 @@ function assembleTransactionSummary(params) {
3156
3314
 
3157
3315
  // src/providers/transaction-response/getDecodedLogs.ts
3158
3316
  import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
3159
- import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3317
+ import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
3160
3318
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3161
3319
  return receipts.reduce((logs, receipt) => {
3162
- if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
3320
+ if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
3163
3321
  const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
3164
- const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3322
+ const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3165
3323
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3166
3324
  logs.push(decodedLog);
3167
3325
  }
@@ -3176,7 +3334,7 @@ var TransactionResponse = class {
3176
3334
  /** Current provider */
3177
3335
  provider;
3178
3336
  /** Gas used on the transaction */
3179
- gasUsed = bn13(0);
3337
+ gasUsed = bn15(0);
3180
3338
  /** The graphql Transaction with receipts object. */
3181
3339
  gqlTransaction;
3182
3340
  abis;
@@ -3254,8 +3412,13 @@ var TransactionResponse = class {
3254
3412
  const decodedTransaction = this.decodeTransaction(
3255
3413
  transaction
3256
3414
  );
3257
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3258
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3415
+ let txReceipts = [];
3416
+ if (transaction?.status && "receipts" in transaction.status) {
3417
+ txReceipts = transaction.status.receipts;
3418
+ }
3419
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3420
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3421
+ const gasPrice = await this.provider.getLatestGasPrice();
3259
3422
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3260
3423
  const transactionSummary = assembleTransactionSummary({
3261
3424
  id: this.id,
@@ -3267,7 +3430,9 @@ var TransactionResponse = class {
3267
3430
  gasPriceFactor,
3268
3431
  abiMap: contractsAbiMap,
3269
3432
  maxInputs,
3270
- gasCosts
3433
+ gasCosts,
3434
+ maxGasPerTx,
3435
+ gasPrice
3271
3436
  });
3272
3437
  return transactionSummary;
3273
3438
  }
@@ -3281,8 +3446,8 @@ var TransactionResponse = class {
3281
3446
  });
3282
3447
  for await (const { statusChange } of subscription) {
3283
3448
  if (statusChange.type === "SqueezedOutStatus") {
3284
- throw new FuelError11(
3285
- ErrorCode11.TRANSACTION_SQUEEZED_OUT,
3449
+ throw new FuelError12(
3450
+ ErrorCode12.TRANSACTION_SQUEEZED_OUT,
3286
3451
  `Transaction Squeezed Out with reason: ${statusChange.reason}`
3287
3452
  );
3288
3453
  }
@@ -3304,14 +3469,26 @@ var TransactionResponse = class {
3304
3469
  gqlTransaction: this.gqlTransaction,
3305
3470
  ...transactionSummary
3306
3471
  };
3472
+ let logs = [];
3307
3473
  if (this.abis) {
3308
- const logs = getDecodedLogs(
3474
+ logs = getDecodedLogs(
3309
3475
  transactionSummary.receipts,
3310
3476
  this.abis.main,
3311
3477
  this.abis.otherContractsAbis
3312
3478
  );
3313
3479
  transactionResult.logs = logs;
3314
3480
  }
3481
+ if (transactionResult.isStatusFailure) {
3482
+ const {
3483
+ receipts,
3484
+ gqlTransaction: { status }
3485
+ } = transactionResult;
3486
+ throw extractTxError({
3487
+ receipts,
3488
+ status,
3489
+ logs
3490
+ });
3491
+ }
3315
3492
  return transactionResult;
3316
3493
  }
3317
3494
  /**
@@ -3320,14 +3497,7 @@ var TransactionResponse = class {
3320
3497
  * @param contractsAbiMap - The contracts ABI map.
3321
3498
  */
3322
3499
  async wait(contractsAbiMap) {
3323
- const result = await this.waitForResult(contractsAbiMap);
3324
- if (result.isStatusFailure) {
3325
- throw new FuelError11(
3326
- ErrorCode11.TRANSACTION_FAILED,
3327
- `Transaction failed: ${result.gqlTransaction.status.reason}`
3328
- );
3329
- }
3330
- return result;
3500
+ return this.waitForResult(contractsAbiMap);
3331
3501
  }
3332
3502
  };
3333
3503
 
@@ -3389,30 +3559,29 @@ var processGqlChain = (chain) => {
3389
3559
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3390
3560
  return {
3391
3561
  name,
3392
- baseChainHeight: bn14(daHeight),
3562
+ baseChainHeight: bn16(daHeight),
3393
3563
  consensusParameters: {
3394
- contractMaxSize: bn14(contractParams.contractMaxSize),
3395
- maxInputs: bn14(txParams.maxInputs),
3396
- maxOutputs: bn14(txParams.maxOutputs),
3397
- maxWitnesses: bn14(txParams.maxWitnesses),
3398
- maxGasPerTx: bn14(txParams.maxGasPerTx),
3399
- maxScriptLength: bn14(scriptParams.maxScriptLength),
3400
- maxScriptDataLength: bn14(scriptParams.maxScriptDataLength),
3401
- maxStorageSlots: bn14(contractParams.maxStorageSlots),
3402
- maxPredicateLength: bn14(predicateParams.maxPredicateLength),
3403
- maxPredicateDataLength: bn14(predicateParams.maxPredicateDataLength),
3404
- maxGasPerPredicate: bn14(predicateParams.maxGasPerPredicate),
3405
- gasPriceFactor: bn14(feeParams.gasPriceFactor),
3406
- gasPerByte: bn14(feeParams.gasPerByte),
3407
- maxMessageDataLength: bn14(predicateParams.maxMessageDataLength),
3408
- chainId: bn14(consensusParameters.chainId),
3409
- baseAssetId: consensusParameters.baseAssetId,
3564
+ contractMaxSize: bn16(contractParams.contractMaxSize),
3565
+ maxInputs: bn16(txParams.maxInputs),
3566
+ maxOutputs: bn16(txParams.maxOutputs),
3567
+ maxWitnesses: bn16(txParams.maxWitnesses),
3568
+ maxGasPerTx: bn16(txParams.maxGasPerTx),
3569
+ maxScriptLength: bn16(scriptParams.maxScriptLength),
3570
+ maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
3571
+ maxStorageSlots: bn16(contractParams.maxStorageSlots),
3572
+ maxPredicateLength: bn16(predicateParams.maxPredicateLength),
3573
+ maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
3574
+ maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
3575
+ gasPriceFactor: bn16(feeParams.gasPriceFactor),
3576
+ gasPerByte: bn16(feeParams.gasPerByte),
3577
+ maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
3578
+ chainId: bn16(consensusParameters.chainId),
3410
3579
  gasCosts
3411
3580
  },
3412
3581
  gasCosts,
3413
3582
  latestBlock: {
3414
3583
  id: latestBlock.id,
3415
- height: bn14(latestBlock.header.height),
3584
+ height: bn16(latestBlock.height),
3416
3585
  time: latestBlock.header.time,
3417
3586
  transactions: latestBlock.transactions.map((i) => ({
3418
3587
  id: i.id
@@ -3482,8 +3651,8 @@ var _Provider = class {
3482
3651
  getChain() {
3483
3652
  const chain = _Provider.chainInfoCache[this.url];
3484
3653
  if (!chain) {
3485
- throw new FuelError12(
3486
- ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
3654
+ throw new FuelError13(
3655
+ ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
3487
3656
  "Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3488
3657
  );
3489
3658
  }
@@ -3495,8 +3664,8 @@ var _Provider = class {
3495
3664
  getNode() {
3496
3665
  const node = _Provider.nodeInfoCache[this.url];
3497
3666
  if (!node) {
3498
- throw new FuelError12(
3499
- ErrorCode12.NODE_INFO_CACHE_EMPTY,
3667
+ throw new FuelError13(
3668
+ ErrorCode13.NODE_INFO_CACHE_EMPTY,
3500
3669
  "Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3501
3670
  );
3502
3671
  }
@@ -3543,8 +3712,8 @@ var _Provider = class {
3543
3712
  static ensureClientVersionIsSupported(nodeInfo) {
3544
3713
  const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
3545
3714
  if (!isMajorSupported || !isMinorSupported) {
3546
- throw new FuelError12(
3547
- FuelError12.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3715
+ throw new FuelError13(
3716
+ FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3548
3717
  `Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
3549
3718
  );
3550
3719
  }
@@ -3607,7 +3776,7 @@ var _Provider = class {
3607
3776
  */
3608
3777
  async getBlockNumber() {
3609
3778
  const { chain } = await this.operations.getChain();
3610
- return bn14(chain.latestBlock.header.height, 10);
3779
+ return bn16(chain.latestBlock.height, 10);
3611
3780
  }
3612
3781
  /**
3613
3782
  * Returns the chain information.
@@ -3617,13 +3786,12 @@ var _Provider = class {
3617
3786
  async fetchNode() {
3618
3787
  const { nodeInfo } = await this.operations.getNodeInfo();
3619
3788
  const processedNodeInfo = {
3620
- maxDepth: bn14(nodeInfo.maxDepth),
3621
- maxTx: bn14(nodeInfo.maxTx),
3622
- minGasPrice: bn14(nodeInfo.minGasPrice),
3789
+ maxDepth: bn16(nodeInfo.maxDepth),
3790
+ maxTx: bn16(nodeInfo.maxTx),
3791
+ minGasPrice: bn16(nodeInfo.minGasPrice),
3623
3792
  nodeVersion: nodeInfo.nodeVersion,
3624
3793
  utxoValidation: nodeInfo.utxoValidation,
3625
- vmBacktrace: nodeInfo.vmBacktrace,
3626
- peers: nodeInfo.peers
3794
+ vmBacktrace: nodeInfo.vmBacktrace
3627
3795
  };
3628
3796
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3629
3797
  return processedNodeInfo;
@@ -3649,17 +3817,6 @@ var _Provider = class {
3649
3817
  } = this.getChain();
3650
3818
  return chainId.toNumber();
3651
3819
  }
3652
- /**
3653
- * Returns the base asset ID
3654
- *
3655
- * @returns A promise that resolves to the base asset ID
3656
- */
3657
- getBaseAssetId() {
3658
- const {
3659
- consensusParameters: { baseAssetId }
3660
- } = this.getChain();
3661
- return baseAssetId;
3662
- }
3663
3820
  /**
3664
3821
  * Submits a transaction to the chain to be executed.
3665
3822
  *
@@ -3685,8 +3842,8 @@ var _Provider = class {
3685
3842
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3686
3843
  for await (const { submitAndAwait } of subscription) {
3687
3844
  if (submitAndAwait.type === "SqueezedOutStatus") {
3688
- throw new FuelError12(
3689
- ErrorCode12.TRANSACTION_SQUEEZED_OUT,
3845
+ throw new FuelError13(
3846
+ ErrorCode13.TRANSACTION_SQUEEZED_OUT,
3690
3847
  `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
3691
3848
  );
3692
3849
  }
@@ -3720,14 +3877,13 @@ var _Provider = class {
3720
3877
  return this.estimateTxDependencies(transactionRequest);
3721
3878
  }
3722
3879
  const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3723
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3724
- encodedTransaction,
3880
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
3881
+ encodedTransactions: encodedTransaction,
3725
3882
  utxoValidation: utxoValidation || false
3726
3883
  });
3727
- const receipts = gqlReceipts.map(processGqlReceipt);
3728
- return {
3729
- receipts
3730
- };
3884
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
3885
+ const receipts = rawReceipts.map(processGqlReceipt);
3886
+ return { receipts, dryrunStatus: status };
3731
3887
  }
3732
3888
  /**
3733
3889
  * Verifies whether enough gas is available to complete transaction.
@@ -3753,7 +3909,7 @@ var _Provider = class {
3753
3909
  } = response;
3754
3910
  if (inputs) {
3755
3911
  inputs.forEach((input, index) => {
3756
- if ("predicateGasUsed" in input && bn14(input.predicateGasUsed).gt(0)) {
3912
+ if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
3757
3913
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3758
3914
  }
3759
3915
  });
@@ -3766,9 +3922,6 @@ var _Provider = class {
3766
3922
  * If there are missing variable outputs,
3767
3923
  * `addVariableOutputs` is called on the transaction.
3768
3924
  *
3769
- * @privateRemarks
3770
- * TODO: Investigate support for missing contract IDs
3771
- * TODO: Add support for missing output messages
3772
3925
  *
3773
3926
  * @param transactionRequest - The transaction request object.
3774
3927
  * @returns A promise.
@@ -3781,16 +3934,19 @@ var _Provider = class {
3781
3934
  missingContractIds: []
3782
3935
  };
3783
3936
  }
3784
- await this.estimatePredicates(transactionRequest);
3785
3937
  let receipts = [];
3786
3938
  const missingContractIds = [];
3787
3939
  let outputVariables = 0;
3940
+ let dryrunStatus;
3788
3941
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3789
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3790
- encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
3942
+ const {
3943
+ dryRun: [{ receipts: rawReceipts, status }]
3944
+ } = await this.operations.dryRun({
3945
+ encodedTransactions: [hexlify12(transactionRequest.toTransactionBytes())],
3791
3946
  utxoValidation: false
3792
3947
  });
3793
- receipts = gqlReceipts.map(processGqlReceipt);
3948
+ receipts = rawReceipts.map(processGqlReceipt);
3949
+ dryrunStatus = status;
3794
3950
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3795
3951
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3796
3952
  if (hasMissingOutputs) {
@@ -3800,6 +3956,11 @@ var _Provider = class {
3800
3956
  transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
3801
3957
  missingContractIds.push(contractId);
3802
3958
  });
3959
+ const { maxFee } = await this.estimateTxGasAndFee({
3960
+ transactionRequest,
3961
+ optimizeGas: false
3962
+ });
3963
+ transactionRequest.maxFee = maxFee;
3803
3964
  } else {
3804
3965
  break;
3805
3966
  }
@@ -3807,7 +3968,133 @@ var _Provider = class {
3807
3968
  return {
3808
3969
  receipts,
3809
3970
  outputVariables,
3810
- missingContractIds
3971
+ missingContractIds,
3972
+ dryrunStatus
3973
+ };
3974
+ }
3975
+ /**
3976
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
3977
+ *
3978
+ * Transactions are dry run in batches. After each dry run, transactions requiring
3979
+ * further modifications are identified. The method iteratively updates these transactions
3980
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
3981
+ *
3982
+ * @param transactionRequests - Array of transaction request objects.
3983
+ * @returns A promise that resolves to an array of results for each transaction.
3984
+ */
3985
+ async estimateMultipleTxDependencies(transactionRequests) {
3986
+ const results = transactionRequests.map(() => ({
3987
+ receipts: [],
3988
+ outputVariables: 0,
3989
+ missingContractIds: [],
3990
+ dryrunStatus: void 0
3991
+ }));
3992
+ const allRequests = clone3(transactionRequests);
3993
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
3994
+ allRequests.forEach((req, index) => {
3995
+ if (req.type === TransactionType8.Script) {
3996
+ serializedTransactionsMap.set(index, hexlify12(req.toTransactionBytes()));
3997
+ }
3998
+ });
3999
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4000
+ let attempt = 0;
4001
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4002
+ const encodedTransactions = transactionsToProcess.map(
4003
+ (index) => serializedTransactionsMap.get(index)
4004
+ );
4005
+ const dryRunResults = await this.operations.dryRun({
4006
+ encodedTransactions,
4007
+ utxoValidation: false
4008
+ });
4009
+ const nextRoundTransactions = [];
4010
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4011
+ const currentResultIndex = transactionsToProcess[i];
4012
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4013
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4014
+ results[currentResultIndex].dryrunStatus = status;
4015
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4016
+ results[currentResultIndex].receipts
4017
+ );
4018
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4019
+ const requestToProcess = allRequests[currentResultIndex];
4020
+ if (hasMissingOutputs && requestToProcess?.type === TransactionType8.Script) {
4021
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4022
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4023
+ missingOutputContractIds.forEach(({ contractId }) => {
4024
+ requestToProcess.addContractInputAndOutput(Address2.fromString(contractId));
4025
+ results[currentResultIndex].missingContractIds.push(contractId);
4026
+ });
4027
+ const { maxFee } = await this.estimateTxGasAndFee({
4028
+ transactionRequest: requestToProcess,
4029
+ optimizeGas: false
4030
+ });
4031
+ requestToProcess.maxFee = maxFee;
4032
+ serializedTransactionsMap.set(
4033
+ currentResultIndex,
4034
+ hexlify12(requestToProcess.toTransactionBytes())
4035
+ );
4036
+ nextRoundTransactions.push(currentResultIndex);
4037
+ allRequests[currentResultIndex] = requestToProcess;
4038
+ }
4039
+ }
4040
+ transactionsToProcess = nextRoundTransactions;
4041
+ attempt += 1;
4042
+ }
4043
+ return results;
4044
+ }
4045
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4046
+ if (estimateTxDependencies) {
4047
+ return this.estimateMultipleTxDependencies(transactionRequests);
4048
+ }
4049
+ const encodedTransactions = transactionRequests.map((tx) => hexlify12(tx.toTransactionBytes()));
4050
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4051
+ encodedTransactions,
4052
+ utxoValidation: utxoValidation || false
4053
+ });
4054
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4055
+ const receipts = rawReceipts.map(processGqlReceipt);
4056
+ return { receipts, dryrunStatus: status };
4057
+ });
4058
+ return results;
4059
+ }
4060
+ async estimateTxGasAndFee(params) {
4061
+ const { transactionRequest, totalGasUsedByPredicates = bn16(0), optimizeGas = true } = params;
4062
+ let { gasPrice } = params;
4063
+ const chainInfo = this.getChain();
4064
+ const { gasPriceFactor } = this.getGasConfig();
4065
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
4066
+ if (!gasPrice) {
4067
+ gasPrice = await this.estimateGasPrice(10);
4068
+ }
4069
+ const shouldSetGaslimit = transactionRequest.type === TransactionType8.Script && !optimizeGas;
4070
+ const minFee = calculateGasFee({
4071
+ gasPrice: bn16(gasPrice),
4072
+ gas: minGas,
4073
+ priceFactor: gasPriceFactor,
4074
+ tip: transactionRequest.tip
4075
+ }).add(1);
4076
+ if (shouldSetGaslimit) {
4077
+ transactionRequest.gasLimit = chainInfo.consensusParameters.maxGasPerTx.sub(
4078
+ minGas.add(totalGasUsedByPredicates)
4079
+ );
4080
+ }
4081
+ let maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4082
+ const maxFee = calculateGasFee({
4083
+ gasPrice: bn16(gasPrice),
4084
+ gas: maxGas,
4085
+ priceFactor: gasPriceFactor,
4086
+ tip: transactionRequest.tip
4087
+ }).add(1);
4088
+ if (shouldSetGaslimit) {
4089
+ maxGas = chainInfo.consensusParameters.maxGasPerTx.sub(maxFee);
4090
+ transactionRequest.gasLimit = maxGas;
4091
+ }
4092
+ return {
4093
+ minGas,
4094
+ minFee,
4095
+ maxGas,
4096
+ maxFee,
4097
+ gasPrice
3811
4098
  };
3812
4099
  }
3813
4100
  /**
@@ -3825,15 +4112,17 @@ var _Provider = class {
3825
4112
  if (estimateTxDependencies) {
3826
4113
  return this.estimateTxDependencies(transactionRequest);
3827
4114
  }
3828
- const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
3829
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3830
- encodedTransaction,
4115
+ const encodedTransactions = [hexlify12(transactionRequest.toTransactionBytes())];
4116
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4117
+ encodedTransactions,
3831
4118
  utxoValidation: true
3832
4119
  });
3833
- const receipts = gqlReceipts.map(processGqlReceipt);
3834
- return {
3835
- receipts
3836
- };
4120
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4121
+ const { id, receipts, status } = dryRunStatus;
4122
+ const processedReceipts = receipts.map(processGqlReceipt);
4123
+ return { id, receipts: processedReceipts, status };
4124
+ });
4125
+ return { receipts: callResult[0].receipts };
3837
4126
  }
3838
4127
  /**
3839
4128
  * Returns a transaction cost to enable user
@@ -3850,80 +4139,80 @@ var _Provider = class {
3850
4139
  * @param tolerance - The tolerance to add on top of the gasUsed.
3851
4140
  * @returns A promise that resolves to the transaction cost object.
3852
4141
  */
3853
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3854
- estimateTxDependencies = true,
3855
- estimatePredicates = true,
3856
- resourcesOwner,
3857
- signatureCallback
3858
- } = {}) {
4142
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3859
4143
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3860
- const chainInfo = this.getChain();
3861
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3862
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
3863
4144
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
3864
4145
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3865
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4146
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
3866
4147
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3867
- if (estimatePredicates) {
3868
- if (isScriptTransaction) {
3869
- txRequestClone.gasLimit = bn14(0);
3870
- }
3871
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3872
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
3873
- }
3874
- await this.estimatePredicates(txRequestClone);
4148
+ txRequestClone.maxFee = bn16(0);
4149
+ if (isScriptTransaction) {
4150
+ txRequestClone.gasLimit = bn16(0);
3875
4151
  }
3876
- if (signatureCallback && isScriptTransaction) {
3877
- await signatureCallback(txRequestClone);
4152
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4153
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
3878
4154
  }
3879
- const minGas = txRequestClone.calculateMinGas(chainInfo);
3880
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4155
+ const signedRequest = clone3(txRequestClone);
4156
+ let addedSignatures = 0;
4157
+ if (signatureCallback && isScriptTransaction) {
4158
+ const lengthBefore = signedRequest.witnesses.length;
4159
+ await signatureCallback(signedRequest);
4160
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4161
+ }
4162
+ await this.estimatePredicates(signedRequest);
4163
+ let { maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4164
+ transactionRequest: signedRequest,
4165
+ optimizeGas: false
4166
+ });
4167
+ txRequestClone.maxFee = maxFee;
3881
4168
  let receipts = [];
3882
4169
  let missingContractIds = [];
3883
4170
  let outputVariables = 0;
3884
- if (isScriptTransaction && estimateTxDependencies) {
3885
- txRequestClone.gasPrice = bn14(0);
3886
- txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4171
+ let gasUsed = bn16(0);
4172
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4173
+ if (isScriptTransaction) {
4174
+ if (signatureCallback) {
4175
+ await signatureCallback(txRequestClone);
4176
+ }
4177
+ txRequestClone.gasLimit = maxGas;
3887
4178
  const result = await this.estimateTxDependencies(txRequestClone);
3888
4179
  receipts = result.receipts;
3889
4180
  outputVariables = result.outputVariables;
3890
4181
  missingContractIds = result.missingContractIds;
4182
+ gasUsed = getGasUsedFromReceipts(receipts);
4183
+ txRequestClone.gasLimit = gasUsed;
4184
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4185
+ transactionRequest: txRequestClone,
4186
+ gasPrice
4187
+ }));
3891
4188
  }
3892
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3893
- const usedFee = calculatePriceWithFactor(
3894
- gasUsed,
3895
- gasPrice,
3896
- gasPriceFactor
3897
- ).normalizeZeroToOne();
3898
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3899
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3900
4189
  return {
3901
4190
  requiredQuantities: allQuantities,
3902
4191
  receipts,
3903
4192
  gasUsed,
3904
- minGasPrice,
3905
4193
  gasPrice,
3906
4194
  minGas,
3907
4195
  maxGas,
3908
- usedFee,
3909
4196
  minFee,
3910
4197
  maxFee,
3911
- estimatedInputs: txRequestClone.inputs,
3912
4198
  outputVariables,
3913
- missingContractIds
4199
+ missingContractIds,
4200
+ addedSignatures,
4201
+ estimatedPredicates: txRequestClone.inputs
3914
4202
  };
3915
4203
  }
3916
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4204
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
3917
4205
  const ownerAddress = Address2.fromAddressOrString(owner);
3918
4206
  const transactionRequest = transactionRequestify(clone3(transactionRequestLike));
3919
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4207
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4208
+ quantitiesToContract
4209
+ });
3920
4210
  transactionRequest.addResources(
3921
4211
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
3922
4212
  );
3923
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
3924
- transactionRequest,
3925
- forwardingQuantities
3926
- );
4213
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4214
+ quantitiesToContract
4215
+ });
3927
4216
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
3928
4217
  return {
3929
4218
  resources,
@@ -3945,11 +4234,10 @@ var _Provider = class {
3945
4234
  return coins.map((coin) => ({
3946
4235
  id: coin.utxoId,
3947
4236
  assetId: coin.assetId,
3948
- amount: bn14(coin.amount),
4237
+ amount: bn16(coin.amount),
3949
4238
  owner: Address2.fromAddressOrString(coin.owner),
3950
- maturity: bn14(coin.maturity).toNumber(),
3951
- blockCreated: bn14(coin.blockCreated),
3952
- txCreatedIdx: bn14(coin.txCreatedIdx)
4239
+ blockCreated: bn16(coin.blockCreated),
4240
+ txCreatedIdx: bn16(coin.txCreatedIdx)
3953
4241
  }));
3954
4242
  }
3955
4243
  /**
@@ -3986,9 +4274,9 @@ var _Provider = class {
3986
4274
  switch (coin.__typename) {
3987
4275
  case "MessageCoin":
3988
4276
  return {
3989
- amount: bn14(coin.amount),
4277
+ amount: bn16(coin.amount),
3990
4278
  assetId: coin.assetId,
3991
- daHeight: bn14(coin.daHeight),
4279
+ daHeight: bn16(coin.daHeight),
3992
4280
  sender: Address2.fromAddressOrString(coin.sender),
3993
4281
  recipient: Address2.fromAddressOrString(coin.recipient),
3994
4282
  nonce: coin.nonce
@@ -3996,12 +4284,11 @@ var _Provider = class {
3996
4284
  case "Coin":
3997
4285
  return {
3998
4286
  id: coin.utxoId,
3999
- amount: bn14(coin.amount),
4287
+ amount: bn16(coin.amount),
4000
4288
  assetId: coin.assetId,
4001
4289
  owner: Address2.fromAddressOrString(coin.owner),
4002
- maturity: bn14(coin.maturity).toNumber(),
4003
- blockCreated: bn14(coin.blockCreated),
4004
- txCreatedIdx: bn14(coin.txCreatedIdx)
4290
+ blockCreated: bn16(coin.blockCreated),
4291
+ txCreatedIdx: bn16(coin.txCreatedIdx)
4005
4292
  };
4006
4293
  default:
4007
4294
  return null;
@@ -4018,13 +4305,13 @@ var _Provider = class {
4018
4305
  async getBlock(idOrHeight) {
4019
4306
  let variables;
4020
4307
  if (typeof idOrHeight === "number") {
4021
- variables = { height: bn14(idOrHeight).toString(10) };
4308
+ variables = { height: bn16(idOrHeight).toString(10) };
4022
4309
  } else if (idOrHeight === "latest") {
4023
4310
  variables = { height: (await this.getBlockNumber()).toString(10) };
4024
4311
  } else if (idOrHeight.length === 66) {
4025
4312
  variables = { blockId: idOrHeight };
4026
4313
  } else {
4027
- variables = { blockId: bn14(idOrHeight).toString(10) };
4314
+ variables = { blockId: bn16(idOrHeight).toString(10) };
4028
4315
  }
4029
4316
  const { block } = await this.operations.getBlock(variables);
4030
4317
  if (!block) {
@@ -4032,7 +4319,7 @@ var _Provider = class {
4032
4319
  }
4033
4320
  return {
4034
4321
  id: block.id,
4035
- height: bn14(block.header.height),
4322
+ height: bn16(block.height),
4036
4323
  time: block.header.time,
4037
4324
  transactionIds: block.transactions.map((tx) => tx.id)
4038
4325
  };
@@ -4047,7 +4334,7 @@ var _Provider = class {
4047
4334
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4048
4335
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4049
4336
  id: block.id,
4050
- height: bn14(block.header.height),
4337
+ height: bn16(block.height),
4051
4338
  time: block.header.time,
4052
4339
  transactionIds: block.transactions.map((tx) => tx.id)
4053
4340
  }));
@@ -4062,7 +4349,7 @@ var _Provider = class {
4062
4349
  async getBlockWithTransactions(idOrHeight) {
4063
4350
  let variables;
4064
4351
  if (typeof idOrHeight === "number") {
4065
- variables = { blockHeight: bn14(idOrHeight).toString(10) };
4352
+ variables = { blockHeight: bn16(idOrHeight).toString(10) };
4066
4353
  } else if (idOrHeight === "latest") {
4067
4354
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4068
4355
  } else {
@@ -4074,7 +4361,7 @@ var _Provider = class {
4074
4361
  }
4075
4362
  return {
4076
4363
  id: block.id,
4077
- height: bn14(block.header.height, 10),
4364
+ height: bn16(block.height, 10),
4078
4365
  time: block.header.time,
4079
4366
  transactionIds: block.transactions.map((tx) => tx.id),
4080
4367
  transactions: block.transactions.map(
@@ -4123,7 +4410,7 @@ var _Provider = class {
4123
4410
  contract: Address2.fromAddressOrString(contractId).toB256(),
4124
4411
  asset: hexlify12(assetId)
4125
4412
  });
4126
- return bn14(contractBalance.amount, 10);
4413
+ return bn16(contractBalance.amount, 10);
4127
4414
  }
4128
4415
  /**
4129
4416
  * Returns the balance for the given owner for the given asset ID.
@@ -4137,7 +4424,7 @@ var _Provider = class {
4137
4424
  owner: Address2.fromAddressOrString(owner).toB256(),
4138
4425
  assetId: hexlify12(assetId)
4139
4426
  });
4140
- return bn14(balance.amount, 10);
4427
+ return bn16(balance.amount, 10);
4141
4428
  }
4142
4429
  /**
4143
4430
  * Returns balances for the given owner.
@@ -4155,7 +4442,7 @@ var _Provider = class {
4155
4442
  const balances = result.balances.edges.map((edge) => edge.node);
4156
4443
  return balances.map((balance) => ({
4157
4444
  assetId: balance.assetId,
4158
- amount: bn14(balance.amount)
4445
+ amount: bn16(balance.amount)
4159
4446
  }));
4160
4447
  }
4161
4448
  /**
@@ -4177,15 +4464,15 @@ var _Provider = class {
4177
4464
  sender: message.sender,
4178
4465
  recipient: message.recipient,
4179
4466
  nonce: message.nonce,
4180
- amount: bn14(message.amount),
4467
+ amount: bn16(message.amount),
4181
4468
  data: message.data
4182
4469
  }),
4183
4470
  sender: Address2.fromAddressOrString(message.sender),
4184
4471
  recipient: Address2.fromAddressOrString(message.recipient),
4185
4472
  nonce: message.nonce,
4186
- amount: bn14(message.amount),
4473
+ amount: bn16(message.amount),
4187
4474
  data: InputMessageCoder.decodeData(message.data),
4188
- daHeight: bn14(message.daHeight)
4475
+ daHeight: bn16(message.daHeight)
4189
4476
  }));
4190
4477
  }
4191
4478
  /**
@@ -4203,8 +4490,8 @@ var _Provider = class {
4203
4490
  nonce
4204
4491
  };
4205
4492
  if (commitBlockId && commitBlockHeight) {
4206
- throw new FuelError12(
4207
- ErrorCode12.INVALID_INPUT_PARAMETERS,
4493
+ throw new FuelError13(
4494
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
4208
4495
  "commitBlockId and commitBlockHeight cannot be used together"
4209
4496
  );
4210
4497
  }
@@ -4238,44 +4525,54 @@ var _Provider = class {
4238
4525
  } = result.messageProof;
4239
4526
  return {
4240
4527
  messageProof: {
4241
- proofIndex: bn14(messageProof.proofIndex),
4528
+ proofIndex: bn16(messageProof.proofIndex),
4242
4529
  proofSet: messageProof.proofSet
4243
4530
  },
4244
4531
  blockProof: {
4245
- proofIndex: bn14(blockProof.proofIndex),
4532
+ proofIndex: bn16(blockProof.proofIndex),
4246
4533
  proofSet: blockProof.proofSet
4247
4534
  },
4248
4535
  messageBlockHeader: {
4249
4536
  id: messageBlockHeader.id,
4250
- daHeight: bn14(messageBlockHeader.daHeight),
4251
- transactionsCount: bn14(messageBlockHeader.transactionsCount),
4537
+ daHeight: bn16(messageBlockHeader.daHeight),
4538
+ transactionsCount: bn16(messageBlockHeader.transactionsCount),
4252
4539
  transactionsRoot: messageBlockHeader.transactionsRoot,
4253
- height: bn14(messageBlockHeader.height),
4540
+ height: bn16(messageBlockHeader.height),
4254
4541
  prevRoot: messageBlockHeader.prevRoot,
4255
4542
  time: messageBlockHeader.time,
4256
4543
  applicationHash: messageBlockHeader.applicationHash,
4257
4544
  messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4258
- messageReceiptCount: bn14(messageBlockHeader.messageReceiptCount)
4545
+ messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount)
4259
4546
  },
4260
4547
  commitBlockHeader: {
4261
4548
  id: commitBlockHeader.id,
4262
- daHeight: bn14(commitBlockHeader.daHeight),
4263
- transactionsCount: bn14(commitBlockHeader.transactionsCount),
4549
+ daHeight: bn16(commitBlockHeader.daHeight),
4550
+ transactionsCount: bn16(commitBlockHeader.transactionsCount),
4264
4551
  transactionsRoot: commitBlockHeader.transactionsRoot,
4265
- height: bn14(commitBlockHeader.height),
4552
+ height: bn16(commitBlockHeader.height),
4266
4553
  prevRoot: commitBlockHeader.prevRoot,
4267
4554
  time: commitBlockHeader.time,
4268
4555
  applicationHash: commitBlockHeader.applicationHash,
4269
4556
  messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4270
- messageReceiptCount: bn14(commitBlockHeader.messageReceiptCount)
4557
+ messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount)
4271
4558
  },
4272
4559
  sender: Address2.fromAddressOrString(sender),
4273
4560
  recipient: Address2.fromAddressOrString(recipient),
4274
4561
  nonce,
4275
- amount: bn14(amount),
4562
+ amount: bn16(amount),
4276
4563
  data
4277
4564
  };
4278
4565
  }
4566
+ async getLatestGasPrice() {
4567
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4568
+ return bn16(latestGasPrice.gasPrice);
4569
+ }
4570
+ async estimateGasPrice(blockHorizon) {
4571
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4572
+ blockHorizon: String(blockHorizon)
4573
+ });
4574
+ return bn16(estimateGasPrice.gasPrice);
4575
+ }
4279
4576
  /**
4280
4577
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4281
4578
  *
@@ -4295,10 +4592,10 @@ var _Provider = class {
4295
4592
  */
4296
4593
  async produceBlocks(amount, startTime) {
4297
4594
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4298
- blocksToProduce: bn14(amount).toString(10),
4595
+ blocksToProduce: bn16(amount).toString(10),
4299
4596
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4300
4597
  });
4301
- return bn14(latestBlockHeight);
4598
+ return bn16(latestBlockHeight);
4302
4599
  }
4303
4600
  // eslint-disable-next-line @typescript-eslint/require-await
4304
4601
  async getTransactionResponse(transactionId) {
@@ -4312,7 +4609,7 @@ cacheInputs_fn = function(inputs) {
4312
4609
  return;
4313
4610
  }
4314
4611
  inputs.forEach((input) => {
4315
- if (input.type === InputType6.Coin) {
4612
+ if (input.type === InputType7.Coin) {
4316
4613
  this.cache?.set(input.id);
4317
4614
  }
4318
4615
  });
@@ -4321,8 +4618,8 @@ __publicField(Provider, "chainInfoCache", {});
4321
4618
  __publicField(Provider, "nodeInfoCache", {});
4322
4619
 
4323
4620
  // src/providers/transaction-summary/get-transaction-summary.ts
4324
- import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
4325
- import { bn as bn15 } from "@fuel-ts/math";
4621
+ import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4622
+ import { bn as bn17 } from "@fuel-ts/math";
4326
4623
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4327
4624
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4328
4625
 
@@ -4439,7 +4736,7 @@ var Account = class extends AbstractAccount {
4439
4736
  */
4440
4737
  get provider() {
4441
4738
  if (!this._provider) {
4442
- throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
4739
+ throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
4443
4740
  }
4444
4741
  return this._provider;
4445
4742
  }
@@ -4491,8 +4788,8 @@ var Account = class extends AbstractAccount {
4491
4788
  if (!hasNextPage) {
4492
4789
  break;
4493
4790
  }
4494
- throw new FuelError14(
4495
- ErrorCode14.NOT_SUPPORTED,
4791
+ throw new FuelError15(
4792
+ ErrorCode15.NOT_SUPPORTED,
4496
4793
  `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
4497
4794
  );
4498
4795
  }
@@ -4517,8 +4814,8 @@ var Account = class extends AbstractAccount {
4517
4814
  if (!hasNextPage) {
4518
4815
  break;
4519
4816
  }
4520
- throw new FuelError14(
4521
- ErrorCode14.NOT_SUPPORTED,
4817
+ throw new FuelError15(
4818
+ ErrorCode15.NOT_SUPPORTED,
4522
4819
  `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
4523
4820
  );
4524
4821
  }
@@ -4530,9 +4827,8 @@ var Account = class extends AbstractAccount {
4530
4827
  * @param assetId - The asset ID to check the balance for.
4531
4828
  * @returns A promise that resolves to the balance amount.
4532
4829
  */
4533
- async getBalance(assetId) {
4534
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4535
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4830
+ async getBalance(assetId = BaseAssetId3) {
4831
+ const amount = await this.provider.getBalance(this.address, assetId);
4536
4832
  return amount;
4537
4833
  }
4538
4834
  /**
@@ -4554,8 +4850,8 @@ var Account = class extends AbstractAccount {
4554
4850
  if (!hasNextPage) {
4555
4851
  break;
4556
4852
  }
4557
- throw new FuelError14(
4558
- ErrorCode14.NOT_SUPPORTED,
4853
+ throw new FuelError15(
4854
+ ErrorCode15.NOT_SUPPORTED,
4559
4855
  `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
4560
4856
  );
4561
4857
  }
@@ -4569,37 +4865,33 @@ var Account = class extends AbstractAccount {
4569
4865
  * @param fee - The estimated transaction fee.
4570
4866
  * @returns A promise that resolves when the resources are added to the transaction.
4571
4867
  */
4572
- async fund(request, coinQuantities, fee) {
4573
- const baseAssetId = this.provider.getBaseAssetId();
4574
- const updatedQuantities = addAmountToAsset({
4575
- amount: bn16(fee),
4576
- assetId: baseAssetId,
4577
- coinQuantities
4868
+ async fund(request, params) {
4869
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4870
+ const txRequest = request;
4871
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4872
+ amount: bn18(fee),
4873
+ assetId: BaseAssetId3,
4874
+ coinQuantities: requiredQuantities
4578
4875
  });
4579
4876
  const quantitiesDict = {};
4580
- updatedQuantities.forEach(({ amount, assetId }) => {
4877
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4581
4878
  quantitiesDict[assetId] = {
4582
4879
  required: amount,
4583
- owned: bn16(0)
4880
+ owned: bn18(0)
4584
4881
  };
4585
4882
  });
4586
- const cachedUtxos = [];
4587
- const cachedMessages = [];
4588
- const owner = this.address.toB256();
4589
- request.inputs.forEach((input) => {
4883
+ txRequest.inputs.forEach((input) => {
4590
4884
  const isResource = "amount" in input;
4591
4885
  if (isResource) {
4592
4886
  const isCoin2 = "owner" in input;
4593
4887
  if (isCoin2) {
4594
4888
  const assetId = String(input.assetId);
4595
- if (input.owner === owner && quantitiesDict[assetId]) {
4596
- const amount = bn16(input.amount);
4889
+ if (quantitiesDict[assetId]) {
4890
+ const amount = bn18(input.amount);
4597
4891
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4598
- cachedUtxos.push(input.id);
4599
4892
  }
4600
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4601
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4602
- cachedMessages.push(input.nonce);
4893
+ } else if (input.amount && quantitiesDict[BaseAssetId3]) {
4894
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4603
4895
  }
4604
4896
  }
4605
4897
  });
@@ -4614,12 +4906,23 @@ var Account = class extends AbstractAccount {
4614
4906
  });
4615
4907
  const needsToBeFunded = missingQuantities.length;
4616
4908
  if (needsToBeFunded) {
4617
- const resources = await this.getResourcesToSpend(missingQuantities, {
4618
- messages: cachedMessages,
4619
- utxos: cachedUtxos
4620
- });
4621
- request.addResources(resources);
4909
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toString());
4910
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4911
+ txRequest.addResources(resources);
4912
+ }
4913
+ txRequest.shiftPredicateData();
4914
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
4915
+ const requestToBeReEstimate = clone4(txRequest);
4916
+ if (addedSignatures) {
4917
+ Array.from({ length: addedSignatures }).forEach(
4918
+ () => requestToBeReEstimate.addEmptyWitness()
4919
+ );
4622
4920
  }
4921
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
4922
+ transactionRequest: requestToBeReEstimate
4923
+ });
4924
+ txRequest.maxFee = maxFee;
4925
+ return txRequest;
4623
4926
  }
4624
4927
  /**
4625
4928
  * A helper that creates a transfer transaction request and returns it.
@@ -4627,29 +4930,25 @@ var Account = class extends AbstractAccount {
4627
4930
  * @param destination - The address of the destination.
4628
4931
  * @param amount - The amount of coins to transfer.
4629
4932
  * @param assetId - The asset ID of the coins to transfer.
4630
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4933
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4631
4934
  * @returns A promise that resolves to the prepared transaction request.
4632
4935
  */
4633
- async createTransfer(destination, amount, assetId, txParams = {}) {
4634
- const { minGasPrice } = this.provider.getGasConfig();
4635
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4636
- const params = { gasPrice: minGasPrice, ...txParams };
4637
- const request = new ScriptTransactionRequest(params);
4638
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
4639
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4936
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4937
+ const request = new ScriptTransactionRequest(txParams);
4938
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4939
+ const txCost = await this.provider.getTransactionCost(request, {
4640
4940
  estimateTxDependencies: true,
4641
4941
  resourcesOwner: this
4642
4942
  });
4643
- request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
4644
- request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
4645
- this.validateGas({
4646
- gasUsed,
4647
- gasPrice: request.gasPrice,
4648
- gasLimit: request.gasLimit,
4649
- minGasPrice
4650
- });
4651
- await this.fund(request, requiredQuantities, maxFee);
4652
- request.updatePredicateInputs(estimatedInputs);
4943
+ if ("gasLimit" in txParams) {
4944
+ this.validateGas({
4945
+ gasUsed: txCost.gasUsed,
4946
+ gasLimit: request.gasLimit
4947
+ });
4948
+ }
4949
+ request.gasLimit = txCost.gasUsed;
4950
+ request.maxFee = txCost.maxFee;
4951
+ await this.fund(request, txCost);
4653
4952
  return request;
4654
4953
  }
4655
4954
  /**
@@ -4661,15 +4960,14 @@ var Account = class extends AbstractAccount {
4661
4960
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4662
4961
  * @returns A promise that resolves to the transaction response.
4663
4962
  */
4664
- async transfer(destination, amount, assetId, txParams = {}) {
4665
- if (bn16(amount).lte(0)) {
4666
- throw new FuelError14(
4667
- ErrorCode14.INVALID_TRANSFER_AMOUNT,
4963
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4964
+ if (bn18(amount).lte(0)) {
4965
+ throw new FuelError15(
4966
+ ErrorCode15.INVALID_TRANSFER_AMOUNT,
4668
4967
  "Transfer amount must be a positive number."
4669
4968
  );
4670
4969
  }
4671
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4672
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4970
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4673
4971
  return this.sendTransaction(request, { estimateTxDependencies: false });
4674
4972
  }
4675
4973
  /**
@@ -4681,40 +4979,38 @@ var Account = class extends AbstractAccount {
4681
4979
  * @param txParams - The optional transaction parameters.
4682
4980
  * @returns A promise that resolves to the transaction response.
4683
4981
  */
4684
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4685
- if (bn16(amount).lte(0)) {
4686
- throw new FuelError14(
4687
- ErrorCode14.INVALID_TRANSFER_AMOUNT,
4982
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4983
+ if (bn18(amount).lte(0)) {
4984
+ throw new FuelError15(
4985
+ ErrorCode15.INVALID_TRANSFER_AMOUNT,
4688
4986
  "Transfer amount must be a positive number."
4689
4987
  );
4690
4988
  }
4691
4989
  const contractAddress = Address3.fromAddressOrString(contractId);
4692
- const { minGasPrice } = this.provider.getGasConfig();
4693
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4694
- const params = { gasPrice: minGasPrice, ...txParams };
4695
4990
  const { script, scriptData } = await assembleTransferToContractScript({
4696
4991
  hexlifiedContractId: contractAddress.toB256(),
4697
- amountToTransfer: bn16(amount),
4698
- assetId: assetIdToTransfer
4992
+ amountToTransfer: bn18(amount),
4993
+ assetId
4699
4994
  });
4700
4995
  const request = new ScriptTransactionRequest({
4701
- ...params,
4996
+ ...txParams,
4702
4997
  script,
4703
4998
  scriptData
4704
4999
  });
4705
5000
  request.addContractInputAndOutput(contractAddress);
4706
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4707
- request,
4708
- [{ amount: bn16(amount), assetId: String(assetIdToTransfer) }]
4709
- );
4710
- request.gasLimit = bn16(params.gasLimit ?? gasUsed);
4711
- this.validateGas({
4712
- gasUsed,
4713
- gasPrice: request.gasPrice,
4714
- gasLimit: request.gasLimit,
4715
- minGasPrice
5001
+ const txCost = await this.provider.getTransactionCost(request, {
5002
+ resourcesOwner: this,
5003
+ quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetId) }]
4716
5004
  });
4717
- await this.fund(request, requiredQuantities, maxFee);
5005
+ if (txParams.gasLimit) {
5006
+ this.validateGas({
5007
+ gasUsed: txCost.gasUsed,
5008
+ gasLimit: request.gasLimit
5009
+ });
5010
+ }
5011
+ request.gasLimit = txCost.gasUsed;
5012
+ request.maxFee = txCost.maxFee;
5013
+ await this.fund(request, txCost);
4718
5014
  return this.sendTransaction(request);
4719
5015
  }
4720
5016
  /**
@@ -4726,40 +5022,36 @@ var Account = class extends AbstractAccount {
4726
5022
  * @returns A promise that resolves to the transaction response.
4727
5023
  */
4728
5024
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4729
- const { minGasPrice } = this.provider.getGasConfig();
4730
- const baseAssetId = this.provider.getBaseAssetId();
4731
5025
  const recipientAddress = Address3.fromAddressOrString(recipient);
4732
5026
  const recipientDataArray = arrayify14(
4733
5027
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4734
5028
  );
4735
5029
  const amountDataArray = arrayify14(
4736
- "0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
5030
+ "0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
4737
5031
  );
4738
5032
  const script = new Uint8Array([
4739
5033
  ...arrayify14(withdrawScript.bytes),
4740
5034
  ...recipientDataArray,
4741
5035
  ...amountDataArray
4742
5036
  ]);
4743
- const params = { script, gasPrice: minGasPrice, ...txParams };
5037
+ const params = { script, ...txParams };
4744
5038
  const request = new ScriptTransactionRequest(params);
4745
- const forwardingQuantities = [{ amount: bn16(amount), assetId: baseAssetId }];
4746
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4747
- request,
4748
- forwardingQuantities
4749
- );
4750
- request.gasLimit = bn16(params.gasLimit ?? gasUsed);
4751
- this.validateGas({
4752
- gasUsed,
4753
- gasPrice: request.gasPrice,
4754
- gasLimit: request.gasLimit,
4755
- minGasPrice
4756
- });
4757
- await this.fund(request, requiredQuantities, maxFee);
5039
+ const quantitiesToContract = [{ amount: bn18(amount), assetId: BaseAssetId3 }];
5040
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5041
+ if (txParams.gasLimit) {
5042
+ this.validateGas({
5043
+ gasUsed: txCost.gasUsed,
5044
+ gasLimit: request.gasLimit
5045
+ });
5046
+ }
5047
+ request.maxFee = txCost.maxFee;
5048
+ request.gasLimit = txCost.gasUsed;
5049
+ await this.fund(request, txCost);
4758
5050
  return this.sendTransaction(request);
4759
5051
  }
4760
5052
  async signMessage(message) {
4761
5053
  if (!this._connector) {
4762
- throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
5054
+ throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
4763
5055
  }
4764
5056
  return this._connector.signMessage(this.address.toString(), message);
4765
5057
  }
@@ -4771,8 +5063,8 @@ var Account = class extends AbstractAccount {
4771
5063
  */
4772
5064
  async signTransaction(transactionRequestLike) {
4773
5065
  if (!this._connector) {
4774
- throw new FuelError14(
4775
- ErrorCode14.MISSING_CONNECTOR,
5066
+ throw new FuelError15(
5067
+ ErrorCode15.MISSING_CONNECTOR,
4776
5068
  "A connector is required to sign transactions."
4777
5069
  );
4778
5070
  }
@@ -4812,21 +5104,10 @@ var Account = class extends AbstractAccount {
4812
5104
  }
4813
5105
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
4814
5106
  }
4815
- validateGas({
4816
- gasUsed,
4817
- gasPrice,
4818
- gasLimit,
4819
- minGasPrice
4820
- }) {
4821
- if (minGasPrice.gt(gasPrice)) {
4822
- throw new FuelError14(
4823
- ErrorCode14.GAS_PRICE_TOO_LOW,
4824
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
4825
- );
4826
- }
5107
+ validateGas({ gasUsed, gasLimit }) {
4827
5108
  if (gasUsed.gt(gasLimit)) {
4828
- throw new FuelError14(
4829
- ErrorCode14.GAS_LIMIT_TOO_LOW,
5109
+ throw new FuelError15(
5110
+ ErrorCode15.GAS_LIMIT_TOO_LOW,
4830
5111
  `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
4831
5112
  );
4832
5113
  }
@@ -4835,7 +5116,7 @@ var Account = class extends AbstractAccount {
4835
5116
 
4836
5117
  // src/signer/signer.ts
4837
5118
  import { Address as Address4 } from "@fuel-ts/address";
4838
- import { randomBytes } from "@fuel-ts/crypto";
5119
+ import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
4839
5120
  import { hash } from "@fuel-ts/hasher";
4840
5121
  import { toBytes } from "@fuel-ts/math";
4841
5122
  import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
@@ -4928,7 +5209,7 @@ var Signer = class {
4928
5209
  * @returns random 32-byte hashed
4929
5210
  */
4930
5211
  static generatePrivateKey(entropy) {
4931
- return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
5212
+ return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
4932
5213
  }
4933
5214
  /**
4934
5215
  * Extended publicKey from a compact publicKey
@@ -4947,13 +5228,13 @@ import { Address as Address5 } from "@fuel-ts/address";
4947
5228
  import {
4948
5229
  bufferFromString,
4949
5230
  keccak256,
4950
- randomBytes as randomBytes2,
5231
+ randomBytes as randomBytes3,
4951
5232
  scrypt,
4952
5233
  stringFromBuffer,
4953
5234
  decryptJsonWalletData,
4954
5235
  encryptJsonWalletData
4955
5236
  } from "@fuel-ts/crypto";
4956
- import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
5237
+ import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
4957
5238
  import { hexlify as hexlify14 } from "@fuel-ts/utils";
4958
5239
  import { v4 as uuidv4 } from "uuid";
4959
5240
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
@@ -4970,7 +5251,7 @@ var removeHexPrefix = (hexString) => {
4970
5251
  async function encryptKeystoreWallet(privateKey, address, password) {
4971
5252
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
4972
5253
  const ownerAddress = Address5.fromAddressOrString(address);
4973
- const salt = randomBytes2(DEFAULT_KEY_SIZE);
5254
+ const salt = randomBytes3(DEFAULT_KEY_SIZE);
4974
5255
  const key = scrypt({
4975
5256
  password: bufferFromString(password),
4976
5257
  salt,
@@ -4979,7 +5260,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
4979
5260
  r: DEFAULT_KDF_PARAMS_R,
4980
5261
  p: DEFAULT_KDF_PARAMS_P
4981
5262
  });
4982
- const iv = randomBytes2(DEFAULT_IV_SIZE);
5263
+ const iv = randomBytes3(DEFAULT_IV_SIZE);
4983
5264
  const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
4984
5265
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
4985
5266
  const macHashUint8Array = keccak256(data);
@@ -5031,8 +5312,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5031
5312
  const macHashUint8Array = keccak256(data);
5032
5313
  const macHash = stringFromBuffer(macHashUint8Array, "hex");
5033
5314
  if (mac !== macHash) {
5034
- throw new FuelError15(
5035
- ErrorCode15.INVALID_PASSWORD,
5315
+ throw new FuelError16(
5316
+ ErrorCode16.INVALID_PASSWORD,
5036
5317
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5037
5318
  );
5038
5319
  }
@@ -5115,7 +5396,7 @@ var BaseWalletUnlocked = class extends Account {
5115
5396
  * @param transactionRequestLike - The transaction request to send.
5116
5397
  * @returns A promise that resolves to the TransactionResponse object.
5117
5398
  */
5118
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5399
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5119
5400
  const transactionRequest = transactionRequestify(transactionRequestLike);
5120
5401
  if (estimateTxDependencies) {
5121
5402
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5154,15 +5435,15 @@ var BaseWalletUnlocked = class extends Account {
5154
5435
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5155
5436
 
5156
5437
  // src/hdwallet/hdwallet.ts
5157
- import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5438
+ import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5158
5439
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5159
- import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5440
+ import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5160
5441
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5161
5442
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5162
5443
 
5163
5444
  // src/mnemonic/mnemonic.ts
5164
- import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
5165
- import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
5445
+ import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5446
+ import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5166
5447
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5167
5448
  import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
5168
5449
  import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
@@ -7220,7 +7501,7 @@ var english = [
7220
7501
  ];
7221
7502
 
7222
7503
  // src/mnemonic/utils.ts
7223
- import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
7504
+ import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
7224
7505
  import { sha256 as sha2562 } from "@fuel-ts/hasher";
7225
7506
  import { arrayify as arrayify16 } from "@fuel-ts/utils";
7226
7507
  function toUtf8Bytes(stri) {
@@ -7237,8 +7518,8 @@ function toUtf8Bytes(stri) {
7237
7518
  i += 1;
7238
7519
  const c2 = str.charCodeAt(i);
7239
7520
  if (i >= str.length || (c2 & 64512) !== 56320) {
7240
- throw new FuelError16(
7241
- ErrorCode16.INVALID_INPUT_PARAMETERS,
7521
+ throw new FuelError17(
7522
+ ErrorCode17.INVALID_INPUT_PARAMETERS,
7242
7523
  "Invalid UTF-8 in the input string."
7243
7524
  );
7244
7525
  }
@@ -7301,8 +7582,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7301
7582
  for (let i = 0; i < words.length; i += 1) {
7302
7583
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
7303
7584
  if (index === -1) {
7304
- throw new FuelError16(
7305
- ErrorCode16.INVALID_MNEMONIC,
7585
+ throw new FuelError17(
7586
+ ErrorCode17.INVALID_MNEMONIC,
7306
7587
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
7307
7588
  );
7308
7589
  }
@@ -7318,8 +7599,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7318
7599
  const checksumMask = getUpperMask(checksumBits);
7319
7600
  const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7320
7601
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7321
- throw new FuelError16(
7322
- ErrorCode16.INVALID_CHECKSUM,
7602
+ throw new FuelError17(
7603
+ ErrorCode17.INVALID_CHECKSUM,
7323
7604
  "Checksum validation failed for the provided mnemonic."
7324
7605
  );
7325
7606
  }
@@ -7333,16 +7614,16 @@ var TestnetPRV = "0x04358394";
7333
7614
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
7334
7615
  function assertWordList(wordlist) {
7335
7616
  if (wordlist.length !== 2048) {
7336
- throw new FuelError17(
7337
- ErrorCode17.INVALID_WORD_LIST,
7617
+ throw new FuelError18(
7618
+ ErrorCode18.INVALID_WORD_LIST,
7338
7619
  `Expected word list length of 2048, but got ${wordlist.length}.`
7339
7620
  );
7340
7621
  }
7341
7622
  }
7342
7623
  function assertEntropy(entropy) {
7343
7624
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
7344
- throw new FuelError17(
7345
- ErrorCode17.INVALID_ENTROPY,
7625
+ throw new FuelError18(
7626
+ ErrorCode18.INVALID_ENTROPY,
7346
7627
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
7347
7628
  );
7348
7629
  }
@@ -7352,7 +7633,7 @@ function assertMnemonic(words) {
7352
7633
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
7353
7634
  ", "
7354
7635
  )}] words, but got ${words.length}.`;
7355
- throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
7636
+ throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
7356
7637
  }
7357
7638
  }
7358
7639
  var Mnemonic = class {
@@ -7470,8 +7751,8 @@ var Mnemonic = class {
7470
7751
  static masterKeysFromSeed(seed) {
7471
7752
  const seedArray = arrayify17(seed);
7472
7753
  if (seedArray.length < 16 || seedArray.length > 64) {
7473
- throw new FuelError17(
7474
- ErrorCode17.INVALID_SEED,
7754
+ throw new FuelError18(
7755
+ ErrorCode18.INVALID_SEED,
7475
7756
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7476
7757
  );
7477
7758
  }
@@ -7516,7 +7797,7 @@ var Mnemonic = class {
7516
7797
  * @returns A randomly generated mnemonic
7517
7798
  */
7518
7799
  static generate(size = 32, extraEntropy = "") {
7519
- const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
7800
+ const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
7520
7801
  return Mnemonic.entropyToMnemonic(entropy);
7521
7802
  }
7522
7803
  };
@@ -7548,7 +7829,7 @@ function isValidExtendedKey(extendedKey) {
7548
7829
  function parsePath(path2, depth = 0) {
7549
7830
  const components = path2.split("/");
7550
7831
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
7551
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path2}`);
7832
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path2}`);
7552
7833
  }
7553
7834
  if (components[0] === "m") {
7554
7835
  components.shift();
@@ -7577,8 +7858,8 @@ var HDWallet = class {
7577
7858
  this.privateKey = hexlify17(config.privateKey);
7578
7859
  } else {
7579
7860
  if (!config.publicKey) {
7580
- throw new FuelError18(
7581
- ErrorCode18.HD_WALLET_ERROR,
7861
+ throw new FuelError19(
7862
+ ErrorCode19.HD_WALLET_ERROR,
7582
7863
  "Both public and private Key cannot be missing. At least one should be provided."
7583
7864
  );
7584
7865
  }
@@ -7607,8 +7888,8 @@ var HDWallet = class {
7607
7888
  const data = new Uint8Array(37);
7608
7889
  if (index & HARDENED_INDEX) {
7609
7890
  if (!privateKey) {
7610
- throw new FuelError18(
7611
- ErrorCode18.HD_WALLET_ERROR,
7891
+ throw new FuelError19(
7892
+ ErrorCode19.HD_WALLET_ERROR,
7612
7893
  "Cannot derive a hardened index without a private Key."
7613
7894
  );
7614
7895
  }
@@ -7622,7 +7903,7 @@ var HDWallet = class {
7622
7903
  const IR = bytes.slice(32);
7623
7904
  if (privateKey) {
7624
7905
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7625
- const ki = bn17(IL).add(privateKey).mod(N).toBytes(32);
7906
+ const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
7626
7907
  return new HDWallet({
7627
7908
  privateKey: ki,
7628
7909
  chainCode: IR,
@@ -7660,8 +7941,8 @@ var HDWallet = class {
7660
7941
  */
7661
7942
  toExtendedKey(isPublic = false, testnet = false) {
7662
7943
  if (this.depth >= 256) {
7663
- throw new FuelError18(
7664
- ErrorCode18.HD_WALLET_ERROR,
7944
+ throw new FuelError19(
7945
+ ErrorCode19.HD_WALLET_ERROR,
7665
7946
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
7666
7947
  );
7667
7948
  }
@@ -7692,10 +7973,10 @@ var HDWallet = class {
7692
7973
  const bytes = arrayify18(decoded);
7693
7974
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7694
7975
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7695
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
7976
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
7696
7977
  }
7697
7978
  if (!validChecksum) {
7698
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7979
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7699
7980
  }
7700
7981
  const depth = bytes[4];
7701
7982
  const parentFingerprint = hexlify17(bytes.slice(5, 9));
@@ -7703,14 +7984,14 @@ var HDWallet = class {
7703
7984
  const chainCode = hexlify17(bytes.slice(13, 45));
7704
7985
  const key = bytes.slice(45, 78);
7705
7986
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7706
- throw new FuelError18(
7707
- ErrorCode18.HD_WALLET_ERROR,
7987
+ throw new FuelError19(
7988
+ ErrorCode19.HD_WALLET_ERROR,
7708
7989
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
7709
7990
  );
7710
7991
  }
7711
7992
  if (isPublicExtendedKey(bytes)) {
7712
7993
  if (key[0] !== 3) {
7713
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
7994
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
7714
7995
  }
7715
7996
  return new HDWallet({
7716
7997
  publicKey: key,
@@ -7721,7 +8002,7 @@ var HDWallet = class {
7721
8002
  });
7722
8003
  }
7723
8004
  if (key[0] !== 0) {
7724
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
8005
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
7725
8006
  }
7726
8007
  return new HDWallet({
7727
8008
  privateKey: key.slice(1),
@@ -7887,20 +8168,21 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
7887
8168
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
7888
8169
 
7889
8170
  // src/test-utils/seedTestWallet.ts
7890
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
8171
+ import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
7891
8172
  var seedTestWallet = async (wallet, quantities) => {
7892
8173
  const genesisWallet = new WalletUnlocked(
7893
- process.env.GENESIS_SECRET || randomBytes4(32),
8174
+ process.env.GENESIS_SECRET || randomBytes5(32),
7894
8175
  wallet.provider
7895
8176
  );
7896
- const resources = await genesisWallet.getResourcesToSpend(quantities);
7897
- const { minGasPrice } = genesisWallet.provider.getGasConfig();
7898
- const request = new ScriptTransactionRequest({
7899
- gasLimit: 1e4,
7900
- gasPrice: minGasPrice
8177
+ const request = new ScriptTransactionRequest();
8178
+ quantities.forEach((quantity) => {
8179
+ const { amount, assetId } = coinQuantityfy(quantity);
8180
+ request.addCoinOutput(wallet.address, amount, assetId);
7901
8181
  });
7902
- request.addResources(resources);
7903
- quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
8182
+ const txCost = await genesisWallet.provider.getTransactionCost(request);
8183
+ request.gasLimit = txCost.gasUsed;
8184
+ request.maxFee = txCost.maxFee;
8185
+ await genesisWallet.fund(request, txCost);
7904
8186
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
7905
8187
  };
7906
8188
 
@@ -7914,7 +8196,7 @@ var generateTestWallet = async (provider, quantities) => {
7914
8196
  };
7915
8197
 
7916
8198
  // src/test-utils/launchNode.ts
7917
- import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
8199
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
7918
8200
  import { toHex as toHex2 } from "@fuel-ts/math";
7919
8201
  import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
7920
8202
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
@@ -8014,7 +8296,7 @@ var launchNode = async ({
8014
8296
  {
8015
8297
  owner: signer.address.toHexString(),
8016
8298
  amount: toHex2(1e9),
8017
- asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
8299
+ asset_id: BaseAssetId4
8018
8300
  }
8019
8301
  ]
8020
8302
  }
@@ -8030,7 +8312,7 @@ var launchNode = async ({
8030
8312
  ["--ip", ipToUse],
8031
8313
  ["--port", portToUse],
8032
8314
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8033
- ["--min-gas-price", "0"],
8315
+ ["--min-gas-price", "1"],
8034
8316
  poaInstant ? ["--poa-instant", "true"] : [],
8035
8317
  ["--consensus-key", consensusKey],
8036
8318
  ["--chain", chainConfigPathToUse],
@@ -8080,10 +8362,9 @@ var launchNode = async ({
8080
8362
  })
8081
8363
  );
8082
8364
  var generateWallets = async (count, provider) => {
8083
- const baseAssetId = provider.getBaseAssetId();
8084
8365
  const wallets = [];
8085
8366
  for (let i = 0; i < count; i += 1) {
8086
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8367
+ const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
8087
8368
  wallets.push(wallet);
8088
8369
  }
8089
8370
  return wallets;
@@ -8093,7 +8374,7 @@ var launchNodeAndGetWallets = async ({
8093
8374
  walletCount = 10
8094
8375
  } = {}) => {
8095
8376
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8096
- const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8377
+ const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8097
8378
  const wallets = await generateWallets(walletCount, provider);
8098
8379
  const cleanup = () => {
8099
8380
  closeNode();