@fuel-ts/account 0.96.0 → 0.97.0

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.
Files changed (41) hide show
  1. package/dist/account.d.ts +6 -0
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/connectors/fuel.d.ts.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.global.js +639 -310
  7. package/dist/index.global.js.map +1 -1
  8. package/dist/index.js +661 -331
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +666 -338
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/predicate/predicate.d.ts +16 -11
  13. package/dist/predicate/predicate.d.ts.map +1 -1
  14. package/dist/providers/__generated__/operations.d.ts +108 -126
  15. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  16. package/dist/providers/provider.d.ts +15 -11
  17. package/dist/providers/provider.d.ts.map +1 -1
  18. package/dist/providers/transaction-request/blob-transaction-request.d.ts +2 -2
  19. package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -1
  20. package/dist/providers/transaction-summary/get-transaction-summary.d.ts +3 -2
  21. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  22. package/dist/providers/transaction-summary/types.d.ts +38 -8
  23. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  24. package/dist/providers/utils/handle-gql-error-message.d.ts +2 -1
  25. package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -1
  26. package/dist/providers/utils/receipts.d.ts.map +1 -1
  27. package/dist/providers/utils/validate-pagination-args.d.ts +9 -0
  28. package/dist/providers/utils/validate-pagination-args.d.ts.map +1 -0
  29. package/dist/test-utils.global.js +376 -248
  30. package/dist/test-utils.global.js.map +1 -1
  31. package/dist/test-utils.js +339 -221
  32. package/dist/test-utils.js.map +1 -1
  33. package/dist/test-utils.mjs +350 -232
  34. package/dist/test-utils.mjs.map +1 -1
  35. package/dist/utils/deployScriptOrPredicate.d.ts +14 -0
  36. package/dist/utils/deployScriptOrPredicate.d.ts.map +1 -0
  37. package/dist/utils/formatTransferToContractScriptData.d.ts +7 -7
  38. package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
  39. package/dist/utils/predicate-script-loader-instructions.d.ts +9 -0
  40. package/dist/utils/predicate-script-loader-instructions.d.ts.map +1 -0
  41. package/package.json +17 -17
@@ -408,7 +408,7 @@ var addAmountToCoinQuantities = (params) => {
408
408
 
409
409
  // src/providers/provider.ts
410
410
  var import_address4 = require("@fuel-ts/address");
411
- var import_errors18 = require("@fuel-ts/errors");
411
+ var import_errors19 = require("@fuel-ts/errors");
412
412
  var import_math19 = require("@fuel-ts/math");
413
413
  var import_transactions22 = require("@fuel-ts/transactions");
414
414
  var import_utils30 = require("@fuel-ts/utils");
@@ -461,9 +461,6 @@ var ReceiptFragmentDoc = import_graphql_tag.default`
461
461
  var SuccessStatusFragmentDoc = import_graphql_tag.default`
462
462
  fragment SuccessStatusFragment on SuccessStatus {
463
463
  type: __typename
464
- block {
465
- id
466
- }
467
464
  time
468
465
  programState {
469
466
  returnType
@@ -476,6 +473,14 @@ var SuccessStatusFragmentDoc = import_graphql_tag.default`
476
473
  totalFee
477
474
  }
478
475
  ${ReceiptFragmentDoc}`;
476
+ var SuccessStatusWithBlockIdFragmentDoc = import_graphql_tag.default`
477
+ fragment SuccessStatusWithBlockIdFragment on SuccessStatus {
478
+ ...SuccessStatusFragment
479
+ block {
480
+ id
481
+ }
482
+ }
483
+ ${SuccessStatusFragmentDoc}`;
479
484
  var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
480
485
  fragment malleableTransactionFieldsFragment on Transaction {
481
486
  receiptsRoot
@@ -520,9 +525,6 @@ var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
520
525
  var FailureStatusFragmentDoc = import_graphql_tag.default`
521
526
  fragment FailureStatusFragment on FailureStatus {
522
527
  type: __typename
523
- block {
524
- id
525
- }
526
528
  totalGas
527
529
  totalFee
528
530
  time
@@ -532,6 +534,14 @@ var FailureStatusFragmentDoc = import_graphql_tag.default`
532
534
  }
533
535
  }
534
536
  ${ReceiptFragmentDoc}`;
537
+ var FailureStatusWithBlockIdFragmentDoc = import_graphql_tag.default`
538
+ fragment FailureStatusWithBlockIdFragment on FailureStatus {
539
+ ...FailureStatusFragment
540
+ block {
541
+ id
542
+ }
543
+ }
544
+ ${FailureStatusFragmentDoc}`;
535
545
  var SqueezedOutStatusFragmentDoc = import_graphql_tag.default`
536
546
  fragment SqueezedOutStatusFragment on SqueezedOutStatus {
537
547
  type: __typename
@@ -544,13 +554,13 @@ var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
544
554
  ...SubmittedStatusFragment
545
555
  }
546
556
  ... on SuccessStatus {
547
- ...SuccessStatusFragment
557
+ ...SuccessStatusWithBlockIdFragment
548
558
  transaction {
549
559
  ...malleableTransactionFieldsFragment
550
560
  }
551
561
  }
552
562
  ... on FailureStatus {
553
- ...FailureStatusFragment
563
+ ...FailureStatusWithBlockIdFragment
554
564
  transaction {
555
565
  ...malleableTransactionFieldsFragment
556
566
  }
@@ -560,9 +570,9 @@ var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
560
570
  }
561
571
  }
562
572
  ${SubmittedStatusFragmentDoc}
563
- ${SuccessStatusFragmentDoc}
573
+ ${SuccessStatusWithBlockIdFragmentDoc}
564
574
  ${MalleableTransactionFieldsFragmentDoc}
565
- ${FailureStatusFragmentDoc}
575
+ ${FailureStatusWithBlockIdFragmentDoc}
566
576
  ${SqueezedOutStatusFragmentDoc}`;
567
577
  var TransactionStatusFragmentDoc = import_graphql_tag.default`
568
578
  fragment transactionStatusFragment on TransactionStatus {
@@ -592,6 +602,12 @@ var TransactionFragmentDoc = import_graphql_tag.default`
592
602
  }
593
603
  }
594
604
  ${TransactionStatusFragmentDoc}`;
605
+ var TransactionRawPayloadFragmentDoc = import_graphql_tag.default`
606
+ fragment transactionRawPayloadFragment on Transaction {
607
+ id
608
+ rawPayload
609
+ }
610
+ `;
595
611
  var InputEstimatePredicatesFragmentDoc = import_graphql_tag.default`
596
612
  fragment inputEstimatePredicatesFragment on Input {
597
613
  ... on InputCoin {
@@ -679,7 +695,6 @@ var CoinFragmentDoc = import_graphql_tag.default`
679
695
  fragment coinFragment on Coin {
680
696
  type: __typename
681
697
  utxoId
682
- owner
683
698
  amount
684
699
  assetId
685
700
  blockCreated
@@ -703,10 +718,15 @@ var MessageFragmentDoc = import_graphql_tag.default`
703
718
  sender
704
719
  recipient
705
720
  data
706
- nonce
707
721
  daHeight
708
722
  }
709
723
  `;
724
+ var GetMessageFragmentDoc = import_graphql_tag.default`
725
+ fragment getMessageFragment on Message {
726
+ ...messageFragment
727
+ nonce
728
+ }
729
+ ${MessageFragmentDoc}`;
710
730
  var MessageProofFragmentDoc = import_graphql_tag.default`
711
731
  fragment messageProofFragment on MessageProof {
712
732
  messageProof {
@@ -751,7 +771,6 @@ var MessageProofFragmentDoc = import_graphql_tag.default`
751
771
  }
752
772
  sender
753
773
  recipient
754
- nonce
755
774
  amount
756
775
  data
757
776
  }
@@ -900,12 +919,6 @@ var RelayedTransactionStatusFragmentDoc = import_graphql_tag.default`
900
919
  }
901
920
  }
902
921
  `;
903
- var TransactionRawPayloadFragmentDoc = import_graphql_tag.default`
904
- fragment transactionRawPayload on Transaction {
905
- id
906
- rawPayload
907
- }
908
- `;
909
922
  var GetVersionDocument = import_graphql_tag.default`
910
923
  query getVersion {
911
924
  nodeInfo {
@@ -948,16 +961,34 @@ var GetTransactionDocument = import_graphql_tag.default`
948
961
  var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
949
962
  query getTransactionWithReceipts($transactionId: TransactionId!) {
950
963
  transaction(id: $transactionId) {
951
- ...transactionFragment
964
+ id
965
+ rawPayload
966
+ status {
967
+ ... on SubmittedStatus {
968
+ ...SubmittedStatusFragment
969
+ }
970
+ ... on SuccessStatus {
971
+ ...SuccessStatusWithBlockIdFragment
972
+ }
973
+ ... on FailureStatus {
974
+ ...FailureStatusWithBlockIdFragment
975
+ }
976
+ ... on SqueezedOutStatus {
977
+ ...SqueezedOutStatusFragment
978
+ }
979
+ }
952
980
  }
953
981
  }
954
- ${TransactionFragmentDoc}`;
982
+ ${SubmittedStatusFragmentDoc}
983
+ ${SuccessStatusWithBlockIdFragmentDoc}
984
+ ${FailureStatusWithBlockIdFragmentDoc}
985
+ ${SqueezedOutStatusFragmentDoc}`;
955
986
  var GetTransactionsDocument = import_graphql_tag.default`
956
987
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
957
988
  transactions(after: $after, before: $before, first: $first, last: $last) {
958
989
  edges {
959
990
  node {
960
- ...transactionFragment
991
+ rawPayload
961
992
  }
962
993
  }
963
994
  pageInfo {
@@ -965,8 +996,7 @@ var GetTransactionsDocument = import_graphql_tag.default`
965
996
  }
