@tokemak/queries 0.4.0 → 0.6.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 (38) hide show
  1. package/dist/functions/getAutopoolDayData.d.ts.map +1 -1
  2. package/dist/functions/getAutopoolHistory.d.ts.map +1 -1
  3. package/dist/functions/getAutopools.d.ts +3 -3
  4. package/dist/functions/getAutopools.d.ts.map +1 -1
  5. package/dist/functions/getAutopoolsRebalances.d.ts.map +1 -1
  6. package/dist/functions/getChainAutopools.d.ts +3 -3
  7. package/dist/functions/getChainAutopools.d.ts.map +1 -1
  8. package/dist/functions/getEthPriceAtBlock.d.ts +2 -2
  9. package/dist/functions/getEthPriceAtBlock.d.ts.map +1 -1
  10. package/dist/functions/getHistoricalTokenPrices.d.ts +1 -1
  11. package/dist/functions/getHistoricalTokenPrices.d.ts.map +1 -1
  12. package/dist/functions/getMultipleAutopoolRebalances.d.ts.map +1 -1
  13. package/dist/functions/getPoolsAndDestinations.d.ts +2 -2
  14. package/dist/functions/getPoolsAndDestinations.d.ts.map +1 -1
  15. package/dist/functions/getRebalanceStats.d.ts +7 -6
  16. package/dist/functions/getRebalanceStats.d.ts.map +1 -1
  17. package/dist/functions/getTokenPrices.d.ts +2 -487
  18. package/dist/functions/getTokenPrices.d.ts.map +1 -1
  19. package/dist/functions/getUserAutopoolBalanceChanges.d.ts.map +1 -1
  20. package/dist/functions/getUserAutopools.d.ts +1 -1
  21. package/dist/functions/getUserAutopools.d.ts.map +1 -1
  22. package/dist/functions/getUserSAuto.d.ts +1 -1
  23. package/dist/functions/getUserSAuto.d.ts.map +1 -1
  24. package/dist/functions/updateRebalanceStats.d.ts +2 -2
  25. package/dist/functions/updateRebalanceStats.d.ts.map +1 -1
  26. package/dist/index.js +362 -461
  27. package/dist/index.mjs +245 -361
  28. package/dist/safe.d.ts +9 -0
  29. package/dist/safe.d.ts.map +1 -0
  30. package/dist/safe.js +860 -0
  31. package/dist/safe.mjs +848 -0
  32. package/package.json +19 -8
  33. package/dist/functions/getBackupApr.d.ts +0 -2
  34. package/dist/functions/getBackupApr.d.ts.map +0 -1
  35. package/dist/functions/getBackupTokenPrices.d.ts +0 -6
  36. package/dist/functions/getBackupTokenPrices.d.ts.map +0 -1
  37. package/dist/functions/getPoolsAndDestinationsBackup.d.ts +0 -67
  38. package/dist/functions/getPoolsAndDestinationsBackup.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -21,12 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AutopoolCategory: () => AutopoolCategory,
24
- BASE_ASSETS: () => BASE_ASSETS,
25
24
  BATCH_SIZE: () => BATCH_SIZE,
26
25
  ETH_BASE_ASSETS: () => ETH_BASE_ASSETS,
27
26
  EUR_BASE_ASSETS: () => EUR_BASE_ASSETS,
28
27
  MessageStatus: () => MessageStatus,
29
- PRICED_TOKENS: () => PRICED_TOKENS,
30
28
  USD_BASE_ASSETS: () => USD_BASE_ASSETS,
31
29
  aggregateSTokeRewardsDayData: () => aggregateSTokeRewardsDayData,
32
30
  arraysToObject: () => arraysToObject,
@@ -276,6 +274,9 @@ var getTokePrice = async () => {
276
274
  }
277
275
  };
278
276
 
277
+ // functions/getAutopools.ts
278
+ var import_core = require("@wagmi/core");
279
+
279
280
  // utils/getExchangeNames.ts
