@fuel-ts/account 0.0.0-rc-1764-20240404125616 → 0.0.0-rc-1832-20240404143349

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +4 -5
  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 +558 -772
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +511 -764
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +392 -644
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +2 -10
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +305 -824
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +1 -1
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +2 -4
  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 +0 -3
  27. package/dist/providers/message.d.ts.map +1 -1
  28. package/dist/providers/provider.d.ts +24 -44
  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 +25 -8
  34. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/utils.d.ts +0 -3
  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 +0 -2
  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 +2 -3
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  43. package/dist/providers/utils/gas.d.ts +2 -8
  44. package/dist/providers/utils/gas.d.ts.map +1 -1
  45. package/dist/test-utils.global.js +551 -729
  46. package/dist/test-utils.global.js.map +1 -1
  47. package/dist/test-utils.js +490 -705
  48. package/dist/test-utils.js.map +1 -1
  49. package/dist/test-utils.mjs +379 -594
  50. package/dist/test-utils.mjs.map +1 -1
  51. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  52. package/package.json +17 -17
@@ -58,16 +58,15 @@ module.exports = __toCommonJS(test_utils_exports);
58
58
 
59
59
  // src/wallet/base-wallet-unlocked.ts
60
60
  var import_hasher3 = require("@fuel-ts/hasher");
61
- var import_utils30 = require("@fuel-ts/utils");
61
+ var import_utils31 = require("@fuel-ts/utils");
62
62
 
63
63
  // src/account.ts
64
64
  var import_address4 = require("@fuel-ts/address");
65
65
  var import_configs12 = require("@fuel-ts/address/configs");
66
66
  var import_errors16 = require("@fuel-ts/errors");
67
67
  var import_interfaces = require("@fuel-ts/interfaces");
68
- var import_math19 = require("@fuel-ts/math");
69
- var import_utils27 = require("@fuel-ts/utils");
70
- var import_ramda4 = require("ramda");
68
+ var import_math18 = require("@fuel-ts/math");
69
+ var import_utils28 = require("@fuel-ts/utils");
71
70
 
72
71
  // src/providers/coin-quantity.ts
73
72
  var import_configs = require("@fuel-ts/address/configs");
@@ -76,24 +75,24 @@ var import_utils = require("@fuel-ts/utils");
76
75
  var coinQuantityfy = (coinQuantityLike) => {
77
76
  let assetId;
78
77
  let amount;
79
- let max;
78
+ let max2;
80
79
  if (Array.isArray(coinQuantityLike)) {
81
80
  amount = coinQuantityLike[0];
82
81
  assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
83
- max = coinQuantityLike[2] ?? void 0;
82
+ max2 = coinQuantityLike[2] ?? void 0;
84
83
  } else {
85
84
  amount = coinQuantityLike.amount;
86
85
  assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
87
- max = coinQuantityLike.max ?? void 0;
86
+ max2 = coinQuantityLike.max ?? void 0;
88
87
  }
89
88
  const bnAmount = (0, import_math.bn)(amount);
90
89
  return {
91
90
  assetId: (0, import_utils.hexlify)(assetId),
92
91
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
93
- max: max ? (0, import_math.bn)(max) : void 0
92
+ max: max2 ? (0, import_math.bn)(max2) : void 0
94
93
  };
95
94
  };
96
- var addAmountToCoinQuantities = (params) => {
95
+ var addAmountToAsset = (params) => {
97
96
  const { amount, assetId } = params;
98
97
  const coinQuantities = [...params.coinQuantities];
99
98
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -108,12 +107,12 @@ var addAmountToCoinQuantities = (params) => {
108
107
  // src/providers/provider.ts
109
108
  var import_address3 = require("@fuel-ts/address");
110
109
  var import_errors14 = require("@fuel-ts/errors");
111
- var import_math16 = require("@fuel-ts/math");
112
- var import_transactions19 = require("@fuel-ts/transactions");
113
- var import_utils22 = require("@fuel-ts/utils");
110
+ var import_math15 = require("@fuel-ts/math");
111
+ var import_transactions18 = require("@fuel-ts/transactions");
112
+ var import_utils23 = require("@fuel-ts/utils");
114
113
  var import_versions = require("@fuel-ts/versions");
115
- var import_utils23 = require("@noble/curves/abstract/utils");
116
- var import_ethers2 = require("ethers");
114
+ var import_utils24 = require("@noble/curves/abstract/utils");
115
+ var import_ethers = require("ethers");
117
116
  var import_graphql_request = require("graphql-request");
118
117
  var import_ramda3 = require("ramda");
119
118
 
@@ -121,10 +120,14 @@ var import_ramda3 = require("ramda");
121
120
  var import_graphql_tag = __toESM(require("graphql-tag"));
122
121
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
123
122
  fragment receiptFragment on Receipt {
124
- id
123
+ contract {
124
+ id
125
+ }
125
126
  pc
126
127
  is
127
- to
128
+ to {
129
+ id
130
+ }
128
131
  toAddress
129
132
  amount
130
133
  assetId
@@ -162,16 +165,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
162
165
  id
163
166
  }
164
167
  time
165
- receipts {
166
- ...receiptFragment
167
- }
168
168
  programState {
169
169
  returnType
170
170
  data
171
171
  }
172
- receipts {
173
- ...receiptFragment
174
- }
175
172
  }
176
173
  ... on FailureStatus {
177
174
  block {
@@ -179,24 +176,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
179
176
  }
180
177
  time
181
178
  reason
182
- receipts {
183
- ...receiptFragment
184
- }
185
179
  }
186
180
  ... on SqueezedOutStatus {
187
181
  reason
188
182
  }
189
183
  }
190
- ${ReceiptFragmentFragmentDoc}`;
184
+ `;
191
185
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
192
186
  fragment transactionFragment on Transaction {
193
187
  id
194
188
  rawPayload
189
+ gasPrice
190
+ receipts {
191
+ ...receiptFragment
192
+ }
195
193
  status {
196
194
  ...transactionStatusFragment
197
195
  }
198
196
  }
199
- ${TransactionStatusFragmentFragmentDoc}`;
197
+ ${ReceiptFragmentFragmentDoc}
198
+ ${TransactionStatusFragmentFragmentDoc}`;
200
199
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
201
200
  fragment inputEstimatePredicatesFragment on Input {
202
201
  ... on InputCoin {
@@ -214,46 +213,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
214
213
  }
215
214
  }
216
215
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
217
- var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
218
- fragment dryRunFailureStatusFragment on DryRunFailureStatus {
219
- reason
220
- programState {
221
- returnType
222
- data
223
- }
224
- }
225
- `;
226
- var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
227
- fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
228
- programState {
229
- returnType
230
- data
231
- }
232
- }
233
- `;
234
- var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
235
- fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
236
- ... on DryRunFailureStatus {
237
- ...dryRunFailureStatusFragment
238
- }
239
- ... on DryRunSuccessStatus {
240
- ...dryRunSuccessStatusFragment
241
- }
242
- }
243
- ${DryRunFailureStatusFragmentFragmentDoc}
244
- ${DryRunSuccessStatusFragmentFragmentDoc}`;
245
- var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
246
- fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
247
- id
248
- status {
249
- ...dryRunTransactionStatusFragment
250
- }
251
- receipts {
252
- ...receiptFragment
253
- }
254
- }
255
- ${DryRunTransactionStatusFragmentFragmentDoc}
256
- ${ReceiptFragmentFragmentDoc}`;
257
216
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
258
217
  fragment coinFragment on Coin {
259
218
  __typename
@@ -261,6 +220,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
261
220
  owner
262
221
  amount
263
222
  assetId
223
+ maturity
264
224
  blockCreated
265
225
  txCreatedIdx
266
226
  }
@@ -337,8 +297,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
337
297
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
338
298
  fragment blockFragment on Block {
339
299
  id
340
- height
341
300
  header {
301
+ height
342
302
  time
343
303
  }
344
304
  transactions {
@@ -408,6 +368,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
408
368
  cb
409
369
  cfei
410
370
  cfsi
371
+ croo
411
372
  div
412
373
  divi
413
374
  ecr1
@@ -490,9 +451,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
490
451
  ccp {
491
452
  ...DependentCostFragment
492
453
  }
493
- croo {
494
- ...DependentCostFragment
495
- }
496
454
  csiz {
497
455
  ...DependentCostFragment
498
456
  }
@@ -615,6 +573,14 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
615
573
  maxTx
616
574
  maxDepth
617
575
  nodeVersion
576
+ peers {
577
+ id
578
+ addresses
579
+ clientVersion
580
+ blockHeight
581
+ lastHeartbeatMs
582
+ appScore
583
+ }
618
584
  }
619
585
  `;
620
586
  var GetVersionDocument = import_graphql_tag.default`
@@ -649,9 +615,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
649
615
  query getTransactionWithReceipts($transactionId: TransactionId!) {
650
616
  transaction(id: $transactionId) {
651
617
  ...transactionFragment
618
+ receipts {
619
+ ...receiptFragment
620
+ }
652
621
  }
653
622
  }
654
- ${TransactionFragmentFragmentDoc}`;
623
+ ${TransactionFragmentFragmentDoc}
624
+ ${ReceiptFragmentFragmentDoc}`;
655
625
  var GetTransactionsDocument = import_graphql_tag.default`
656
626
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
657
627
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -779,20 +749,6 @@ var GetBalanceDocument = import_graphql_tag.default`
779
749
  }
780
750
  }
781
751
  ${BalanceFragmentFragmentDoc}`;
782
- var GetLatestGasPriceDocument = import_graphql_tag.default`
783
- query getLatestGasPrice {
784
- latestGasPrice {
785
- gasPrice
786
- }
787
- }
788
- `;
789
- var EstimateGasPriceDocument = import_graphql_tag.default`
790
- query estimateGasPrice($blockHorizon: U32!) {
791
- estimateGasPrice(blockHorizon: $blockHorizon) {
792
- gasPrice
793
- }
794
- }
795
- `;
796
752
  var GetBalancesDocument = import_graphql_tag.default`
797
753
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
798
754
  balances(
@@ -847,12 +803,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
847
803
  }
848
804
  `;
849
805
  var DryRunDocument = import_graphql_tag.default`
850
- mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
851
- dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
852
- ...dryRunTransactionExecutionStatusFragment
806
+ mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
807
+ dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
808
+ ...receiptFragment
853
809
  }
854
810
  }
855
- ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
811
+ ${ReceiptFragmentFragmentDoc}`;
856
812
  var SubmitDocument = import_graphql_tag.default`