966
997
  }
967
998
  }
968
- ${TransactionFragmentDoc}
969
- ${PageInfoFragmentDoc}`;
999
+ ${PageInfoFragmentDoc}`;
970
1000
  var GetTransactionsByOwnerDocument = import_graphql_tag.default`
971
1001
  query getTransactionsByOwner($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
972
1002
  transactionsByOwner(
@@ -1025,7 +1055,7 @@ var GetBlockWithTransactionsDocument = import_graphql_tag.default`
1025
1055
  block(id: $blockId, height: $blockHeight) {
1026
1056
  ...blockFragment
1027
1057
  transactions {
1028
- ...transactionRawPayload
1058
+ ...transactionRawPayloadFragment
1029
1059
  }
1030
1060
  }
1031
1061
  }
@@ -1050,6 +1080,7 @@ var GetCoinDocument = import_graphql_tag.default`
1050
1080
  query getCoin($coinId: UtxoId!) {
1051
1081
  coin(utxoId: $coinId) {
1052
1082
  ...coinFragment
1083
+ owner
1053
1084
  }
1054
1085
  }
1055
1086
  ${CoinFragmentDoc}`;
@@ -1158,13 +1189,13 @@ var GetMessagesDocument = import_graphql_tag.default`
1158
1189
  }
1159
1190
  edges {
1160
1191
  node {
1161
- ...messageFragment
1192
+ ...getMessageFragment
1162
1193
  }
1163
1194
  }
1164
1195
  }
1165
1196
  }
1166
1197
  ${PageInfoFragmentDoc}
1167
- ${MessageFragmentDoc}`;
1198
+ ${GetMessageFragmentDoc}`;
1168
1199
  var GetMessageProofDocument = import_graphql_tag.default`