280
281
  function getExchangeNames(destinationVaults) {
281
282
  const uniqueNamesSet = /* @__PURE__ */ new Set();
@@ -626,22 +627,8 @@ async function paginateQuery(queryFn, arrayKey, options = {}) {
626
627
  return results;
627
628
  }
628
629
 
629
- // functions/getPoolsAndDestinationsBackup.ts
630
- var import_utils2 = require("@tokemak/utils");
631
- var getPoolsAndDestinationsBackup = async (chainId) => {
632
- try {
633
- const networkName = (0, import_utils2.getNetwork)(chainId)?.name.toLowerCase();
634
- const backupData = await getBlobData(
635
- `${networkName}-getPoolsAndDestinations-latest-success.json`
636
- );
637
- return backupData?.data;
638
- } catch (e) {
639
- console.error(e);
640
- }
641
- };
642
-
643
630
  // functions/getChainAutopools.ts
644
- var import_utils6 = require("@tokemak/utils");
631
+ var import_utils4 = require("@tokemak/utils");
645
632
  var import_viem2 = require("viem");
646
633
 
647
634
  // constants/tokenOrders.ts
@@ -743,16 +730,14 @@ var import_chains2 = require("viem/chains");
743
730
 
744
731
  // functions/getPoolsAndDestinations.ts
745
732
  var import_config = require("@tokemak/config");
746
- var import_core = require("@wagmi/core");
747
733
  var import_abis = require("@tokemak/abis");
748
- var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
734
+ var getPoolsAndDestinations = async (client, { chainId }) => {
749
735
  try {
750
736
  const { lens } = (0, import_config.getCoreConfig)(chainId);
751
- const { autoPools, destinations } = await (0, import_core.readContract)(wagmiConfig, {
737
+ const { autoPools, destinations } = await client.readContract({
752
738
  address: lens,
753
739
  abi: import_abis.lensAbi,
754
- functionName: "getPoolsAndDestinations",
755
- chainId
740
+ functionName: "getPoolsAndDestinations"
756
741
  });
757
742
  const autopoolsAndDestinations = mergeArraysWithKey(
758
743
  autoPools,
@@ -765,30 +750,9 @@ var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
765
750
  }
766
751
  };
767
752
 
768
- // functions/getBackupApr.ts
769
- var import_utils4 = require("@tokemak/utils");
770
- var getBackupApr = async (chainId, poolAddress) => {
771
- try {
772
- const networkName = (0, import_utils4.getNetwork)(chainId)?.name.toLowerCase();
773
- const backupData = await getBlobData(
774
- `${networkName}-getChainAutopools-latest-success.json`
775
- );
776
- if (backupData) {
777
- const backupApr = backupData.data.find(
778
- (item) => item.poolAddress.toLowerCase() === poolAddress.toLowerCase()
779
- )?.apr.base;
780
- return backupApr || 0;
781
- }
782
- } catch (e) {
783
- console.error(e);
784
- return 0;
785
- }
786
- return null;
787
- };
788
-
789
753
  // functions/getChainAutopools.ts
790
754
  var import_constants6 = require("@tokemak/constants");
791
- var getChainAutopools = async (wagmiConfig, {
755
+ var getChainAutopools = async (client, {
792
756
  chainId,
793
757
  prices
794
758
  }) => {
@@ -802,24 +766,22 @@ var getChainAutopools = async (wagmiConfig, {
802
766
  const genStratAprs = await getGenStratAprs({
803
767
  chainId
804
768
  });
805
- let autopoolsAndDestinations = await getPoolsAndDestinations(wagmiConfig, {
769
+ const autopoolsAndDestinations = await getPoolsAndDestinations(client, {
806
770
  chainId
807
771
  });
808
772
  if (!autopoolsAndDestinations) {
809
- const backupData = await getPoolsAndDestinationsBackup(chainId);
810
- if (backupData) {
811
- autopoolsAndDestinations = backupData;
812
- } else {
813
- throw new Error(`No autopools and destinations found for ${chainId}`);
814
- }
773
+ throw new Error(`No autopools and destinations found for ${chainId}`);
815
774
  }
816
- const vaultAddedMapping = vaultAddeds.reduce((acc, vaultAdded) => {
817
- acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
818
- return acc;
819
- }, {});
775
+ const vaultAddedMapping = vaultAddeds.reduce(
776
+ (acc, vaultAdded) => {
777
+ acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
778
+ return acc;
779
+ },
780
+ {}
781
+ );
820
782
  const autopools = await Promise.all(
821
783
  autopoolsAndDestinations.map(async (autopool) => {
822
- let baseAsset = (0, import_utils6.getToken)(autopool.baseAsset);
784
+ let baseAsset = (0, import_utils4.getToken)(autopool.baseAsset);
823
785
  if (!baseAsset?.symbol) {
824
786
  console.error(
825
787
  "FIX THIS BEFORE PROD: base asset not found",
@@ -834,18 +796,18 @@ var getChainAutopools = async (wagmiConfig, {
834
796
  }) || 0;
835
797
  }
836
798
  const timestamp = vaultAddedMapping[autopool.poolAddress.toLowerCase()];
837
- const totalAssets = (0, import_utils6.formatUnitsNum)(
799
+ const totalAssets = (0, import_utils4.formatUnitsNum)(
838
800
  autopool.totalAssets,
839
801
  baseAsset.decimals
840
802
  );
841
803
  const tvl = totalAssets * baseAssetPrice;
842
- const totalIdleAssets = (0, import_utils6.formatUnitsNum)(
804
+ const totalIdleAssets = (0, import_utils4.formatUnitsNum)(
843
805
  autopool.totalIdle,
844
806
  baseAsset.decimals
845
807
  );
846
808
  const exchangeValues = {};
847
809
  const destinations = autopool.destinations.map((destination) => {
848
- const debtValueHeldByVaultEth = (0, import_utils6.formatUnitsNum)(
810
+ const debtValueHeldByVaultEth = (0, import_utils4.formatUnitsNum)(
849
811
  destination.debtValueHeldByVault,
850
812
  baseAsset.decimals
851
813
  );
@@ -858,8 +820,8 @@ var getChainAutopools = async (wagmiConfig, {
858
820
  destination.underlyingTokenValueHeld
859
821
  );
860
822
  let underlyingTokens = tokensWithValue.map((token) => {
861
- const tokenDetails = (0, import_utils6.getToken)(token.tokenAddress);
862
- let value = (0, import_utils6.formatUnitsNum)(
823
+ const tokenDetails = (0, import_utils4.getToken)(token.tokenAddress);
824
+ let value = (0, import_utils4.formatUnitsNum)(
863
825
  token.valueHeldInEth,
864
826
  baseAsset.decimals
865
827
  );
@@ -875,7 +837,7 @@ var getChainAutopools = async (wagmiConfig, {
875
837
  if (underlyingTokenAddress) {
876
838
  underlyingTokens = [
877
839
  {
878
- ...(0, import_utils6.getToken)(underlyingTokenAddress, chainId),
840
+ ...(0, import_utils4.getToken)(underlyingTokenAddress, chainId),
879
841
  valueUsd: debtValueHeldByVaultEth * baseAssetPrice,
880
842
  value: debtValueHeldByVaultEth
881
843
  }
@@ -887,11 +849,11 @@ var getChainAutopools = async (wagmiConfig, {
887
849
  ...destination,
888
850
  debtValueHeldByVaultUsd: debtValueHeldByVaultEth * baseAssetPrice,
889
851
  debtValueHeldByVaultEth,
890
- compositeReturn: isGenStrat ? genStratAprs?.[autopool.poolAddress]?.[destination.vaultAddress]?.apr || 0 : (0, import_utils6.formatEtherNum)(destination.compositeReturn),
852
+ compositeReturn: isGenStrat ? genStratAprs?.[autopool.poolAddress]?.[destination.vaultAddress]?.apr || 0 : (0, import_utils4.formatEtherNum)(destination.compositeReturn),
891
853
  debtValueHeldByVaultAllocation: debtValueHeldByVaultEth / totalAssets,
892
854
  underlyingTokens,
893
- poolName: (0, import_utils6.formatPoolName)(destination.lpTokenName),
894
- exchange: (0, import_utils6.getProtocol)(destination.exchangeName)
855
+ poolName: (0, import_utils4.formatPoolName)(destination.lpTokenName),
856
+ exchange: (0, import_utils4.getProtocol)(destination.exchangeName)
895
857
  };
896
858
  });
897
859
  const HIDDEN_DESTINATION_SYMBOLS = ["USR", "WSTUSR"];
@@ -902,7 +864,7 @@ var getChainAutopools = async (wagmiConfig, {
902
864
  );
903
865
  const uniqueExchanges = Array.from(
904
866
  new Set(
905
- filteredDestinations.map((d) => (0, import_utils6.getProtocol)(d.exchangeName)).filter(Boolean)
867
+ filteredDestinations.map((d) => (0, import_utils4.getProtocol)(d.exchangeName)).filter(Boolean)
906
868
  )
907
869
  );
908
870
  const uniqueExchangesWithValueHeld = uniqueExchanges.map((exchange) => {
@@ -938,15 +900,18 @@ var getChainAutopools = async (wagmiConfig, {
938
900
  },
939
901
  []
940
902
  );
941
- const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce((acc, token) => {
942
- if (acc[token.address]) {
943
- acc[token.address].valueUsd += token.valueUsd;
944
- acc[token.address].value += token.value;
945
- } else {
946
- acc[token.address] = { ...token };
947
- }
948
- return acc;
949
- }, {});
903
+ const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
904
+ (acc, token) => {
905
+ if (acc[token.address]) {
906
+ acc[token.address].valueUsd += token.valueUsd;
907
+ acc[token.address].value += token.value;
908
+ } else {
909
+ acc[token.address] = { ...token };
910
+ }
911
+ return acc;
912
+ },
913
+ {}
914
+ );
950
915
  const HIDDEN_TOKEN_SYMBOLS = ["USR", "WSTUSR"];
951
916
  const uniqueTokens = Object.values(uniqueTokensWithValueHeldMap).filter(
952
917
  (token) => !HIDDEN_TOKEN_SYMBOLS.includes(token.symbol?.toUpperCase())
@@ -975,24 +940,12 @@ var getChainAutopools = async (wagmiConfig, {
975
940
  const aprs = autopoolsApr.find(
976
941
  (autopoolApr) => (0, import_viem2.getAddress)(autopoolApr.id) === (0, import_viem2.getAddress)(autopool.poolAddress)
977
942
  );
978
- let baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
943
+ const baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
979
944
  let extraApr = 0;
980
- if (baseApr === void 0) {
981
- try {
982
- const backupApr = await getBackupApr(chainId, autopool.poolAddress);
983
- if (backupApr) {
984
- baseApr = backupApr;
985
- console.log("using backup apr", backupApr);
986
- }
987
- } catch (e) {
988
- console.error(e);
989
- console.log("unable to retrieve backup apr");
990
- }
991
- }
992
945
  let extraRewards = [];
993
946
  if (aprs?.rewards && aprs.rewards.length > 0) {
994
947
  extraRewards = aprs.rewards.map((reward) => {
995
- const token = (0, import_utils6.getToken)(reward.rewardToken, chainId);
948
+ const token = (0, import_utils4.getToken)(reward.rewardToken, chainId);
996
949
  return {
997
950
  ...token,
998
951
  apr: reward.rewardApy / 100
@@ -1000,11 +953,8 @@ var getChainAutopools = async (wagmiConfig, {
1000
953
  });
1001
954
  }
1002
955
  extraApr = extraRewards.reduce((acc, reward) => acc + reward.apr, 0);
1003
- if (baseApr === void 0) baseApr = 0;
1004
- if (autopool.symbol === "autoETH") {
1005
- baseApr = 0.024;
1006
- }
1007
- const combinedApr = baseApr + extraApr;
956
+ const baseForMath = baseApr ?? 0;
957
+ const combinedApr = baseForMath + extraApr;
1008
958
  let denominatedToken = import_tokenlist3.ETH_TOKEN;
1009
959
  let useDenominatedValues = false;
1010
960
  const denominationData = autopoolsDenomination.find(
@@ -1014,7 +964,7 @@ var getChainAutopools = async (wagmiConfig, {
1014
964
  if (denominatedIn?.symbol?.toLowerCase() === "weth") {
1015
965
  denominatedToken = import_tokenlist3.ETH_TOKEN;
1016
966
  } else {
1017
- denominatedToken = (0, import_utils6.getToken)(denominatedIn?.id);
967
+ denominatedToken = (0, import_utils4.getToken)(denominatedIn?.id);
1018
968
  if (denominatedToken) {
1019
969
  useDenominatedValues = true;
1020
970
  }
@@ -1029,12 +979,12 @@ var getChainAutopools = async (wagmiConfig, {
1029
979
  tokenAddress: denominatedToken.address
1030
980
  }) || 0;
1031
981
  }
1032
- const navPerShareBaseAsset = (0, import_utils6.formatUnitsNum)(
982
+ const navPerShareBaseAsset = (0, import_utils4.formatUnitsNum)(
1033
983
  autopool.navPerShare,
1034
984
  baseAsset.decimals
1035
985
  );
1036
986
  const assets = convertBaseAssetToTokenPricesAndDenom(
1037
- (0, import_utils6.formatUnitsNum)(autopool.totalAssets, baseAsset.decimals),
987
+ (0, import_utils4.formatUnitsNum)(autopool.totalAssets, baseAsset.decimals),
1038
988
  baseAssetPrice,
1039
989
  denominatedTokenPrice,
1040
990
  prices
@@ -1059,7 +1009,7 @@ var getChainAutopools = async (wagmiConfig, {
1059
1009
  prices
1060
1010
  );
1061
1011
  const baseDailyEarnings = convertBaseAssetToTokenPricesAndDenom(
1062
- totalAssets * baseApr / import_constants6.DAYS_PER_YEAR,
1012
+ totalAssets * baseForMath / import_constants6.DAYS_PER_YEAR,
1063
1013
  baseAssetPrice,
1064
1014
  denominatedTokenPrice,
1065
1015
  prices
@@ -1067,36 +1017,39 @@ var getChainAutopools = async (wagmiConfig, {
1067
1017
  const tokenOrder = [UIBaseAsset.symbol, ...UITokenOrder].filter(
1068
1018
  (value, index, array) => array.indexOf(value) === index
1069
1019
  );
1070
- const UITokens = uniqueTokens.reduce((acc, token) => {
1071
- try {
1072
- const parentAsset = token.extensions?.parentAsset;
1073
- if (parentAsset) {
1074
- const parentToken = import_tokenlist3.ALL_TOKENS.find(
1075
- (t) => t.symbol.toLowerCase() === parentAsset.toLowerCase()
1076
- );
1077
- if (parentToken && !acc.some(
1078
- (t) => t?.address?.toLowerCase() === parentToken?.address?.toLowerCase()
1020
+ const UITokens = uniqueTokens.reduce(
1021
+ (acc, token) => {
1022
+ try {
1023
+ const parentAsset = token.extensions?.parentAsset;
1024
+ if (parentAsset) {
1025
+ const parentToken = import_tokenlist3.ALL_TOKENS.find(
1026
+ (t) => t.symbol.toLowerCase() === parentAsset.toLowerCase()
1027
+ );
1028
+ if (parentToken && !acc.some(
1029
+ (t) => t?.address?.toLowerCase() === parentToken?.address?.toLowerCase()
1030
+ )) {
1031
+ acc.push({
1032
+ ...parentToken,
1033
+ valueUsd: 0,
1034
+ value: 0,
1035
+ allocation: 0
1036
+ });
1037
+ }
1038
+ } else if (!acc.some(
1039
+ (t) => t?.address?.toLowerCase() === token?.address?.toLowerCase()
1079
1040
  )) {
1080
- acc.push({
1081
- ...parentToken,
1082
- valueUsd: 0,
1083
- value: 0,
1084
- allocation: 0
1085
- });
1041
+ acc.push(token);
1086
1042
  }
1087
- } else if (!acc.some(
1088
- (t) => t?.address?.toLowerCase() === token?.address?.toLowerCase()
1089
- )) {
1090
- acc.push(token);
1043
+ } catch (error) {
1044
+ console.warn(
1045
+ `Error processing token: ${token?.symbol || "unknown"}`,
1046
+ error
1047
+ );
1091
1048
  }
1092
- } catch (error) {
1093
- console.warn(
1094
- `Error processing token: ${token?.symbol || "unknown"}`,
1095
- error
1096
- );
1097
- }
1098
- return acc;
1099
- }, []).sort((a, b) => {
1049
+ return acc;
1050
+ },
1051
+ []
1052
+ ).sort((a, b) => {
1100
1053
  try {
1101
1054
  const aIndex = tokenOrder.indexOf(a.symbol.toUpperCase());
1102
1055
  const bIndex = tokenOrder.indexOf(b.symbol.toUpperCase());
@@ -1139,7 +1092,7 @@ var getChainAutopools = async (wagmiConfig, {
1139
1092
  });
1140
1093
  const autopoolInfo = getAutopoolInfo(autopool.symbol);
1141
1094
  if (autopoolInfo && !autopoolInfo.description) {
1142
- autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${(0, import_utils6.getNetwork)(chainId)?.name}.`;
1095
+ autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${(0, import_utils4.getNetwork)(chainId)?.name}.`;
1143
1096
  }
1144
1097
  return {
1145
1098
  ...autopool,
@@ -1165,9 +1118,9 @@ var getChainAutopools = async (wagmiConfig, {
1165
1118
  UITokens,
1166
1119
  UIExchanges: finalUIExchanges,
1167
1120
  tokens: uniqueTokens,
1168
- chain: (0, import_utils6.getNetwork)(chainId),
1121
+ chain: (0, import_utils4.getNetwork)(chainId),
1169
1122
  apr: {
1170
- base: baseApr,
1123
+ base: baseApr ?? null,
1171
1124
  extraAprs: extraRewards,
1172
1125
  combined: combinedApr,
1173
1126
  hasExtraAprs: extraRewards.length > 0
@@ -1205,12 +1158,13 @@ var getAutopools = async (wagmiConfig, {
1205
1158
  try {
1206
1159
  const chains = getChainsForEnv({ includeTestnet });
1207
1160
  const autopools = (await Promise.all(
1208
- chains.map(
1209
- (chain) => getChainAutopools(wagmiConfig, {
1161
+ chains.map((chain) => {
1162
+ const chainId = chain?.chainId;
1163
+ return getChainAutopools((0, import_core.getPublicClient)(wagmiConfig, { chainId }), {
1210
1164
  prices,
1211
- chainId: chain?.chainId
1212
- })
1213
- )
1165
+ chainId
1166
+ });
1167
+ })
1214
1168
  )).flat();
1215
1169
  const sortedAutopoolsByTimestamp = autopools.sort(
1216
1170
  (a, b) => b.timestamp - a.timestamp
@@ -1257,7 +1211,7 @@ var getAutopoolsRebalances = async (chainId = 1) => {
1257
1211
 
1258
1212
  // functions/getAutopoolDayData.ts
1259
1213
  var import_viem4 = require("viem");
1260
- var import_utils10 = require("@tokemak/utils");
1214
+ var import_utils8 = require("@tokemak/utils");
1261
1215
  var import_constants7 = require("@tokemak/constants");
1262
1216
  var import_graph_cli4 = require("@tokemak/graph-cli");
1263
1217
  var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_constants7.TOKEMAK_LAUNCH_TIMESTAMP) => {
@@ -1268,13 +1222,14 @@ var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_co
1268
1222
  timestamp: startTimestamp
1269
1223
  });
1270
1224
  const formattedDayDatas = autopoolDayDatas.map((autoPoolDayData) => {
1271
- const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
1225
+ const baseDecimals = Number(autoPoolDayData.baseAsset.decimals) || 18;
1226
+ const navPerShare = Number(autoPoolDayData.nav) / Number(autoPoolDayData.totalSupply) * Math.pow(10, 18 - baseDecimals);
1272
1227
  let baseApy = autoPoolDayData.autopoolApy;
1273
1228
  let rewarderApy = 0;
1274
- const formattedRewarder7DayMAApy = (0, import_utils10.formatEtherNum)(
1229
+ const formattedRewarder7DayMAApy = (0, import_utils8.formatEtherNum)(
1275
1230
  BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
1276
1231
  );
1277
- const formattedRewarder30DayMAApy = (0, import_utils10.formatEtherNum)(
1232
+ const formattedRewarder30DayMAApy = (0, import_utils8.formatEtherNum)(
1278
1233
  BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
1279
1234
  );
1280
1235
  if (formattedRewarder7DayMAApy) {
@@ -1402,7 +1357,7 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
1402
1357
  var import_viem6 = require("viem");
1403
1358
  var import_core2 = require("@wagmi/core");
1404
1359
  var import_abis2 = require("@tokemak/abis");
1405
- var import_utils12 = require("@tokemak/utils");
1360
+ var import_utils10 = require("@tokemak/utils");
1406
1361
  var getAutopoolUser = async (config, {
1407
1362
  autopool,
1408
1363
  address,
@@ -1444,14 +1399,14 @@ var getAutopoolUser = async (config, {
1444
1399
  args: [address],
1445
1400
  chainId: autopool?.chain?.chainId
1446
1401
  });
1447
- const stakedShares = (0, import_utils12.formatEtherNum)(stakedPoolShares);
1402
+ const stakedShares = (0, import_utils10.formatEtherNum)(stakedPoolShares);
1448
1403
  const staked = convertBaseAssetToTokenPricesAndDenom(
1449
1404
  stakedShares * (autopool?.navPerShare.baseAsset || 0),
1450
1405
  autopool?.baseAsset.price,
1451
1406
  autopool?.denomination.price,
1452
1407
  prices
1453
1408
  );
1454
- const unstakedShares = (0, import_utils12.formatEtherNum)(unstakedPoolShares || 0n);
1409
+ const unstakedShares = (0, import_utils10.formatEtherNum)(unstakedPoolShares || 0n);
1455
1410
  const unstaked = convertBaseAssetToTokenPricesAndDenom(
1456
1411
  unstakedShares * (autopool?.navPerShare.baseAsset || 0),
1457
1412
  autopool?.baseAsset.price,
@@ -1466,7 +1421,7 @@ var getAutopoolUser = async (config, {
1466
1421
  prices
1467
1422
  );
1468
1423
  const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
1469
- (0, import_utils12.formatUnitsNum)(
1424
+ (0, import_utils10.formatUnitsNum)(
1470
1425
  userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
1471
1426
  autopool?.baseAsset.decimals
1472
1427
  ),
@@ -1475,7 +1430,7 @@ var getAutopoolUser = async (config, {
1475
1430
  prices
1476
1431
  );
1477
1432
  const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
1478
- (0, import_utils12.formatUnitsNum)(
1433
+ (0, import_utils10.formatUnitsNum)(
1479
1434
  userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
1480
1435
  autopool?.baseAsset.decimals
1481
1436
  ),
@@ -1500,7 +1455,7 @@ var getAutopoolUser = async (config, {
1500
1455
  );
1501
1456
  let lastDeposit;
1502
1457
  if (poolEvents && poolEvents?.length > 0) {
1503
- lastDeposit = (0, import_utils12.convertTimestampToDate)(
1458
+ lastDeposit = (0, import_utils10.convertTimestampToDate)(
1504
1459
  poolEvents[poolEvents.length - 1].timestamp
1505
1460
  ).toLocaleDateString("en-US", {
1506
1461
  day: "2-digit",
@@ -1534,7 +1489,7 @@ var getAutopoolUser = async (config, {
1534
1489
 
1535
1490
  // functions/getAutopoolUserActivity.ts
1536
1491
  var import_graph_cli6 = require("@tokemak/graph-cli");
1537
- var import_utils15 = require("@tokemak/utils");
1492
+ var import_utils13 = require("@tokemak/utils");
1538
1493
  var getAutopoolUserActivity = async ({
1539
1494
  autopool,
1540
1495
  userAddress
@@ -1596,7 +1551,7 @@ var getAutopoolUserActivity = async ({
1596
1551
  } else {
1597
1552
  eventType = "Unknown";
1598
1553
  }
1599
- const netDeposits = (0, import_utils15.formatUnitsNum)(
1554
+ const netDeposits = (0, import_utils13.formatUnitsNum)(
1600
1555
  userActivityTotals[activity.vaultAddress].totalDeposits - userActivityTotals[activity.vaultAddress].totalWithdrawals,
1601
1556
  autopool.baseAsset.decimals
1602
1557
  );
@@ -1624,7 +1579,7 @@ var getAutopoolUserActivity = async ({
1624
1579
  var import_graph_cli7 = require("@tokemak/graph-cli");
1625
1580
  var import_constants8 = require("@tokemak/constants");
1626
1581
  var import_chains3 = require("viem/chains");
1627
- var import_utils17 = require("@tokemak/utils");
1582
+ var import_utils15 = require("@tokemak/utils");
1628
1583
  var getAutopoolUserHistory = async ({
1629
1584
  userAddress,
1630
1585
  autopool,
@@ -1675,8 +1630,8 @@ var getAutopoolUserHistory = async ({
1675
1630
  const matchingAutopoolDayData = autopoolDayData.find(
1676
1631
  (autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
1677
1632
  );
1678
- const userPortionOfVault = (0, import_utils17.formatEtherNum)(userVaultDayData.totalShares) / (0, import_utils17.formatEtherNum)(matchingAutopoolDayData?.totalSupply);
1679
- const userNav = userPortionOfVault * (0, import_utils17.formatUnitsNum)(
1633
+ const userPortionOfVault = (0, import_utils15.formatEtherNum)(userVaultDayData.totalShares) / (0, import_utils15.formatEtherNum)(matchingAutopoolDayData?.totalSupply);
1634
+ const userNav = userPortionOfVault * (0, import_utils15.formatUnitsNum)(
1680
1635
  BigInt(matchingAutopoolDayData?.nav || 0),
1681
1636
  autopool?.baseAsset.decimals
1682
1637
  );
@@ -2856,7 +2811,7 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
2856
2811
  // functions/getUserAutoEthRewards.ts
2857
2812
  var import_abis4 = require("@tokemak/abis");
2858
2813
  var import_core6 = require("@wagmi/core");
2859
- var import_utils19 = require("@tokemak/utils");
2814
+ var import_utils17 = require("@tokemak/utils");
2860
2815
  var getAutoEthRewards = async (wagmiConfig, {
2861
2816
  account,
2862
2817
  currentCycleIndex,
@@ -2894,7 +2849,7 @@ var getAutoEthRewards = async (wagmiConfig, {
2894
2849
  const currentAmount = Number(drippingHashPayload?.summary?.currentAmount);
2895
2850
  const previousAmount = Number(drippingHashPayload?.summary?.previousAmount);
2896
2851
  const cycleDuration = 604800;
2897
- const lastCycleStart = (0, import_utils19.convertChainCycleToUnix)(Number(currentCycleIndex));
2852
+ const lastCycleStart = (0, import_utils17.convertChainCycleToUnix)(Number(currentCycleIndex));
2898
2853
  const timeSinceCycleStart = Date.now() / 1e3 - lastCycleStart;
2899
2854
  const currentUserRewards = currentAmount * Math.min(timeSinceCycleStart, cycleDuration) / cycleDuration + previousAmount;
2900
2855
  const lastWeekRewards = Number(lastWeekHashPayload?.summary?.currentAmount);
@@ -2915,7 +2870,7 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
2915
2870
  rewardsHash,
2916
2871
  chainId
2917
2872
  });
2918
- const currentUserRewardsUsd = (0, import_utils19.formatCurrency)(
2873
+ const currentUserRewardsUsd = (0, import_utils17.formatCurrency)(
2919
2874
  ethPrice * (autoETHRewards?.currentUserRewards || 0)
2920
2875
  );
2921
2876
  return { ...autoETHRewards, currentUserRewardsUsd };
@@ -3103,11 +3058,11 @@ var getChainUserAutopoolsHistory = async ({
3103
3058
  };
3104
3059
 
3105
3060
  // functions/getUserAutopoolsHistory.ts
3106
- var import_utils23 = require("@tokemak/utils");
3061
+ var import_utils21 = require("@tokemak/utils");
3107
3062
 
3108
3063
  // functions/getTokenValueDayDatas.ts
3109
3064
  var import_chains10 = require("viem/chains");
3110
- var import_utils20 = require("@tokemak/utils");
3065
+ var import_utils18 = require("@tokemak/utils");
3111
3066
  var import_viem10 = require("viem");
3112
3067
  var import_graph_cli10 = require("@tokemak/graph-cli");
3113
3068
  var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainnet.id) => {
@@ -3117,7 +3072,7 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainn
3117
3072
  tokenAddress: tokenAddress.toLowerCase()
3118
3073
  });
3119
3074
  const historicalPrice = tokenValueDayDatas.map((tokenValueDayData) => {
3120
- const date = (0, import_utils20.convertTimestampToDate)(
3075
+ const date = (0, import_utils18.convertTimestampToDate)(
3121
3076
  tokenValueDayData.lastSnapshotTimestamp
3122
3077
  );
3123
3078
  const usdPrice = (0, import_viem10.formatUnits)(tokenValueDayData.priceInUsd, 8);
@@ -3133,117 +3088,8 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainn
3133
3088
  }
3134
3089
  };
3135
3090
 
3136
- // functions/getTokenPrices.ts
3137
- var import_tokenlist6 = require("@tokemak/tokenlist");
3138
- var import_constants16 = require("@tokemak/constants");
3139
-
3140
- // functions/getBackupTokenPrices.ts
3141
- var getBackupTokenPrices = async () => {
3142
- try {
3143
- const backupData = await getBlobData(`getTokenPrices-latest-success.json`);
3144
- if (backupData) {
3145
- return backupData;
3146
- }
3147
- } catch (e) {
3148
- console.error(e);
3149
- return void 0;
3150
- }
3151
- return void 0;
3152
- };
3153
-
3154
- // functions/getTokenPrices.ts
3155
- var BASE_ASSETS = [
3156
- { ...import_tokenlist6.ETH_TOKEN, symbol: "ETH", coinGeckoId: "ethereum" },
3157
- { ...import_tokenlist6.PXETH_TOKEN, symbol: "PXETH", coinGeckoId: "dinero-staked-eth" },
3158
- { ...import_tokenlist6.USDC_TOKEN, symbol: "USDC", coinGeckoId: "usd-coin" },
3159
- { ...import_tokenlist6.DOLA_TOKEN, symbol: "DOLA", coinGeckoId: "dola-usd" },
3160
- { ...import_tokenlist6.S_TOKEN, symbol: "S" },
3161
- { ...import_tokenlist6.EURC_TOKEN, symbol: "EURC", coinGeckoId: "euro-coin" },
3162
- { ...import_tokenlist6.USDT_TOKEN, symbol: "USDT", coinGeckoId: "tether" },
3163
- { ...import_tokenlist6.USDT0_TOKEN, symbol: "USDT0", coinGeckoId: "tether" }
3164
- ];
3165
- var PRICED_TOKENS = [
3166
- ...BASE_ASSETS,
3167
- { ...import_tokenlist6.TOKE_TOKEN, symbol: "TOKE" },
3168
- { ...import_tokenlist6.AUTO_TOKEN, symbol: "AUTO" },
3169
- { ...import_tokenlist6.SILO_TOKEN, symbol: "SILO" },
3170
- { ...import_tokenlist6.XPL_TOKEN, address: import_tokenlist6.WXPL_TOKEN.address, symbol: "XPL" },
3171
- { ...import_tokenlist6.MON_TOKEN, address: import_tokenlist6.WMON_TOKEN.address, symbol: "MON" },
3172
- { ...import_tokenlist6.USDT0_TOKEN, symbol: "USDT0" }
3173
- ];
3174
- var WRAPPED_TOKENS = [
3175
- { ...import_tokenlist6.WETH_TOKEN, symbol: "WETH" },
3176
- { ...import_tokenlist6.WS_TOKEN, symbol: "WS" },
3177
- { ...import_tokenlist6.WXPL_TOKEN, symbol: "WXPL" },
3178
- { ...import_tokenlist6.WMON_TOKEN, symbol: "WMON" }
3179
- ];
3180
- var isStale = (timestamp) => {
3181
- return timestamp - Math.floor(Date.now() / 1e3) > 5 * 60;
3182
- };
3183
- var getTokenPrices = async (isCronJob = false) => {
3184
- try {
3185
- const body = {
3186
- tokens: PRICED_TOKENS.map((asset) => ({
3187
- token: asset.address,
3188
- chainId: asset.chainId,
3189
- systemName: "gen3",
3190
- timeoutMS: 5 * 1e3
3191
- }))
3192
- };
3193
- const response = await fetch(`${import_constants16.TOKEMAK_PRICES_STAGING_URL}`, {
3194
- method: "POST",
3195
- headers: {
3196
- "Content-Type": "application/json"
3197
- },
3198
- body: JSON.stringify(body)
3199
- });
3200
- const data = await response.json();
3201
- const prices = PRICED_TOKENS.reduce((acc, asset) => {
3202
- const priceData = data.find(
3203
- (item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
3204
- );
3205
- acc[asset.symbol] = priceData?.price ?? 0;
3206
- return acc;
3207
- }, {});
3208
- const timestamp = Math.floor(Date.now() / 1e3);
3209
- return {
3210
- timestamp,
3211
- isStale: false,
3212
- prices: {
3213
- ...prices,
3214
- AUTO: prices.TOKE,
3215
- WETH: prices.ETH,
3216
- WS: prices.S,
3217
- WXPL: prices.XPL
3218
- }
3219
- };
3220
- } catch (e) {
3221
- if (isCronJob) {
3222
- return {
3223
- prices: void 0,
3224
- timestamp: void 0,
3225
- isStale: false
3226
- };
3227
- } else {
3228
- const backupPrices = await getBackupTokenPrices();
3229
- if (backupPrices) {
3230
- return {
3231
- prices: backupPrices.prices,
3232
- timestamp: backupPrices.timestamp,
3233
- isStale: isStale(backupPrices.timestamp)
3234
- };
3235
- }
3236
- return {
3237
- prices: void 0,
3238
- timestamp: void 0,
3239
- isStale: false
3240
- };
3241
- }
3242
- }
3243
- };
3244
-
3245
3091
  // functions/getHistoricalTokenPrices.ts
3246
- var import_tokenlist7 = require("@tokemak/tokenlist");
3092
+ var import_tokenlist6 = require("@tokemak/tokenlist");
3247
3093
  var hasCoinGeckoId = (asset) => typeof asset?.coinGeckoId === "string" && asset.coinGeckoId.length > 0;
3248
3094
  var getBlobHistoricalTokenPrices = async (tokenSymbol) => {
3249
3095
  const blobName = `historical_v2/${tokenSymbol}-latest-success.json`;
@@ -3258,9 +3104,9 @@ var getBlobHistoricalTokenPrices = async (tokenSymbol) => {
3258
3104
  var getHistoricalTokenPrices = async () => {
3259
3105
  const ETH_ADDRESS_IN_SUBGRAPH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
3260
3106
  const historicalBaseAssetPrices = await Promise.all(
3261
- BASE_ASSETS.map(async (baseAsset) => {
3107
+ import_tokenlist6.BASE_ASSETS.map(async (baseAsset) => {
3262
3108
  if (!hasCoinGeckoId(baseAsset)) {
3263
- const address = baseAsset.address === import_tokenlist7.ETH_TOKEN.address ? ETH_ADDRESS_IN_SUBGRAPH : baseAsset.address;
3109
+ const address = baseAsset.address === import_tokenlist6.ETH_TOKEN.address ? ETH_ADDRESS_IN_SUBGRAPH : baseAsset.address;
3264
3110
  const prices2 = await getTokenValueDayDatas(
3265
3111
  address,
3266
3112
  baseAsset.chainId
@@ -3284,7 +3130,7 @@ var getHistoricalTokenPrices = async () => {
3284
3130
  (timestamp) => {
3285
3131
  const prices = {};
3286
3132
  const baseAssetsWithUsd = [
3287
- ...BASE_ASSETS.map((asset) => asset.symbol),
3133
+ ...import_tokenlist6.BASE_ASSETS.map((asset) => asset.symbol),
3288
3134
  "USD"
3289
3135
  ];
3290
3136
  const usdPrices = /* @__PURE__ */ new Map();
@@ -3386,7 +3232,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
3386
3232
  Math.floor(sharesRatio * Number(SCALE))
3387
3233
  );
3388
3234
  const navBigInt = sharesRatioBigInt * BigInt(dayData.nav) / SCALE;
3389
- const navNum = (0, import_utils23.formatUnitsNum)(
3235
+ const navNum = (0, import_utils21.formatUnitsNum)(
3390
3236
  navBigInt,
3391
3237
  dayData.baseAsset.decimals
3392
3238
  );
@@ -3457,7 +3303,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
3457
3303
  let finalAggregatedHistoryArray = Object.keys(aggregatedHistoryArray).map(
3458
3304
  (dateKey) => ({
3459
3305
  date: aggregatedHistoryArray[dateKey].date,
3460
- formattedDate: (0, import_utils23.formatDateToReadable)(aggregatedHistoryArray[dateKey].date),
3306
+ formattedDate: (0, import_utils21.formatDateToReadable)(aggregatedHistoryArray[dateKey].date),
3461
3307
  nav: {
3462
3308
  ETH: aggregatedHistoryArray[dateKey].nav.ETH,
3463
3309
  USD: aggregatedHistoryArray[dateKey].nav.USD,
@@ -3505,7 +3351,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
3505
3351
  return sum;
3506
3352
  }
3507
3353
  const decimals = vault.baseAsset.decimals;
3508
- const assetChangeNum = (0, import_utils23.formatUnitsNum)(
3354
+ const assetChangeNum = (0, import_utils21.formatUnitsNum)(
3509
3355
  BigInt(event.assetChange || 0n),
3510
3356
  decimals
3511
3357
  );
@@ -3749,13 +3595,13 @@ var getChainUserAutopools = async ({
3749
3595
  };
3750
3596
 
3751
3597
  // functions/getUserAutopools.ts
3752
- var import_utils25 = require("@tokemak/utils");
3753
- var import_tokenlist8 = require("@tokemak/tokenlist");
3598
+ var import_utils23 = require("@tokemak/utils");
3599
+ var import_tokenlist7 = require("@tokemak/tokenlist");
3754
3600
 
3755
3601
  // functions/getUserAutopool.tsx
3756
3602
  var import_viem11 = require("viem");
3757
3603
  var import_core12 = require("@wagmi/core");
3758
- var import_utils24 = require("@tokemak/utils");
3604
+ var import_utils22 = require("@tokemak/utils");
3759
3605
  var import_abis10 = require("@tokemak/abis");
3760
3606
  var getUserAutopool = async (wagmiConfig, {
3761
3607
  address,
@@ -3804,10 +3650,10 @@ var getUserAutopool = async (wagmiConfig, {
3804
3650
  args: [address],
3805
3651
  chainId: autopool?.chain?.chainId
3806
3652
  });
3807
- const stakedShares = (0, import_utils24.formatEtherNum)(stakedPoolShares);
3653
+ const stakedShares = (0, import_utils22.formatEtherNum)(stakedPoolShares);
3808
3654
  const stakedNav = stakedShares * (autopool?.navPerShare.baseAsset || 0);
3809
3655
  const stakedNavUsd = stakedShares * (autopool?.navPerShare.USD || 0);
3810
- const unstakedShares = (0, import_utils24.formatEtherNum)(unstakedPoolShares || 0n);
3656
+ const unstakedShares = (0, import_utils22.formatEtherNum)(unstakedPoolShares || 0n);
3811
3657
  const unstakedNav = unstakedShares * (autopool?.navPerShare.USD || 0);
3812
3658
  const unstakedNavUsd = unstakedShares * (autopool?.navPerShare.USD || 0);
3813
3659
  const totalShares = unstakedShares + stakedShares;
@@ -3828,7 +3674,7 @@ var getUserAutopool = async (wagmiConfig, {
3828
3674
  });
3829
3675
  pastRewarderBalances = pastRewards.map(({ result }, index) => {
3830
3676
  const balance = result;
3831
- const shares = (0, import_utils24.formatEtherNum)(result);
3677
+ const shares = (0, import_utils22.formatEtherNum)(result);
3832
3678
  const nav = shares * (autopool?.navPerShare.baseAsset || 0);
3833
3679
  const navUsd = shares * (autopool?.navPerShare.USD || 0);
3834
3680
  return {
@@ -3893,7 +3739,7 @@ function accumulateMap(dest, delta, multiplier = 1) {
3893
3739
  }
3894
3740
  var createInitialCurrencyValues = () => {
3895
3741
  const currencies = Object.fromEntries([
3896
- ...PRICED_TOKENS.map((token) => [token.symbol, 0]),
3742
+ ...import_tokenlist7.PRICED_TOKENS.map((token) => [token.symbol, 0]),
3897
3743
  ["USD", 0]
3898
3744
  ]);
3899
3745
  return currencies;
@@ -3946,14 +3792,14 @@ var getUserAutopools = async ({
3946
3792
  );
3947
3793
  if (autopoolData) {
3948
3794
  const isDOLA = autopoolData.symbol === "autoDOLA" && userAutoDOLA;
3949
- const userShares = isDOLA ? userAutoDOLA?.totalShares : (0, import_utils25.formatEtherNum)(userAutopool?.totalShares);
3950
- const totalVaultShares = (0, import_utils25.formatEtherNum)(autopoolData?.totalSupply);
3795
+ const userShares = isDOLA ? userAutoDOLA?.totalShares : (0, import_utils23.formatEtherNum)(userAutopool?.totalShares);
3796
+ const totalVaultShares = (0, import_utils23.formatEtherNum)(autopoolData?.totalSupply);
3951
3797
  const userShareOfVault = userShares / totalVaultShares;
3952
- const totalDeposits = (0, import_utils25.formatUnitsNum)(
3798
+ const totalDeposits = (0, import_utils23.formatUnitsNum)(
3953
3799
  userActivity?.totals[userAutopool.vaultAddress]?.totalDeposits || 0n,
3954
3800
  autopoolData?.baseAsset.decimals
3955
3801
  );
3956
- const totalWithdrawals = (0, import_utils25.formatUnitsNum)(
3802
+ const totalWithdrawals = (0, import_utils23.formatUnitsNum)(
3957
3803
  userActivity?.totals[userAutopool.vaultAddress]?.totalWithdrawals || 0n,
3958
3804
  autopoolData?.baseAsset.decimals
3959
3805
  );
@@ -3962,7 +3808,7 @@ var getUserAutopools = async ({
3962
3808
  );
3963
3809
  let lastDeposit;
3964
3810
  if (poolEvents && poolEvents?.length > 0) {
3965
- lastDeposit = (0, import_utils25.convertTimestampToDate)(
3811
+ lastDeposit = (0, import_utils23.convertTimestampToDate)(
3966
3812
  poolEvents[poolEvents.length - 1].timestamp
3967
3813
  ).toLocaleDateString("en-US", {
3968
3814
  day: "2-digit",
@@ -4062,7 +3908,7 @@ var getUserAutopools = async ({
4062
3908
  totalWithdrawals: prev.totalWithdrawals + totalWithdrawals
4063
3909
  };
4064
3910
  const stakedBalance = isDOLA ? userAutoDOLA?.staked.balance : BigInt(userAutopool?.stakedShares);
4065
- const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0, import_utils25.formatEtherNum)(stakedBalance);
3911
+ const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0, import_utils23.formatEtherNum)(stakedBalance);
4066
3912
  const stakedNav = stakedShares * (autopoolData?.navPerShare.baseAsset || 0);
4067
3913
  const staked = convertBaseAssetToTokenPrices(
4068
3914
  stakedNav,
@@ -4070,7 +3916,7 @@ var getUserAutopools = async ({
4070
3916
  prices
4071
3917
  );
4072
3918
  const unstakedBalance = isDOLA ? userAutoDOLA?.unstaked.balance : BigInt(userAutopool?.walletShares);
4073
- const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0, import_utils25.formatEtherNum)(unstakedBalance);
3919
+ const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0, import_utils23.formatEtherNum)(unstakedBalance);
4074
3920
  const unstakedNav = unstakedShares * (autopoolData?.navPerShare.baseAsset || 0);
4075
3921
  const unstaked = convertBaseAssetToTokenPrices(
4076
3922
  unstakedNav,
@@ -4079,7 +3925,7 @@ var getUserAutopools = async ({
4079
3925
  );
4080
3926
  const stakedRatio = stakedShares / userShares;
4081
3927
  const unstakedRatio = 1 - stakedRatio;
4082
- const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * autopoolData?.apr?.base;
3928
+ const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * (autopoolData?.apr?.base ?? 0);
4083
3929
  return {
4084
3930
  name: autopoolData?.name,
4085
3931
  symbol: autopoolData?.symbol,
@@ -4111,7 +3957,7 @@ var getUserAutopools = async ({
4111
3957
  };
4112
3958
  }
4113
3959
  });
4114
- let denominatedToken = import_tokenlist8.ETH_TOKEN;
3960
+ let denominatedToken = import_tokenlist7.ETH_TOKEN;
4115
3961
  const useDenomination = userAutopoolsWithData.filter((autopool) => autopool?.useDenomination).length === 1 && userAutopoolsWithData.length === 1;
4116
3962
  if (useDenomination) {
4117
3963
  const autopoolWithDenomination = userAutopoolsWithData.find(
@@ -4121,13 +3967,16 @@ var getUserAutopools = async ({
4121
3967
  denominatedToken = autopoolWithDenomination?.denomination;
4122
3968
  }
4123
3969
  }
4124
- const nav = Object.values(categories).reduce((acc, { nav: nav2 }) => {
4125
- return Object.keys(nav2).reduce((sumAcc, key) => {
4126
- const typedKey = key;
4127
- sumAcc[typedKey] = (sumAcc[typedKey] || 0) + nav2[typedKey];
4128
- return sumAcc;
4129
- }, acc);
4130
- }, {});
3970
+ const nav = Object.values(categories).reduce(
3971
+ (acc, { nav: nav2 }) => {
3972
+ return Object.keys(nav2).reduce((sumAcc, key) => {
3973
+ const typedKey = key;
3974
+ sumAcc[typedKey] = (sumAcc[typedKey] || 0) + nav2[typedKey];
3975
+ return sumAcc;
3976
+ }, acc);
3977
+ },
3978
+ {}
3979
+ );
4131
3980
  const idleWithTokenPrices = userAutopoolsWithData.reduce(
4132
3981
  (acc, userAutopool) => {
4133
3982
  if (!userAutopool) return acc;
@@ -4155,20 +4004,26 @@ var getUserAutopools = async ({
4155
4004
  ...idle2,
4156
4005
  allocation: idle2.USD / nav.USD
4157
4006
  }));
4158
- const returns = Object.values(categories).reduce((acc, { returns: returns2 }) => {
4159
- return Object.keys(returns2).reduce((sumAcc, key) => {
4160
- const typedKey = key;
4161
- sumAcc[typedKey] = (sumAcc[typedKey] || 0) + returns2[typedKey];
4162
- return sumAcc;
4163
- }, acc);
4164
- }, {});
4165
- const supplied = Object.values(categories).reduce((acc, { supplied: supplied2 }) => {
4166
- return Object.keys(supplied2).reduce((sumAcc, key) => {
4167
- const typedKey = key;
4168
- sumAcc[typedKey] = (sumAcc[typedKey] || 0) + supplied2[typedKey];
4169
- return sumAcc;
4170
- }, acc);
4171
- }, {});
4007
+ const returns = Object.values(categories).reduce(
4008
+ (acc, { returns: returns2 }) => {
4009
+ return Object.keys(returns2).reduce((sumAcc, key) => {
4010
+ const typedKey = key;
4011
+ sumAcc[typedKey] = (sumAcc[typedKey] || 0) + returns2[typedKey];
4012
+ return sumAcc;
4013
+ }, acc);
4014
+ },
4015
+ {}
4016
+ );
4017
+ const supplied = Object.values(categories).reduce(
4018
+ (acc, { supplied: supplied2 }) => {
4019
+ return Object.keys(supplied2).reduce((sumAcc, key) => {
4020
+ const typedKey = key;
4021
+ sumAcc[typedKey] = (sumAcc[typedKey] || 0) + supplied2[typedKey];
4022
+ return sumAcc;
4023
+ }, acc);
4024
+ },
4025
+ {}
4026
+ );
4172
4027
  const userExchangesWithAllocations = Object.values(userExchanges).map(
4173
4028
  (userExchange) => {
4174
4029
  return {
@@ -4230,11 +4085,14 @@ var getUserAutopools = async ({
4230
4085
  categories[categoryKey] = {
4231
4086
  ...categoryData,
4232
4087
  apr,
4233
- avgDailyReturns: Object.keys(categoryData.nav).reduce((acc, key) => {
4234
- const typedKey = key;
4235
- acc[typedKey] = dailyRate * categoryData.nav[typedKey];
4236
- return acc;
4237
- }, {})
4088
+ avgDailyReturns: Object.keys(categoryData.nav).reduce(
4089
+ (acc, key) => {
4090
+ const typedKey = key;
4091
+ acc[typedKey] = dailyRate * categoryData.nav[typedKey];
4092
+ return acc;
4093
+ },
4094
+ {}
4095
+ )
4238
4096
  };
4239
4097
  });
4240
4098
  return {
@@ -4303,10 +4161,10 @@ var getUserTokenBalances = async ({
4303
4161
  };
4304
4162
 
4305
4163
  // functions/getTokenList.ts
4306
- var import_tokenlist9 = require("@tokemak/tokenlist");
4164
+ var import_tokenlist8 = require("@tokemak/tokenlist");
4307
4165
  var getTokenList = async () => {
4308
4166
  try {
4309
- let url = `${import_tokenlist9.TOKEMAK_LISTS_URL}/swap_enabled.json`;
4167
+ let url = `${import_tokenlist8.TOKEMAK_LISTS_URL}/swap_enabled.json`;
4310
4168
  const listResponse = await fetch(url);
4311
4169
  const { tokens: tokenList } = await listResponse.json();
4312
4170
  return tokenList;
@@ -4427,8 +4285,8 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
4427
4285
  };
4428
4286
 
4429
4287
  // functions/getUserAutopoolsRewards.ts
4430
- var import_utils29 = require("@tokemak/utils");
4431
- var import_tokenlist10 = require("@tokemak/tokenlist");
4288
+ var import_utils27 = require("@tokemak/utils");
4289
+ var import_tokenlist9 = require("@tokemak/tokenlist");
4432
4290
  var import_chains11 = require("viem/chains");
4433
4291
  var getUserAutopoolsRewards = async (wagmiConfig, {
4434
4292
  address,
@@ -4458,16 +4316,16 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4458
4316
  return [];
4459
4317
  }
4460
4318
  return autopool.extraRewarders.map((extraRewards2) => {
4461
- const rewarderToken = (0, import_utils29.getToken)(
4319
+ const rewarderToken = (0, import_utils27.getToken)(
4462
4320
  extraRewards2.rewardToken?.id,
4463
4321
  autopool.chain?.chainId
4464
4322
  );
4465
4323
  const claimableAmount = rewards ? rewards[(0, import_viem14.getAddress)(extraRewards2.rewardToken?.id)] : 0n;
4466
4324
  let price = tokenPrices[rewarderToken.symbol] || 0;
4467
4325
  if (rewarderToken.symbol === "XSILO") {
4468
- price = tokenPrices[import_tokenlist10.SILO_TOKEN.symbol] || 0;
4326
+ price = tokenPrices[import_tokenlist9.SILO_TOKEN.symbol] || 0;
4469
4327
  }
4470
- const formattedAmount = (0, import_utils29.formatUnitsNum)(
4328
+ const formattedAmount = (0, import_utils27.formatUnitsNum)(
4471
4329
  claimableAmount,
4472
4330
  rewarderToken.decimals || 18
4473
4331
  );
@@ -4485,7 +4343,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4485
4343
  const tokenRewards = {};
4486
4344
  Object.values(chainUserRewards).forEach((autopoolRewards) => {
4487
4345
  Object.entries(autopoolRewards).forEach(([tokenAddress, amount]) => {
4488
- const token = (0, import_utils29.getToken)(tokenAddress, chainId);
4346
+ const token = (0, import_utils27.getToken)(tokenAddress, chainId);
4489
4347
  const tokenSymbol = token.symbol;
4490
4348
  if (!tokenRewards[tokenSymbol]) {
4491
4349
  tokenRewards[tokenSymbol] = {
@@ -4503,9 +4361,9 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4503
4361
  ([tokenSymbol, { amount, decimals }]) => {
4504
4362
  let price = tokenPrices[tokenSymbol] || 0;
4505
4363
  if (tokenSymbol === "XSILO") {
4506
- price = tokenPrices[import_tokenlist10.SILO_TOKEN.symbol] || 0;
4364
+ price = tokenPrices[import_tokenlist9.SILO_TOKEN.symbol] || 0;
4507
4365
  }
4508
- const formattedAmount = (0, import_utils29.formatUnitsNum)(amount, decimals || 18);
4366
+ const formattedAmount = (0, import_utils27.formatUnitsNum)(amount, decimals || 18);
4509
4367
  tokenRewards[tokenSymbol] = {
4510
4368
  amount,
4511
4369
  formattedAmount,
@@ -4520,7 +4378,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4520
4378
  tokenRewards["TOKE"] = {
4521
4379
  ...undefinedToken,
4522
4380
  USD: undefinedToken.formattedAmount * price,
4523
- logoURI: import_tokenlist10.TOKE_TOKEN.logoURI
4381
+ logoURI: import_tokenlist9.TOKE_TOKEN.logoURI
4524
4382
  };
4525
4383
  delete tokenRewards["undefined"];
4526
4384
  }
@@ -4576,10 +4434,10 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4576
4434
 
4577
4435
  // functions/getAmountWithdrawn.ts
4578
4436
  var import_viem16 = require("viem");
4579
- var import_utils31 = require("@tokemak/utils");
4437
+ var import_utils29 = require("@tokemak/utils");
4580
4438
 
4581
4439
  // functions/getSwapQuote.ts
4582
- var import_constants17 = require("@tokemak/constants");
4440
+ var import_constants16 = require("@tokemak/constants");
4583
4441
 
4584
4442
  // functions/getAddressFromSystemRegistry.ts
4585
4443
  var import_core15 = require("@wagmi/core");
@@ -4606,25 +4464,25 @@ var getAutopilotRouter = async (wagmiConfig, { chainId }) => await getAddressFro
4606
4464
 
4607
4465
  // functions/getSwapQuote.ts
4608
4466
  var import_config10 = require("@tokemak/config");
4609
- var import_tokenlist11 = require("@tokemak/tokenlist");
4467
+ var import_tokenlist10 = require("@tokemak/tokenlist");
4610
4468
  var import_chains12 = require("viem/chains");
4611
4469
  var getSwapQuote = async (config, { chainId, ...params }) => {
4612
4470
  try {
4613
4471
  if (!params.sellToken || !params.buyToken) {
4614
4472
  throw new Error("Sell token and buy token are required");
4615
4473
  }
4616
- if (params.sellToken === import_tokenlist11.ETH_TOKEN.address) {
4474
+ if (params.sellToken === import_tokenlist10.ETH_TOKEN.address) {
4617
4475
  params.sellToken = (0, import_config10.getCoreConfig)(chainId).weth;
4618
4476
  if (chainId === import_chains12.sonic.id) {
4619
- params.sellToken = import_tokenlist11.WS_TOKEN.address;
4477
+ params.sellToken = import_tokenlist10.WS_TOKEN.address;
4620
4478
  }
4621
4479
  if (chainId === import_chains12.plasma.id) {
4622
- params.sellToken = import_tokenlist11.WXPL_TOKEN.address;
4480
+ params.sellToken = import_tokenlist10.WXPL_TOKEN.address;
4623
4481
  }
4624
4482
  }
4625
4483
  const sellAmount = params.sellAmount.toString();
4626
4484
  const taker = await getAutopilotRouter(config, { chainId });
4627
- const response = await fetch(import_constants17.TOKEMAK_SWAP_QUOTE_URL, {
4485
+ const response = await fetch(import_constants16.TOKEMAK_SWAP_QUOTE_URL, {
4628
4486
  method: "POST",
4629
4487
  headers: {
4630
4488
  "Content-Type": "application/json"
@@ -4655,7 +4513,7 @@ var import_abis13 = require("@tokemak/abis");
4655
4513
  var import_config11 = require("@tokemak/config");
4656
4514
  var import_autopilot_swap_route_calc = require("@tokemak/autopilot-swap-route-calc");
4657
4515
  var import_viem15 = require("viem");
4658
- var import_constants18 = require("@tokemak/constants");
4516
+ var import_constants17 = require("@tokemak/constants");
4659
4517
  var getDynamicSwap = async ({
4660
4518
  address,
4661
4519
  amount,
@@ -4679,7 +4537,7 @@ var getDynamicSwap = async ({
4679
4537
  client.transport.transports[0].value.url,
4680
4538
  address,
4681
4539
  amount,
4682
- import_constants18.LIQUIDATION_PROBE_AMOUNT
4540
+ import_constants17.LIQUIDATION_PROBE_AMOUNT
4683
4541
  );
4684
4542
  if (liquidations?.liquidations?.length > 0) {
4685
4543
  tokensToLiquidate = liquidations.liquidations;
@@ -4700,12 +4558,12 @@ var getDynamicSwap = async ({
4700
4558
  chainId,
4701
4559
  systemName: "gen3",
4702
4560
  // slippageBps: Math.floor(slippage * 10000),
4703
- slippageBps: import_constants18.DYNAMIC_SWAP_DEFAULT_SLIPPAGE_BPS,
4561
+ slippageBps: import_constants17.DYNAMIC_SWAP_DEFAULT_SLIPPAGE_BPS,
4704
4562
  tokensToLiquidate,
4705
4563
  sellAllOnlyCompatible: true
4706
4564
  })
4707
4565
  };
4708
- dynamicSwaps = await (await fetch(import_constants18.TOKEMAK_DYNAMIC_SWAP_ROUTES_URL, requestInit)).json();
4566
+ dynamicSwaps = await (await fetch(import_constants17.TOKEMAK_DYNAMIC_SWAP_ROUTES_URL, requestInit)).json();
4709
4567
  if (dynamicSwaps?.success) {
4710
4568
  const autopoolRouter = await getAutopilotRouter(config, { chainId });
4711
4569
  if (!autopoolRouter) {
@@ -4726,7 +4584,7 @@ var getDynamicSwap = async ({
4726
4584
  data: x.data
4727
4585
  }))
4728
4586
  ],
4729
- account: user || import_constants18.SIMULATION_PLACEHOLDER_ADDRESS
4587
+ account: user || import_constants17.SIMULATION_PLACEHOLDER_ADDRESS
4730
4588
  });
4731
4589
  } catch (e) {
4732
4590
  if (e instanceof import_viem15.ContractFunctionExecutionError && e.cause instanceof import_viem15.ContractFunctionRevertedError && e.cause.data?.errorName === "PreviewRedeemWithRoutesResult") {
@@ -4744,7 +4602,7 @@ var getDynamicSwap = async ({
4744
4602
  functionName: "previewRedeem",
4745
4603
  args: [amount],
4746
4604
  chainId,
4747
- account: user || import_constants18.SIMULATION_PLACEHOLDER_ADDRESS
4605
+ account: user || import_constants17.SIMULATION_PLACEHOLDER_ADDRESS
4748
4606
  });
4749
4607
  if (previewRedeemOnChain >= previewRedeem) {
4750
4608
  standardPreviewRedeem = true;
@@ -4758,7 +4616,7 @@ var getDynamicSwap = async ({
4758
4616
  };
4759
4617
 
4760
4618
  // functions/getAmountWithdrawn.ts
4761
- var import_tokenlist12 = require("@tokemak/tokenlist");
4619
+ var import_tokenlist11 = require("@tokemak/tokenlist");
4762
4620
  var import_config12 = require("@tokemak/config");
4763
4621
  var import_core17 = require("@wagmi/core");
4764
4622
  var import_abis14 = require("@tokemak/abis");
@@ -4790,13 +4648,13 @@ var getAmountWithdrawn = async ({
4790
4648
  let quote;
4791
4649
  let convertedAssets;
4792
4650
  if (!!dynamicSwap?.previewRedeem) {
4793
- const minAmountWithSlippage = (0, import_utils31.calculateMinAmountWithSlippage)(
4651
+ const minAmountWithSlippage = (0, import_utils29.calculateMinAmountWithSlippage)(
4794
4652
  dynamicSwap?.previewRedeem,
4795
4653
  slippage
4796
4654
  );
4797
4655
  let minAmount = (0, import_viem16.formatUnits)(minAmountWithSlippage, decimals);
4798
4656
  if (isSwap) {
4799
- if (buyToken === import_tokenlist12.ETH_TOKEN.address) {
4657
+ if (buyToken === import_tokenlist11.ETH_TOKEN.address) {
4800
4658
  const weth = (0, import_config12.getCoreConfig)(chainId).weth;
4801
4659
  buyToken = weth;
4802
4660
  }
@@ -4814,7 +4672,7 @@ var getAmountWithdrawn = async ({
4814
4672
  buyToken,
4815
4673
  sellToken,
4816
4674
  sellAmount: dynamicSwap?.previewRedeem,
4817
- slippageBps: (0, import_utils31.convertNumToBps)(slippage),
4675
+ slippageBps: (0, import_utils29.convertNumToBps)(slippage),
4818
4676
  chainId,
4819
4677
  includeSources: "0xV2",
4820
4678
  sellAll: true
@@ -4842,7 +4700,7 @@ var getAmountWithdrawn = async ({
4842
4700
  // functions/getAmountDeposited.ts
4843
4701
  var import_core18 = require("@wagmi/core");
4844
4702
  var import_abis15 = require("@tokemak/abis");
4845
- var import_utils32 = require("@tokemak/utils");
4703
+ var import_utils30 = require("@tokemak/utils");
4846
4704
  var getAmountDeposited = async ({
4847
4705
  address,
4848
4706
  chainId,
@@ -4863,13 +4721,13 @@ var getAmountDeposited = async ({
4863
4721
  chainId
4864
4722
  });
4865
4723
  if (!isSwap) {
4866
- let minAmountWithSlippage = (0, import_utils32.calculateMinAmountWithSlippage)(
4724
+ let minAmountWithSlippage = (0, import_utils30.calculateMinAmountWithSlippage)(
4867
4725
  previewDeposit,
4868
4726
  slippage
4869
4727
  );
4870
- return (0, import_utils32.formatEtherNum)(minAmountWithSlippage);
4728
+ return (0, import_utils30.formatEtherNum)(minAmountWithSlippage);
4871
4729
  } else {
4872
- return (0, import_utils32.formatEtherNum)(previewDeposit);
4730
+ return (0, import_utils30.formatEtherNum)(previewDeposit);
4873
4731
  }
4874
4732
  } catch (e) {
4875
4733
  console.error(e);
@@ -4987,7 +4845,7 @@ var waitForMessageReceived = async ({
4987
4845
  // functions/getChainUserSToke.ts
4988
4846
  var import_abis18 = require("@tokemak/abis");
4989
4847
  var import_config13 = require("@tokemak/config");
4990
- var import_utils33 = require("@tokemak/utils");
4848
+ var import_utils31 = require("@tokemak/utils");
4991
4849
  var import_core21 = require("@wagmi/core");
4992
4850
  var import_viem18 = require("viem");
4993
4851
  var import_chains13 = require("viem/chains");
@@ -5063,8 +4921,8 @@ var getChainUserSToke = async (wagmiConfig, {
5063
4921
  if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
5064
4922
  balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
5065
4923
  }
5066
- const withdrawalAmountUsd = (0, import_utils33.formatCurrency)(
5067
- (0, import_utils33.formatEtherNum)(withdrawalAmount) * tokePrice
4924
+ const withdrawalAmountUsd = (0, import_utils31.formatCurrency)(
4925
+ (0, import_utils31.formatEtherNum)(withdrawalAmount) * tokePrice
5068
4926
  );
5069
4927
  const lockDuration = Number(depositLockDuration);
5070
4928
  const lockCycle = Number(depositLockCycle);
@@ -5085,16 +4943,16 @@ var getChainUserSToke = async (wagmiConfig, {
5085
4943
  const withdrawAvailable = lockRenew - 1;
5086
4944
  const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
5087
4945
  const addedLockedToke = depositAmount - rolloverDepositAmount;
5088
- const balanceUSD = (0, import_utils33.formatCurrency)(
4946
+ const balanceUSD = (0, import_utils31.formatCurrency)(
5089
4947
  Number((0, import_viem18.formatEther)(balanceExcludingWithdrawal)) * tokePrice
5090
4948
  );
5091
- const balanceExcludingWithdrawalUsd = (0, import_utils33.formatCurrency)(
5092
- (0, import_utils33.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
4949
+ const balanceExcludingWithdrawalUsd = (0, import_utils31.formatCurrency)(
4950
+ (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
5093
4951
  );
5094
4952
  const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
5095
4953
  const hasRequestedUnlock = withdrawalAmount > 0n;
5096
- const unlockRequestPeriodStartUnix = (0, import_utils33.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
5097
- const unlockRequestPeriodEndUnix = (0, import_utils33.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
4954
+ const unlockRequestPeriodStartUnix = (0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
4955
+ const unlockRequestPeriodEndUnix = (0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
5098
4956
  const hasBalance = balance > 0n;
5099
4957
  const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
5100
4958
  const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
@@ -5104,8 +4962,8 @@ var getChainUserSToke = async (wagmiConfig, {
5104
4962
  lockDurationInMonths = lockDuration - 1;
5105
4963
  }
5106
4964
  const unlockPeriodDateRangeArray = [
5107
- new Date((0, import_utils33.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
5108
- new Date((0, import_utils33.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
4965
+ new Date((0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
4966
+ new Date((0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
5109
4967
  ];
5110
4968
  const {
5111
4969
  unlockPeriodDateRange,
@@ -5117,18 +4975,18 @@ var getChainUserSToke = async (wagmiConfig, {
5117
4975
  unlockPeriodDateRangeArray,
5118
4976
  chainId === import_chains13.sepolia.id ? "time" : "date"
5119
4977
  );
5120
- const totalActiveUserCredits = (0, import_utils33.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
5121
- const totalUserCredits = (0, import_utils33.formatEtherNum)(balance) * lockDurationInMonths;
4978
+ const totalActiveUserCredits = (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
4979
+ const totalUserCredits = (0, import_utils31.formatEtherNum)(balance) * lockDurationInMonths;
5122
4980
  return {
5123
4981
  balance,
5124
4982
  balanceUSD,
5125
4983
  balanceExcludingWithdrawal: hasBalance ? (0, import_viem18.formatEther)(balanceExcludingWithdrawal) : "0.00",
5126
4984
  balanceExcludingWithdrawalUsd,
5127
4985
  hasBalanceExcludingWithdrawal,
5128
- timeLeftBeforeUnlockRequestAvailable: (0, import_utils33.convertSecondsToRemainingTime)(
4986
+ timeLeftBeforeUnlockRequestAvailable: (0, import_utils31.convertSecondsToRemainingTime)(
5129
4987
  unlockRequestPeriodStartUnix
5130
4988
  ),
5131
- timeLeftBeforeUnlockRequestUnavailable: (0, import_utils33.convertSecondsToRemainingTime)(
4989
+ timeLeftBeforeUnlockRequestUnavailable: (0, import_utils31.convertSecondsToRemainingTime)(
5132
4990
  unlockRequestPeriodEndUnix
5133
4991
  ),
5134
4992
  withdrawalAmount,
@@ -5145,7 +5003,7 @@ var getChainUserSToke = async (wagmiConfig, {
5145
5003
  unlockRenewalDate,
5146
5004
  lockDurationInMonths,
5147
5005
  boost: lockDuration,
5148
- points: (0, import_utils33.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
5006
+ points: (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
5149
5007
  totalActiveCredits: totalActiveUserCredits,
5150
5008
  totalCredits: totalUserCredits
5151
5009
  };
@@ -5157,7 +5015,7 @@ var getChainUserSToke = async (wagmiConfig, {
5157
5015
  };
5158
5016
 
5159
5017
  // functions/getUserSToke.ts
5160
- var import_utils35 = require("@tokemak/utils");
5018
+ var import_utils33 = require("@tokemak/utils");
5161
5019
  var getUserSToke = async (wagmiConfig, {
5162
5020
  address,
5163
5021
  tokePrice,
@@ -5184,8 +5042,8 @@ var getUserSToke = async (wagmiConfig, {
5184
5042
  }
5185
5043
  return acc;
5186
5044
  }, 0n);
5187
- const totalBalance = (0, import_utils35.formatEtherNum)(totalBalanceRaw || 0n);
5188
- const totalBalanceUsd = (0, import_utils35.formatCurrency)(totalBalance * tokePrice);
5045
+ const totalBalance = (0, import_utils33.formatEtherNum)(totalBalanceRaw || 0n);
5046
+ const totalBalanceUsd = (0, import_utils33.formatCurrency)(totalBalance * tokePrice);
5189
5047
  const hasBalance = totalBalance > 0;
5190
5048
  return {
5191
5049
  chains: { ...userSToke },
@@ -5202,9 +5060,9 @@ var getUserSToke = async (wagmiConfig, {
5202
5060
  var import_viem19 = require("viem");
5203
5061
  var import_core22 = require("@wagmi/core");
5204
5062
  var import_abis19 = require("@tokemak/abis");
5205
- var import_utils37 = require("@tokemak/utils");
5063
+ var import_utils35 = require("@tokemak/utils");
5206
5064
  var import_config14 = require("@tokemak/config");
5207
- var import_utils38 = require("@tokemak/utils");
5065
+ var import_utils36 = require("@tokemak/utils");
5208
5066
  var getChainSToke = async (wagmiConfig, {
5209
5067
  tokePrice,
5210
5068
  chainId
@@ -5230,15 +5088,15 @@ var getChainSToke = async (wagmiConfig, {
5230
5088
  ]
5231
5089
  });
5232
5090
  const tvl = Number((0, import_viem19.formatEther)(totalSupply || 0n)) * tokePrice;
5233
- const secondsLeftBeforeNextCycle = (0, import_utils37.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
5091
+ const secondsLeftBeforeNextCycle = (0, import_utils35.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
5234
5092
  return {
5235
5093
  rawTotalSupply: totalSupply,
5236
- totalSupply: (0, import_utils37.formatLargeNumber)((0, import_viem19.formatEther)(totalSupply || 0n)),
5237
- tvl: (0, import_utils37.formatTVL)(tvl),
5094
+ totalSupply: (0, import_utils35.formatLargeNumber)((0, import_viem19.formatEther)(totalSupply || 0n)),
5095
+ tvl: (0, import_utils35.formatTVL)(tvl),
5238
5096
  rawTVL: tvl,
5239
5097
  currentCycle,
5240
- chain: (0, import_utils38.getNetwork)(chainId),
5241
- timeBeforeNextCycle: (0, import_utils37.convertSecondsToRemainingTime)(
5098
+ chain: (0, import_utils36.getNetwork)(chainId),
5099
+ timeBeforeNextCycle: (0, import_utils35.convertSecondsToRemainingTime)(
5242
5100
  secondsLeftBeforeNextCycle
5243
5101
  )
5244
5102
  };
@@ -5249,7 +5107,7 @@ var getChainSToke = async (wagmiConfig, {
5249
5107
  };
5250
5108
 
5251
5109
  // functions/getSToke.ts
5252
- var import_utils39 = require("@tokemak/utils");
5110
+ var import_utils37 = require("@tokemak/utils");
5253
5111
  var import_viem20 = require("viem");
5254
5112
  var getSToke = async (wagmiConfig, {
5255
5113
  tokePrice,
@@ -5269,14 +5127,14 @@ var getSToke = async (wagmiConfig, {
5269
5127
  }
5270
5128
  return acc;
5271
5129
  }, 0n);
5272
- const totalSupply = (0, import_utils39.formatLargeNumber)((0, import_viem20.formatEther)(totalSupplyBigInt || 0n));
5130
+ const totalSupply = (0, import_utils37.formatLargeNumber)((0, import_viem20.formatEther)(totalSupplyBigInt || 0n));
5273
5131
  let tvlNum = Object.values(sToke).reduce((acc, item) => {
5274
5132
  if (item && item.rawTVL) {
5275
5133
  return acc + item.rawTVL;
5276
5134
  }
5277
5135
  return acc;
5278
5136
  }, 0);
5279
- const tvl = (0, import_utils39.formatTVL)(tvlNum);
5137
+ const tvl = (0, import_utils37.formatTVL)(tvlNum);
5280
5138
  return { totalSupply, rawTotalSupply: totalSupplyBigInt, tvl, rawTVL: tvlNum, chains: { ...sToke } };
5281
5139
  } catch (e) {
5282
5140
  console.error(e);
@@ -5330,7 +5188,7 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
5330
5188
  // functions/getChainSTokeRewards.ts
5331
5189
  var import_config15 = require("@tokemak/config");
5332
5190
  var import_viem21 = require("viem");
5333
- var import_utils41 = require("@tokemak/utils");
5191
+ var import_utils39 = require("@tokemak/utils");
5334
5192
  var import_graph_cli15 = require("@tokemak/graph-cli");
5335
5193
  var getChainSTokeRewards = async ({
5336
5194
  chainId
@@ -5354,9 +5212,9 @@ var getChainSTokeRewards = async ({
5354
5212
  if (!whitelistedPools.includes(pool.id.toLowerCase())) {
5355
5213
  continue;
5356
5214
  }
5357
- const convertedBalance = (0, import_utils41.formatEtherNum)(pool.balance);
5215
+ const convertedBalance = (0, import_utils39.formatEtherNum)(pool.balance);
5358
5216
  const convertedBalanceUSD = Number((0, import_viem21.formatUnits)(pool.balanceUSD, 8));
5359
- const convertedApr = (0, import_utils41.formatEtherNum)(pool.currentAprPerCredit);
5217
+ const convertedApr = (0, import_utils39.formatEtherNum)(pool.currentAprPerCredit);
5360
5218
  if (minApr === null || convertedApr < minApr) {
5361
5219
  minApr = convertedApr;
5362
5220
  }
@@ -5430,7 +5288,7 @@ var getSTokeRewards = async ({
5430
5288
 
5431
5289
  // functions/getChainUserSTokeRewards.ts
5432
5290
  var import_config16 = require("@tokemak/config");
5433
- var import_utils44 = require("@tokemak/utils");
5291
+ var import_utils42 = require("@tokemak/utils");
5434
5292
  var getChainUserSTokeRewards = async (wagmiConfig, {
5435
5293
  address,
5436
5294
  chainId,
@@ -5481,14 +5339,14 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
5481
5339
  throw fallbackError;
5482
5340
  }
5483
5341
  }
5484
- const claimableNum = (0, import_utils44.formatEtherNum)(tokeRewards?.claimable || 0n);
5342
+ const claimableNum = (0, import_utils42.formatEtherNum)(tokeRewards?.claimable || 0n);
5485
5343
  const claimableUsd = tokePrice * claimableNum;
5486
5344
  const hasClaimable = claimableNum > 0n;
5487
- const pendingRewards = (0, import_utils44.formatEtherNum)(
5345
+ const pendingRewards = (0, import_utils42.formatEtherNum)(
5488
5346
  tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
5489
5347
  );
5490
5348
  const pendingRewardsUsd = tokePrice * pendingRewards;
5491
- const totalRewardsReceived = (0, import_utils44.formatEtherNum)(
5349
+ const totalRewardsReceived = (0, import_utils42.formatEtherNum)(
5492
5350
  tokeRewards.rewardsPayload.payload.amount || 0n
5493
5351
  );
5494
5352
  const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
@@ -5504,6 +5362,56 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
5504
5362
  };
5505
5363
  };
5506
5364
 
5365
+ // functions/getTokenPrices.ts
5366
+ var import_tokenlist12 = require("@tokemak/tokenlist");
5367
+ var import_constants18 = require("@tokemak/constants");
5368
+ var getTokenPrices = async () => {
5369
+ try {
5370
+ const body = {
5371
+ tokens: import_tokenlist12.PRICED_TOKENS.map((asset) => ({
5372
+ token: asset.address,
5373
+ chainId: asset.chainId,
5374
+ systemName: "gen3",
5375
+ timeoutMS: 5 * 1e3
5376
+ }))
5377
+ };
5378
+ const response = await fetch(`${import_constants18.TOKEMAK_PRICES_STAGING_URL}`, {
5379
+ method: "POST",
5380
+ headers: {
5381
+ "Content-Type": "application/json"
5382
+ },
5383
+ body: JSON.stringify(body)
5384
+ });
5385
+ const data = await response.json();
5386
+ const prices = import_tokenlist12.PRICED_TOKENS.reduce((acc, asset) => {
5387
+ const priceData = data.find(
5388
+ (item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
5389
+ );
5390
+ acc[asset.symbol] = priceData?.price ?? 0;
5391
+ return acc;
5392
+ }, {});
5393
+ const timestamp = Math.floor(Date.now() / 1e3);
5394
+ return {
5395
+ timestamp,
5396
+ isStale: false,
5397
+ prices: {
5398
+ ...prices,
5399
+ WETH: prices.ETH,
5400
+ WS: prices.S,
5401
+ WXPL: prices.XPL,
5402
+ WMON: prices.MON
5403
+ }
5404
+ };
5405
+ } catch (e) {
5406
+ console.error("getTokenPrices failed:", e);
5407
+ return {
5408
+ prices: void 0,
5409
+ timestamp: void 0,
5410
+ isStale: false
5411
+ };
5412
+ }
5413
+ };
5414
+
5507
5415
  // functions/getChainSubgraphStatus.ts
5508
5416
  var import_graph_cli16 = require("@tokemak/graph-cli");
5509
5417
  var getChainSubgraphStatus = async (chain) => {
@@ -5564,7 +5472,7 @@ var getSubgraphStatus = async (includeTestnet = false) => {
5564
5472
  var import_core24 = require("@wagmi/core");
5565
5473
  var import_abis21 = require("@tokemak/abis");
5566
5474
  var import_viem22 = require("viem");
5567
- var import_utils46 = require("@tokemak/utils");
5475
+ var import_utils44 = require("@tokemak/utils");
5568
5476
  var import_config17 = require("@tokemak/config");
5569
5477
  var import_chains14 = require("viem/chains");
5570
5478
  var publicClient = (0, import_viem22.createPublicClient)({
@@ -5598,11 +5506,11 @@ var getCycleV1 = async (wagmiConfig, {
5598
5506
  });
5599
5507
  const rolloverEvents = await publicClient.getFilterLogs({ filter });
5600
5508
  const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
5601
- const secondsLeftBeforeNextCycle = (0, import_utils46.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
5509
+ const secondsLeftBeforeNextCycle = (0, import_utils44.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
5602
5510
  return {
5603
5511
  currentCycleIndex,
5604
5512
  cycleRolloverBlockNumber,
5605
- timeBeforeNextCycle: (0, import_utils46.convertSecondsToRemainingTime)(
5513
+ timeBeforeNextCycle: (0, import_utils44.convertSecondsToRemainingTime)(
5606
5514
  secondsLeftBeforeNextCycle
5607
5515
  )
5608
5516
  };
@@ -5613,7 +5521,7 @@ var getCycleV1 = async (wagmiConfig, {
5613
5521
  };
5614
5522
 
5615
5523
  // functions/getProtocolStats.ts
5616
- var import_utils47 = require("@tokemak/utils");
5524
+ var import_utils45 = require("@tokemak/utils");
5617
5525
  var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
5618
5526
  try {
5619
5527
  if (!autopools || !stoke || !sushiLP) {
@@ -5643,12 +5551,12 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
5643
5551
  Object.entries(categories).map(([key, value]) => [
5644
5552
  key,
5645
5553
  {
5646
- tvl: (0, import_utils47.formatTVL)(value.tvl),
5647
- supply: (0, import_utils47.formatLargeNumber)(value.supply || 0)
5554
+ tvl: (0, import_utils45.formatTVL)(value.tvl),
5555
+ supply: (0, import_utils45.formatLargeNumber)(value.supply || 0)
5648
5556
  }
5649
5557
  ])
5650
5558
  );
5651
- const tvl = (0, import_utils47.formatTVL)(
5559
+ const tvl = (0, import_utils45.formatTVL)(
5652
5560
  autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0) + (EthAutoLP?.tvlUsd || 0) + (sauto?.rawTVL || 0)
5653
5561
  );
5654
5562
  const vaultAddresses = autopools?.flatMap(
@@ -5657,33 +5565,33 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
5657
5565
  const uniqueVaultAddresses = [...new Set(vaultAddresses)];
5658
5566
  const totalDestinations = uniqueVaultAddresses.length;
5659
5567
  const stakedTVL = {
5660
- totalSupply: (0, import_utils47.formatLargeNumber)(
5661
- (0, import_utils47.formatEtherNum)(
5568
+ totalSupply: (0, import_utils45.formatLargeNumber)(
5569
+ (0, import_utils45.formatEtherNum)(
5662
5570
  (sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
5663
5571
  )
5664
5572
  ),
5665
- tvl: (0, import_utils47.formatTVL)((sauto?.rawTVL || 0) + stoke.rawTVL)
5573
+ tvl: (0, import_utils45.formatTVL)((sauto?.rawTVL || 0) + stoke.rawTVL)
5666
5574
  };
5667
5575
  return {
5668
5576
  autopools: {
5669
- tvl: (0, import_utils47.formatTVL)(autopoolTVL),
5577
+ tvl: (0, import_utils45.formatTVL)(autopoolTVL),
5670
5578
  tvlNum: autopoolTVL,
5671
5579
  categories: formattedCategories
5672
5580
  },
5673
5581
  stoke: {
5674
- tvl: (0, import_utils47.formatTVL)(stoke.rawTVL),
5582
+ tvl: (0, import_utils45.formatTVL)(stoke.rawTVL),
5675
5583
  tvlNum: stoke.rawTVL,
5676
5584
  totalSupply: `${stoke.totalSupply} TOKE`
5677
5585
  },
5678
5586
  sushiLP: {
5679
- tvl: (0, import_utils47.formatTVL)(sushiLP?.tvl || 0),
5587
+ tvl: (0, import_utils45.formatTVL)(sushiLP?.tvl || 0),
5680
5588
  totalSupply: sushiLP?.totalSupply || 0
5681
5589
  },
5682
5590
  EthAutoLP: {
5683
- tvl: (0, import_utils47.formatTVL)(EthAutoLP?.tvlUsd || 0)
5591
+ tvl: (0, import_utils45.formatTVL)(EthAutoLP?.tvlUsd || 0)
5684
5592
  },
5685
5593
  sauto: {
5686
- tvl: (0, import_utils47.formatTVL)(sauto?.rawTVL || 0),
5594
+ tvl: (0, import_utils45.formatTVL)(sauto?.rawTVL || 0),
5687
5595
  tvlNum: sauto?.rawTVL || 0,
5688
5596
  totalSupply: `${sauto?.totalSupply} AUTO`
5689
5597
  },
@@ -5702,27 +5610,25 @@ var import_graph_cli17 = require("@tokemak/graph-cli");
5702
5610
 
5703
5611
  // functions/getEthPriceAtBlock.ts
5704
5612
  var import_config18 = require("@tokemak/config");
5705
- var import_core25 = require("@wagmi/core");
5706
5613
  var import_abis22 = require("@tokemak/abis");
5707
5614
  var import_tokenlist13 = require("@tokemak/tokenlist");
5708
- var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
5615
+ var getEthPriceAtBlock = async (client, blockNumber, chainId) => {
5709
5616
  const config = (0, import_config18.getCoreConfig)(chainId);
5710
5617
  const rootPriceOracle = config.rootPriceOracle;
5711
5618
  const weth = config.weth;
5712
5619
  const usdc = import_tokenlist13.USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || import_tokenlist13.USDC_TOKEN.address;
5713
- const priceAtBlock = await (0, import_core25.readContract)(wagmiConfig, {
5620
+ const priceAtBlock = await client.readContract({
5714
5621
  address: rootPriceOracle,
5715
5622
  abi: import_abis22.rootPriceOracleAbi,
5716
5623
  functionName: "getPriceInQuote",
5717
5624
  args: [weth, usdc],
5718
- blockNumber,
5719
- chainId
5625
+ blockNumber
5720
5626
  });
5721
5627
  return priceAtBlock;
5722
5628
  };
5723
5629
 
5724
5630
  // functions/getRebalanceStats.ts
5725
- var import_utils49 = require("@tokemak/utils");
5631
+ var import_utils47 = require("@tokemak/utils");
5726
5632
  var import_tokenlist14 = require("@tokemak/tokenlist");
5727
5633
  var import_chains15 = require("viem/chains");
5728
5634
  var BATCH_SIZE = 500;
@@ -5746,17 +5652,17 @@ function inferBaseAssetDecimals(rebalance, chainId) {
5746
5652
  }
5747
5653
  return import_tokenlist14.USDC_TOKEN.decimals;
5748
5654
  }
5749
- var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
5655
+ var getRebalanceValueUsd = async (rebalance, chainId, client) => {
5750
5656
  const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
5751
5657
  if (ethWei === 0n) return null;
5752
5658
  try {
5753
5659
  const price = await getEthPriceAtBlock(
5754
- wagmiConfig,
5660
+ client,
5755
5661
  BigInt(rebalance.blockNumber),
5756
5662
  chainId
5757
5663
  );
5758
- const ethUsd = Number((0, import_utils49.formatUnitsNum)(price, import_tokenlist14.USDC_TOKEN.decimals));
5759
- const ethAmt = Number((0, import_utils49.formatEtherNum)(ethWei));
5664
+ const ethUsd = Number((0, import_utils47.formatUnitsNum)(price, import_tokenlist14.USDC_TOKEN.decimals));
5665
+ const ethAmt = Number((0, import_utils47.formatEtherNum)(ethWei));
5760
5666
  const usd = ethAmt * ethUsd;
5761
5667
  return usd;
5762
5668
  } catch (e) {
@@ -5764,19 +5670,15 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
5764
5670
  return null;
5765
5671
  }
5766
5672
  };
5767
- var processRebalance = async (rebalance, chainId, wagmiConfig) => {
5673
+ var processRebalance = async (rebalance, chainId, client) => {
5768
5674
  const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
5769
5675
  const baseAssetAmount = Number(
5770
- (0, import_utils49.formatUnitsNum)(
5676
+ (0, import_utils47.formatUnitsNum)(
5771
5677
  BigInt(rebalance.tokenOutValueBaseAsset || "0"),
5772
5678
  baseDecimals
5773
5679
  )
5774
5680
  );
5775
- const ethPathUsd = await getRebalanceValueUsd(
5776
- rebalance,
5777
- chainId,
5778
- wagmiConfig
5779
- );
5681
+ const ethPathUsd = await getRebalanceValueUsd(rebalance, chainId, client);
5780
5682
  if (ethPathUsd != null) {
5781
5683
  return {
5782
5684
  autopool: rebalance.autopool,
@@ -5796,12 +5698,12 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
5796
5698
  valueInAsset: baseAssetAmount
5797
5699
  };
5798
5700
  };
5799
- var processRebalancesInBatches = async (rebalances, chainId, wagmiConfig) => {
5701
+ var processRebalancesInBatches = async (rebalances, chainId, client) => {
5800
5702
  const processedRebalances = [];
5801
5703
  for (let i = 0; i < rebalances.length; i += BATCH_SIZE) {
5802
5704
  const batch = rebalances.slice(i, i + BATCH_SIZE);
5803
5705
  const batchPromises = batch.map(
5804
- async (rebalance) => processRebalance(rebalance, chainId, wagmiConfig)
5706
+ async (rebalance) => processRebalance(rebalance, chainId, client)
5805
5707
  );
5806
5708
  const batchResults = await Promise.all(batchPromises);
5807
5709
  processedRebalances.push(...batchResults);
@@ -5826,18 +5728,15 @@ var calculateRebalanceStats = (rebalances) => {
5826
5728
  rebalances
5827
5729
  };
5828
5730
  };
5829
- var getRebalanceStats = async (wagmiConfig, {
5731
+ var getRebalanceStats = async (getClient, {
5830
5732
  includeTestnet = false
5831
5733
  }) => {
5832
5734
  const chains = getChainsForEnv({ includeTestnet });
5833
5735
  const rebalances = await Promise.all(
5834
5736
  chains.map(async (chain) => {
5835
5737
  const rawRebalances = await fetchChainRebalances(chain.chainId);
5836
- return processRebalancesInBatches(
5837
- rawRebalances,
5838
- chain.chainId,
5839
- wagmiConfig
5840
- );
5738
+ const client = getClient(chain.chainId);
5739
+ return processRebalancesInBatches(rawRebalances, chain.chainId, client);
5841
5740
  })
5842
5741
  );
5843
5742
  const allRebalances = rebalances.flat();
@@ -5845,6 +5744,7 @@ var getRebalanceStats = async (wagmiConfig, {
5845
5744
  };
5846
5745
 
5847
5746
  // functions/updateRebalanceStats.ts
5747
+ var import_core25 = require("@wagmi/core");
5848
5748
  var updateRebalanceStats = async (wagmiConfig, {
5849
5749
  currentRebalances,
5850
5750
  includeTestnet = false
@@ -5859,10 +5759,13 @@ var updateRebalanceStats = async (wagmiConfig, {
5859
5759
  )
5860
5760
  );
5861
5761
  if (newRawRebalances.length > 0) {
5762
+ const client = (0, import_core25.getPublicClient)(wagmiConfig, {
5763
+ chainId: chain.chainId
5764
+ });
5862
5765
  return processRebalancesInBatches(
5863
5766
  newRawRebalances,
5864
5767
  chain.chainId,
5865
- wagmiConfig
5768
+ client
5866
5769
  );
5867
5770
  }
5868
5771
  return [];
@@ -5876,7 +5779,7 @@ var updateRebalanceStats = async (wagmiConfig, {
5876
5779
  // functions/getUserSAuto.ts
5877
5780
  var import_abis23 = require("@tokemak/abis");
5878
5781
  var import_config19 = require("@tokemak/config");
5879
- var import_utils51 = require("@tokemak/utils");
5782
+ var import_utils49 = require("@tokemak/utils");
5880
5783
  var import_core26 = require("@wagmi/core");
5881
5784
  var import_viem23 = require("viem");
5882
5785
  var import_chains16 = require("viem/chains");
@@ -5938,8 +5841,8 @@ var getUserSAuto = async (wagmiConfig, {
5938
5841
  if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
5939
5842
  balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
5940
5843
  }
5941
- const withdrawalAmountUsd = (0, import_utils51.formatCurrency)(
5942
- (0, import_utils51.formatEtherNum)(withdrawalAmount) * autoPrice
5844
+ const withdrawalAmountUsd = (0, import_utils49.formatCurrency)(
5845
+ (0, import_utils49.formatEtherNum)(withdrawalAmount) * autoPrice
5943
5846
  );
5944
5847
  const lockDuration = Number(depositLockDuration);
5945
5848
  const lockCycle = Number(depositLockCycle);
@@ -5949,24 +5852,24 @@ var getUserSAuto = async (wagmiConfig, {
5949
5852
  const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
5950
5853
  const lockRenew = currentCycle - lockStart > lockDuration ? currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement : currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd;
5951
5854
  const withdrawAvailable = lockRenew - 1;
5952
- const balanceUSD = (0, import_utils51.formatCurrency)(
5855
+ const balanceUSD = (0, import_utils49.formatCurrency)(
5953
5856
  Number((0, import_viem23.formatEther)(balanceExcludingWithdrawal)) * autoPrice
5954
5857
  );
5955
- const balanceExcludingWithdrawalUsd = (0, import_utils51.formatCurrency)(
5956
- (0, import_utils51.formatEtherNum)(balanceExcludingWithdrawal) * autoPrice
5858
+ const balanceExcludingWithdrawalUsd = (0, import_utils49.formatCurrency)(
5859
+ (0, import_utils49.formatEtherNum)(balanceExcludingWithdrawal) * autoPrice
5957
5860
  );
5958
5861
  const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
5959
5862
  const hasRequestedUnlock = withdrawalAmount > 0n;
5960
- const unlockRequestPeriodStartUnix = (0, import_utils51.convertAutoCycleToUnix)(withdrawAvailable) - Date.now() / 1e3;
5961
- const unlockRequestPeriodEndUnix = (0, import_utils51.convertAutoCycleToUnix)(lockRenew) - Date.now() / 1e3;
5863
+ const unlockRequestPeriodStartUnix = (0, import_utils49.convertAutoCycleToUnix)(withdrawAvailable) - Date.now() / 1e3;
5864
+ const unlockRequestPeriodEndUnix = (0, import_utils49.convertAutoCycleToUnix)(lockRenew) - Date.now() / 1e3;
5962
5865
  const hasBalance = balance > 0n;
5963
5866
  const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
5964
5867
  const hasUnlockableBalance = withdrawalMinCycle <= BigInt(currentCycle) && withdrawalAmount > 0n;
5965
5868
  const cyclesInAMonth = 4;
5966
5869
  const lockDurationInMonths = lockDuration / cyclesInAMonth;
5967
5870
  const unlockPeriodDateRangeArray = [
5968
- new Date((0, import_utils51.convertAutoCycleToUnix)(withdrawAvailable) * 1e3),
5969
- new Date((0, import_utils51.convertAutoCycleToUnix)(lockRenew) * 1e3)
5871
+ new Date((0, import_utils49.convertAutoCycleToUnix)(withdrawAvailable) * 1e3),
5872
+ new Date((0, import_utils49.convertAutoCycleToUnix)(lockRenew) * 1e3)
5970
5873
  ];
5971
5874
  const {
5972
5875
  unlockPeriodDateRange,
@@ -5975,20 +5878,20 @@ var getUserSAuto = async (wagmiConfig, {
5975
5878
  unlockPeriodStartDate,
5976
5879
  unlockRenewalDate
5977
5880
  } = formatDateRange(unlockPeriodDateRangeArray, "date");
5978
- const totalActiveUserCredits = (0, import_utils51.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
5979
- const totalUserCredits = (0, import_utils51.formatEtherNum)(balance) * lockDurationInMonths;
5881
+ const totalActiveUserCredits = (0, import_utils49.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
5882
+ const totalUserCredits = (0, import_utils49.formatEtherNum)(balance) * lockDurationInMonths;
5980
5883
  const hasAddedLockedAuto = depositAmount > 0n;
5981
5884
  const addedLockedAuto = depositAmount;
5982
5885
  return {
5983
5886
  balance,
5984
5887
  balanceUSD,
5985
- balanceExcludingWithdrawal: hasBalance ? (0, import_utils51.formatAmount)((0, import_viem23.formatEther)(balanceExcludingWithdrawal)) : "0.00",
5888
+ balanceExcludingWithdrawal: hasBalance ? (0, import_viem23.formatEther)(balanceExcludingWithdrawal) : "0.00",
5986
5889
  balanceExcludingWithdrawalUsd,
5987
5890
  hasBalanceExcludingWithdrawal,
5988
- timeLeftBeforeUnlockRequestAvailable: (0, import_utils51.convertSecondsToRemainingTime)(
5891
+ timeLeftBeforeUnlockRequestAvailable: (0, import_utils49.convertSecondsToRemainingTime)(
5989
5892
  unlockRequestPeriodStartUnix
5990
5893
  ),
5991
- timeLeftBeforeUnlockRequestUnavailable: (0, import_utils51.convertSecondsToRemainingTime)(
5894
+ timeLeftBeforeUnlockRequestUnavailable: (0, import_utils49.convertSecondsToRemainingTime)(
5992
5895
  unlockRequestPeriodEndUnix
5993
5896
  ),
5994
5897
  withdrawalAmount,
@@ -6005,7 +5908,7 @@ var getUserSAuto = async (wagmiConfig, {
6005
5908
  unlockRenewalDate,
6006
5909
  lockDurationInMonths,
6007
5910
  boost: lockDuration,
6008
- points: (0, import_utils51.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
5911
+ points: (0, import_utils49.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
6009
5912
  totalActiveCredits: totalActiveUserCredits,
6010
5913
  totalCredits: totalUserCredits,
6011
5914
  hasBalance
@@ -6020,7 +5923,7 @@ var getUserSAuto = async (wagmiConfig, {
6020
5923
  var import_viem24 = require("viem");
6021
5924
  var import_core27 = require("@wagmi/core");
6022
5925
  var import_abis24 = require("@tokemak/abis");
6023
- var import_utils53 = require("@tokemak/utils");
5926
+ var import_utils51 = require("@tokemak/utils");
6024
5927
  var import_config20 = require("@tokemak/config");
6025
5928
  var import_chains17 = require("viem/chains");
6026
5929
  var getSAuto = async (wagmiConfig, {
@@ -6048,14 +5951,14 @@ var getSAuto = async (wagmiConfig, {
6048
5951
  ]
6049
5952
  });
6050
5953
  const tvl = Number((0, import_viem24.formatEther)(totalSupply || 0n)) * autoPrice;
6051
- const secondsLeftBeforeNextCycle = (0, import_utils53.convertAutoCycleToUnix)(Number(currentCycle) + 1) - Date.now() / 1e3;
5954
+ const secondsLeftBeforeNextCycle = (0, import_utils51.convertAutoCycleToUnix)(Number(currentCycle) + 1) - Date.now() / 1e3;
6052
5955
  return {
6053
5956
  rawTotalSupply: totalSupply,
6054
- totalSupply: (0, import_utils53.formatLargeNumber)((0, import_viem24.formatEther)(totalSupply || 0n)),
6055
- tvl: (0, import_utils53.formatTVL)(tvl),
5957
+ totalSupply: (0, import_utils51.formatLargeNumber)((0, import_viem24.formatEther)(totalSupply || 0n)),
5958
+ tvl: (0, import_utils51.formatTVL)(tvl),
6056
5959
  rawTVL: tvl,
6057
5960
  currentCycle,
6058
- timeBeforeNextCycle: (0, import_utils53.convertSecondsToRemainingTime)(
5961
+ timeBeforeNextCycle: (0, import_utils51.convertSecondsToRemainingTime)(
6059
5962
  secondsLeftBeforeNextCycle
6060
5963
  )
6061
5964
  };
@@ -6067,7 +5970,7 @@ var getSAuto = async (wagmiConfig, {
6067
5970
 
6068
5971
  // functions/getSAutoRewards.ts
6069
5972
  var import_viem25 = require("viem");
6070
- var import_utils54 = require("@tokemak/utils");
5973
+ var import_utils52 = require("@tokemak/utils");
6071
5974
  var import_graph_cli18 = require("@tokemak/graph-cli");
6072
5975
  var import_chains18 = require("viem/chains");
6073
5976
  var getSAutoRewards = async () => {
@@ -6079,7 +5982,7 @@ var getSAutoRewards = async () => {
6079
5982
  "globalRewardsBalanceDayDatas"
6080
5983
  );
6081
5984
  const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
6082
- return acc + (0, import_utils54.formatEtherNum)(balance.balance);
5985
+ return acc + (0, import_utils52.formatEtherNum)(balance.balance);
6083
5986
  }, 0);
6084
5987
  const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
6085
5988
  return acc + Number((0, import_viem25.formatUnits)(balance.balanceUSD, 8));
@@ -6087,13 +5990,13 @@ var getSAutoRewards = async () => {
6087
5990
  const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
6088
5991
  (dayData) => ({
6089
5992
  timestamp: String(dayData.timestamp),
6090
- balance: (0, import_utils54.formatEtherNum)(dayData.balance),
5993
+ balance: (0, import_utils52.formatEtherNum)(dayData.balance),
6091
5994
  balanceUSD: Number((0, import_viem25.formatUnits)(dayData.balanceUSD, 8)),
6092
- earned: (0, import_utils54.formatEtherNum)(dayData.earned),
5995
+ earned: (0, import_utils52.formatEtherNum)(dayData.earned),
6093
5996
  earnedUSD: Number((0, import_viem25.formatUnits)(dayData.earnedUSD, 8)),
6094
- dayAprPerCredit: (0, import_utils54.formatEtherNum)(dayData.dayAprPerCredit),
6095
- formattedDate: (0, import_utils54.formatDateToReadable)(
6096
- (0, import_utils54.convertTimestampToDate)(Number(dayData.timestamp))
5997
+ dayAprPerCredit: (0, import_utils52.formatEtherNum)(dayData.dayAprPerCredit),
5998
+ formattedDate: (0, import_utils52.formatDateToReadable)(
5999
+ (0, import_utils52.convertTimestampToDate)(Number(dayData.timestamp))
6097
6000
  )
6098
6001
  })
6099
6002
  );
@@ -6110,7 +6013,7 @@ var getSAutoRewards = async () => {
6110
6013
 
6111
6014
  // functions/getUserSAutoRewards.ts
6112
6015
  var import_config21 = require("@tokemak/config");
6113
- var import_utils56 = require("@tokemak/utils");
6016
+ var import_utils54 = require("@tokemak/utils");
6114
6017
  var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
6115
6018
  const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = (0, import_config21.getMainnetConfig)();
6116
6019
  const currentCycle = await getCurrentCycleId(wagmiConfig, {
@@ -6156,19 +6059,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
6156
6059
  return null;
6157
6060
  }
6158
6061
  }
6159
- const claimableNum = (0, import_utils56.formatEtherNum)(autoRewards?.claimable || 0n);
6062
+ const claimableNum = (0, import_utils54.formatEtherNum)(autoRewards?.claimable || 0n);
6160
6063
  const claimableUsd = autoPrice * claimableNum;
6161
6064
  const hasClaimable = claimableNum > 0;
6162
- let pendingRewards = (0, import_utils56.formatEtherNum)(
6065
+ let pendingRewards = (0, import_utils54.formatEtherNum)(
6163
6066
  autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
6164
6067
  );
6165
6068
  if (currentCycle === 4242n) {
6166
- pendingRewards = (0, import_utils56.formatEtherNum)(
6069
+ pendingRewards = (0, import_utils54.formatEtherNum)(
6167
6070
  autoRewards?.rewardsPayload.payload.amount || 0n
6168
6071
  );
6169
6072
  }
6170
6073
  const pendingRewardsUsd = autoPrice * pendingRewards;
6171
- const totalRewardsReceived = (0, import_utils56.formatEtherNum)(
6074
+ const totalRewardsReceived = (0, import_utils54.formatEtherNum)(
6172
6075
  autoRewards.rewardsPayload.payload.amount || 0n
6173
6076
  );
6174
6077
  const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
@@ -6203,7 +6106,7 @@ var getUserMerklRewards = async (address) => {
6203
6106
 
6204
6107
  // functions/getUserEthAutoLPRewards.ts
6205
6108
  var import_viem26 = require("viem");
6206
- var import_utils57 = require("@tokemak/utils");
6109
+ var import_utils55 = require("@tokemak/utils");
6207
6110
  var import_tokenlist15 = require("@tokemak/tokenlist");
6208
6111
  var getUserEthAutoLPRewards = async (address) => {
6209
6112
  const rewards = await getUserMerklRewards(address);
@@ -6214,8 +6117,8 @@ var getUserEthAutoLPRewards = async (address) => {
6214
6117
  const amount = autoRewards?.amount;
6215
6118
  const claimed = autoRewards?.claimed;
6216
6119
  const claimable = Number(amount) - Number(claimed);
6217
- const formattedClaimable = (0, import_utils57.formatAmount)(
6218
- (0, import_utils57.formatUnitsNum)(BigInt(claimable || 0), 18)
6120
+ const formattedClaimable = (0, import_utils55.formatAmount)(
6121
+ (0, import_utils55.formatUnitsNum)(BigInt(claimable || 0), 18)
6219
6122
  );
6220
6123
  const users = [];
6221
6124
  const tokens = [];
@@ -6269,7 +6172,7 @@ async function getMerklPoolApr({
6269
6172
  // functions/getSAutoApr.ts
6270
6173
  var import_graph_cli19 = require("@tokemak/graph-cli");
6271
6174
  var import_chains19 = require("viem/chains");
6272
- var import_utils58 = require("@tokemak/utils");
6175
+ var import_utils56 = require("@tokemak/utils");
6273
6176
  var getSAutoApr = async () => {
6274
6177
  try {
6275
6178
  const { GetSAutoApr } = (0, import_graph_cli19.getSdkByChainId)(import_chains19.mainnet.id);
@@ -6288,12 +6191,12 @@ var getSAutoApr = async () => {
6288
6191
  aprFormatted: void 0
6289
6192
  };
6290
6193
  }
6291
- const aprPerCredit = (0, import_utils58.formatEtherNum)(rawApr);
6194
+ const aprPerCredit = (0, import_utils56.formatEtherNum)(rawApr);
6292
6195
  const lockDuration = 16;
6293
6196
  const apr = aprPerCredit * lockDuration;
6294
6197
  return {
6295
6198
  apr,
6296
- aprFormatted: (0, import_utils58.formatPercent)(apr)
6199
+ aprFormatted: (0, import_utils56.formatPercent)(apr)
6297
6200
  };
6298
6201
  } catch (error) {
6299
6202
  console.error("Error fetching sAUTO APR:", error);
@@ -6360,12 +6263,10 @@ var getCombinedRewards = async () => {
6360
6263
  // Annotate the CommonJS export names for ESM import in node:
6361
6264
  0 && (module.exports = {
6362
6265
  AutopoolCategory,
6363
- BASE_ASSETS,
6364
6266
  BATCH_SIZE,
6365
6267
  ETH_BASE_ASSETS,
6366
6268
  EUR_BASE_ASSETS,
6367
6269
  MessageStatus,
6368
- PRICED_TOKENS,
6369
6270
  USD_BASE_ASSETS,
6370
6271
  aggregateSTokeRewardsDayData,
6371
6272
  arraysToObject,