857
813
  mutation submit($encodedTransaction: HexString!) {
858
814
  submit(tx: $encodedTransaction) {
@@ -935,12 +891,6 @@ function getSdk(requester) {
935
891
  getBalance(variables, options) {
936
892
  return requester(GetBalanceDocument, variables, options);
937
893
  },
938
- getLatestGasPrice(variables, options) {
939
- return requester(GetLatestGasPriceDocument, variables, options);
940
- },
941
- estimateGasPrice(variables, options) {
942
- return requester(EstimateGasPriceDocument, variables, options);
943
- },
944
894
  getBalances(variables, options) {
945
895
  return requester(GetBalancesDocument, variables, options);
946
896
  },
@@ -1124,6 +1074,7 @@ var inputify = (value) => {
1124
1074
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1125
1075
  },
1126
1076
  witnessIndex: value.witnessIndex,
1077
+ maturity: value.maturity ?? 0,
1127
1078
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1128
1079
  predicateLength: predicate.length,
1129
1080
  predicateDataLength: predicateData.length,
@@ -1237,7 +1188,6 @@ var import_configs7 = require("@fuel-ts/address/configs");
1237
1188
  var import_math7 = require("@fuel-ts/math");
1238
1189
  var import_transactions6 = require("@fuel-ts/transactions");
1239
1190
  var import_utils9 = require("@fuel-ts/utils");
1240
- var import_ethers = require("ethers");
1241
1191
 
1242
1192
  // src/providers/resource.ts
1243
1193
  var isCoin = (resource) => "id" in resource;
@@ -1273,8 +1223,8 @@ function assembleReceiptByType(receipt) {
1273
1223
  case "CALL" /* Call */: {
1274
1224
  const callReceipt = {
1275
1225
  type: import_transactions3.ReceiptType.Call,
1276
- from: hexOrZero(receipt.id || receipt.contractId),
1277
- to: hexOrZero(receipt?.to),
1226
+ from: hexOrZero(receipt.contract?.id),
1227
+ to: hexOrZero(receipt?.to?.id),
1278
1228
  amount: (0, import_math4.bn)(receipt.amount),
1279
1229
  assetId: hexOrZero(receipt.assetId),
1280
1230
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1288,7 +1238,7 @@ function assembleReceiptByType(receipt) {
1288
1238
  case "RETURN" /* Return */: {
1289
1239
  const returnReceipt = {
1290
1240
  type: import_transactions3.ReceiptType.Return,
1291
- id: hexOrZero(receipt.id || receipt.contractId),
1241
+ id: hexOrZero(receipt.contract?.id),
1292
1242
  val: (0, import_math4.bn)(receipt.val),
1293
1243
  pc: (0, import_math4.bn)(receipt.pc),
1294
1244
  is: (0, import_math4.bn)(receipt.is)
@@ -1298,7 +1248,7 @@ function assembleReceiptByType(receipt) {
1298
1248
  case "RETURN_DATA" /* ReturnData */: {
1299
1249
  const returnDataReceipt = {
1300
1250
  type: import_transactions3.ReceiptType.ReturnData,
1301
- id: hexOrZero(receipt.id || receipt.contractId),
1251
+ id: hexOrZero(receipt.contract?.id),
1302
1252
  ptr: (0, import_math4.bn)(receipt.ptr),
1303
1253
  len: (0, import_math4.bn)(receipt.len),
1304
1254
  digest: hexOrZero(receipt.digest),
@@ -1310,7 +1260,7 @@ function assembleReceiptByType(receipt) {
1310
1260
  case "PANIC" /* Panic */: {
1311
1261
  const panicReceipt = {
1312
1262
  type: import_transactions3.ReceiptType.Panic,
1313
- id: hexOrZero(receipt.id),
1263
+ id: hexOrZero(receipt.contract?.id),
1314
1264
  reason: (0, import_math4.bn)(receipt.reason),
1315
1265
  pc: (0, import_math4.bn)(receipt.pc),
1316
1266
  is: (0, import_math4.bn)(receipt.is),
@@ -1321,7 +1271,7 @@ function assembleReceiptByType(receipt) {
1321
1271
  case "REVERT" /* Revert */: {
1322
1272
  const revertReceipt = {
1323
1273
  type: import_transactions3.ReceiptType.Revert,
1324
- id: hexOrZero(receipt.id || receipt.contractId),
1274
+ id: hexOrZero(receipt.contract?.id),
1325
1275
  val: (0, import_math4.bn)(receipt.ra),
1326
1276
  pc: (0, import_math4.bn)(receipt.pc),
1327
1277
  is: (0, import_math4.bn)(receipt.is)
@@ -1331,7 +1281,7 @@ function assembleReceiptByType(receipt) {
1331
1281
  case "LOG" /* Log */: {
1332
1282
  const logReceipt = {
1333
1283
  type: import_transactions3.ReceiptType.Log,
1334
- id: hexOrZero(receipt.id || receipt.contractId),
1284
+ id: hexOrZero(receipt.contract?.id),
1335
1285
  val0: (0, import_math4.bn)(receipt.ra),
1336
1286
  val1: (0, import_math4.bn)(receipt.rb),
1337
1287
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1344,7 +1294,7 @@ function assembleReceiptByType(receipt) {
1344
1294
  case "LOG_DATA" /* LogData */: {
1345
1295
  const logDataReceipt = {
1346
1296
  type: import_transactions3.ReceiptType.LogData,
1347
- id: hexOrZero(receipt.id || receipt.contractId),
1297
+ id: hexOrZero(receipt.contract?.id),
1348
1298
  val0: (0, import_math4.bn)(receipt.ra),
1349
1299
  val1: (0, import_math4.bn)(receipt.rb),
1350
1300
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1358,8 +1308,8 @@ function assembleReceiptByType(receipt) {
1358
1308
  case "TRANSFER" /* Transfer */: {
1359
1309
  const transferReceipt = {
1360
1310
  type: import_transactions3.ReceiptType.Transfer,
1361
- from: hexOrZero(receipt.id || receipt.contractId),
1362
- to: hexOrZero(receipt.toAddress || receipt?.to),
1311
+ from: hexOrZero(receipt.contract?.id),
1312
+ to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1363
1313
  amount: (0, import_math4.bn)(receipt.amount),
1364
1314
  assetId: hexOrZero(receipt.assetId),
1365
1315
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1370,8 +1320,8 @@ function assembleReceiptByType(receipt) {
1370
1320
  case "TRANSFER_OUT" /* TransferOut */: {
1371
1321
  const transferOutReceipt = {
1372
1322
  type: import_transactions3.ReceiptType.TransferOut,
1373
- from: hexOrZero(receipt.id || receipt.contractId),
1374
- to: hexOrZero(receipt.toAddress || receipt.to),
1323
+ from: hexOrZero(receipt.contract?.id),
1324
+ to: hexOrZero(receipt.toAddress || receipt.to?.id),
1375
1325
  amount: (0, import_math4.bn)(receipt.amount),
1376
1326
  assetId: hexOrZero(receipt.assetId),
1377
1327
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1414,7 +1364,7 @@ function assembleReceiptByType(receipt) {
1414
1364
  return receiptMessageOut;
1415
1365
  }
1416
1366
  case "MINT" /* Mint */: {
1417
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1367
+ const contractId = hexOrZero(receipt.contract?.id);
1418
1368
  const subId = hexOrZero(receipt.subId);
1419
1369
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1420
1370
  const mintReceipt = {
@@ -1429,7 +1379,7 @@ function assembleReceiptByType(receipt) {
1429
1379
  return mintReceipt;
1430
1380
  }
1431
1381
  case "BURN" /* Burn */: {
1432
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1382
+ const contractId = hexOrZero(receipt.contract?.id);
1433
1383
  const subId = hexOrZero(receipt.subId);
1434
1384
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1435
1385
  const burnReceipt = {
@@ -1455,6 +1405,7 @@ var import_errors6 = require("@fuel-ts/errors");
1455
1405
  var import_math5 = require("@fuel-ts/math");
1456
1406
  var import_transactions4 = require("@fuel-ts/transactions");
1457
1407
  var import_utils6 = require("@fuel-ts/utils");
1408
+ var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1458
1409
  var getGasUsedFromReceipts = (receipts) => {
1459
1410
  const scriptResult = receipts.filter(
1460
1411
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1475,28 +1426,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1475
1426
  }
1476
1427
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1477
1428
  const witnessCache = [];
1478
- const chargeableInputs = inputs.filter((input) => {
1479
- const isCoinOrMessage = "owner" in input || "sender" in input;
1480
- if (isCoinOrMessage) {
1481
- if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1482
- return true;
1483
- }
1484
- if (!witnessCache.includes(input.witnessIndex)) {
1485
- witnessCache.push(input.witnessIndex);
1486
- return true;
1487
- }
1488
- }
1489
- return false;
1490
- });
1491
- const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1492
- const totalGas = chargeableInputs.reduce((total, input) => {
1429
+ const totalGas = inputs.reduce((total, input) => {
1493
1430
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1494
1431
  return total.add(
1495
- vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1432
+ resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1496
1433
  );
1497
1434
  }
1498
- return total.add(gasCosts.ecr1);
1499
- }, (0, import_math5.bn)(0));
1435
+ if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1436
+ witnessCache.push(input.witnessIndex);
1437
+ return total.add(gasCosts.ecr1);
1438
+ }
1439
+ return total;
1440
+ }, (0, import_math5.bn)());
1500
1441
  return totalGas;
1501
1442
  }
1502
1443
  function getMinGas(params) {
@@ -1508,20 +1449,12 @@ function getMinGas(params) {
1508
1449
  return minGas;
1509
1450
  }
1510
1451
  function getMaxGas(params) {
1511
- const {
1512
- gasPerByte,
1513
- witnessesLength,
1514
- witnessLimit,
1515
- minGas,
1516
- gasLimit = (0, import_math5.bn)(0),
1517
- maxGasPerTx
1518
- } = params;
1452
+ const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1519
1453
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1520
1454
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1521
1455
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1522
1456
  }
1523
- const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1524
- return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1457
+ return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1525
1458
  }
1526
1459
  function calculateMetadataGasForTxCreate({
1527
1460
  gasCosts,
@@ -1543,10 +1476,6 @@ function calculateMetadataGasForTxScript({
1543
1476
  }) {
1544
1477
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1545
1478
  }
1546
- var calculateGasFee = (params) => {
1547
- const { gas, gasPrice, priceFactor, tip } = params;
1548
- return gas.mul(gasPrice).div(priceFactor).add(tip);
1549
- };
1550
1479
 
1551
1480
  // src/providers/utils/json.ts
1552
1481
  var import_utils7 = require("@fuel-ts/utils");
@@ -1683,7 +1612,7 @@ var witnessify = (value) => {
1683
1612
  // src/providers/transaction-request/transaction-request.ts
1684
1613
  var BaseTransactionRequest = class {
1685
1614
  /** Gas price for transaction */
1686
- tip;
1615
+ gasPrice;
1687
1616
  /** Block until which tx cannot be included */
1688
1617
  maturity;
1689
1618
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1702,7 +1631,7 @@ var BaseTransactionRequest = class {
1702
1631
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1703
1632
  */
1704
1633
  constructor({
1705
- tip,
1634
+ gasPrice,
1706
1635
  maturity,
1707
1636
  maxFee,
1708
1637
  witnessLimit,
@@ -1710,7 +1639,7 @@ var BaseTransactionRequest = class {
1710
1639
  outputs,
1711
1640
  witnesses
1712
1641
  } = {}) {
1713
- this.tip = (0, import_math7.bn)(tip);
1642
+ this.gasPrice = (0, import_math7.bn)(gasPrice);
1714
1643
  this.maturity = maturity ?? 0;
1715
1644
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1716
1645
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1721,9 +1650,9 @@ var BaseTransactionRequest = class {
1721
1650
  static getPolicyMeta(req) {
1722
1651
  let policyTypes = 0;
1723
1652
  const policies = [];
1724
- if (req.tip) {
1725
- policyTypes += import_transactions6.PolicyType.Tip;
1726
- policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1653
+ if (req.gasPrice) {
1654
+ policyTypes += import_transactions6.PolicyType.GasPrice;
1655
+ policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1727
1656
  }
1728
1657
  if (req.witnessLimit) {
1729
1658
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -1910,10 +1839,10 @@ var BaseTransactionRequest = class {
1910
1839
  * @param predicate - Predicate bytes.
1911
1840
  * @param predicateData - Predicate data bytes.
1912
1841
  */
1913
- addCoinInput(coin) {
1842
+ addCoinInput(coin, predicate) {
1914
1843
  const { assetId, owner, amount } = coin;
1915
1844
  let witnessIndex;
1916
- if (coin.predicate) {
1845
+ if (predicate) {
1917
1846
  witnessIndex = 0;
1918
1847
  } else {
1919
1848
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1928,7 +1857,9 @@ var BaseTransactionRequest = class {
1928
1857
  amount,
1929
1858
  assetId,
1930
1859
  txPointer: "0x00000000000000000000000000000000",
1931
- witnessIndex
1860
+ witnessIndex,
1861
+ predicate: predicate?.bytes,
1862
+ predicateData: predicate?.predicateDataBytes
1932
1863
  };
1933
1864
  this.pushInput(input);
1934
1865
  this.addChangeOutput(owner, assetId);
@@ -1941,11 +1872,11 @@ var BaseTransactionRequest = class {
1941
1872
  * @param predicate - Predicate bytes.
1942
1873
  * @param predicateData - Predicate data bytes.
1943
1874
  */
1944
- addMessageInput(message) {
1875
+ addMessageInput(message, predicate) {
1945
1876
  const { recipient, sender, amount } = message;
1946
1877
  const assetId = import_configs7.BaseAssetId;
1947
1878
  let witnessIndex;
1948
- if (message.predicate) {
1879
+ if (predicate) {
1949
1880
  witnessIndex = 0;
1950
1881
  } else {
1951
1882
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1959,7 +1890,9 @@ var BaseTransactionRequest = class {
1959
1890
  sender: sender.toB256(),
1960
1891
  recipient: recipient.toB256(),
1961
1892
  amount,
1962
- witnessIndex
1893
+ witnessIndex,
1894
+ predicate: predicate?.bytes,
1895
+ predicateData: predicate?.predicateDataBytes
1963
1896
  };
1964
1897
  this.pushInput(input);
1965
1898
  this.addChangeOutput(recipient, assetId);
@@ -1990,6 +1923,32 @@ var BaseTransactionRequest = class {
1990
1923
  resources.forEach((resource) => this.addResource(resource));
1991
1924
  return this;
1992
1925
  }
1926
+ /**
1927
+ * Adds multiple resources to the transaction by adding coin/message inputs and change
1928
+ * outputs from the related assetIds.
1929
+ *
1930
+ * @param resources - The resources to add.
1931
+ * @returns This transaction.
1932
+ */
1933
+ addPredicateResource(resource, predicate) {
1934
+ if (isCoin(resource)) {
1935
+ this.addCoinInput(resource, predicate);
1936
+ } else {
1937
+ this.addMessageInput(resource, predicate);
1938
+ }
1939
+ return this;
1940
+ }
1941
+ /**
1942
+ * Adds multiple predicate coin/message inputs to the transaction and change outputs
1943
+ * from the related assetIds.
1944
+ *
1945
+ * @param resources - The resources to add.
1946
+ * @returns This transaction.
1947
+ */
1948
+ addPredicateResources(resources, predicate) {
1949
+ resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1950
+ return this;
1951
+ }
1993
1952
  /**
1994
1953
  * Adds a coin output to the transaction.
1995
1954
  *
@@ -2069,7 +2028,7 @@ var BaseTransactionRequest = class {
2069
2028
  }
2070
2029
  calculateMaxGas(chainInfo, minGas) {
2071
2030
  const { consensusParameters } = chainInfo;
2072
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2031
+ const { gasPerByte } = consensusParameters;
2073
2032
  const witnessesLength = this.toTransaction().witnesses.reduce(
2074
2033
  (acc, wit) => acc + wit.dataLength,
2075
2034
  0
@@ -2078,8 +2037,7 @@ var BaseTransactionRequest = class {
2078
2037
  gasPerByte,
2079
2038
  minGas,
2080
2039
  witnessesLength,
2081
- witnessLimit: this.witnessLimit,
2082
- maxGasPerTx
2040
+ witnessLimit: this.witnessLimit
2083
2041
  });
2084
2042
  }
2085
2043
  /**
@@ -2089,6 +2047,12 @@ var BaseTransactionRequest = class {
2089
2047
  * @param quantities - CoinQuantity Array.
2090
2048
  */
2091
2049
  fundWithFakeUtxos(quantities, resourcesOwner) {
2050
+ let idCounter = 0;
2051
+ const generateId = () => {
2052
+ const counterString = String(idCounter++);
2053
+ const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2054
+ return id;
2055
+ };
2092
2056
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2093
2057
  if ("assetId" in input) {
2094
2058
  return input.assetId === assetId;
@@ -2097,20 +2061,17 @@ var BaseTransactionRequest = class {
2097
2061
  });
2098
2062
  const updateAssetInput = (assetId, quantity) => {
2099
2063
  const assetInput = findAssetInput(assetId);
2100
- let usedQuantity = quantity;
2101
- if (assetId === import_configs7.BaseAssetId) {
2102
- usedQuantity = (0, import_math7.bn)("1000000000000000000");
2103
- }
2104
2064
  if (assetInput && "assetId" in assetInput) {
2105
- assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33));
2106
- assetInput.amount = usedQuantity;
2065
+ assetInput.id = generateId();
2066
+ assetInput.amount = quantity;
2107
2067
  } else {
2108
2068
  this.addResources([
2109
2069
  {
2110
- id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33)),
2111
- amount: usedQuantity,
2070
+ id: generateId(),
2071
+ amount: quantity,
2112
2072
  assetId,
2113
2073
  owner: resourcesOwner || import_address.Address.fromRandom(),
2074
+ maturity: 0,
2114
2075
  blockCreated: (0, import_math7.bn)(1),
2115
2076
  txCreatedIdx: (0, import_math7.bn)(1)
2116
2077
  }
@@ -2142,7 +2103,7 @@ var BaseTransactionRequest = class {
2142
2103
  toJSON() {
2143
2104
  return normalizeJSON(this);
2144
2105
  }
2145
- updatePredicateGasUsed(inputs) {
2106
+ updatePredicateInputs(inputs) {
2146
2107
  this.inputs.forEach((i) => {
2147
2108
  let correspondingInput;
2148
2109
  switch (i.type) {
@@ -2164,15 +2125,6 @@ var BaseTransactionRequest = class {
2164
2125
  }
2165
2126
  });
2166
2127
  }
2167
- shiftPredicateData() {
2168
- this.inputs.forEach((input) => {
2169
- if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2170
- input.predicateData = input.paddPredicateData(
2171
- BaseTransactionRequest.getPolicyMeta(this).policies.length
2172
- );
2173
- }
2174
- });
2175
- }
2176
2128
  };
2177
2129
 
2178
2130
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2509,7 +2461,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2509
2461
  }
2510
2462
  calculateMaxGas(chainInfo, minGas) {
2511
2463
  const { consensusParameters } = chainInfo;
2512
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2464
+ const { gasPerByte } = consensusParameters;
2513
2465
  const witnessesLength = this.toTransaction().witnesses.reduce(
2514
2466
  (acc, wit) => acc + wit.dataLength,
2515
2467
  0
@@ -2519,8 +2471,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2519
2471
  minGas,
2520
2472
  witnessesLength,
2521
2473
  witnessLimit: this.witnessLimit,
2522
- gasLimit: this.gasLimit,
2523
- maxGasPerTx
2474
+ gasLimit: this.gasLimit
2524
2475
  });
2525
2476
  }
2526
2477
  /**
@@ -2595,32 +2546,15 @@ var transactionRequestify = (obj) => {
2595
2546
  }
2596
2547
  }
2597
2548
  };
2598
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2599
- (acc, input) => {
2600
- if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2601
- acc.utxos.push(input.id);
2602
- }
2603
- if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2604
- acc.messages.push(input.nonce);
2605
- }
2606
- return acc;
2607
- },
2608
- {
2609
- utxos: [],
2610
- messages: []
2611
- }
2612
- );
2613
2549
 
2614
2550
  // src/providers/transaction-response/transaction-response.ts
2615
2551
  var import_errors13 = require("@fuel-ts/errors");
2616
- var import_math15 = require("@fuel-ts/math");
2617
- var import_transactions18 = require("@fuel-ts/transactions");
2618
- var import_utils20 = require("@fuel-ts/utils");
2552
+ var import_math14 = require("@fuel-ts/math");
2553
+ var import_transactions17 = require("@fuel-ts/transactions");
2554
+ var import_utils21 = require("@fuel-ts/utils");
2619
2555
 
2620
2556
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2621
- var import_math14 = require("@fuel-ts/math");
2622
- var import_transactions16 = require("@fuel-ts/transactions");
2623
- var import_utils18 = require("@fuel-ts/utils");
2557
+ var import_utils19 = require("@fuel-ts/utils");
2624
2558
 
2625
2559
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2626
2560
  var import_math11 = require("@fuel-ts/math");
@@ -2628,10 +2562,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
2628
2562
  var import_utils16 = require("@fuel-ts/utils");
2629
2563
  var calculateTransactionFee = (params) => {
2630
2564
  const {
2631
- gasPrice,
2565
+ gasUsed,
2632
2566
  rawPayload,
2633
- tip,
2634
- consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2567
+ consensusParameters: { gasCosts, feeParams }
2635
2568
  } = params;
2636
2569
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2637
2570
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2641,7 +2574,8 @@ var calculateTransactionFee = (params) => {
2641
2574
  return {
2642
2575
  fee: (0, import_math11.bn)(0),
2643
2576
  minFee: (0, import_math11.bn)(0),
2644
- maxFee: (0, import_math11.bn)(0)
2577
+ maxFee: (0, import_math11.bn)(0),
2578
+ feeFromGasUsed: (0, import_math11.bn)(0)
2645
2579
  };
2646
2580
  }
2647
2581
  const { type, witnesses, inputs, policies } = transaction;
@@ -2673,6 +2607,7 @@ var calculateTransactionFee = (params) => {
2673
2607
  metadataGas,
2674
2608
  txBytesSize: transactionBytes.length
2675
2609
  });
2610
+ const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2676
2611
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2677
2612
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2678
2613
  const maxGas = getMaxGas({
@@ -2680,25 +2615,17 @@ var calculateTransactionFee = (params) => {
2680
2615
  minGas,
2681
2616
  witnessesLength,
2682
2617
  gasLimit,
2683
- witnessLimit,
2684
- maxGasPerTx
2685
- });
2686
- const minFee = calculateGasFee({
2687
- gasPrice,
2688
- gas: minGas,
2689
- priceFactor: gasPriceFactor,
2690
- tip
2691
- });
2692
- const maxFee = calculateGasFee({
2693
- gasPrice,
2694
- gas: maxGas,
2695
- priceFactor: gasPriceFactor,
2696
- tip
2618
+ witnessLimit
2697
2619
  });
2620
+ const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2621
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2622
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2623
+ const fee = minFee.add(feeFromGasUsed);
2698
2624
  return {
2625
+ fee,
2699
2626
  minFee,
2700
2627
  maxFee,
2701
- fee: maxFee
2628
+ feeFromGasUsed
2702
2629
  };
2703
2630
  };
2704
2631
 
@@ -3265,12 +3192,10 @@ function assembleTransactionSummary(params) {
3265
3192
  gqlTransactionStatus,
3266
3193
  abiMap = {},
3267
3194
  maxInputs,
3268
- gasCosts,
3269
- maxGasPerTx,
3270
- gasPrice
3195
+ gasCosts
3271
3196
  } = params;
3272
3197
  const gasUsed = getGasUsedFromReceipts(receipts);
3273
- const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3198
+ const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3274
3199
  const operations = getOperations({
3275
3200
  transactionType: transaction.type,
3276
3201
  inputs: transaction.inputs || [],
@@ -3281,14 +3206,11 @@ function assembleTransactionSummary(params) {
3281
3206
  maxInputs
3282
3207
  });
3283
3208
  const typeName = getTransactionTypeName(transaction.type);
3284
- const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3285
3209
  const { fee } = calculateTransactionFee({
3286
- gasPrice,
3210
+ gasUsed,
3287
3211
  rawPayload,
3288
- tip,
3289
3212
  consensusParameters: {
3290
3213
  gasCosts,
3291
- maxGasPerTx,
3292
3214
  feeParams: {
3293
3215
  gasPerByte,
3294
3216
  gasPriceFactor
@@ -3300,7 +3222,7 @@ function assembleTransactionSummary(params) {
3300
3222
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3301
3223
  let date;
3302
3224
  if (time) {
3303
- date = import_utils18.DateTime.fromTai64(time);
3225
+ date = import_utils19.DateTime.fromTai64(time);
3304
3226
  }
3305
3227
  const transactionSummary = {
3306
3228
  id,
@@ -3328,12 +3250,12 @@ function assembleTransactionSummary(params) {
3328
3250
 
3329
3251
  // src/providers/transaction-response/getDecodedLogs.ts
3330
3252
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
3331
- var import_transactions17 = require("@fuel-ts/transactions");
3253
+ var import_transactions16 = require("@fuel-ts/transactions");
3332
3254
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3333
3255
  return receipts.reduce((logs, receipt) => {
3334
- if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3256
+ if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3335
3257
  const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3336
- const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3258
+ const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3337
3259
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3338
3260
  logs.push(decodedLog);
3339
3261
  }
@@ -3348,7 +3270,7 @@ var TransactionResponse = class {
3348
3270
  /** Current provider */
3349
3271
  provider;
3350
3272
  /** Gas used on the transaction */
3351
- gasUsed = (0, import_math15.bn)(0);
3273
+ gasUsed = (0, import_math14.bn)(0);
3352
3274
  /** The graphql Transaction with receipts object. */
3353
3275
  gqlTransaction;
3354
3276
  abis;
@@ -3406,8 +3328,8 @@ var TransactionResponse = class {
3406
3328
  * @returns The decoded transaction.
3407
3329
  */
3408
3330
  decodeTransaction(transactionWithReceipts) {
3409
- return new import_transactions18.TransactionCoder().decode(
3410
- (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3331
+ return new import_transactions17.TransactionCoder().decode(
3332
+ (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3411
3333
  0
3412
3334
  )?.[0];
3413
3335
  }
@@ -3426,27 +3348,20 @@ var TransactionResponse = class {
3426
3348
  const decodedTransaction = this.decodeTransaction(
3427
3349
  transaction
3428
3350
  );
3429
- let txReceipts = [];
3430
- if (transaction?.status && "receipts" in transaction.status) {
3431
- txReceipts = transaction.status.receipts;
3432
- }
3433
- const receipts = txReceipts.map(processGqlReceipt) || [];
3434
- const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3435
- const gasPrice = await this.provider.getLatestGasPrice();
3351
+ const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3352
+ const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3436
3353
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3437
3354
  const transactionSummary = assembleTransactionSummary({
3438
3355
  id: this.id,
3439
3356
  receipts,
3440
3357
  transaction: decodedTransaction,
3441
- transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3358
+ transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3442
3359
  gqlTransactionStatus: transaction.status,
3443
3360
  gasPerByte,
3444
3361
  gasPriceFactor,
3445
3362
  abiMap: contractsAbiMap,
3446
3363
  maxInputs,
3447
- gasCosts,
3448
- maxGasPerTx,
3449
- gasPrice
3364
+ gasCosts
3450
3365
  });
3451
3366
  return transactionSummary;
3452
3367
  }
@@ -3573,29 +3488,29 @@ var processGqlChain = (chain) => {
3573
3488
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3574
3489
  return {
3575
3490
  name,
3576
- baseChainHeight: (0, import_math16.bn)(daHeight),
3491
+ baseChainHeight: (0, import_math15.bn)(daHeight),
3577
3492
  consensusParameters: {
3578
- contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3579
- maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3580
- maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3581
- maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3582
- maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3583
- maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3584
- maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3585
- maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3586
- maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3587
- maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3588
- maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3589
- gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3590
- gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3591
- maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3592
- chainId: (0, import_math16.bn)(consensusParameters.chainId),
3493
+ contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3494
+ maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3495
+ maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3496
+ maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3497
+ maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3498
+ maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3499
+ maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3500
+ maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3501
+ maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3502
+ maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3503
+ maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3504
+ gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3505
+ gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3506
+ maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3507
+ chainId: (0, import_math15.bn)(consensusParameters.chainId),
3593
3508
  gasCosts
3594
3509
  },
3595
3510
  gasCosts,
3596
3511
  latestBlock: {
3597
3512
  id: latestBlock.id,
3598
- height: (0, import_math16.bn)(latestBlock.height),
3513
+ height: (0, import_math15.bn)(latestBlock.header.height),
3599
3514
  time: latestBlock.header.time,
3600
3515
  transactions: latestBlock.transactions.map((i) => ({
3601
3516
  id: i.id
@@ -3780,7 +3695,7 @@ var _Provider = class {
3780
3695
  name,
3781
3696
  consensusParameters: { chainId }
3782
3697
  } = await this.getChain();
3783
- const network = new import_ethers2.Network(name, chainId.toNumber());
3698
+ const network = new import_ethers.Network(name, chainId.toNumber());
3784
3699
  return Promise.resolve(network);
3785
3700
  }
3786
3701
  /**
@@ -3790,7 +3705,7 @@ var _Provider = class {
3790
3705
  */
3791
3706
  async getBlockNumber() {
3792
3707
  const { chain } = await this.operations.getChain();
3793
- return (0, import_math16.bn)(chain.latestBlock.height, 10);
3708
+ return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
3794
3709
  }
3795
3710
  /**
3796
3711
  * Returns the chain information.
@@ -3800,12 +3715,13 @@ var _Provider = class {
3800
3715
  async fetchNode() {
3801
3716
  const { nodeInfo } = await this.operations.getNodeInfo();
3802
3717
  const processedNodeInfo = {
3803
- maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
3804
- maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3805
- minGasPrice: (0, import_math16.bn)(nodeInfo.minGasPrice),
3718
+ maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3719
+ maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3720
+ minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
3806
3721
  nodeVersion: nodeInfo.nodeVersion,
3807
3722
  utxoValidation: nodeInfo.utxoValidation,
3808
- vmBacktrace: nodeInfo.vmBacktrace
3723
+ vmBacktrace: nodeInfo.vmBacktrace,
3724
+ peers: nodeInfo.peers
3809
3725
  };
3810
3726
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3811
3727
  return processedNodeInfo;
@@ -3847,9 +3763,9 @@ var _Provider = class {
3847
3763
  if (estimateTxDependencies) {
3848
3764
  await this.estimateTxDependencies(transactionRequest);
3849
3765
  }
3850
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3766
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3851
3767
  let abis;
3852
- if (transactionRequest.type === import_transactions19.TransactionType.Script) {
3768
+ if (transactionRequest.type === import_transactions18.TransactionType.Script) {
3853
3769
  abis = transactionRequest.abis;
3854
3770
  }
3855
3771
  if (awaitExecution) {
@@ -3890,14 +3806,15 @@ var _Provider = class {
3890
3806
  if (estimateTxDependencies) {
3891
3807
  return this.estimateTxDependencies(transactionRequest);
3892
3808
  }
3893
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3894
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
3895
- encodedTransactions: encodedTransaction,
3809
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3810
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
3811
+ encodedTransaction,
3896
3812
  utxoValidation: utxoValidation || false
3897
3813
  });
3898
- const [{ receipts: rawReceipts, status }] = dryRunStatuses;
3899
- const receipts = rawReceipts.map(processGqlReceipt);
3900
- return { receipts, dryrunStatus: status };
3814
+ const receipts = gqlReceipts.map(processGqlReceipt);
3815
+ return {
3816
+ receipts
3817
+ };
3901
3818
  }
3902
3819
  /**
3903
3820
  * Verifies whether enough gas is available to complete transaction.
@@ -3908,13 +3825,13 @@ var _Provider = class {
3908
3825
  async estimatePredicates(transactionRequest) {
3909
3826
  const shouldEstimatePredicates = Boolean(
3910
3827
  transactionRequest.inputs.find(
3911
- (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
3828
+ (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
3912
3829
  )
3913
3830
  );
3914
3831
  if (!shouldEstimatePredicates) {
3915
3832
  return transactionRequest;
3916
3833
  }
3917
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3834
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3918
3835
  const response = await this.operations.estimatePredicates({
3919
3836
  encodedTransaction
3920
3837
  });
@@ -3923,7 +3840,7 @@ var _Provider = class {
3923
3840
  } = response;
3924
3841
  if (inputs) {
3925
3842
  inputs.forEach((input, index) => {
3926
- if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
3843
+ if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
3927
3844
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3928
3845
  }
3929
3846
  });
@@ -3936,31 +3853,31 @@ var _Provider = class {
3936
3853
  * If there are missing variable outputs,
3937
3854
  * `addVariableOutputs` is called on the transaction.
3938
3855
  *
3856
+ * @privateRemarks
3857
+ * TODO: Investigate support for missing contract IDs
3858
+ * TODO: Add support for missing output messages
3939
3859
  *
3940
3860
  * @param transactionRequest - The transaction request object.
3941
3861
  * @returns A promise.
3942
3862
  */
3943
3863
  async estimateTxDependencies(transactionRequest) {
3944
- if (transactionRequest.type === import_transactions19.TransactionType.Create) {
3864
+ if (transactionRequest.type === import_transactions18.TransactionType.Create) {
3945
3865
  return {
3946
3866
  receipts: [],
3947
3867
  outputVariables: 0,
3948
3868
  missingContractIds: []
3949
3869
  };
3950
3870
  }
3871
+ await this.estimatePredicates(transactionRequest);
3951
3872
  let receipts = [];
3952
3873
  const missingContractIds = [];
3953
3874
  let outputVariables = 0;
3954
- let dryrunStatus;
3955
3875
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3956
- const {
3957
- dryRun: [{ receipts: rawReceipts, status }]
3958
- } = await this.operations.dryRun({
3959
- encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
3876
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
3877
+ encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
3960
3878
  utxoValidation: false
3961
3879
  });
3962
- receipts = rawReceipts.map(processGqlReceipt);
3963
- dryrunStatus = status;
3880
+ receipts = gqlReceipts.map(processGqlReceipt);
3964
3881
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3965
3882
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3966
3883
  if (hasMissingOutputs) {
@@ -3970,11 +3887,6 @@ var _Provider = class {
3970
3887
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
3971
3888
  missingContractIds.push(contractId);
3972
3889
  });
3973
- const { maxFee } = await this.estimateTxGasAndFee({
3974
- transactionRequest,
3975
- optimizeGas: false
3976
- });
3977
- transactionRequest.maxFee = maxFee;
3978
3890
  } else {
3979
3891
  break;
3980
3892
  }
@@ -3982,133 +3894,7 @@ var _Provider = class {
3982
3894
  return {
3983
3895
  receipts,
3984
3896
  outputVariables,
3985
- missingContractIds,
3986
- dryrunStatus
3987
- };
3988
- }
3989
- /**
3990
- * Dry runs multiple transactions and checks for missing dependencies in batches.
3991
- *
3992
- * Transactions are dry run in batches. After each dry run, transactions requiring
3993
- * further modifications are identified. The method iteratively updates these transactions
3994
- * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
3995
- *
3996
- * @param transactionRequests - Array of transaction request objects.
3997
- * @returns A promise that resolves to an array of results for each transaction.
3998
- */
3999
- async estimateMultipleTxDependencies(transactionRequests) {
4000
- const results = transactionRequests.map(() => ({
4001
- receipts: [],
4002
- outputVariables: 0,
4003
- missingContractIds: [],
4004
- dryrunStatus: void 0
4005
- }));
4006
- const allRequests = (0, import_ramda3.clone)(transactionRequests);
4007
- const serializedTransactionsMap = /* @__PURE__ */ new Map();
4008
- allRequests.forEach((req, index) => {
4009
- if (req.type === import_transactions19.TransactionType.Script) {
4010
- serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4011
- }
4012
- });
4013
- let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4014
- let attempt = 0;
4015
- while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4016
- const encodedTransactions = transactionsToProcess.map(
4017
- (index) => serializedTransactionsMap.get(index)
4018
- );
4019
- const dryRunResults = await this.operations.dryRun({
4020
- encodedTransactions,
4021
- utxoValidation: false
4022
- });
4023
- const nextRoundTransactions = [];
4024
- for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4025
- const currentResultIndex = transactionsToProcess[i];
4026
- const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4027
- results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4028
- results[currentResultIndex].dryrunStatus = status;
4029
- const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4030
- results[currentResultIndex].receipts
4031
- );
4032
- const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4033
- const requestToProcess = allRequests[currentResultIndex];
4034
- if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4035
- results[currentResultIndex].outputVariables += missingOutputVariables.length;
4036
- requestToProcess.addVariableOutputs(missingOutputVariables.length);
4037
- missingOutputContractIds.forEach(({ contractId }) => {
4038
- requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4039
- results[currentResultIndex].missingContractIds.push(contractId);
4040
- });
4041
- const { maxFee } = await this.estimateTxGasAndFee({
4042
- transactionRequest: requestToProcess,
4043
- optimizeGas: false
4044
- });
4045
- requestToProcess.maxFee = maxFee;
4046
- serializedTransactionsMap.set(
4047
- currentResultIndex,
4048
- (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4049
- );
4050
- nextRoundTransactions.push(currentResultIndex);
4051
- allRequests[currentResultIndex] = requestToProcess;
4052
- }
4053
- }
4054
- transactionsToProcess = nextRoundTransactions;
4055
- attempt += 1;
4056
- }
4057
- return results;
4058
- }
4059
- async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4060
- if (estimateTxDependencies) {
4061
- return this.estimateMultipleTxDependencies(transactionRequests);
4062
- }
4063
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4064
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4065
- encodedTransactions,
4066
- utxoValidation: utxoValidation || false
4067
- });
4068
- const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4069
- const receipts = rawReceipts.map(processGqlReceipt);
4070
- return { receipts, dryrunStatus: status };
4071
- });
4072
- return results;
4073
- }
4074
- async estimateTxGasAndFee(params) {
4075
- const { transactionRequest, totalGasUsedByPredicates = (0, import_math16.bn)(0), optimizeGas = true } = params;
4076
- let { gasPrice } = params;
4077
- const chainInfo = this.getChain();
4078
- const { gasPriceFactor } = this.getGasConfig();
4079
- const minGas = transactionRequest.calculateMinGas(chainInfo);
4080
- if (!gasPrice) {
4081
- gasPrice = await this.estimateGasPrice(10);
4082
- }
4083
- const shouldSetGaslimit = transactionRequest.type === import_transactions19.TransactionType.Script && !optimizeGas;
4084
- const minFee = calculateGasFee({
4085
- gasPrice: (0, import_math16.bn)(gasPrice),
4086
- gas: minGas,
4087
- priceFactor: gasPriceFactor,
4088
- tip: transactionRequest.tip
4089
- }).add(1);
4090
- if (shouldSetGaslimit) {
4091
- transactionRequest.gasLimit = chainInfo.consensusParameters.maxGasPerTx.sub(
4092
- minGas.add(totalGasUsedByPredicates)
4093
- );
4094
- }
4095
- let maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4096
- const maxFee = calculateGasFee({
4097
- gasPrice: (0, import_math16.bn)(gasPrice),
4098
- gas: maxGas,
4099
- priceFactor: gasPriceFactor,
4100
- tip: transactionRequest.tip
4101
- }).add(1);
4102
- if (shouldSetGaslimit) {
4103
- maxGas = chainInfo.consensusParameters.maxGasPerTx.sub(maxFee);
4104
- transactionRequest.gasLimit = maxGas;
4105
- }
4106
- return {
4107
- minGas,
4108
- minFee,
4109
- maxGas,
4110
- maxFee,
4111
- gasPrice
3897
+ missingContractIds
4112
3898
  };
4113
3899
  }
4114
3900
  /**
@@ -4126,17 +3912,15 @@ var _Provider = class {
4126
3912
  if (estimateTxDependencies) {
4127
3913
  return this.estimateTxDependencies(transactionRequest);
4128
3914
  }
4129
- const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4130
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4131
- encodedTransactions,
3915
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3916
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
3917
+ encodedTransaction,
4132
3918
  utxoValidation: true
4133
3919
  });
4134
- const callResult = dryRunStatuses.map((dryRunStatus) => {
4135
- const { id, receipts, status } = dryRunStatus;
4136
- const processedReceipts = receipts.map(processGqlReceipt);
4137
- return { id, receipts: processedReceipts, status };
4138
- });
4139
- return { receipts: callResult[0].receipts };
3920
+ const receipts = gqlReceipts.map(processGqlReceipt);
3921
+ return {
3922
+ receipts
3923
+ };
4140
3924
  }
4141
3925
  /**
4142
3926
  * Returns a transaction cost to enable user
@@ -4153,80 +3937,80 @@ var _Provider = class {
4153
3937
  * @param tolerance - The tolerance to add on top of the gasUsed.
4154
3938
  * @returns A promise that resolves to the transaction cost object.
4155
3939
  */
4156
- async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3940
+ async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3941
+ estimateTxDependencies = true,
3942
+ estimatePredicates = true,
3943
+ resourcesOwner,
3944
+ signatureCallback
3945
+ } = {}) {
4157
3946
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4158
- const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
3947
+ const chainInfo = this.getChain();
3948
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3949
+ const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
3950
+ const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4159
3951
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4160
- const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
3952
+ const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4161
3953
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4162
- txRequestClone.maxFee = (0, import_math16.bn)(0);
4163
- if (isScriptTransaction) {
4164
- txRequestClone.gasLimit = (0, import_math16.bn)(0);
4165
- }
4166
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4167
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
3954
+ if (estimatePredicates) {
3955
+ if (isScriptTransaction) {
3956
+ txRequestClone.gasLimit = (0, import_math15.bn)(0);
3957
+ }
3958
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3959
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
3960
+ }
3961
+ await this.estimatePredicates(txRequestClone);
4168
3962
  }
4169
- const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4170
- let addedSignatures = 0;
4171
3963
  if (signatureCallback && isScriptTransaction) {
4172
- const lengthBefore = signedRequest.witnesses.length;
4173
- await signatureCallback(signedRequest);
4174
- addedSignatures = signedRequest.witnesses.length - lengthBefore;
4175
- }
4176
- await this.estimatePredicates(signedRequest);
4177
- let { maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4178
- transactionRequest: signedRequest,
4179
- optimizeGas: false
4180
- });
4181
- txRequestClone.maxFee = maxFee;
3964
+ await signatureCallback(txRequestClone);
3965
+ }
3966
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
3967
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4182
3968
  let receipts = [];
4183
3969
  let missingContractIds = [];
4184
3970
  let outputVariables = 0;
4185
- let gasUsed = (0, import_math16.bn)(0);
4186
- txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4187
- if (isScriptTransaction) {
4188
- if (signatureCallback) {
4189
- await signatureCallback(txRequestClone);
4190
- }
4191
- txRequestClone.gasLimit = maxGas;
3971
+ if (isScriptTransaction && estimateTxDependencies) {
3972
+ txRequestClone.gasPrice = (0, import_math15.bn)(0);
3973
+ txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4192
3974
  const result = await this.estimateTxDependencies(txRequestClone);
4193
3975
  receipts = result.receipts;
4194
3976
  outputVariables = result.outputVariables;
4195
3977
  missingContractIds = result.missingContractIds;
4196
- gasUsed = getGasUsedFromReceipts(receipts);
4197
- txRequestClone.gasLimit = gasUsed;
4198
- ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4199
- transactionRequest: txRequestClone,
4200
- gasPrice
4201
- }));
4202
3978
  }
3979
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3980
+ const usedFee = calculatePriceWithFactor(
3981
+ gasUsed,
3982
+ gasPrice,
3983
+ gasPriceFactor
3984
+ ).normalizeZeroToOne();
3985
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3986
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4203
3987
  return {
4204
3988
  requiredQuantities: allQuantities,
4205
3989
  receipts,
4206
3990
  gasUsed,
3991
+ minGasPrice,
4207
3992
  gasPrice,
4208
3993
  minGas,
4209
3994
  maxGas,
3995
+ usedFee,
4210
3996
  minFee,
4211
3997
  maxFee,
3998
+ estimatedInputs: txRequestClone.inputs,
4212
3999
  outputVariables,
4213
- missingContractIds,
4214
- addedSignatures,
4215
- estimatedPredicates: txRequestClone.inputs
4000
+ missingContractIds
4216
4001
  };
4217
4002
  }
4218
- async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4003
+ async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4219
4004
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4220
4005
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4221
- const transactionCost = await this.getTransactionCost(transactionRequest, {
4222
- quantitiesToContract
4223
- });
4006
+ const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4224
4007
  transactionRequest.addResources(
4225
4008
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4226
4009
  );
4227
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4228
- quantitiesToContract
4229
- });
4010
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4011
+ transactionRequest,
4012
+ forwardingQuantities
4013
+ );
4230
4014
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4231
4015
  return {
4232
4016
  resources,
@@ -4242,16 +4026,17 @@ var _Provider = class {
4242
4026
  const result = await this.operations.getCoins({
4243
4027
  first: 10,
4244
4028
  ...paginationArgs,
4245
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4029
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4246
4030
  });
4247
4031
  const coins = result.coins.edges.map((edge) => edge.node);
4248
4032
  return coins.map((coin) => ({
4249
4033
  id: coin.utxoId,
4250
4034
  assetId: coin.assetId,
4251
- amount: (0, import_math16.bn)(coin.amount),
4035
+ amount: (0, import_math15.bn)(coin.amount),
4252
4036
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4253
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4254
- txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4037
+ maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4038
+ blockCreated: (0, import_math15.bn)(coin.blockCreated),
4039
+ txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4255
4040
  }));
4256
4041
  }
4257
4042
  /**
@@ -4265,19 +4050,19 @@ var _Provider = class {
4265
4050
  async getResourcesToSpend(owner, quantities, excludedIds) {
4266
4051
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4267
4052
  const excludeInput = {
4268
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4269
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4053
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4054
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4270
4055
  };
4271
4056
  if (this.cache) {
4272
4057
  const uniqueUtxos = new Set(
4273
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4058
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4274
4059
  );
4275
4060
  excludeInput.utxos = Array.from(uniqueUtxos);
4276
4061
  }
4277
4062
  const coinsQuery = {
4278
4063
  owner: ownerAddress.toB256(),
4279
4064
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4280
- assetId: (0, import_utils22.hexlify)(assetId),
4065
+ assetId: (0, import_utils23.hexlify)(assetId),
4281
4066
  amount: amount.toString(10),
4282
4067
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4283
4068
  })),
@@ -4288,9 +4073,9 @@ var _Provider = class {
4288
4073
  switch (coin.__typename) {
4289
4074
  case "MessageCoin":
4290
4075
  return {
4291
- amount: (0, import_math16.bn)(coin.amount),
4076
+ amount: (0, import_math15.bn)(coin.amount),
4292
4077
  assetId: coin.assetId,
4293
- daHeight: (0, import_math16.bn)(coin.daHeight),
4078
+ daHeight: (0, import_math15.bn)(coin.daHeight),
4294
4079
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4295
4080
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4296
4081
  nonce: coin.nonce
@@ -4298,11 +4083,12 @@ var _Provider = class {
4298
4083
  case "Coin":
4299
4084
  return {
4300
4085
  id: coin.utxoId,
4301
- amount: (0, import_math16.bn)(coin.amount),
4086
+ amount: (0, import_math15.bn)(coin.amount),
4302
4087
  assetId: coin.assetId,
4303
4088
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4304
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4305
- txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4089
+ maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4090
+ blockCreated: (0, import_math15.bn)(coin.blockCreated),
4091
+ txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4306
4092
  };
4307
4093
  default:
4308
4094
  return null;
@@ -4319,13 +4105,13 @@ var _Provider = class {
4319
4105
  async getBlock(idOrHeight) {
4320
4106
  let variables;
4321
4107
  if (typeof idOrHeight === "number") {
4322
- variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4108
+ variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4323
4109
  } else if (idOrHeight === "latest") {
4324
4110
  variables = { height: (await this.getBlockNumber()).toString(10) };
4325
4111
  } else if (idOrHeight.length === 66) {
4326
4112
  variables = { blockId: idOrHeight };
4327
4113
  } else {
4328
- variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4114
+ variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4329
4115
  }
4330
4116
  const { block } = await this.operations.getBlock(variables);
4331
4117
  if (!block) {
@@ -4333,7 +4119,7 @@ var _Provider = class {
4333
4119
  }
4334
4120
  return {
4335
4121
  id: block.id,
4336
- height: (0, import_math16.bn)(block.height),
4122
+ height: (0, import_math15.bn)(block.header.height),
4337
4123
  time: block.header.time,
4338
4124
  transactionIds: block.transactions.map((tx) => tx.id)
4339
4125
  };
@@ -4348,7 +4134,7 @@ var _Provider = class {
4348
4134
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4349
4135
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4350
4136
  id: block.id,
4351
- height: (0, import_math16.bn)(block.height),
4137
+ height: (0, import_math15.bn)(block.header.height),
4352
4138
  time: block.header.time,
4353
4139
  transactionIds: block.transactions.map((tx) => tx.id)
4354
4140
  }));
@@ -4363,7 +4149,7 @@ var _Provider = class {
4363
4149
  async getBlockWithTransactions(idOrHeight) {
4364
4150
  let variables;
4365
4151
  if (typeof idOrHeight === "number") {
4366
- variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4152
+ variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4367
4153
  } else if (idOrHeight === "latest") {
4368
4154
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4369
4155
  } else {
@@ -4375,11 +4161,11 @@ var _Provider = class {
4375
4161
  }
4376
4162
  return {
4377
4163
  id: block.id,
4378
- height: (0, import_math16.bn)(block.height, 10),
4164
+ height: (0, import_math15.bn)(block.header.height, 10),
4379
4165
  time: block.header.time,
4380
4166
  transactionIds: block.transactions.map((tx) => tx.id),
4381
4167
  transactions: block.transactions.map(
4382
- (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4168
+ (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4383
4169
  )
4384
4170
  };
4385
4171
  }
@@ -4394,8 +4180,8 @@ var _Provider = class {
4394
4180
  if (!transaction) {
4395
4181
  return null;
4396
4182
  }
4397
- return new import_transactions19.TransactionCoder().decode(
4398
- (0, import_utils22.arrayify)(transaction.rawPayload),
4183
+ return new import_transactions18.TransactionCoder().decode(
4184
+ (0, import_utils23.arrayify)(transaction.rawPayload),
4399
4185
  0
4400
4186
  )?.[0];
4401
4187
  }
@@ -4422,9 +4208,9 @@ var _Provider = class {
4422
4208
  async getContractBalance(contractId, assetId) {
4423
4209
  const { contractBalance } = await this.operations.getContractBalance({
4424
4210
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4425
- asset: (0, import_utils22.hexlify)(assetId)
4211
+ asset: (0, import_utils23.hexlify)(assetId)
4426
4212
  });
4427
- return (0, import_math16.bn)(contractBalance.amount, 10);
4213
+ return (0, import_math15.bn)(contractBalance.amount, 10);
4428
4214
  }
4429
4215
  /**
4430
4216
  * Returns the balance for the given owner for the given asset ID.
@@ -4436,9 +4222,9 @@ var _Provider = class {
4436
4222
  async getBalance(owner, assetId) {
4437
4223
  const { balance } = await this.operations.getBalance({
4438
4224
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4439
- assetId: (0, import_utils22.hexlify)(assetId)
4225
+ assetId: (0, import_utils23.hexlify)(assetId)
4440
4226
  });
4441
- return (0, import_math16.bn)(balance.amount, 10);
4227
+ return (0, import_math15.bn)(balance.amount, 10);
4442
4228
  }
4443
4229
  /**
4444
4230
  * Returns balances for the given owner.
@@ -4456,7 +4242,7 @@ var _Provider = class {
4456
4242
  const balances = result.balances.edges.map((edge) => edge.node);
4457
4243
  return balances.map((balance) => ({
4458
4244
  assetId: balance.assetId,
4459
- amount: (0, import_math16.bn)(balance.amount)
4245
+ amount: (0, import_math15.bn)(balance.amount)
4460
4246
  }));
4461
4247
  }
4462
4248
  /**
@@ -4474,19 +4260,19 @@ var _Provider = class {
4474
4260
  });
4475
4261
  const messages = result.messages.edges.map((edge) => edge.node);
4476
4262
  return messages.map((message) => ({
4477
- messageId: import_transactions19.InputMessageCoder.getMessageId({
4263
+ messageId: import_transactions18.InputMessageCoder.getMessageId({
4478
4264
  sender: message.sender,
4479
4265
  recipient: message.recipient,
4480
4266
  nonce: message.nonce,
4481
- amount: (0, import_math16.bn)(message.amount),
4267
+ amount: (0, import_math15.bn)(message.amount),
4482
4268
  data: message.data
4483
4269
  }),
4484
4270
  sender: import_address3.Address.fromAddressOrString(message.sender),
4485
4271
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4486
4272
  nonce: message.nonce,
4487
- amount: (0, import_math16.bn)(message.amount),
4488
- data: import_transactions19.InputMessageCoder.decodeData(message.data),
4489
- daHeight: (0, import_math16.bn)(message.daHeight)
4273
+ amount: (0, import_math15.bn)(message.amount),
4274
+ data: import_transactions18.InputMessageCoder.decodeData(message.data),
4275
+ daHeight: (0, import_math15.bn)(message.daHeight)
4490
4276
  }));
4491
4277
  }
4492
4278
  /**
@@ -4539,54 +4325,44 @@ var _Provider = class {
4539
4325
  } = result.messageProof;
4540
4326
  return {
4541
4327
  messageProof: {
4542
- proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4328
+ proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4543
4329
  proofSet: messageProof.proofSet
4544
4330
  },
4545
4331
  blockProof: {
4546
- proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4332
+ proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4547
4333
  proofSet: blockProof.proofSet
4548
4334
  },
4549
4335
  messageBlockHeader: {
4550
4336
  id: messageBlockHeader.id,
4551
- daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4552
- transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4337
+ daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4338
+ transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4553
4339
  transactionsRoot: messageBlockHeader.transactionsRoot,
4554
- height: (0, import_math16.bn)(messageBlockHeader.height),
4340
+ height: (0, import_math15.bn)(messageBlockHeader.height),
4555
4341
  prevRoot: messageBlockHeader.prevRoot,
4556
4342
  time: messageBlockHeader.time,
4557
4343
  applicationHash: messageBlockHeader.applicationHash,
4558
4344
  messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4559
- messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount)
4345
+ messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4560
4346
  },
4561
4347
  commitBlockHeader: {
4562
4348
  id: commitBlockHeader.id,
4563
- daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4564
- transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4349
+ daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4350
+ transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4565
4351
  transactionsRoot: commitBlockHeader.transactionsRoot,
4566
- height: (0, import_math16.bn)(commitBlockHeader.height),
4352
+ height: (0, import_math15.bn)(commitBlockHeader.height),
4567
4353
  prevRoot: commitBlockHeader.prevRoot,
4568
4354
  time: commitBlockHeader.time,
4569
4355
  applicationHash: commitBlockHeader.applicationHash,
4570
4356
  messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4571
- messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount)
4357
+ messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4572
4358
  },
4573
4359
  sender: import_address3.Address.fromAddressOrString(sender),
4574
4360
  recipient: import_address3.Address.fromAddressOrString(recipient),
4575
4361
  nonce,
4576
- amount: (0, import_math16.bn)(amount),
4362
+ amount: (0, import_math15.bn)(amount),
4577
4363
  data
4578
4364
  };
4579
4365
  }
4580
- async getLatestGasPrice() {
4581
- const { latestGasPrice } = await this.operations.getLatestGasPrice();
4582
- return (0, import_math16.bn)(latestGasPrice.gasPrice);
4583
- }
4584
- async estimateGasPrice(blockHorizon) {
4585
- const { estimateGasPrice } = await this.operations.estimateGasPrice({
4586
- blockHorizon: String(blockHorizon)
4587
- });
4588
- return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4589
- }
4590
4366
  /**
4591
4367
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4592
4368
  *
@@ -4606,10 +4382,10 @@ var _Provider = class {
4606
4382
  */
4607
4383
  async produceBlocks(amount, startTime) {
4608
4384
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4609
- blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4610
- startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4385
+ blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4386
+ startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4611
4387
  });
4612
- return (0, import_math16.bn)(latestBlockHeight);
4388
+ return (0, import_math15.bn)(latestBlockHeight);
4613
4389
  }
4614
4390
  // eslint-disable-next-line @typescript-eslint/require-await
4615
4391
  async getTransactionResponse(transactionId) {
@@ -4623,7 +4399,7 @@ cacheInputs_fn = function(inputs) {
4623
4399
  return;
4624
4400
  }
4625
4401
  inputs.forEach((input) => {
4626
- if (input.type === import_transactions19.InputType.Coin) {
4402
+ if (input.type === import_transactions18.InputType.Coin) {
4627
4403
  this.cache?.set(input.id);
4628
4404
  }
4629
4405
  });
@@ -4633,9 +4409,9 @@ __publicField(Provider, "nodeInfoCache", {});
4633
4409
 
4634
4410
  // src/providers/transaction-summary/get-transaction-summary.ts
4635
4411
  var import_errors15 = require("@fuel-ts/errors");
4636
- var import_math17 = require("@fuel-ts/math");
4637
- var import_transactions20 = require("@fuel-ts/transactions");
4638
- var import_utils25 = require("@fuel-ts/utils");
4412
+ var import_math16 = require("@fuel-ts/math");
4413
+ var import_transactions19 = require("@fuel-ts/transactions");
4414
+ var import_utils26 = require("@fuel-ts/utils");
4639
4415
 
4640
4416
  // src/providers/chains.ts
4641
4417
  var CHAIN_IDS = {
@@ -4684,17 +4460,17 @@ var assets = [
4684
4460
 
4685
4461
  // src/utils/formatTransferToContractScriptData.ts
4686
4462
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
4687
- var import_math18 = require("@fuel-ts/math");
4688
- var import_utils26 = require("@fuel-ts/utils");
4463
+ var import_math17 = require("@fuel-ts/math");
4464
+ var import_utils27 = require("@fuel-ts/utils");
4689
4465
  var asm = __toESM(require("@fuels/vm-asm"));
4690
4466
  var formatTransferToContractScriptData = (params) => {
4691
4467
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4692
4468
  const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4693
- const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4469
+ const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4694
4470
  const scriptData = Uint8Array.from([
4695
- ...(0, import_utils26.arrayify)(hexlifiedContractId),
4471
+ ...(0, import_utils27.arrayify)(hexlifiedContractId),
4696
4472
  ...encoded,
4697
- ...(0, import_utils26.arrayify)(assetId)
4473
+ ...(0, import_utils27.arrayify)(assetId)
4698
4474
  ]);
4699
4475
  return scriptData;
4700
4476
  };
@@ -4879,33 +4655,36 @@ var Account = class extends import_interfaces.AbstractAccount {
4879
4655
  * @param fee - The estimated transaction fee.
4880
4656
  * @returns A promise that resolves when the resources are added to the transaction.
4881
4657
  */
4882
- async fund(request, params) {
4883
- const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4884
- const txRequest = request;
4885
- const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4886
- amount: (0, import_math19.bn)(fee),
4658
+ async fund(request, coinQuantities, fee) {
4659
+ const updatedQuantities = addAmountToAsset({
4660
+ amount: (0, import_math18.bn)(fee),
4887
4661
  assetId: import_configs12.BaseAssetId,
4888
- coinQuantities: requiredQuantities
4662
+ coinQuantities
4889
4663
  });
4890
4664
  const quantitiesDict = {};
4891
- requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4665
+ updatedQuantities.forEach(({ amount, assetId }) => {
4892
4666
  quantitiesDict[assetId] = {
4893
4667
  required: amount,
4894
- owned: (0, import_math19.bn)(0)
4668
+ owned: (0, import_math18.bn)(0)
4895
4669
  };
4896
4670
  });
4897
- txRequest.inputs.forEach((input) => {
4671
+ const cachedUtxos = [];
4672
+ const cachedMessages = [];
4673
+ const owner = this.address.toB256();
4674
+ request.inputs.forEach((input) => {
4898
4675
  const isResource = "amount" in input;
4899
4676
  if (isResource) {
4900
4677
  const isCoin2 = "owner" in input;
4901
4678
  if (isCoin2) {
4902
4679
  const assetId = String(input.assetId);
4903
- if (quantitiesDict[assetId]) {
4904
- const amount = (0, import_math19.bn)(input.amount);
4680
+ if (input.owner === owner && quantitiesDict[assetId]) {
4681
+ const amount = (0, import_math18.bn)(input.amount);
4905
4682
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4683
+ cachedUtxos.push(input.id);
4906
4684
  }
4907
- } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
4685
+ } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
4908
4686
  quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
4687
+ cachedMessages.push(input.nonce);
4909
4688
  }
4910
4689
  }
4911
4690
  });
@@ -4920,23 +4699,12 @@ var Account = class extends import_interfaces.AbstractAccount {
4920
4699
  });
4921
4700
  const needsToBeFunded = missingQuantities.length;
4922
4701
  if (needsToBeFunded) {
4923
- const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toString());
4924
- const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4925
- txRequest.addResources(resources);
4926
- }
4927
- txRequest.shiftPredicateData();
4928
- txRequest.updatePredicateGasUsed(estimatedPredicates);
4929
- const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
4930
- if (addedSignatures) {
4931
- Array.from({ length: addedSignatures }).forEach(
4932
- () => requestToBeReEstimate.addEmptyWitness()
4933
- );
4702
+ const resources = await this.getResourcesToSpend(missingQuantities, {
4703
+ messages: cachedMessages,
4704
+ utxos: cachedUtxos
4705
+ });
4706
+ request.addResources(resources);
4934
4707
  }
4935
- const { maxFee } = await this.provider.estimateTxGasAndFee({
4936
- transactionRequest: requestToBeReEstimate
4937
- });
4938
- txRequest.maxFee = maxFee;
4939
- return txRequest;
4940
4708
  }
4941
4709
  /**
4942
4710
  * A helper that creates a transfer transaction request and returns it.
@@ -4944,25 +4712,28 @@ var Account = class extends import_interfaces.AbstractAccount {
4944
4712
  * @param destination - The address of the destination.
4945
4713
  * @param amount - The amount of coins to transfer.
4946
4714
  * @param assetId - The asset ID of the coins to transfer.
4947
- * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4715
+ * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4948
4716
  * @returns A promise that resolves to the prepared transaction request.
4949
4717
  */
4950
4718
  async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4951
- const request = new ScriptTransactionRequest(txParams);
4719
+ const { minGasPrice } = this.provider.getGasConfig();
4720
+ const params = { gasPrice: minGasPrice, ...txParams };
4721
+ const request = new ScriptTransactionRequest(params);
4952
4722
  request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
4953
- const txCost = await this.provider.getTransactionCost(request, {
4723
+ const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4954
4724
  estimateTxDependencies: true,
4955
4725
  resourcesOwner: this
4956
4726
  });
4957
- if ("gasLimit" in txParams) {
4958
- this.validateGas({
4959
- gasUsed: txCost.gasUsed,
4960
- gasLimit: request.gasLimit
4961
- });
4962
- }
4963
- request.gasLimit = txCost.gasUsed;
4964
- request.maxFee = txCost.maxFee;
4965
- await this.fund(request, txCost);
4727
+ request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
4728
+ request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
4729
+ this.validateGas({
4730
+ gasUsed,
4731
+ gasPrice: request.gasPrice,
4732
+ gasLimit: request.gasLimit,
4733
+ minGasPrice
4734
+ });
4735
+ await this.fund(request, requiredQuantities, maxFee);
4736
+ request.updatePredicateInputs(estimatedInputs);
4966
4737
  return request;
4967
4738
  }
4968
4739
  /**
@@ -4975,7 +4746,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4975
4746
  * @returns A promise that resolves to the transaction response.
4976
4747
  */
4977
4748
  async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4978
- if ((0, import_math19.bn)(amount).lte(0)) {
4749
+ if ((0, import_math18.bn)(amount).lte(0)) {
4979
4750
  throw new import_errors16.FuelError(
4980
4751
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4981
4752
  "Transfer amount must be a positive number."
@@ -4994,37 +4765,38 @@ var Account = class extends import_interfaces.AbstractAccount {
4994
4765
  * @returns A promise that resolves to the transaction response.
4995
4766
  */
4996
4767
  async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4997
- if ((0, import_math19.bn)(amount).lte(0)) {
4768
+ if ((0, import_math18.bn)(amount).lte(0)) {
4998
4769
  throw new import_errors16.FuelError(
4999
4770
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5000
4771
  "Transfer amount must be a positive number."
5001
4772
  );
5002
4773
  }
5003
4774
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4775
+ const { minGasPrice } = this.provider.getGasConfig();
4776
+ const params = { gasPrice: minGasPrice, ...txParams };
5004
4777
  const { script, scriptData } = await assembleTransferToContractScript({
5005
4778
  hexlifiedContractId: contractAddress.toB256(),
5006
- amountToTransfer: (0, import_math19.bn)(amount),
4779
+ amountToTransfer: (0, import_math18.bn)(amount),
5007
4780
  assetId
5008
4781
  });
5009
4782
  const request = new ScriptTransactionRequest({
5010
- ...txParams,
4783
+ ...params,
5011
4784
  script,
5012
4785
  scriptData
5013
4786
  });
5014
4787
  request.addContractInputAndOutput(contractAddress);
5015
- const txCost = await this.provider.getTransactionCost(request, {
5016
- resourcesOwner: this,
5017
- quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
4788
+ const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4789
+ request,
4790
+ [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
4791
+ );
4792
+ request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4793
+ this.validateGas({
4794
+ gasUsed,
4795
+ gasPrice: request.gasPrice,
4796
+ gasLimit: request.gasLimit,
4797
+ minGasPrice
5018
4798
  });
5019
- if (txParams.gasLimit) {
5020
- this.validateGas({
5021
- gasUsed: txCost.gasUsed,
5022
- gasLimit: request.gasLimit
5023
- });
5024
- }
5025
- request.gasLimit = txCost.gasUsed;
5026
- request.maxFee = txCost.maxFee;
5027
- await this.fund(request, txCost);
4799
+ await this.fund(request, requiredQuantities, maxFee);
5028
4800
  return this.sendTransaction(request);
5029
4801
  }
5030
4802
  /**
@@ -5036,31 +4808,34 @@ var Account = class extends import_interfaces.AbstractAccount {
5036
4808
  * @returns A promise that resolves to the transaction response.
5037
4809
  */
5038
4810
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4811
+ const { minGasPrice } = this.provider.getGasConfig();
5039
4812
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5040
- const recipientDataArray = (0, import_utils27.arrayify)(
4813
+ const recipientDataArray = (0, import_utils28.arrayify)(
5041
4814
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5042
4815
  );
5043
- const amountDataArray = (0, import_utils27.arrayify)(
5044
- "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
4816
+ const amountDataArray = (0, import_utils28.arrayify)(
4817
+ "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5045
4818
  );
5046
4819
  const script = new Uint8Array([
5047
- ...(0, import_utils27.arrayify)(withdrawScript.bytes),
4820
+ ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5048
4821
  ...recipientDataArray,
5049
4822
  ...amountDataArray
5050
4823
  ]);
5051
- const params = { script, ...txParams };
4824
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5052
4825
  const request = new ScriptTransactionRequest(params);
5053
- const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5054
- const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5055
- if (txParams.gasLimit) {
5056
- this.validateGas({
5057
- gasUsed: txCost.gasUsed,
5058
- gasLimit: request.gasLimit
5059
- });
5060
- }
5061
- request.maxFee = txCost.maxFee;
5062
- request.gasLimit = txCost.gasUsed;
5063
- await this.fund(request, txCost);
4826
+ const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
4827
+ const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4828
+ request,
4829
+ forwardingQuantities
4830
+ );
4831
+ request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4832
+ this.validateGas({
4833
+ gasUsed,
4834
+ gasPrice: request.gasPrice,
4835
+ gasLimit: request.gasLimit,
4836
+ minGasPrice
4837
+ });
4838
+ await this.fund(request, requiredQuantities, maxFee);
5064
4839
  return this.sendTransaction(request);
5065
4840
  }
5066
4841
  async signMessage(message) {
@@ -5118,7 +4893,18 @@ var Account = class extends import_interfaces.AbstractAccount {
5118
4893
  }
5119
4894
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5120
4895
  }
5121
- validateGas({ gasUsed, gasLimit }) {
4896
+ validateGas({
4897
+ gasUsed,
4898
+ gasPrice,
4899
+ gasLimit,
4900
+ minGasPrice
4901
+ }) {
4902
+ if (minGasPrice.gt(gasPrice)) {
4903
+ throw new import_errors16.FuelError(
4904
+ import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
4905
+ `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
4906
+ );
4907
+ }
5122
4908
  if (gasUsed.gt(gasLimit)) {
5123
4909
  throw new import_errors16.FuelError(
5124
4910
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -5132,8 +4918,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5132
4918
  var import_address5 = require("@fuel-ts/address");
5133
4919
  var import_crypto = require("@fuel-ts/crypto");
5134
4920
  var import_hasher2 = require("@fuel-ts/hasher");
5135
- var import_math20 = require("@fuel-ts/math");
5136
- var import_utils28 = require("@fuel-ts/utils");
4921
+ var import_math19 = require("@fuel-ts/math");
4922
+ var import_utils29 = require("@fuel-ts/utils");
5137
4923
  var import_secp256k1 = require("@noble/curves/secp256k1");
5138
4924
  var Signer = class {
5139
4925
  address;
@@ -5152,10 +4938,10 @@ var Signer = class {
5152
4938
  privateKey = `0x${privateKey}`;
5153
4939
  }
5154
4940
  }
5155
- const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5156
- this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5157
- this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5158
- this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
4941
+ const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
4942
+ this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
4943
+ this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
4944
+ this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5159
4945
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5160
4946
  }
5161
4947
  /**
@@ -5169,11 +4955,11 @@ var Signer = class {
5169
4955
  * @returns hashed signature
5170
4956
  */
5171
4957
  sign(data) {
5172
- const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5173
- const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5174
- const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
4958
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
4959
+ const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
4960
+ const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5175
4961
  s[0] |= (signature.recovery || 0) << 7;
5176
- return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
4962
+ return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5177
4963
  }
5178
4964
  /**
5179
4965
  * Add point on the current elliptic curve
@@ -5182,8 +4968,8 @@ var Signer = class {
5182
4968
  * @returns compressed point on the curve
5183
4969
  */
5184
4970
  addPoint(point) {
5185
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5186
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
4971
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
4972
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5187
4973
  const result = p0.add(p1);
5188
4974
  return `0x${result.toHex(true)}`;
5189
4975
  }
@@ -5195,16 +4981,16 @@ var Signer = class {
5195
4981
  * @returns public key from signature from the
5196
4982
  */
5197
4983
  static recoverPublicKey(data, signature) {
5198
- const signedMessageBytes = (0, import_utils28.arrayify)(signature);
4984
+ const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5199
4985
  const r = signedMessageBytes.slice(0, 32);
5200
4986
  const s = signedMessageBytes.slice(32, 64);
5201
4987
  const recoveryParam = (s[0] & 128) >> 7;
5202
4988
  s[0] &= 127;
5203
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
4989
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5204
4990
  recoveryParam
5205
4991
  );
5206
- const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5207
- return (0, import_utils28.hexlify)(publicKey);
4992
+ const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
4993
+ return (0, import_utils29.hexlify)(publicKey);
5208
4994
  }
5209
4995
  /**
5210
4996
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5223,7 +5009,7 @@ var Signer = class {
5223
5009
  * @returns random 32-byte hashed
5224
5010
  */
5225
5011
  static generatePrivateKey(entropy) {
5226
- return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
5012
+ return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
5227
5013
  }
5228
5014
  /**
5229
5015
  * Extended publicKey from a compact publicKey
@@ -5232,8 +5018,8 @@ var Signer = class {
5232
5018
  * @returns extended publicKey
5233
5019
  */
5234
5020
  static extendPublicKey(publicKey) {
5235
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5236
- return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5021
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5022
+ return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5237
5023
  }
5238
5024
  };
5239
5025
 
@@ -5241,7 +5027,7 @@ var Signer = class {
5241
5027
  var import_address6 = require("@fuel-ts/address");
5242
5028
  var import_crypto2 = require("@fuel-ts/crypto");
5243
5029
  var import_errors17 = require("@fuel-ts/errors");
5244
- var import_utils29 = require("@fuel-ts/utils");
5030
+ var import_utils30 = require("@fuel-ts/utils");
5245
5031
  var import_uuid = require("uuid");
5246
5032
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5247
5033
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5324,7 +5110,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5324
5110
  );
5325
5111
  }
5326
5112
  const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5327
- const privateKey = (0, import_utils29.hexlify)(buffer);
5113
+ const privateKey = (0, import_utils30.hexlify)(buffer);
5328
5114
  return privateKey;
5329
5115
  }
5330
5116
 
@@ -5369,7 +5155,7 @@ var BaseWalletUnlocked = class extends Account {
5369
5155
  */
5370
5156
  async signMessage(message) {
5371
5157
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5372
- return (0, import_utils30.hexlify)(signedMessage);
5158
+ return (0, import_utils31.hexlify)(signedMessage);
5373
5159
  }
5374
5160
  /**
5375
5161
  * Signs a transaction with the wallet's private key.
@@ -5382,7 +5168,7 @@ var BaseWalletUnlocked = class extends Account {
5382
5168
  const chainId = this.provider.getChainId();
5383
5169
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5384
5170
  const signature = await this.signer().sign(hashedTransaction);
5385
- return (0, import_utils30.hexlify)(signature);
5171
+ return (0, import_utils31.hexlify)(signature);
5386
5172
  }
5387
5173
  /**
5388
5174
  * Populates a transaction with the witnesses signature.
@@ -5402,7 +5188,7 @@ var BaseWalletUnlocked = class extends Account {
5402
5188
  * @param transactionRequestLike - The transaction request to send.
5403
5189
  * @returns A promise that resolves to the TransactionResponse object.
5404
5190
  */
5405
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5191
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5406
5192
  const transactionRequest = transactionRequestify(transactionRequestLike);
5407
5193
  if (estimateTxDependencies) {
5408
5194
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5443,16 +5229,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5443
5229
  // src/hdwallet/hdwallet.ts
5444
5230
  var import_errors20 = require("@fuel-ts/errors");
5445
5231
  var import_hasher6 = require("@fuel-ts/hasher");
5446
- var import_math21 = require("@fuel-ts/math");
5447
- var import_utils34 = require("@fuel-ts/utils");
5448
- var import_ethers4 = require("ethers");
5232
+ var import_math20 = require("@fuel-ts/math");
5233
+ var import_utils35 = require("@fuel-ts/utils");
5234
+ var import_ethers3 = require("ethers");
5449
5235
 
5450
5236
  // src/mnemonic/mnemonic.ts
5451
5237
  var import_crypto3 = require("@fuel-ts/crypto");
5452
5238
  var import_errors19 = require("@fuel-ts/errors");
5453
5239
  var import_hasher5 = require("@fuel-ts/hasher");
5454
- var import_utils32 = require("@fuel-ts/utils");
5455
- var import_ethers3 = require("ethers");
5240
+ var import_utils33 = require("@fuel-ts/utils");
5241
+ var import_ethers2 = require("ethers");
5456
5242
 
5457
5243
  // src/wordlists/words/english.ts
5458
5244
  var english = [
@@ -7509,7 +7295,7 @@ var english = [
7509
7295
  // src/mnemonic/utils.ts
7510
7296
  var import_errors18 = require("@fuel-ts/errors");
7511
7297
  var import_hasher4 = require("@fuel-ts/hasher");
7512
- var import_utils31 = require("@fuel-ts/utils");
7298
+ var import_utils32 = require("@fuel-ts/utils");
7513
7299
  function toUtf8Bytes(stri) {
7514
7300
  const str = stri.normalize("NFKD");
7515
7301
  const result = [];
@@ -7576,14 +7362,14 @@ function entropyToMnemonicIndices(entropy) {
7576
7362
  }
7577
7363
  }
7578
7364
  const checksumBits = entropy.length / 4;
7579
- const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7365
+ const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7580
7366
  indices[indices.length - 1] <<= checksumBits;
7581
7367
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7582
7368
  return indices;
7583
7369
  }
7584
7370
  function mnemonicWordsToEntropy(words, wordlist) {
7585
7371
  const size = Math.ceil(11 * words.length / 8);
7586
- const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7372
+ const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7587
7373
  let offset = 0;
7588
7374
  for (let i = 0; i < words.length; i += 1) {
7589
7375
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7603,7 +7389,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7603
7389
  const entropyBits = 32 * words.length / 3;
7604
7390
  const checksumBits = words.length / 3;
7605
7391
  const checksumMask = getUpperMask(checksumBits);
7606
- const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7392
+ const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7607
7393
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7608
7394
  throw new import_errors18.FuelError(
7609
7395
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7678,7 +7464,7 @@ var Mnemonic = class {
7678
7464
  static mnemonicToEntropy(phrase, wordlist = english) {
7679
7465
  const words = getWords(phrase);
7680
7466
  assertMnemonic(words);
7681
- return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7467
+ return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7682
7468
  }
7683
7469
  /**
7684
7470
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7686,7 +7472,7 @@ var Mnemonic = class {
7686
7472
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7687
7473
  */
7688
7474
  static entropyToMnemonic(entropy, wordlist = english) {
7689
- const entropyBytes = (0, import_utils32.arrayify)(entropy);
7475
+ const entropyBytes = (0, import_utils33.arrayify)(entropy);
7690
7476
  assertWordList(wordlist);
7691
7477
  assertEntropy(entropyBytes);
7692
7478
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7700,7 +7486,7 @@ var Mnemonic = class {
7700
7486
  assertMnemonic(getWords(phrase));
7701
7487
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7702
7488
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7703
- return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7489
+ return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7704
7490
  }
7705
7491
  /**
7706
7492
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7755,14 +7541,14 @@ var Mnemonic = class {
7755
7541
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7756
7542
  */
7757
7543
  static masterKeysFromSeed(seed) {
7758
- const seedArray = (0, import_utils32.arrayify)(seed);
7544
+ const seedArray = (0, import_utils33.arrayify)(seed);
7759
7545
  if (seedArray.length < 16 || seedArray.length > 64) {
7760
7546
  throw new import_errors19.FuelError(
7761
7547
  import_errors19.ErrorCode.INVALID_SEED,
7762
7548
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7763
7549
  );
7764
7550
  }
7765
- return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
7551
+ return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7766
7552
  }
7767
7553
  /**
7768
7554
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7773,22 +7559,22 @@ var Mnemonic = class {
7773
7559
  */
7774
7560
  static seedToExtendedKey(seed, testnet = false) {
7775
7561
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7776
- const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7562
+ const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7777
7563
  const depth = "0x00";
7778
7564
  const fingerprint = "0x00000000";
7779
7565
  const index = "0x00000000";
7780
7566
  const chainCode = masterKey.slice(32);
7781
7567
  const privateKey = masterKey.slice(0, 32);
7782
- const extendedKey = (0, import_utils32.concat)([
7568
+ const extendedKey = (0, import_utils33.concat)([
7783
7569
  prefix,
7784
7570
  depth,
7785
7571
  fingerprint,
7786
7572
  index,
7787
7573
  chainCode,
7788
- (0, import_utils32.concat)(["0x00", privateKey])
7574
+ (0, import_utils33.concat)(["0x00", privateKey])
7789
7575
  ]);
7790
- const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7791
- return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7576
+ const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7577
+ return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
7792
7578
  }
7793
7579
  /**
7794
7580
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7803,7 +7589,7 @@ var Mnemonic = class {
7803
7589
  * @returns A randomly generated mnemonic
7804
7590
  */
7805
7591
  static generate(size = 32, extraEntropy = "") {
7806
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7592
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7807
7593
  return Mnemonic.entropyToMnemonic(entropy);
7808
7594
  }
7809
7595
  };
@@ -7811,12 +7597,12 @@ var mnemonic_default = Mnemonic;
7811
7597
 
7812
7598
  // src/hdwallet/hdwallet.ts
7813
7599
  var HARDENED_INDEX = 2147483648;
7814
- var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
7815
- var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7816
- var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7817
- var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7600
+ var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
7601
+ var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
7602
+ var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
7603
+ var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
7818
7604
  function base58check(data) {
7819
- return (0, import_ethers4.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7605
+ return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7820
7606
  }
7821
7607
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7822
7608
  if (isPublic) {
@@ -7825,11 +7611,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7825
7611
  return testnet ? TestnetPRV2 : MainnetPRV2;
7826
7612
  }
7827
7613
  function isPublicExtendedKey(extendedKey) {
7828
- return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
7614
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
7829
7615
  }
7830
7616
  function isValidExtendedKey(extendedKey) {
7831
7617
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
7832
- (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
7618
+ (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
7833
7619
  );
7834
7620
  }
7835
7621
  function parsePath(path2, depth = 0) {
@@ -7847,8 +7633,8 @@ function parsePath(path2, depth = 0) {
7847
7633
  var HDWallet = class {
7848
7634
  depth = 0;
7849
7635
  index = 0;
7850
- fingerprint = (0, import_utils34.hexlify)("0x00000000");
7851
- parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
7636
+ fingerprint = (0, import_utils35.hexlify)("0x00000000");
7637
+ parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
7852
7638
  privateKey;
7853
7639
  publicKey;
7854
7640
  chainCode;
@@ -7860,8 +7646,8 @@ var HDWallet = class {
7860
7646
  constructor(config) {
7861
7647
  if (config.privateKey) {
7862
7648
  const signer = new Signer(config.privateKey);
7863
- this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
7864
- this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
7649
+ this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
7650
+ this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
7865
7651
  } else {
7866
7652
  if (!config.publicKey) {
7867
7653
  throw new import_errors20.FuelError(
@@ -7869,10 +7655,10 @@ var HDWallet = class {
7869
7655
  "Both public and private Key cannot be missing. At least one should be provided."
7870
7656
  );
7871
7657
  }
7872
- this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7658
+ this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
7873
7659
  }
7874
7660
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7875
- this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7661
+ this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7876
7662
  this.depth = config.depth || this.depth;
7877
7663
  this.index = config.index || this.index;
7878
7664
  this.chainCode = config.chainCode;
@@ -7888,9 +7674,9 @@ var HDWallet = class {
7888
7674
  * @returns A new instance of HDWallet on the derived index
7889
7675
  */
7890
7676
  deriveIndex(index) {
7891
- const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
7892
- const publicKey = (0, import_utils34.arrayify)(this.publicKey);
7893
- const chainCode = (0, import_utils34.arrayify)(this.chainCode);
7677
+ const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
7678
+ const publicKey = (0, import_utils35.arrayify)(this.publicKey);
7679
+ const chainCode = (0, import_utils35.arrayify)(this.chainCode);
7894
7680
  const data = new Uint8Array(37);
7895
7681
  if (index & HARDENED_INDEX) {
7896
7682
  if (!privateKey) {
@@ -7901,15 +7687,15 @@ var HDWallet = class {
7901
7687
  }
7902
7688
  data.set(privateKey, 1);
7903
7689
  } else {
7904
- data.set((0, import_utils34.arrayify)(this.publicKey));
7690
+ data.set((0, import_utils35.arrayify)(this.publicKey));
7905
7691
  }
7906
- data.set((0, import_math21.toBytes)(index, 4), 33);
7907
- const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
7692
+ data.set((0, import_math20.toBytes)(index, 4), 33);
7693
+ const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7908
7694
  const IL = bytes.slice(0, 32);
7909
7695
  const IR = bytes.slice(32);
7910
7696
  if (privateKey) {
7911
7697
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7912
- const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
7698
+ const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
7913
7699
  return new HDWallet({
7914
7700
  privateKey: ki,
7915
7701
  chainCode: IR,
@@ -7918,7 +7704,7 @@ var HDWallet = class {
7918
7704
  parentFingerprint: this.fingerprint
7919
7705
  });
7920
7706
  }
7921
- const signer = new Signer((0, import_utils34.hexlify)(IL));
7707
+ const signer = new Signer((0, import_utils35.hexlify)(IL));
7922
7708
  const Ki = signer.addPoint(publicKey);
7923
7709
  return new HDWallet({
7924
7710
  publicKey: Ki,
@@ -7953,12 +7739,12 @@ var HDWallet = class {
7953
7739
  );
7954
7740
  }
7955
7741
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
7956
- const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
7742
+ const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
7957
7743
  const parentFingerprint = this.parentFingerprint;
7958
- const index = (0, import_math21.toHex)(this.index, 4);
7744
+ const index = (0, import_math20.toHex)(this.index, 4);
7959
7745
  const chainCode = this.chainCode;
7960
- const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
7961
- const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7746
+ const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
7747
+ const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7962
7748
  return base58check(extendedKey);
7963
7749
  }
7964
7750
  /**
@@ -7970,13 +7756,13 @@ var HDWallet = class {
7970
7756
  static fromSeed(seed) {
7971
7757
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
7972
7758
  return new HDWallet({
7973
- chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
7974
- privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
7759
+ chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
7760
+ privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
7975
7761
  });
7976
7762
  }
7977
7763
  static fromExtendedKey(extendedKey) {
7978
- const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
7979
- const bytes = (0, import_utils34.arrayify)(decoded);
7764
+ const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7765
+ const bytes = (0, import_utils35.arrayify)(decoded);
7980
7766
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7981
7767
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7982
7768
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -7985,9 +7771,9 @@ var HDWallet = class {
7985
7771
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7986
7772
  }
7987
7773
  const depth = bytes[4];
7988
- const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
7989
- const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7990
- const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
7774
+ const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
7775
+ const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7776
+ const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
7991
7777
  const key = bytes.slice(45, 78);
7992
7778
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7993
7779
  throw new import_errors20.FuelError(
@@ -8180,15 +7966,14 @@ var seedTestWallet = async (wallet, quantities) => {
8180
7966
  process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
8181
7967
  wallet.provider
8182
7968
  );
8183
- const request = new ScriptTransactionRequest();
8184
- quantities.forEach((quantity) => {
8185
- const { amount, assetId } = coinQuantityfy(quantity);
8186
- request.addCoinOutput(wallet.address, amount, assetId);
7969
+ const resources = await genesisWallet.getResourcesToSpend(quantities);
7970
+ const { minGasPrice } = genesisWallet.provider.getGasConfig();
7971
+ const request = new ScriptTransactionRequest({
7972
+ gasLimit: 1e4,
7973
+ gasPrice: minGasPrice
8187
7974
  });
8188
- const txCost = await genesisWallet.provider.getTransactionCost(request);
8189
- request.gasLimit = txCost.gasUsed;
8190
- request.maxFee = txCost.maxFee;
8191
- await genesisWallet.fund(request, txCost);
7975
+ request.addResources(resources);
7976
+ quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
8192
7977
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
8193
7978
  };
8194
7979
 
@@ -8203,8 +7988,8 @@ var generateTestWallet = async (provider, quantities) => {
8203
7988
 
8204
7989
  // src/test-utils/launchNode.ts
8205
7990
  var import_configs13 = require("@fuel-ts/address/configs");
8206
- var import_math22 = require("@fuel-ts/math");
8207
- var import_utils35 = require("@fuel-ts/utils");
7991
+ var import_math21 = require("@fuel-ts/math");
7992
+ var import_utils36 = require("@fuel-ts/utils");
8208
7993
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8209
7994
  var import_child_process = require("child_process");
8210
7995
  var import_crypto5 = require("crypto");
@@ -8262,7 +8047,7 @@ var launchNode = async ({
8262
8047
  "--poa-instant"
8263
8048
  ]);
8264
8049
  const chainConfigPath = getFlagValueFromArgs(args, "--chain");
8265
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
8050
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8266
8051
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8267
8052
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8268
8053
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
@@ -8288,20 +8073,20 @@ var launchNode = async ({
8288
8073
  (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8289
8074
  }
8290
8075
  const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
8291
- let chainConfig = import_utils35.defaultChainConfig;
8076
+ let chainConfig = import_utils36.defaultChainConfig;
8292
8077
  if (!process.env.GENESIS_SECRET) {
8293
8078
  const pk = Signer.generatePrivateKey();
8294
8079
  const signer = new Signer(pk);
8295
- process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
8080
+ process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8296
8081
  chainConfig = {
8297
- ...import_utils35.defaultChainConfig,
8082
+ ...import_utils36.defaultChainConfig,
8298
8083
  initial_state: {
8299
- ...import_utils35.defaultChainConfig.initial_state,
8084
+ ...import_utils36.defaultChainConfig.initial_state,
8300
8085
  coins: [
8301
- ...import_utils35.defaultChainConfig.initial_state.coins,
8086
+ ...import_utils36.defaultChainConfig.initial_state.coins,
8302
8087
  {
8303
8088
  owner: signer.address.toHexString(),
8304
- amount: (0, import_math22.toHex)(1e9),
8089
+ amount: (0, import_math21.toHex)(1e9),
8305
8090
  asset_id: import_configs13.BaseAssetId
8306
8091
  }
8307
8092
  ]
@@ -8318,7 +8103,7 @@ var launchNode = async ({
8318
8103
  ["--ip", ipToUse],
8319
8104
  ["--port", portToUse],
8320
8105
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8321
- ["--min-gas-price", "1"],
8106
+ ["--min-gas-price", "0"],
8322
8107
  poaInstant ? ["--poa-instant", "true"] : [],
8323
8108
  ["--consensus-key", consensusKey],
8324
8109
  ["--chain", chainConfigPathToUse],
@@ -8380,7 +8165,7 @@ var launchNodeAndGetWallets = async ({
8380
8165
  walletCount = 10
8381
8166
  } = {}) => {
8382
8167
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8383
- const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8168
+ const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8384
8169
  const wallets = await generateWallets(walletCount, provider);
8385
8170
  const cleanup = () => {
8386
8171
  closeNode();