1169
1200
  query getMessageProof($transactionId: TransactionId!, $nonce: Nonce!, $commitBlockId: BlockId, $commitBlockHeight: U32) {
1170
1201
  messageProof(
@@ -1237,6 +1268,17 @@ var IsUserAccountDocument = import_graphql_tag.default`
1237
1268
  }
1238
1269
  }
1239
1270
  `;
1271
+ var GetConsensusParametersVersionDocument = import_graphql_tag.default`
1272
+ query getConsensusParametersVersion {
1273
+ chain {
1274
+ latestBlock {
1275
+ header {
1276
+ consensusParametersVersion
1277
+ }
1278
+ }
1279
+ }
1280
+ }
1281
+ `;
1240
1282
  var SubmitAndAwaitDocument = import_graphql_tag.default`
1241
1283
  subscription submitAndAwait($encodedTransaction: HexString!) {
1242
1284
  submitAndAwait(tx: $encodedTransaction) {
@@ -1356,6 +1398,9 @@ function getSdk(requester) {
1356
1398
  isUserAccount(variables, options) {
1357
1399
  return requester(IsUserAccountDocument, variables, options);
1358
1400
  },
1401
+ getConsensusParametersVersion(variables, options) {
1402
+ return requester(GetConsensusParametersVersionDocument, variables, options);
1403
+ },
1359
1404
  submitAndAwait(variables, options) {
1360
1405
  return requester(SubmitAndAwaitDocument, variables, options);
1361
1406
  },
@@ -1682,9 +1727,11 @@ function assembleReceiptByType(receipt) {
1682
1727
  const { receiptType } = receipt;
1683
1728
  switch (receiptType) {
1684
1729
  case "CALL" /* Call */: {
1730
+ const id = hexOrZero(receipt.id || receipt.contractId);
1685
1731
  const callReceipt = {
1686
1732
  type: import_transactions3.ReceiptType.Call,
1687
- from: hexOrZero(receipt.id || receipt.contractId),
1733
+ id,
1734
+ from: id,
1688
1735
  to: hexOrZero(receipt?.to),
1689
1736
  amount: (0, import_math5.bn)(receipt.amount),
1690
1737
  assetId: hexOrZero(receipt.assetId),
@@ -1741,24 +1788,36 @@ function assembleReceiptByType(receipt) {
1741
1788
  return revertReceipt;
1742
1789
  }
1743
1790
  case "LOG" /* Log */: {
1791
+ const ra = (0, import_math5.bn)(receipt.ra);
1792
+ const rb = (0, import_math5.bn)(receipt.rb);
1793
+ const rc = (0, import_math5.bn)(receipt.rc);
1794
+ const rd = (0, import_math5.bn)(receipt.rd);
1744
1795
  const logReceipt = {
1745
1796
  type: import_transactions3.ReceiptType.Log,
1746
1797
  id: hexOrZero(receipt.id || receipt.contractId),
1747
- val0: (0, import_math5.bn)(receipt.ra),
1748
- val1: (0, import_math5.bn)(receipt.rb),
1749
- val2: (0, import_math5.bn)(receipt.rc),
1750
- val3: (0, import_math5.bn)(receipt.rd),
1798
+ ra,
1799
+ rb,
1800
+ rc,
1801
+ rd,
1802
+ val0: ra,
1803
+ val1: rb,
1804
+ val2: rc,
1805
+ val3: rd,
1751
1806
  pc: (0, import_math5.bn)(receipt.pc),
1752
1807
  is: (0, import_math5.bn)(receipt.is)
1753
1808
  };
1754
1809
  return logReceipt;
1755
1810
  }
1756
1811
  case "LOG_DATA" /* LogData */: {
1812
+ const ra = (0, import_math5.bn)(receipt.ra);
1813
+ const rb = (0, import_math5.bn)(receipt.rb);
1757
1814
  const logDataReceipt = {
1758
1815
  type: import_transactions3.ReceiptType.LogData,
1759
1816
  id: hexOrZero(receipt.id || receipt.contractId),
1760
- val0: (0, import_math5.bn)(receipt.ra),
1761
- val1: (0, import_math5.bn)(receipt.rb),
1817
+ ra,
1818
+ rb,
1819
+ val0: ra,
1820
+ val1: rb,
1762
1821
  ptr: (0, import_math5.bn)(receipt.ptr),
1763
1822
  len: (0, import_math5.bn)(receipt.len),
1764
1823
  digest: hexOrZero(receipt.digest),
@@ -1769,9 +1828,11 @@ function assembleReceiptByType(receipt) {
1769
1828
  return logDataReceipt;
1770
1829
  }
1771
1830
  case "TRANSFER" /* Transfer */: {
1831
+ const id = hexOrZero(receipt.id || receipt.contractId);
1772
1832
  const transferReceipt = {
1773
1833
  type: import_transactions3.ReceiptType.Transfer,
1774
- from: hexOrZero(receipt.id || receipt.contractId),
1834
+ id,
1835
+ from: id,
1775
1836
  to: hexOrZero(receipt.toAddress || receipt?.to),
1776
1837
  amount: (0, import_math5.bn)(receipt.amount),
1777
1838
  assetId: hexOrZero(receipt.assetId),
@@ -1781,9 +1842,11 @@ function assembleReceiptByType(receipt) {
1781
1842
  return transferReceipt;
1782
1843
  }
1783
1844
  case "TRANSFER_OUT" /* TransferOut */: {
1845
+ const id = hexOrZero(receipt.id || receipt.contractId);
1784
1846
  const transferOutReceipt = {
1785
1847
  type: import_transactions3.ReceiptType.TransferOut,
1786
- from: hexOrZero(receipt.id || receipt.contractId),
1848
+ id,
1849
+ from: id,
1787
1850
  to: hexOrZero(receipt.toAddress || receipt.to),
1788
1851
  amount: (0, import_math5.bn)(receipt.amount),
1789
1852
  assetId: hexOrZero(receipt.assetId),
@@ -2760,7 +2823,7 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
2760
2823
  type = import_transactions7.TransactionType.Blob;
2761
2824
  /** Blob ID */
2762
2825
  blobId;
2763
- /** Witness index of contract bytecode to create */
2826
+ /** Witness index of the bytecode to create */
2764
2827
  witnessIndex;
2765
2828
  /**
2766
2829
  * Creates an instance `BlobTransactionRequest`.
@@ -4091,14 +4154,14 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
4091
4154
  switch (gqlTransactionStatus.type) {
4092
4155
  case "SuccessStatus":
4093
4156
  time = gqlTransactionStatus.time;
4094
- blockId = gqlTransactionStatus.block.id;
4157
+ blockId = gqlTransactionStatus.block?.id;
4095
4158
  isStatusSuccess = true;
4096
4159
  totalFee = (0, import_math16.bn)(gqlTransactionStatus.totalFee);
4097
4160
  totalGas = (0, import_math16.bn)(gqlTransactionStatus.totalGas);
4098
4161
  break;
4099
4162
  case "FailureStatus":
4100
4163
  time = gqlTransactionStatus.time;
4101
- blockId = gqlTransactionStatus.block.id;
4164
+ blockId = gqlTransactionStatus.block?.id;
4102
4165
  isStatusFailure = true;
4103
4166
  totalFee = (0, import_math16.bn)(gqlTransactionStatus.totalFee);
4104
4167
  totalGas = (0, import_math16.bn)(gqlTransactionStatus.totalGas);
@@ -4533,17 +4596,60 @@ var handleGqlErrorMessage = (errorMessage, rawError) => {
4533
4596
  {},
4534
4597
  rawError
4535
4598
  );
4599
+ case "max number of coins is reached while trying to fit the target" /* MAX_COINS_REACHED */:
4600
+ throw new import_errors17.FuelError(
4601
+ import_errors17.ErrorCode.MAX_COINS_REACHED,
4602
+ "The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.",
4603
+ {},
4604
+ rawError
4605
+ );
4536
4606
  default:
4537
4607
  throw new import_errors17.FuelError(import_errors17.ErrorCode.INVALID_REQUEST, errorMessage);
4538
4608
  }
4539
4609
  };
4540
4610
 
4611
+ // src/providers/utils/validate-pagination-args.ts
4612
+ var import_errors18 = require("@fuel-ts/errors");
4613
+ var validatePaginationArgs = (params) => {
4614
+ const { paginationLimit, inputArgs = {} } = params;
4615
+ const { first, last, after, before } = inputArgs;
4616
+ if (after && before) {
4617
+ throw new import_errors18.FuelError(
4618
+ import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
4619
+ 'Pagination arguments "after" and "before" cannot be used together'
4620
+ );
4621
+ }
4622
+ if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
4623
+ throw new import_errors18.FuelError(
4624
+ import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
4625
+ `Pagination limit for this query cannot exceed ${paginationLimit} items`
4626
+ );
4627
+ }
4628
+ if (first && before) {
4629
+ throw new import_errors18.FuelError(
4630
+ import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
4631
+ 'The use of pagination argument "first" with "before" is not supported'
4632
+ );
4633
+ }
4634
+ if (last && after) {
4635
+ throw new import_errors18.FuelError(
4636
+ import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
4637
+ 'The use of pagination argument "last" with "after" is not supported'
4638
+ );
4639
+ }
4640
+ if (!first && !last) {
4641
+ inputArgs.first = paginationLimit;
4642
+ }
4643
+ return inputArgs;
4644
+ };
4645
+
4541
4646
  // src/providers/provider.ts
4542
4647
  var MAX_RETRIES = 10;
4543
4648
  var RESOURCES_PAGE_SIZE_LIMIT = 512;
4544
4649
  var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
4545
4650
  var BLOCKS_PAGE_SIZE_LIMIT = 5;
4546
4651
  var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
4652
+ var GAS_USED_MODIFIER = 1.2;
4547
4653
  var processGqlChain = (chain) => {
4548
4654
  const { name, daHeight, consensusParameters } = chain;
4549
4655
  const {
@@ -4619,6 +4725,8 @@ var _Provider = class {
4619
4725
  __publicField(this, "url");
4620
4726
  /** @hidden */
4621
4727
  __publicField(this, "urlWithoutAuth");
4728
+ /** @hidden */
4729
+ __publicField(this, "consensusParametersTimestamp");
4622
4730
  __publicField(this, "options", {
4623
4731
  timeout: void 0,
4624
4732
  resourceCacheTTL: void 0,
@@ -4679,7 +4787,7 @@ var _Provider = class {
4679
4787
  try {
4680
4788
  parsedUrl = new URL(url);
4681
4789
  } catch (error) {
4682
- throw new import_errors18.FuelError(import_errors18.FuelError.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
4790
+ throw new import_errors19.FuelError(import_errors19.FuelError.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
4683
4791
  }
4684
4792
  const username = parsedUrl.username;
4685
4793
  const password = parsedUrl.password;
@@ -4714,8 +4822,8 @@ var _Provider = class {
4714
4822
  getChain() {
4715
4823
  const chain = _Provider.chainInfoCache[this.urlWithoutAuth];
4716
4824
  if (!chain) {
4717
- throw new import_errors18.FuelError(
4718
- import_errors18.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
4825
+ throw new import_errors19.FuelError(
4826
+ import_errors19.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
4719
4827
  "Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
4720
4828
  );
4721
4829
  }
@@ -4729,8 +4837,8 @@ var _Provider = class {
4729
4837
  getNode() {
4730
4838
  const node = _Provider.nodeInfoCache[this.urlWithoutAuth];
4731
4839
  if (!node) {
4732
- throw new import_errors18.FuelError(
4733
- import_errors18.ErrorCode.NODE_INFO_CACHE_EMPTY,
4840
+ throw new import_errors19.FuelError(
4841
+ import_errors19.ErrorCode.NODE_INFO_CACHE_EMPTY,
4734
4842
  "Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
4735
4843
  );
4736
4844
  }
@@ -4771,16 +4879,19 @@ var _Provider = class {
4771
4879
  }
4772
4880
  /**
4773
4881
  * Return the chain and node information.
4774
- *
4882
+ * @param ignoreCache - If true, ignores the cache and re-fetch configs.
4775
4883
  * @returns A promise that resolves to the Chain and NodeInfo.
4776
4884
  */
4777
- async fetchChainAndNodeInfo() {
4885
+ async fetchChainAndNodeInfo(ignoreCache = false) {
4778
4886
  let nodeInfo;
4779
4887
  let chain;
4780
4888
  try {
4889
+ if (ignoreCache) {
4890
+ throw new Error(`Jumps to the catch block andre-fetch`);
4891
+ }
4781
4892
  nodeInfo = this.getNode();
4782
4893
  chain = this.getChain();
4783
- } catch (error) {
4894
+ } catch (_err) {
4784
4895
  const data = await this.operations.getChainAndNodeInfo();
4785
4896
  nodeInfo = {
4786
4897
  maxDepth: (0, import_math19.bn)(data.nodeInfo.maxDepth),
@@ -4793,6 +4904,7 @@ var _Provider = class {
4793
4904
  chain = processGqlChain(data.chain);
4794
4905
  _Provider.chainInfoCache[this.urlWithoutAuth] = chain;
4795
4906
  _Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
4907
+ this.consensusParametersTimestamp = Date.now();
4796
4908
  }
4797
4909
  return {
4798
4910
  chain,
@@ -4942,18 +5054,25 @@ Supported fuel-core version: ${supportedVersion}.`
4942
5054
  } = this.getChain();
4943
5055
  return baseAssetId;
4944
5056
  }
4945
- validateTransaction(tx, consensusParameters) {
4946
- const { maxOutputs, maxInputs } = consensusParameters.txParameters;
5057
+ /**
5058
+ * @hidden
5059
+ */
5060
+ validateTransaction(tx) {
5061
+ const {
5062
+ consensusParameters: {
5063
+ txParameters: { maxInputs, maxOutputs }
5064
+ }
5065
+ } = this.getChain();
4947
5066
  if ((0, import_math19.bn)(tx.inputs.length).gt(maxInputs)) {
4948
- throw new import_errors18.FuelError(
4949
- import_errors18.ErrorCode.MAX_INPUTS_EXCEEDED,
4950
- "The transaction exceeds the maximum allowed number of inputs."
5067
+ throw new import_errors19.FuelError(
5068
+ import_errors19.ErrorCode.MAX_INPUTS_EXCEEDED,
5069
+ `The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
4951
5070
  );
4952
5071
  }
4953
5072
  if ((0, import_math19.bn)(tx.outputs.length).gt(maxOutputs)) {
4954
- throw new import_errors18.FuelError(
4955
- import_errors18.ErrorCode.MAX_OUTPUTS_EXCEEDED,
4956
- "The transaction exceeds the maximum allowed number of outputs."
5073
+ throw new import_errors19.FuelError(
5074
+ import_errors19.ErrorCode.MAX_OUTPUTS_EXCEEDED,
5075
+ `The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
4957
5076
  );
4958
5077
  }
4959
5078
  }
@@ -4972,8 +5091,7 @@ Supported fuel-core version: ${supportedVersion}.`
4972
5091
  if (estimateTxDependencies) {
4973
5092
  await this.estimateTxDependencies(transactionRequest);
4974
5093
  }
4975
- const { consensusParameters } = this.getChain();
4976
- this.validateTransaction(transactionRequest, consensusParameters);
5094
+ this.validateTransaction(transactionRequest);
4977
5095
  const encodedTransaction = (0, import_utils30.hexlify)(transactionRequest.toTransactionBytes());
4978
5096
  let abis;
4979
5097
  if (isTransactionTypeScript(transactionRequest)) {
@@ -5061,6 +5179,7 @@ Supported fuel-core version: ${supportedVersion}.`
5061
5179
  const missingContractIds = [];
5062
5180
  let outputVariables = 0;
5063
5181
  let dryRunStatus;
5182
+ this.validateTransaction(transactionRequest);
5064
5183
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
5065
5184
  const {
5066
5185
  dryRun: [{ receipts: rawReceipts, status }]
@@ -5183,6 +5302,27 @@ Supported fuel-core version: ${supportedVersion}.`
5183
5302
  });
5184
5303
  return results;
5185
5304
  }
5305
+ async autoRefetchConfigs() {
5306
+ const now = Date.now();
5307
+ const diff = now - (this.consensusParametersTimestamp ?? 0);
5308
+ if (diff < 6e4) {
5309
+ return;
5310
+ }
5311
+ const chainInfo = this.getChain();
5312
+ const {
5313
+ consensusParameters: { version: previous }
5314
+ } = chainInfo;
5315
+ const {
5316
+ chain: {
5317
+ latestBlock: {
5318
+ header: { consensusParametersVersion: current }
5319
+ }
5320
+ }
5321
+ } = await this.operations.getConsensusParametersVersion();
5322
+ if (previous !== current) {
5323
+ await this.fetchChainAndNodeInfo(true);
5324
+ }
5325
+ }
5186
5326
  /**
5187
5327
  * Estimates the transaction gas and fee based on the provided transaction request.
5188
5328
  * @param transactionRequest - The transaction request object.
@@ -5191,6 +5331,7 @@ Supported fuel-core version: ${supportedVersion}.`
5191
5331
  async estimateTxGasAndFee(params) {
5192
5332
  const { transactionRequest } = params;
5193
5333
  let { gasPrice } = params;
5334
+ await this.autoRefetchConfigs();
5194
5335
  const chainInfo = this.getChain();
5195
5336
  const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
5196
5337
  const minGas = transactionRequest.calculateMinGas(chainInfo);
@@ -5304,7 +5445,9 @@ Supported fuel-core version: ${supportedVersion}.`
5304
5445
  if (dryRunStatus && "reason" in dryRunStatus) {
5305
5446
  throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
5306
5447
  }
5307
- gasUsed = getGasUsedFromReceipts(receipts);
5448
+ const { maxGasPerTx } = this.getGasConfig();
5449
+ const pristineGasUsed = getGasUsedFromReceipts(receipts);
5450
+ gasUsed = (0, import_math19.bn)(pristineGasUsed.muln(GAS_USED_MODIFIER)).max(maxGasPerTx.sub(minGas));
5308
5451
  txRequestClone.gasLimit = gasUsed;
5309
5452
  ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
5310
5453
  transactionRequest: txRequestClone,
@@ -5341,7 +5484,7 @@ Supported fuel-core version: ${supportedVersion}.`
5341
5484
  const {
5342
5485
  coins: { edges, pageInfo }
5343
5486
  } = await this.operations.getCoins({
5344
- ...this.validatePaginationArgs({
5487
+ ...validatePaginationArgs({
5345
5488
  paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
5346
5489
  inputArgs: paginationArgs
5347
5490
  }),
@@ -5351,7 +5494,7 @@ Supported fuel-core version: ${supportedVersion}.`
5351
5494
  id: node.utxoId,
5352
5495
  assetId: node.assetId,
5353
5496
  amount: (0, import_math19.bn)(node.amount),
5354
- owner: import_address4.Address.fromAddressOrString(node.owner),
5497
+ owner: ownerAddress,
5355
5498
  blockCreated: (0, import_math19.bn)(node.blockCreated),
5356
5499
  txCreatedIdx: (0, import_math19.bn)(node.txCreatedIdx)
5357
5500
  }));
@@ -5405,7 +5548,7 @@ Supported fuel-core version: ${supportedVersion}.`
5405
5548
  id: coin.utxoId,
5406
5549
  amount: (0, import_math19.bn)(coin.amount),
5407
5550
  assetId: coin.assetId,
5408
- owner: import_address4.Address.fromAddressOrString(coin.owner),
5551
+ owner: ownerAddress,
5409
5552
  blockCreated: (0, import_math19.bn)(coin.blockCreated),
5410
5553
  txCreatedIdx: (0, import_math19.bn)(coin.txCreatedIdx)
5411
5554
  };
@@ -5480,7 +5623,7 @@ Supported fuel-core version: ${supportedVersion}.`
5480
5623
  const {
5481
5624
  blocks: { edges, pageInfo }
5482
5625
  } = await this.operations.getBlocks({
5483
- ...this.validatePaginationArgs({
5626
+ ...validatePaginationArgs({
5484
5627
  paginationLimit: BLOCKS_PAGE_SIZE_LIMIT,
5485
5628
  inputArgs: params
5486
5629
  })
@@ -5559,7 +5702,7 @@ Supported fuel-core version: ${supportedVersion}.`
5559
5702
  0
5560
5703
  )?.[0];
5561
5704
  } catch (error) {
5562
- if (error instanceof import_errors18.FuelError && error.code === import_errors18.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
5705
+ if (error instanceof import_errors19.FuelError && error.code === import_errors19.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
5563
5706
  console.warn("Unsupported transaction type encountered");
5564
5707
  return null;
5565
5708
  }
@@ -5575,7 +5718,7 @@ Supported fuel-core version: ${supportedVersion}.`
5575
5718
  const {
5576
5719
  transactions: { edges, pageInfo }
5577
5720
  } = await this.operations.getTransactions({
5578
- ...this.validatePaginationArgs({
5721
+ ...validatePaginationArgs({
5579
5722
  inputArgs: paginationArgs,
5580
5723
  paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
5581
5724
  })
@@ -5585,7 +5728,7 @@ Supported fuel-core version: ${supportedVersion}.`
5585
5728
  try {
5586
5729
  return coder.decode((0, import_utils30.arrayify)(rawPayload), 0)[0];
5587
5730
  } catch (error) {
5588
- if (error instanceof import_errors18.FuelError && error.code === import_errors18.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
5731
+ if (error instanceof import_errors19.FuelError && error.code === import_errors19.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
5589
5732
  console.warn("Unsupported transaction type encountered");
5590
5733
  return null;
5591
5734
  }
@@ -5670,7 +5813,7 @@ Supported fuel-core version: ${supportedVersion}.`
5670
5813
  const {
5671
5814
  messages: { edges, pageInfo }
5672
5815
  } = await this.operations.getMessages({
5673
- ...this.validatePaginationArgs({
5816
+ ...validatePaginationArgs({
5674
5817
  inputArgs: paginationArgs,
5675
5818
  paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
5676
5819
  }),
@@ -5711,8 +5854,8 @@ Supported fuel-core version: ${supportedVersion}.`
5711
5854
  nonce
5712
5855
  };
5713
5856
  if (commitBlockId && commitBlockHeight) {
5714
- throw new import_errors18.FuelError(
5715
- import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
5857
+ throw new import_errors19.FuelError(
5858
+ import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
5716
5859
  "commitBlockId and commitBlockHeight cannot be used together"
5717
5860
  );
5718
5861
  }
@@ -5894,13 +6037,13 @@ Supported fuel-core version: ${supportedVersion}.`
5894
6037
  messageId: import_transactions22.InputMessageCoder.getMessageId({
5895
6038
  sender: rawMessage.sender,
5896
6039
  recipient: rawMessage.recipient,
5897
- nonce: rawMessage.nonce,
6040
+ nonce,
5898
6041
  amount: (0, import_math19.bn)(rawMessage.amount),
5899
6042
  data: rawMessage.data
5900
6043
  }),
5901
6044
  sender: import_address4.Address.fromAddressOrString(rawMessage.sender),
5902
6045
  recipient: import_address4.Address.fromAddressOrString(rawMessage.recipient),
5903
- nonce: rawMessage.nonce,
6046
+ nonce,
5904
6047
  amount: (0, import_math19.bn)(rawMessage.amount),
5905
6048
  data: import_transactions22.InputMessageCoder.decodeData(rawMessage.data),
5906
6049
  daHeight: (0, import_math19.bn)(rawMessage.daHeight)
@@ -5922,41 +6065,6 @@ Supported fuel-core version: ${supportedVersion}.`
5922
6065
  }
5923
6066
  return relayedTransactionStatus;
5924
6067
  }
5925
- /**
5926
- * @hidden
5927
- */
5928
- validatePaginationArgs(params) {
5929
- const { paginationLimit, inputArgs = {} } = params;
5930
- const { first, last, after, before } = inputArgs;
5931
- if (after && before) {
5932
- throw new import_errors18.FuelError(
5933
- import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
5934
- 'Pagination arguments "after" and "before" cannot be used together'
5935
- );
5936
- }
5937
- if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
5938
- throw new import_errors18.FuelError(
5939
- import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
5940
- `Pagination limit for this query cannot exceed ${paginationLimit} items`
5941
- );
5942
- }
5943
- if (first && before) {
5944
- throw new import_errors18.FuelError(
5945
- import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
5946
- 'The use of pagination argument "first" with "before" is not supported'
5947
- );
5948
- }
5949
- if (last && after) {
5950
- throw new import_errors18.FuelError(
5951
- import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
5952
- 'The use of pagination argument "last" with "after" is not supported'
5953
- );
5954
- }
5955
- if (!first && !last) {
5956
- inputArgs.first = paginationLimit;
5957
- }
5958
- return inputArgs;
5959
- }
5960
6068
  /**
5961
6069
  * @hidden
5962
6070
  */
@@ -6002,7 +6110,7 @@ __publicField(Provider, "chainInfoCache", {});
6002
6110
  __publicField(Provider, "nodeInfoCache", {});
6003
6111
 
6004
6112
  // src/providers/transaction-summary/get-transaction-summary.ts
6005
- var import_errors19 = require("@fuel-ts/errors");
6113
+ var import_errors20 = require("@fuel-ts/errors");
6006
6114
  var import_math20 = require("@fuel-ts/math");
6007
6115
  var import_transactions23 = require("@fuel-ts/transactions");
6008
6116
  var import_utils33 = require("@fuel-ts/utils");
@@ -6636,7 +6744,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
6636
6744
 
6637
6745
  // src/test-utils/wallet-config.ts
6638
6746
  var import_crypto9 = require("@fuel-ts/crypto");
6639
- var import_errors25 = require("@fuel-ts/errors");
6747
+ var import_errors26 = require("@fuel-ts/errors");
6640
6748
  var import_utils44 = require("@fuel-ts/utils");
6641
6749
 
6642
6750
  // src/wallet/base-wallet-unlocked.ts
@@ -6645,9 +6753,9 @@ var import_utils39 = require("@fuel-ts/utils");
6645
6753
 
6646
6754
  // src/account.ts
6647
6755
  var import_abi_coder8 = require("@fuel-ts/abi-coder");
6648
- var import_address5 = require("@fuel-ts/address");
6756
+ var import_address6 = require("@fuel-ts/address");
6649
6757
  var import_crypto5 = require("@fuel-ts/crypto");
6650
- var import_errors20 = require("@fuel-ts/errors");
6758
+ var import_errors21 = require("@fuel-ts/errors");
6651
6759
  var import_interfaces = require("@fuel-ts/interfaces");
6652
6760
  var import_math22 = require("@fuel-ts/math");
6653
6761
  var import_transactions24 = require("@fuel-ts/transactions");
@@ -6670,37 +6778,46 @@ var mergeQuantities = (...coinQuantities) => {
6670
6778
 
6671
6779
  // src/utils/formatTransferToContractScriptData.ts
6672
6780
  var import_abi_coder7 = require("@fuel-ts/abi-coder");
6781
+ var import_address5 = require("@fuel-ts/address");
6673
6782
  var import_math21 = require("@fuel-ts/math");
6674
6783
  var import_utils36 = require("@fuel-ts/utils");
6675
6784
  var asm = __toESM(require("@fuels/vm-asm"));
6676
- var formatTransferToContractScriptData = (params) => {
6677
- const { assetId, amountToTransfer, hexlifiedContractId } = params;
6785
+ var formatTransferToContractScriptData = (transferParams) => {
6678
6786
  const numberCoder = new import_abi_coder7.BigNumberCoder("u64");
6679
- const encoded = numberCoder.encode(new import_math21.BN(amountToTransfer).toNumber());
6680
- const scriptData = Uint8Array.from([
6681
- ...(0, import_utils36.arrayify)(hexlifiedContractId),
6682
- ...encoded,
6683
- ...(0, import_utils36.arrayify)(assetId)
6684
- ]);
6685
- return scriptData;
6787
+ return transferParams.reduce((acc, transferParam) => {
6788
+ const { assetId, amount, contractId } = transferParam;
6789
+ const encoded = numberCoder.encode(new import_math21.BN(amount).toNumber());
6790
+ const scriptData = (0, import_utils36.concat)([
6791
+ import_address5.Address.fromAddressOrString(contractId).toBytes(),
6792
+ encoded,
6793
+ (0, import_utils36.arrayify)(assetId)
6794
+ ]);
6795
+ return (0, import_utils36.concat)([acc, scriptData]);
6796
+ }, new Uint8Array());
6686
6797
  };
6687
- var assembleTransferToContractScript = async (params) => {
6688
- const scriptData = formatTransferToContractScriptData(params);
6798
+ var assembleTransferToContractScript = async (transferParams) => {
6799
+ const scriptData = formatTransferToContractScriptData(transferParams);
6689
6800
  await asm.initWasm();
6690
- const gtf2 = asm.gtf(16, 0, asm.GTFArgs.ScriptData);
6691
- const addi2 = asm.addi(17, 16, 32);
6692
- const lw2 = asm.lw(18, 17, 0);
6693
- const addi22 = asm.addi(19, 17, 8);
6694
- const tr2 = asm.tr(16, 18, 19);
6695
- const ret2 = asm.ret(1);
6696
- const script = Uint8Array.from([
6697
- ...gtf2.to_bytes(),
6698
- ...addi2.to_bytes(),
6699
- ...lw2.to_bytes(),
6700
- ...addi22.to_bytes(),
6701
- ...tr2.to_bytes(),
6702
- ...ret2.to_bytes()
6703
- ]);
6801
+ let script = new Uint8Array();
6802
+ transferParams.forEach((_, i) => {
6803
+ const offset = (import_abi_coder7.CONTRACT_ID_LEN + import_abi_coder7.WORD_SIZE + import_abi_coder7.ASSET_ID_LEN) * i;
6804
+ script = (0, import_utils36.concat)([
6805
+ script,
6806
+ // Load ScriptData into register 0x10.
6807
+ asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
6808
+ // Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
6809
+ asm.addi(17, 16, offset).to_bytes(),
6810
+ // Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
6811
+ asm.addi(18, 17, import_abi_coder7.CONTRACT_ID_LEN).to_bytes(),
6812
+ // Load word to the amount at 0x12 into register 0x13.
6813
+ asm.lw(19, 18, 0).to_bytes(),
6814
+ // Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
6815
+ asm.addi(20, 18, import_abi_coder7.WORD_SIZE).to_bytes(),
6816
+ // Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
6817
+ asm.tr(17, 19, 20).to_bytes()
6818
+ ]);
6819
+ });
6820
+ script = (0, import_utils36.concat)([script, asm.ret(1).to_bytes()]);
6704
6821
  return { script, scriptData };
6705
6822
  };
6706
6823
 
@@ -6730,7 +6847,7 @@ var Account = class extends import_interfaces.AbstractAccount {
6730
6847
  super();
6731
6848
  this._provider = provider;
6732
6849
  this._connector = connector;
6733
- this.address = import_address5.Address.fromDynamicInput(address);
6850
+ this.address = import_address6.Address.fromDynamicInput(address);
6734
6851
  }
6735
6852
  /**
6736
6853
  * The provider used to interact with the network.
@@ -6741,7 +6858,7 @@ var Account = class extends import_interfaces.AbstractAccount {
6741
6858
  */
6742
6859
  get provider() {
6743
6860
  if (!this._provider) {
6744
- throw new import_errors20.FuelError(import_errors20.ErrorCode.MISSING_PROVIDER, "Provider not set");
6861
+ throw new import_errors21.FuelError(import_errors21.ErrorCode.MISSING_PROVIDER, "Provider not set");
6745
6862
  }
6746
6863
  return this._provider;
6747
6864
  }
@@ -6892,11 +7009,12 @@ var Account = class extends import_interfaces.AbstractAccount {
6892
7009
  fundingAttempts += 1;
6893
7010
  }
6894
7011
  if (needsToBeFunded) {
6895
- throw new import_errors20.FuelError(
6896
- import_errors20.ErrorCode.NOT_ENOUGH_FUNDS,
7012
+ throw new import_errors21.FuelError(
7013
+ import_errors21.ErrorCode.NOT_ENOUGH_FUNDS,
6897
7014
  `The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
6898
7015
  );
6899
7016
  }
7017
+ this.provider.validateTransaction(request);
6900
7018
  request.updatePredicateGasUsed(estimatedPredicates);
6901
7019
  const requestToReestimate = (0, import_ramda9.clone)(request);
6902
7020
  if (addedSignatures) {
@@ -6963,7 +7081,7 @@ var Account = class extends import_interfaces.AbstractAccount {
6963
7081
  const { destination, amount, assetId } = transferParams;
6964
7082
  this.validateTransferAmount(amount);
6965
7083
  request.addCoinOutput(
6966
- import_address5.Address.fromAddressOrString(destination),
7084
+ import_address6.Address.fromAddressOrString(destination),
6967
7085
  amount,
6968
7086
  assetId ?? this.provider.getBaseAssetId()
6969
7087
  );
@@ -6997,35 +7115,35 @@ var Account = class extends import_interfaces.AbstractAccount {
6997
7115
  * @returns A promise that resolves to the transaction response.
6998
7116
  */
6999
7117
  async transferToContract(contractId, amount, assetId, txParams = {}) {
7000
- if ((0, import_math22.bn)(amount).lte(0)) {
7001
- throw new import_errors20.FuelError(
7002
- import_errors20.ErrorCode.INVALID_TRANSFER_AMOUNT,
7003
- "Transfer amount must be a positive number."
7004
- );
7005
- }
7006
- const contractAddress = import_address5.Address.fromAddressOrString(contractId);
7007
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
7008
- const { script, scriptData } = await assembleTransferToContractScript({
7009
- hexlifiedContractId: contractAddress.toB256(),
7010
- amountToTransfer: (0, import_math22.bn)(amount),
7011
- assetId: assetIdToTransfer
7012
- });
7118
+ return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams);
7119
+ }
7120
+ async batchTransferToContracts(contractTransferParams, txParams = {}) {
7013
7121
  let request = new ScriptTransactionRequest({
7014
- ...txParams,
7015
- script,
7016
- scriptData
7017
- });
7018
- request.addContractInputAndOutput(contractAddress);
7019
- const txCost = await this.getTransactionCost(request, {
7020
- quantities: [{ amount: (0, import_math22.bn)(amount), assetId: String(assetIdToTransfer) }]
7122
+ ...txParams
7021
7123
  });
7022
- request = this.validateGasLimitAndMaxFee({
7023
- transactionRequest: request,
7024
- gasUsed: txCost.gasUsed,
7025
- maxFee: txCost.maxFee,
7026
- txParams
7124
+ const quantities = [];
7125
+ const transferParams = contractTransferParams.map((transferParam) => {
7126
+ const amount = (0, import_math22.bn)(transferParam.amount);
7127
+ const contractAddress = import_address6.Address.fromAddressOrString(transferParam.contractId);
7128
+ const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : this.provider.getBaseAssetId();
7129
+ if (amount.lte(0)) {
7130
+ throw new import_errors21.FuelError(
7131
+ import_errors21.ErrorCode.INVALID_TRANSFER_AMOUNT,
7132
+ "Transfer amount must be a positive number."
7133
+ );
7134
+ }
7135
+ request.addContractInputAndOutput(contractAddress);
7136
+ quantities.push({ amount, assetId });
7137
+ return {
7138
+ amount,
7139
+ contractId: contractAddress.toB256(),
7140
+ assetId
7141
+ };
7027
7142
  });
7028
- await this.fund(request, txCost);
7143
+ const { script, scriptData } = await assembleTransferToContractScript(transferParams);
7144
+ request.script = script;
7145
+ request.scriptData = scriptData;
7146
+ request = await this.estimateAndFundTransaction(request, txParams, { quantities });
7029
7147
  return this.sendTransaction(request);
7030
7148
  }
7031
7149
  /**
@@ -7037,7 +7155,7 @@ var Account = class extends import_interfaces.AbstractAccount {
7037
7155
  * @returns A promise that resolves to the transaction response.
7038
7156
  */
7039
7157
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
7040
- const recipientAddress = import_address5.Address.fromAddressOrString(recipient);
7158
+ const recipientAddress = import_address6.Address.fromAddressOrString(recipient);
7041
7159
  const recipientDataArray = (0, import_utils37.arrayify)(
7042
7160
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
7043
7161
  );
@@ -7125,7 +7243,7 @@ var Account = class extends import_interfaces.AbstractAccount {
7125
7243
  */
7126
7244
  async signMessage(message) {
7127
7245
  if (!this._connector) {
7128
- throw new import_errors20.FuelError(import_errors20.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
7246
+ throw new import_errors21.FuelError(import_errors21.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
7129
7247
  }
7130
7248
  return this._connector.signMessage(this.address.toString(), message);
7131
7249
  }
@@ -7137,8 +7255,8 @@ var Account = class extends import_interfaces.AbstractAccount {
7137
7255
  */
7138
7256
  async signTransaction(transactionRequestLike) {
7139
7257
  if (!this._connector) {
7140
- throw new import_errors20.FuelError(
7141
- import_errors20.ErrorCode.MISSING_CONNECTOR,
7258
+ throw new import_errors21.FuelError(
7259
+ import_errors21.ErrorCode.MISSING_CONNECTOR,
7142
7260
  "A connector is required to sign transactions."
7143
7261
  );
7144
7262
  }
@@ -7197,16 +7315,16 @@ var Account = class extends import_interfaces.AbstractAccount {
7197
7315
  /** @hidden * */
7198
7316
  validateTransferAmount(amount) {
7199
7317
  if ((0, import_math22.bn)(amount).lte(0)) {
7200
- throw new import_errors20.FuelError(
7201
- import_errors20.ErrorCode.INVALID_TRANSFER_AMOUNT,
7318
+ throw new import_errors21.FuelError(
7319
+ import_errors21.ErrorCode.INVALID_TRANSFER_AMOUNT,
7202
7320
  "Transfer amount must be a positive number."
7203
7321
  );
7204
7322
  }
7205
7323
  }
7206
7324
  /** @hidden * */
7207
- async estimateAndFundTransaction(transactionRequest, txParams) {
7325
+ async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
7208
7326
  let request = transactionRequest;
7209
- const txCost = await this.getTransactionCost(request);
7327
+ const txCost = await this.getTransactionCost(request, costParams);
7210
7328
  request = this.validateGasLimitAndMaxFee({
7211
7329
  transactionRequest: request,
7212
7330
  gasUsed: txCost.gasUsed,
@@ -7227,16 +7345,16 @@ var Account = class extends import_interfaces.AbstractAccount {
7227
7345
  if (!(0, import_utils37.isDefined)(setGasLimit)) {
7228
7346
  request.gasLimit = gasUsed;
7229
7347
  } else if (gasUsed.gt(setGasLimit)) {
7230
- throw new import_errors20.FuelError(
7231
- import_errors20.ErrorCode.GAS_LIMIT_TOO_LOW,
7348
+ throw new import_errors21.FuelError(
7349
+ import_errors21.ErrorCode.GAS_LIMIT_TOO_LOW,
7232
7350
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
7233
7351
  );
7234
7352
  }
7235
7353
  if (!(0, import_utils37.isDefined)(setMaxFee)) {
7236
7354
  request.maxFee = maxFee;
7237
7355
  } else if (maxFee.gt(setMaxFee)) {
7238
- throw new import_errors20.FuelError(
7239
- import_errors20.ErrorCode.MAX_FEE_TOO_LOW,
7356
+ throw new import_errors21.FuelError(
7357
+ import_errors21.ErrorCode.MAX_FEE_TOO_LOW,
7240
7358
  `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
7241
7359
  );
7242
7360
  }
@@ -7245,9 +7363,9 @@ var Account = class extends import_interfaces.AbstractAccount {
7245
7363
  };
7246
7364
 
7247
7365
  // src/wallet/keystore-wallet.ts
7248
- var import_address6 = require("@fuel-ts/address");
7366
+ var import_address7 = require("@fuel-ts/address");
7249
7367
  var import_crypto6 = require("@fuel-ts/crypto");
7250
- var import_errors21 = require("@fuel-ts/errors");
7368
+ var import_errors22 = require("@fuel-ts/errors");
7251
7369
  var import_utils38 = require("@fuel-ts/utils");
7252
7370
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
7253
7371
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -7262,7 +7380,7 @@ var removeHexPrefix = (hexString) => {
7262
7380
  };
7263
7381
  async function encryptKeystoreWallet(privateKey, address, password) {
7264
7382
  const privateKeyBuffer = (0, import_crypto6.bufferFromString)(removeHexPrefix(privateKey), "hex");
7265
- const ownerAddress = import_address6.Address.fromAddressOrString(address);
7383
+ const ownerAddress = import_address7.Address.fromAddressOrString(address);
7266
7384
  const salt = (0, import_crypto6.randomBytes)(DEFAULT_KEY_SIZE);
7267
7385
  const key = (0, import_crypto6.scrypt)({
7268
7386
  password: (0, import_crypto6.bufferFromString)(password),
@@ -7324,8 +7442,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
7324
7442
  const macHashUint8Array = (0, import_crypto6.keccak256)(data);
7325
7443
  const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
7326
7444
  if (mac !== macHash) {
7327
- throw new import_errors21.FuelError(
7328
- import_errors21.ErrorCode.INVALID_PASSWORD,
7445
+ throw new import_errors22.FuelError(
7446
+ import_errors22.ErrorCode.INVALID_PASSWORD,
7329
7447
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
7330
7448
  );
7331
7449
  }
@@ -7455,14 +7573,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
7455
7573
 
7456
7574
  // src/hdwallet/hdwallet.ts
7457
7575
  var import_crypto8 = require("@fuel-ts/crypto");
7458
- var import_errors24 = require("@fuel-ts/errors");
7576
+ var import_errors25 = require("@fuel-ts/errors");
7459
7577
  var import_hasher7 = require("@fuel-ts/hasher");
7460
7578
  var import_math23 = require("@fuel-ts/math");
7461
7579
  var import_utils43 = require("@fuel-ts/utils");
7462
7580
 
7463
7581
  // src/mnemonic/mnemonic.ts
7464
7582
  var import_crypto7 = require("@fuel-ts/crypto");
7465
- var import_errors23 = require("@fuel-ts/errors");
7583
+ var import_errors24 = require("@fuel-ts/errors");
7466
7584
  var import_hasher6 = require("@fuel-ts/hasher");
7467
7585
  var import_utils41 = require("@fuel-ts/utils");
7468
7586
 
@@ -9519,7 +9637,7 @@ var english = [
9519
9637
  ];
9520
9638
 
9521
9639
  // src/mnemonic/utils.ts
9522
- var import_errors22 = require("@fuel-ts/errors");
9640
+ var import_errors23 = require("@fuel-ts/errors");
9523
9641
  var import_hasher5 = require("@fuel-ts/hasher");
9524
9642
  var import_utils40 = require("@fuel-ts/utils");
9525
9643
  function getLowerMask(bits) {
@@ -9568,8 +9686,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
9568
9686
  for (let i = 0; i < words.length; i += 1) {
9569
9687
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
9570
9688
  if (index === -1) {
9571
- throw new import_errors22.FuelError(
9572
- import_errors22.ErrorCode.INVALID_MNEMONIC,
9689
+ throw new import_errors23.FuelError(
9690
+ import_errors23.ErrorCode.INVALID_MNEMONIC,
9573
9691
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
9574
9692
  );
9575
9693
  }
@@ -9585,8 +9703,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
9585
9703
  const checksumMask = getUpperMask(checksumBits);
9586
9704
  const checksum = (0, import_utils40.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
9587
9705
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
9588
- throw new import_errors22.FuelError(
9589
- import_errors22.ErrorCode.INVALID_CHECKSUM,
9706
+ throw new import_errors23.FuelError(
9707
+ import_errors23.ErrorCode.INVALID_CHECKSUM,
9590
9708
  "Checksum validation failed for the provided mnemonic."
9591
9709
  );
9592
9710
  }
@@ -9600,16 +9718,16 @@ var TestnetPRV = "0x04358394";
9600
9718
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
9601
9719
  function assertWordList(wordlist) {
9602
9720
  if (wordlist.length !== 2048) {
9603
- throw new import_errors23.FuelError(
9604
- import_errors23.ErrorCode.INVALID_WORD_LIST,
9721
+ throw new import_errors24.FuelError(
9722
+ import_errors24.ErrorCode.INVALID_WORD_LIST,
9605
9723
  `Expected word list length of 2048, but got ${wordlist.length}.`
9606
9724
  );
9607
9725
  }
9608
9726
  }
9609
9727
  function assertEntropy(entropy) {
9610
9728
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
9611
- throw new import_errors23.FuelError(
9612
- import_errors23.ErrorCode.INVALID_ENTROPY,
9729
+ throw new import_errors24.FuelError(
9730
+ import_errors24.ErrorCode.INVALID_ENTROPY,
9613
9731
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
9614
9732
  );
9615
9733
  }
@@ -9619,7 +9737,7 @@ function assertMnemonic(words) {
9619
9737
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
9620
9738
  ", "
9621
9739
  )}] words, but got ${words.length}.`;
9622
- throw new import_errors23.FuelError(import_errors23.ErrorCode.INVALID_MNEMONIC, errorMsg);
9740
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.INVALID_MNEMONIC, errorMsg);
9623
9741
  }
9624
9742
  }
9625
9743
  var Mnemonic = class {
@@ -9737,8 +9855,8 @@ var Mnemonic = class {
9737
9855
  static masterKeysFromSeed(seed) {
9738
9856
  const seedArray = (0, import_utils41.arrayify)(seed);
9739
9857
  if (seedArray.length < 16 || seedArray.length > 64) {
9740
- throw new import_errors23.FuelError(
9741
- import_errors23.ErrorCode.INVALID_SEED,
9858
+ throw new import_errors24.FuelError(
9859
+ import_errors24.ErrorCode.INVALID_SEED,
9742
9860
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
9743
9861
  );
9744
9862
  }
@@ -9815,7 +9933,7 @@ function isValidExtendedKey(extendedKey) {
9815
9933
  function parsePath(path2, depth = 0) {
9816
9934
  const components = path2.split("/");
9817
9935
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
9818
- throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
9936
+ throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
9819
9937
  }
9820
9938
  if (components[0] === "m") {
9821
9939
  components.shift();
@@ -9844,8 +9962,8 @@ var HDWallet = class {
9844
9962
  this.privateKey = (0, import_utils43.hexlify)(config.privateKey);
9845
9963
  } else {
9846
9964
  if (!config.publicKey) {
9847
- throw new import_errors24.FuelError(
9848
- import_errors24.ErrorCode.HD_WALLET_ERROR,
9965
+ throw new import_errors25.FuelError(
9966
+ import_errors25.ErrorCode.HD_WALLET_ERROR,
9849
9967
  "Both public and private Key cannot be missing. At least one should be provided."
9850
9968
  );
9851
9969
  }
@@ -9874,8 +9992,8 @@ var HDWallet = class {
9874
9992
  const data = new Uint8Array(37);
9875
9993
  if (index & HARDENED_INDEX) {
9876
9994
  if (!privateKey) {
9877
- throw new import_errors24.FuelError(
9878
- import_errors24.ErrorCode.HD_WALLET_ERROR,
9995
+ throw new import_errors25.FuelError(
9996
+ import_errors25.ErrorCode.HD_WALLET_ERROR,
9879
9997
  "Cannot derive a hardened index without a private Key."
9880
9998
  );
9881
9999
  }
@@ -9927,8 +10045,8 @@ var HDWallet = class {
9927
10045
  */
9928
10046
  toExtendedKey(isPublic = false, testnet = false) {
9929
10047
  if (this.depth >= 256) {
9930
- throw new import_errors24.FuelError(
9931
- import_errors24.ErrorCode.HD_WALLET_ERROR,
10048
+ throw new import_errors25.FuelError(
10049
+ import_errors25.ErrorCode.HD_WALLET_ERROR,
9932
10050
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
9933
10051
  );
9934
10052
  }
@@ -9959,10 +10077,10 @@ var HDWallet = class {
9959
10077
  const bytes = (0, import_utils43.arrayify)(decoded);
9960
10078
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
9961
10079
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
9962
- throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
10080
+ throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
9963
10081
  }
9964
10082
  if (!validChecksum) {
9965
- throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
10083
+ throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
9966
10084
  }
9967
10085
  const depth = bytes[4];
9968
10086
  const parentFingerprint = (0, import_utils43.hexlify)(bytes.slice(5, 9));
@@ -9970,14 +10088,14 @@ var HDWallet = class {
9970
10088
  const chainCode = (0, import_utils43.hexlify)(bytes.slice(13, 45));
9971
10089
  const key = bytes.slice(45, 78);
9972
10090
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
9973
- throw new import_errors24.FuelError(
9974
- import_errors24.ErrorCode.HD_WALLET_ERROR,
10091
+ throw new import_errors25.FuelError(
10092
+ import_errors25.ErrorCode.HD_WALLET_ERROR,
9975
10093
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
9976
10094
  );
9977
10095
  }
9978
10096
  if (isPublicExtendedKey(bytes)) {
9979
10097
  if (key[0] !== 3) {
9980
- throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
10098
+ throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
9981
10099
  }
9982
10100
  return new HDWallet({
9983
10101
  publicKey: key,
@@ -9988,7 +10106,7 @@ var HDWallet = class {
9988
10106
  });
9989
10107
  }
9990
10108
  if (key[0] !== 0) {
9991
- throw new import_errors24.FuelError(import_errors24.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
10109
+ throw new import_errors25.FuelError(import_errors25.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
9992
10110
  }
9993
10111
  return new HDWallet({
9994
10112
  privateKey: key.slice(1),
@@ -10232,26 +10350,26 @@ var WalletsConfig = class {
10232
10350
  amountPerCoin
10233
10351
  }) {
10234
10352
  if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
10235
- throw new import_errors25.FuelError(
10236
- import_errors25.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10353
+ throw new import_errors26.FuelError(
10354
+ import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10237
10355
  "Number of wallets must be greater than zero."
10238
10356
  );
10239
10357
  }
10240
10358
  if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
10241
- throw new import_errors25.FuelError(
10242
- import_errors25.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10359
+ throw new import_errors26.FuelError(
10360
+ import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10243
10361
  "Number of assets per wallet must be greater than zero."
10244
10362
  );
10245
10363
  }
10246
10364
  if (coinsPerAsset <= 0) {
10247
- throw new import_errors25.FuelError(
10248
- import_errors25.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10365
+ throw new import_errors26.FuelError(
10366
+ import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10249
10367
  "Number of coins per asset must be greater than zero."
10250
10368
  );
10251
10369
  }
10252
10370
  if (amountPerCoin < 0) {
10253
- throw new import_errors25.FuelError(
10254
- import_errors25.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10371
+ throw new import_errors26.FuelError(
10372
+ import_errors26.FuelError.CODES.INVALID_INPUT_PARAMETERS,
10255
10373
  "Amount per coin must be greater than or equal to zero."
10256
10374
  );
10257
10375
  }
@@ -10322,7 +10440,7 @@ async function setupTestProviderAndWallets({
10322
10440
  }
10323
10441
 
10324
10442
  // src/test-utils/test-message.ts
10325
- var import_address7 = require("@fuel-ts/address");
10443
+ var import_address8 = require("@fuel-ts/address");
10326
10444
  var import_crypto10 = require("@fuel-ts/crypto");
10327
10445
  var import_math24 = require("@fuel-ts/math");
10328
10446
  var import_utils46 = require("@fuel-ts/utils");
@@ -10340,8 +10458,8 @@ var TestMessage = class {
10340
10458
  * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
10341
10459
  */
10342
10460
  constructor({
10343
- sender = import_address7.Address.fromRandom(),
10344
- recipient = import_address7.Address.fromRandom(),
10461
+ sender = import_address8.Address.fromRandom(),
10462
+ recipient = import_address8.Address.fromRandom(),
10345
10463
  nonce = (0, import_utils46.hexlify)((0, import_crypto10.randomBytes)(32)),
10346
10464
  amount = 1e6,
10347
10465
  data = "",