@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.mjs CHANGED
@@ -127,6 +127,9 @@ var getTokePrice = async () => {
127
127
  }
128
128
  };
129
129
 
130
+ // functions/getAutopools.ts
131
+ import { getPublicClient } from "@wagmi/core";
132
+
130
133
  // utils/getExchangeNames.ts
131
134
  function getExchangeNames(destinationVaults) {
132
135
  const uniqueNamesSet = /* @__PURE__ */ new Set();
@@ -487,26 +490,12 @@ async function paginateQuery(queryFn, arrayKey, options = {}) {
487
490
  return results;
488
491
  }
489
492
 
490
- // functions/getPoolsAndDestinationsBackup.ts
491
- import { getNetwork } from "@tokemak/utils";
492
- var getPoolsAndDestinationsBackup = async (chainId) => {
493
- try {
494
- const networkName = getNetwork(chainId)?.name.toLowerCase();
495
- const backupData = await getBlobData(
496
- `${networkName}-getPoolsAndDestinations-latest-success.json`
497
- );
498
- return backupData?.data;
499
- } catch (e) {
500
- console.error(e);
501
- }
502
- };
503
-
504
493
  // functions/getChainAutopools.ts
505
494
  import {
506
495
  formatEtherNum as formatEtherNum2,
507
496
  formatPoolName,
508
497
  formatUnitsNum,
509
- getNetwork as getNetwork3,
498
+ getNetwork,
510
499
  getProtocol,
511
500
  getToken
512
501
  } from "@tokemak/utils";
@@ -620,16 +609,14 @@ import { sonic } from "viem/chains";
620
609
 
621
610
  // functions/getPoolsAndDestinations.ts
622
611
  import { getCoreConfig } from "@tokemak/config";
623
- import { readContract } from "@wagmi/core";
624
612
  import { lensAbi } from "@tokemak/abis";
625
- var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
613
+ var getPoolsAndDestinations = async (client, { chainId }) => {
626
614
  try {
627
615
  const { lens } = getCoreConfig(chainId);
628
- const { autoPools, destinations } = await readContract(wagmiConfig, {
616
+ const { autoPools, destinations } = await client.readContract({
629
617
  address: lens,
630
618
  abi: lensAbi,
631
- functionName: "getPoolsAndDestinations",
632
- chainId
619
+ functionName: "getPoolsAndDestinations"
633
620
  });
634
621
  const autopoolsAndDestinations = mergeArraysWithKey(
635
622
  autoPools,
@@ -642,27 +629,6 @@ var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
642
629
  }
643
630
  };
644
631
 
645
- // functions/getBackupApr.ts
646
- import { getNetwork as getNetwork2 } from "@tokemak/utils";
647
- var getBackupApr = async (chainId, poolAddress) => {
648
- try {
649
- const networkName = getNetwork2(chainId)?.name.toLowerCase();
650
- const backupData = await getBlobData(
651
- `${networkName}-getChainAutopools-latest-success.json`
652
- );
653
- if (backupData) {
654
- const backupApr = backupData.data.find(
655
- (item) => item.poolAddress.toLowerCase() === poolAddress.toLowerCase()
656
- )?.apr.base;
657
- return backupApr || 0;
658
- }
659
- } catch (e) {
660
- console.error(e);
661
- return 0;
662
- }
663
- return null;
664
- };
665
-
666
632
  // functions/getChainAutopools.ts
667
633
  import {
668
634
  NEW_AUTOPOOL_THRESHOLD_DAYS,
@@ -670,7 +636,7 @@ import {
670
636
  DEAD_ADDRESS,
671
637
  ZERO_ADDRESS
672
638
  } from "@tokemak/constants";
673
- var getChainAutopools = async (wagmiConfig, {
639
+ var getChainAutopools = async (client, {
674
640
  chainId,
675
641
  prices
676
642
  }) => {
@@ -684,21 +650,19 @@ var getChainAutopools = async (wagmiConfig, {
684
650
  const genStratAprs = await getGenStratAprs({
685
651
  chainId
686
652
  });
687
- let autopoolsAndDestinations = await getPoolsAndDestinations(wagmiConfig, {
653
+ const autopoolsAndDestinations = await getPoolsAndDestinations(client, {
688
654
  chainId
689
655
  });
690
656
  if (!autopoolsAndDestinations) {
691
- const backupData = await getPoolsAndDestinationsBackup(chainId);
692
- if (backupData) {
693
- autopoolsAndDestinations = backupData;
694
- } else {
695
- throw new Error(`No autopools and destinations found for ${chainId}`);
696
- }
657
+ throw new Error(`No autopools and destinations found for ${chainId}`);
697
658
  }
698
- const vaultAddedMapping = vaultAddeds.reduce((acc, vaultAdded) => {
699
- acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
700
- return acc;
701
- }, {});
659
+ const vaultAddedMapping = vaultAddeds.reduce(
660
+ (acc, vaultAdded) => {
661
+ acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
662
+ return acc;
663
+ },
664
+ {}
665
+ );
702
666
  const autopools = await Promise.all(
703
667
  autopoolsAndDestinations.map(async (autopool) => {
704
668
  let baseAsset = getToken(autopool.baseAsset);
@@ -820,15 +784,18 @@ var getChainAutopools = async (wagmiConfig, {
820
784
  },
821
785
  []
822
786
  );
823
- const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce((acc, token) => {
824
- if (acc[token.address]) {
825
- acc[token.address].valueUsd += token.valueUsd;
826
- acc[token.address].value += token.value;
827
- } else {
828
- acc[token.address] = { ...token };
829
- }
830
- return acc;
831
- }, {});
787
+ const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
788
+ (acc, token) => {
789
+ if (acc[token.address]) {
790
+ acc[token.address].valueUsd += token.valueUsd;
791
+ acc[token.address].value += token.value;
792
+ } else {
793
+ acc[token.address] = { ...token };
794
+ }
795
+ return acc;
796
+ },
797
+ {}
798
+ );
832
799
  const HIDDEN_TOKEN_SYMBOLS = ["USR", "WSTUSR"];
833
800
  const uniqueTokens = Object.values(uniqueTokensWithValueHeldMap).filter(
834
801
  (token) => !HIDDEN_TOKEN_SYMBOLS.includes(token.symbol?.toUpperCase())
@@ -857,20 +824,8 @@ var getChainAutopools = async (wagmiConfig, {
857
824
  const aprs = autopoolsApr.find(
858
825
  (autopoolApr) => getAddress(autopoolApr.id) === getAddress(autopool.poolAddress)
859
826
  );
860
- let baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
827
+ const baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
861
828
  let extraApr = 0;
862
- if (baseApr === void 0) {
863
- try {
864
- const backupApr = await getBackupApr(chainId, autopool.poolAddress);
865
- if (backupApr) {
866
- baseApr = backupApr;
867
- console.log("using backup apr", backupApr);
868
- }
869
- } catch (e) {
870
- console.error(e);
871
- console.log("unable to retrieve backup apr");
872
- }
873
- }
874
829
  let extraRewards = [];
875
830
  if (aprs?.rewards && aprs.rewards.length > 0) {
876
831
  extraRewards = aprs.rewards.map((reward) => {
@@ -882,11 +837,8 @@ var getChainAutopools = async (wagmiConfig, {
882
837
  });
883
838
  }
884
839
  extraApr = extraRewards.reduce((acc, reward) => acc + reward.apr, 0);
885
- if (baseApr === void 0) baseApr = 0;
886
- if (autopool.symbol === "autoETH") {
887
- baseApr = 0.024;
888
- }
889
- const combinedApr = baseApr + extraApr;
840
+ const baseForMath = baseApr ?? 0;
841
+ const combinedApr = baseForMath + extraApr;
890
842
  let denominatedToken = ETH_TOKEN;
891
843
  let useDenominatedValues = false;
892
844
  const denominationData = autopoolsDenomination.find(
@@ -941,7 +893,7 @@ var getChainAutopools = async (wagmiConfig, {
941
893
  prices
942
894
  );
943
895
  const baseDailyEarnings = convertBaseAssetToTokenPricesAndDenom(
944
- totalAssets * baseApr / DAYS_PER_YEAR,
896
+ totalAssets * baseForMath / DAYS_PER_YEAR,
945
897
  baseAssetPrice,
946
898
  denominatedTokenPrice,
947
899
  prices
@@ -949,36 +901,39 @@ var getChainAutopools = async (wagmiConfig, {
949
901
  const tokenOrder = [UIBaseAsset.symbol, ...UITokenOrder].filter(
950
902
  (value, index, array) => array.indexOf(value) === index
951
903
  );
952
- const UITokens = uniqueTokens.reduce((acc, token) => {
953
- try {
954
- const parentAsset = token.extensions?.parentAsset;
955
- if (parentAsset) {
956
- const parentToken = ALL_TOKENS.find(
957
- (t) => t.symbol.toLowerCase() === parentAsset.toLowerCase()
958
- );
959
- if (parentToken && !acc.some(
960
- (t) => t?.address?.toLowerCase() === parentToken?.address?.toLowerCase()
904
+ const UITokens = uniqueTokens.reduce(
905
+ (acc, token) => {
906
+ try {
907
+ const parentAsset = token.extensions?.parentAsset;
908
+ if (parentAsset) {
909
+ const parentToken = ALL_TOKENS.find(
910
+ (t) => t.symbol.toLowerCase() === parentAsset.toLowerCase()
911
+ );
912
+ if (parentToken && !acc.some(
913
+ (t) => t?.address?.toLowerCase() === parentToken?.address?.toLowerCase()
914
+ )) {
915
+ acc.push({
916
+ ...parentToken,
917
+ valueUsd: 0,
918
+ value: 0,
919
+ allocation: 0
920
+ });
921
+ }
922
+ } else if (!acc.some(
923
+ (t) => t?.address?.toLowerCase() === token?.address?.toLowerCase()
961
924
  )) {
962
- acc.push({
963
- ...parentToken,
964
- valueUsd: 0,
965
- value: 0,
966
- allocation: 0
967
- });
925
+ acc.push(token);
968
926
  }
969
- } else if (!acc.some(
970
- (t) => t?.address?.toLowerCase() === token?.address?.toLowerCase()
971
- )) {
972
- acc.push(token);
927
+ } catch (error) {
928
+ console.warn(
929
+ `Error processing token: ${token?.symbol || "unknown"}`,
930
+ error
931
+ );
973
932
  }
974
- } catch (error) {
975
- console.warn(
976
- `Error processing token: ${token?.symbol || "unknown"}`,
977
- error
978
- );
979
- }
980
- return acc;
981
- }, []).sort((a, b) => {
933
+ return acc;
934
+ },
935
+ []
936
+ ).sort((a, b) => {
982
937
  try {
983
938
  const aIndex = tokenOrder.indexOf(a.symbol.toUpperCase());
984
939
  const bIndex = tokenOrder.indexOf(b.symbol.toUpperCase());
@@ -1021,7 +976,7 @@ var getChainAutopools = async (wagmiConfig, {
1021
976
  });
1022
977
  const autopoolInfo = getAutopoolInfo(autopool.symbol);
1023
978
  if (autopoolInfo && !autopoolInfo.description) {
1024
- autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${getNetwork3(chainId)?.name}.`;
979
+ autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${getNetwork(chainId)?.name}.`;
1025
980
  }
1026
981
  return {
1027
982
  ...autopool,
@@ -1047,9 +1002,9 @@ var getChainAutopools = async (wagmiConfig, {
1047
1002
  UITokens,
1048
1003
  UIExchanges: finalUIExchanges,
1049
1004
  tokens: uniqueTokens,
1050
- chain: getNetwork3(chainId),
1005
+ chain: getNetwork(chainId),
1051
1006
  apr: {
1052
- base: baseApr,
1007
+ base: baseApr ?? null,
1053
1008
  extraAprs: extraRewards,
1054
1009
  combined: combinedApr,
1055
1010
  hasExtraAprs: extraRewards.length > 0
@@ -1087,12 +1042,13 @@ var getAutopools = async (wagmiConfig, {
1087
1042
  try {
1088
1043
  const chains = getChainsForEnv({ includeTestnet });
1089
1044
  const autopools = (await Promise.all(
1090
- chains.map(
1091
- (chain) => getChainAutopools(wagmiConfig, {
1045
+ chains.map((chain) => {
1046
+ const chainId = chain?.chainId;
1047
+ return getChainAutopools(getPublicClient(wagmiConfig, { chainId }), {
1092
1048
  prices,
1093
- chainId: chain?.chainId
1094
- })
1095
- )
1049
+ chainId
1050
+ });
1051
+ })
1096
1052
  )).flat();
1097
1053
  const sortedAutopoolsByTimestamp = autopools.sort(
1098
1054
  (a, b) => b.timestamp - a.timestamp
@@ -1150,7 +1106,8 @@ var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_L
1150
1106
  timestamp: startTimestamp
1151
1107
  });
1152
1108
  const formattedDayDatas = autopoolDayDatas.map((autoPoolDayData) => {
1153
- const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
1109
+ const baseDecimals = Number(autoPoolDayData.baseAsset.decimals) || 18;
1110
+ const navPerShare = Number(autoPoolDayData.nav) / Number(autoPoolDayData.totalSupply) * Math.pow(10, 18 - baseDecimals);
1154
1111
  let baseApy = autoPoolDayData.autopoolApy;
1155
1112
  let rewarderApy = 0;
1156
1113
  const formattedRewarder7DayMAApy = formatEtherNum3(
@@ -1282,7 +1239,7 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
1282
1239
 
1283
1240
  // functions/getAutopoolUser.ts
1284
1241
  import { erc20Abi } from "viem";
1285
- import { readContract as readContract2, readContracts } from "@wagmi/core";
1242
+ import { readContract, readContracts } from "@wagmi/core";
1286
1243
  import { autopoolEthAbi } from "@tokemak/abis";
1287
1244
  import {
1288
1245
  convertTimestampToDate as convertTimestampToDate2,
@@ -1323,7 +1280,7 @@ var getAutopoolUser = async (config, {
1323
1280
  if (unstakedPoolSharesError) {
1324
1281
  throw new Error("Error fetching unstaked pool shares");
1325
1282
  }
1326
- const stakedPoolShares = await readContract2(config, {
1283
+ const stakedPoolShares = await readContract(config, {
1327
1284
  address: autopoolRewarderContract,
1328
1285
  abi: erc20Abi,
1329
1286
  functionName: "balanceOf",
@@ -2753,7 +2710,7 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
2753
2710
 
2754
2711
  // functions/getUserAutoEthRewards.ts
2755
2712
  import { autoEthRewardsHashAbi } from "@tokemak/abis";
2756
- import { readContract as readContract3 } from "@wagmi/core";
2713
+ import { readContract as readContract2 } from "@wagmi/core";
2757
2714
  import { convertChainCycleToUnix, formatCurrency } from "@tokemak/utils";
2758
2715
  var getAutoEthRewards = async (wagmiConfig, {
2759
2716
  account,
@@ -2763,14 +2720,14 @@ var getAutoEthRewards = async (wagmiConfig, {
2763
2720
  chainId
2764
2721
  }) => {
2765
2722
  try {
2766
- const [, drippingHash] = await readContract3(wagmiConfig, {
2723
+ const [, drippingHash] = await readContract2(wagmiConfig, {
2767
2724
  address: rewardsHash,
2768
2725
  abi: autoEthRewardsHashAbi,
2769
2726
  functionName: "cycleHashes",
2770
2727
  args: [currentCycleIndex - 306n],
2771
2728
  chainId
2772
2729
  });
2773
- const [, lastWeekHash] = await readContract3(wagmiConfig, {
2730
+ const [, lastWeekHash] = await readContract2(wagmiConfig, {
2774
2731
  address: rewardsHash,
2775
2732
  abi: autoEthRewardsHashAbi,
2776
2733
  functionName: "cycleHashes",
@@ -2821,7 +2778,7 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
2821
2778
 
2822
2779
  // functions/getUserRewardsV1.ts
2823
2780
  import { rewardsV1Abi, rewardsV1HashAbi } from "@tokemak/abis";
2824
- import { readContract as readContract4 } from "@wagmi/core";
2781
+ import { readContract as readContract3 } from "@wagmi/core";
2825
2782
  var getUserRewardsV1 = async (wagmiConfig, {
2826
2783
  address,
2827
2784
  rewardsCycleIndex,
@@ -2831,7 +2788,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
2831
2788
  chainId
2832
2789
  }) => {
2833
2790
  try {
2834
- const [latestClaimableHash, cycleRewardsHash] = await readContract4(
2791
+ const [latestClaimableHash, cycleRewardsHash] = await readContract3(
2835
2792
  wagmiConfig,
2836
2793
  {
2837
2794
  address: rewardsV1Hash,
@@ -2855,7 +2812,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
2855
2812
  const {
2856
2813
  payload: { chainId: payloadChainId, cycle, wallet, amount }
2857
2814
  } = latestClaimablePayload;
2858
- const claimable = await readContract4(wagmiConfig, {
2815
+ const claimable = await readContract3(wagmiConfig, {
2859
2816
  address: rewardsV1,
2860
2817
  abi: rewardsV1Abi,
2861
2818
  functionName: "getClaimableAmount",
@@ -2872,7 +2829,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
2872
2829
 
2873
2830
  // functions/getUserV1.ts
2874
2831
  import { rewardsV1Abi as rewardsV1Abi2, stakingV1Abi } from "@tokemak/abis";
2875
- import { readContract as readContract5 } from "@wagmi/core";
2832
+ import { readContract as readContract4 } from "@wagmi/core";
2876
2833
  import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
2877
2834
  import { mainnet as mainnet6 } from "viem/chains";
2878
2835
  var getUserV1 = async (wagmiConfig, {
@@ -2891,7 +2848,7 @@ var getUserV1 = async (wagmiConfig, {
2891
2848
  missedTokeRewards
2892
2849
  } = getMainnetConfig3(mainnet6.id);
2893
2850
  try {
2894
- const userStakedTokeV1 = await readContract5(wagmiConfig, {
2851
+ const userStakedTokeV1 = await readContract4(wagmiConfig, {
2895
2852
  address: stakingV1,
2896
2853
  abi: stakingV1Abi,
2897
2854
  functionName: "availableForWithdrawal",
@@ -2923,7 +2880,7 @@ var getUserV1 = async (wagmiConfig, {
2923
2880
  const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
2924
2881
  const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
2925
2882
  const amount = autoEthGuardedRewardsPayload?.payload?.amount;
2926
- const claimableAutoEth = await readContract5(wagmiConfig, {
2883
+ const claimableAutoEth = await readContract4(wagmiConfig, {
2927
2884
  address: autoEthGuardedRewards,
2928
2885
  abi: rewardsV1Abi2,
2929
2886
  functionName: "getClaimableAmount",
@@ -2947,7 +2904,7 @@ var getUserV1 = async (wagmiConfig, {
2947
2904
  const {
2948
2905
  payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
2949
2906
  } = missedTokeRewardsPayload;
2950
- claimableMissedToke = await readContract5(wagmiConfig, {
2907
+ claimableMissedToke = await readContract4(wagmiConfig, {
2951
2908
  address: missedTokeRewards,
2952
2909
  abi: rewardsV1Abi2,
2953
2910
  functionName: "getClaimableAmount",
@@ -3034,135 +2991,8 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = mainnet7.id) => {
3034
2991
  }
3035
2992
  };
3036
2993
 
3037
- // functions/getTokenPrices.ts
3038
- import {
3039
- ETH_TOKEN as ETH_TOKEN4,
3040
- PXETH_TOKEN,
3041
- TOKE_TOKEN as TOKE_TOKEN2,
3042
- USDC_TOKEN,
3043
- S_TOKEN as S_TOKEN2,
3044
- DOLA_TOKEN,
3045
- WETH_TOKEN as WETH_TOKEN2,
3046
- WS_TOKEN as WS_TOKEN2,
3047
- EURC_TOKEN,
3048
- SILO_TOKEN,
3049
- WXPL_TOKEN as WXPL_TOKEN2,
3050
- USDT_TOKEN,
3051
- XPL_TOKEN as XPL_TOKEN2,
3052
- USDT0_TOKEN,
3053
- AUTO_TOKEN as AUTO_TOKEN3,
3054
- MON_TOKEN,
3055
- WMON_TOKEN
3056
- } from "@tokemak/tokenlist";
3057
- import { TOKEMAK_PRICES_STAGING_URL } from "@tokemak/constants";
3058
-
3059
- // functions/getBackupTokenPrices.ts
3060
- var getBackupTokenPrices = async () => {
3061
- try {
3062
- const backupData = await getBlobData(`getTokenPrices-latest-success.json`);
3063
- if (backupData) {
3064
- return backupData;
3065
- }
3066
- } catch (e) {
3067
- console.error(e);
3068
- return void 0;
3069
- }
3070
- return void 0;
3071
- };
3072
-
3073
- // functions/getTokenPrices.ts
3074
- var BASE_ASSETS = [
3075
- { ...ETH_TOKEN4, symbol: "ETH", coinGeckoId: "ethereum" },
3076
- { ...PXETH_TOKEN, symbol: "PXETH", coinGeckoId: "dinero-staked-eth" },
3077
- { ...USDC_TOKEN, symbol: "USDC", coinGeckoId: "usd-coin" },
3078
- { ...DOLA_TOKEN, symbol: "DOLA", coinGeckoId: "dola-usd" },
3079
- { ...S_TOKEN2, symbol: "S" },
3080
- { ...EURC_TOKEN, symbol: "EURC", coinGeckoId: "euro-coin" },
3081
- { ...USDT_TOKEN, symbol: "USDT", coinGeckoId: "tether" },
3082
- { ...USDT0_TOKEN, symbol: "USDT0", coinGeckoId: "tether" }
3083
- ];
3084
- var PRICED_TOKENS = [
3085
- ...BASE_ASSETS,
3086
- { ...TOKE_TOKEN2, symbol: "TOKE" },
3087
- { ...AUTO_TOKEN3, symbol: "AUTO" },
3088
- { ...SILO_TOKEN, symbol: "SILO" },
3089
- { ...XPL_TOKEN2, address: WXPL_TOKEN2.address, symbol: "XPL" },
3090
- { ...MON_TOKEN, address: WMON_TOKEN.address, symbol: "MON" },
3091
- { ...USDT0_TOKEN, symbol: "USDT0" }
3092
- ];
3093
- var WRAPPED_TOKENS = [
3094
- { ...WETH_TOKEN2, symbol: "WETH" },
3095
- { ...WS_TOKEN2, symbol: "WS" },
3096
- { ...WXPL_TOKEN2, symbol: "WXPL" },
3097
- { ...WMON_TOKEN, symbol: "WMON" }
3098
- ];
3099
- var isStale = (timestamp) => {
3100
- return timestamp - Math.floor(Date.now() / 1e3) > 5 * 60;
3101
- };
3102
- var getTokenPrices = async (isCronJob = false) => {
3103
- try {
3104
- const body = {
3105
- tokens: PRICED_TOKENS.map((asset) => ({
3106
- token: asset.address,
3107
- chainId: asset.chainId,
3108
- systemName: "gen3",
3109
- timeoutMS: 5 * 1e3
3110
- }))
3111
- };
3112
- const response = await fetch(`${TOKEMAK_PRICES_STAGING_URL}`, {
3113
- method: "POST",
3114
- headers: {
3115
- "Content-Type": "application/json"
3116
- },
3117
- body: JSON.stringify(body)
3118
- });
3119
- const data = await response.json();
3120
- const prices = PRICED_TOKENS.reduce((acc, asset) => {
3121
- const priceData = data.find(
3122
- (item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
3123
- );
3124
- acc[asset.symbol] = priceData?.price ?? 0;
3125
- return acc;
3126
- }, {});
3127
- const timestamp = Math.floor(Date.now() / 1e3);
3128
- return {
3129
- timestamp,
3130
- isStale: false,
3131
- prices: {
3132
- ...prices,
3133
- AUTO: prices.TOKE,
3134
- WETH: prices.ETH,
3135
- WS: prices.S,
3136
- WXPL: prices.XPL
3137
- }
3138
- };
3139
- } catch (e) {
3140
- if (isCronJob) {
3141
- return {
3142
- prices: void 0,
3143
- timestamp: void 0,
3144
- isStale: false
3145
- };
3146
- } else {
3147
- const backupPrices = await getBackupTokenPrices();
3148
- if (backupPrices) {
3149
- return {
3150
- prices: backupPrices.prices,
3151
- timestamp: backupPrices.timestamp,
3152
- isStale: isStale(backupPrices.timestamp)
3153
- };
3154
- }
3155
- return {
3156
- prices: void 0,
3157
- timestamp: void 0,
3158
- isStale: false
3159
- };
3160
- }
3161
- }
3162
- };
3163
-
3164
2994
  // functions/getHistoricalTokenPrices.ts
3165
- import { ETH_TOKEN as ETH_TOKEN5 } from "@tokemak/tokenlist";
2995
+ import { BASE_ASSETS, ETH_TOKEN as ETH_TOKEN4 } from "@tokemak/tokenlist";
3166
2996
  var hasCoinGeckoId = (asset) => typeof asset?.coinGeckoId === "string" && asset.coinGeckoId.length > 0;
3167
2997
  var getBlobHistoricalTokenPrices = async (tokenSymbol) => {
3168
2998
  const blobName = `historical_v2/${tokenSymbol}-latest-success.json`;
@@ -3179,7 +3009,7 @@ var getHistoricalTokenPrices = async () => {
3179
3009
  const historicalBaseAssetPrices = await Promise.all(
3180
3010
  BASE_ASSETS.map(async (baseAsset) => {
3181
3011
  if (!hasCoinGeckoId(baseAsset)) {
3182
- const address = baseAsset.address === ETH_TOKEN5.address ? ETH_ADDRESS_IN_SUBGRAPH : baseAsset.address;
3012
+ const address = baseAsset.address === ETH_TOKEN4.address ? ETH_ADDRESS_IN_SUBGRAPH : baseAsset.address;
3183
3013
  const prices2 = await getTokenValueDayDatas(
3184
3014
  address,
3185
3015
  baseAsset.chainId
@@ -3673,11 +3503,11 @@ import {
3673
3503
  formatEtherNum as formatEtherNum8,
3674
3504
  formatUnitsNum as formatUnitsNum6
3675
3505
  } from "@tokemak/utils";
3676
- import { ETH_TOKEN as ETH_TOKEN6 } from "@tokemak/tokenlist";
3506
+ import { ETH_TOKEN as ETH_TOKEN5, PRICED_TOKENS } from "@tokemak/tokenlist";
3677
3507
 
3678
3508
  // functions/getUserAutopool.tsx
3679
3509
  import { erc20Abi as erc20Abi4 } from "viem";
3680
- import { readContract as readContract6, readContracts as readContracts8 } from "@wagmi/core";
3510
+ import { readContract as readContract5, readContracts as readContracts8 } from "@wagmi/core";
3681
3511
  import { formatEtherNum as formatEtherNum7 } from "@tokemak/utils";
3682
3512
  import { autopoolEthAbi as autopoolEthAbi2 } from "@tokemak/abis";
3683
3513
  var getUserAutopool = async (wagmiConfig, {
@@ -3720,7 +3550,7 @@ var getUserAutopool = async (wagmiConfig, {
3720
3550
  if (unstakedPoolSharesError) {
3721
3551
  throw new Error("Error fetching unstaked pool shares");
3722
3552
  }
3723
- const stakedPoolShares = await readContract6(wagmiConfig, {
3553
+ const stakedPoolShares = await readContract5(wagmiConfig, {
3724
3554
  address: autopoolRewarderContract,
3725
3555
  abi: erc20Abi4,
3726
3556
  functionName: "balanceOf",
@@ -4002,7 +3832,7 @@ var getUserAutopools = async ({
4002
3832
  );
4003
3833
  const stakedRatio = stakedShares / userShares;
4004
3834
  const unstakedRatio = 1 - stakedRatio;
4005
- const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * autopoolData?.apr?.base;
3835
+ const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * (autopoolData?.apr?.base ?? 0);
4006
3836
  return {
4007
3837
  name: autopoolData?.name,
4008
3838
  symbol: autopoolData?.symbol,
@@ -4034,7 +3864,7 @@ var getUserAutopools = async ({
4034
3864
  };
4035
3865
  }
4036
3866
  });
4037
- let denominatedToken = ETH_TOKEN6;
3867
+ let denominatedToken = ETH_TOKEN5;
4038
3868
  const useDenomination = userAutopoolsWithData.filter((autopool) => autopool?.useDenomination).length === 1 && userAutopoolsWithData.length === 1;
4039
3869
  if (useDenomination) {
4040
3870
  const autopoolWithDenomination = userAutopoolsWithData.find(
@@ -4044,13 +3874,16 @@ var getUserAutopools = async ({
4044
3874
  denominatedToken = autopoolWithDenomination?.denomination;
4045
3875
  }
4046
3876
  }
4047
- const nav = Object.values(categories).reduce((acc, { nav: nav2 }) => {
4048
- return Object.keys(nav2).reduce((sumAcc, key) => {
4049
- const typedKey = key;
4050
- sumAcc[typedKey] = (sumAcc[typedKey] || 0) + nav2[typedKey];
4051
- return sumAcc;
4052
- }, acc);
4053
- }, {});
3877
+ const nav = Object.values(categories).reduce(
3878
+ (acc, { nav: nav2 }) => {
3879
+ return Object.keys(nav2).reduce((sumAcc, key) => {
3880
+ const typedKey = key;
3881
+ sumAcc[typedKey] = (sumAcc[typedKey] || 0) + nav2[typedKey];
3882
+ return sumAcc;
3883
+ }, acc);
3884
+ },
3885
+ {}
3886
+ );
4054
3887
  const idleWithTokenPrices = userAutopoolsWithData.reduce(
4055
3888
  (acc, userAutopool) => {
4056
3889
  if (!userAutopool) return acc;
@@ -4078,20 +3911,26 @@ var getUserAutopools = async ({
4078
3911
  ...idle2,
4079
3912
  allocation: idle2.USD / nav.USD
4080
3913
  }));
4081
- const returns = Object.values(categories).reduce((acc, { returns: returns2 }) => {
4082
- return Object.keys(returns2).reduce((sumAcc, key) => {
4083
- const typedKey = key;
4084
- sumAcc[typedKey] = (sumAcc[typedKey] || 0) + returns2[typedKey];
4085
- return sumAcc;
4086
- }, acc);
4087
- }, {});
4088
- const supplied = Object.values(categories).reduce((acc, { supplied: supplied2 }) => {
4089
- return Object.keys(supplied2).reduce((sumAcc, key) => {
4090
- const typedKey = key;
4091
- sumAcc[typedKey] = (sumAcc[typedKey] || 0) + supplied2[typedKey];
4092
- return sumAcc;
4093
- }, acc);
4094
- }, {});
3914
+ const returns = Object.values(categories).reduce(
3915
+ (acc, { returns: returns2 }) => {
3916
+ return Object.keys(returns2).reduce((sumAcc, key) => {
3917
+ const typedKey = key;
3918
+ sumAcc[typedKey] = (sumAcc[typedKey] || 0) + returns2[typedKey];
3919
+ return sumAcc;
3920
+ }, acc);
3921
+ },
3922
+ {}
3923
+ );
3924
+ const supplied = Object.values(categories).reduce(
3925
+ (acc, { supplied: supplied2 }) => {
3926
+ return Object.keys(supplied2).reduce((sumAcc, key) => {
3927
+ const typedKey = key;
3928
+ sumAcc[typedKey] = (sumAcc[typedKey] || 0) + supplied2[typedKey];
3929
+ return sumAcc;
3930
+ }, acc);
3931
+ },
3932
+ {}
3933
+ );
4095
3934
  const userExchangesWithAllocations = Object.values(userExchanges).map(
4096
3935
  (userExchange) => {
4097
3936
  return {
@@ -4153,11 +3992,14 @@ var getUserAutopools = async ({
4153
3992
  categories[categoryKey] = {
4154
3993
  ...categoryData,
4155
3994
  apr,
4156
- avgDailyReturns: Object.keys(categoryData.nav).reduce((acc, key) => {
4157
- const typedKey = key;
4158
- acc[typedKey] = dailyRate * categoryData.nav[typedKey];
4159
- return acc;
4160
- }, {})
3995
+ avgDailyReturns: Object.keys(categoryData.nav).reduce(
3996
+ (acc, key) => {
3997
+ const typedKey = key;
3998
+ acc[typedKey] = dailyRate * categoryData.nav[typedKey];
3999
+ return acc;
4000
+ },
4001
+ {}
4002
+ )
4161
4003
  };
4162
4004
  });
4163
4005
  return {
@@ -4255,7 +4097,7 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
4255
4097
  };
4256
4098
 
4257
4099
  // functions/getAllowance.ts
4258
- import { readContract as readContract7 } from "@wagmi/core";
4100
+ import { readContract as readContract6 } from "@wagmi/core";
4259
4101
  import { erc20Abi as erc20Abi5 } from "viem";
4260
4102
  var getAllowance = async (wagmiConfig, {
4261
4103
  token,
@@ -4263,7 +4105,7 @@ var getAllowance = async (wagmiConfig, {
4263
4105
  spender
4264
4106
  }) => {
4265
4107
  try {
4266
- const allowance = await readContract7(wagmiConfig, {
4108
+ const allowance = await readContract6(wagmiConfig, {
4267
4109
  address: token,
4268
4110
  abi: erc20Abi5,
4269
4111
  functionName: "allowance",
@@ -4310,7 +4152,7 @@ import { getAddress as getAddress4 } from "viem";
4310
4152
 
4311
4153
  // functions/getChainUserAutopoolsRewards.ts
4312
4154
  import { getCoreConfig as getCoreConfig2 } from "@tokemak/config";
4313
- import { readContract as readContract8 } from "@wagmi/core";
4155
+ import { readContract as readContract7 } from "@wagmi/core";
4314
4156
  import { lensAbi as lensAbi2 } from "@tokemak/abis";
4315
4157
  var getChainUserAutopoolsRewards = async (wagmiConfig, {
4316
4158
  chainId,
@@ -4318,7 +4160,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
4318
4160
  }) => {
4319
4161
  try {
4320
4162
  const coreConfig = getCoreConfig2(chainId);
4321
- const userRewardsInfo = await readContract8(wagmiConfig, {
4163
+ const userRewardsInfo = await readContract7(wagmiConfig, {
4322
4164
  address: coreConfig.lens,
4323
4165
  abi: lensAbi2,
4324
4166
  functionName: "getUserRewardInfo",
@@ -4351,7 +4193,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
4351
4193
 
4352
4194
  // functions/getUserAutopoolsRewards.ts
4353
4195
  import { formatUnitsNum as formatUnitsNum7, getToken as getToken2 } from "@tokemak/utils";
4354
- import { SILO_TOKEN as SILO_TOKEN2, TOKE_TOKEN as TOKE_TOKEN3 } from "@tokemak/tokenlist";
4196
+ import { SILO_TOKEN, TOKE_TOKEN as TOKE_TOKEN2 } from "@tokemak/tokenlist";
4355
4197
  import { plasma } from "viem/chains";
4356
4198
  var getUserAutopoolsRewards = async (wagmiConfig, {
4357
4199
  address,
@@ -4388,7 +4230,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4388
4230
  const claimableAmount = rewards ? rewards[getAddress4(extraRewards2.rewardToken?.id)] : 0n;
4389
4231
  let price = tokenPrices[rewarderToken.symbol] || 0;
4390
4232
  if (rewarderToken.symbol === "XSILO") {
4391
- price = tokenPrices[SILO_TOKEN2.symbol] || 0;
4233
+ price = tokenPrices[SILO_TOKEN.symbol] || 0;
4392
4234
  }
4393
4235
  const formattedAmount = formatUnitsNum7(
4394
4236
  claimableAmount,
@@ -4426,7 +4268,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4426
4268
  ([tokenSymbol, { amount, decimals }]) => {
4427
4269
  let price = tokenPrices[tokenSymbol] || 0;
4428
4270
  if (tokenSymbol === "XSILO") {
4429
- price = tokenPrices[SILO_TOKEN2.symbol] || 0;
4271
+ price = tokenPrices[SILO_TOKEN.symbol] || 0;
4430
4272
  }
4431
4273
  const formattedAmount = formatUnitsNum7(amount, decimals || 18);
4432
4274
  tokenRewards[tokenSymbol] = {
@@ -4443,7 +4285,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
4443
4285
  tokenRewards["TOKE"] = {
4444
4286
  ...undefinedToken,
4445
4287
  USD: undefinedToken.formattedAmount * price,
4446
- logoURI: TOKE_TOKEN3.logoURI
4288
+ logoURI: TOKE_TOKEN2.logoURI
4447
4289
  };
4448
4290
  delete tokenRewards["undefined"];
4449
4291
  }
@@ -4508,7 +4350,7 @@ import {
4508
4350
  import { TOKEMAK_SWAP_QUOTE_URL } from "@tokemak/constants";
4509
4351
 
4510
4352
  // functions/getAddressFromSystemRegistry.ts
4511
- import { readContract as readContract9 } from "@wagmi/core";
4353
+ import { readContract as readContract8 } from "@wagmi/core";
4512
4354
  import { getCoreConfig as getCoreConfig3 } from "@tokemak/config";
4513
4355
  import { systemRegistryAbi as systemRegistryAbi2 } from "@tokemak/abis";
4514
4356
  var getAddressFromSystemRegistry = async (wagmiConfig, {
@@ -4516,7 +4358,7 @@ var getAddressFromSystemRegistry = async (wagmiConfig, {
4516
4358
  functionName
4517
4359
  }) => {
4518
4360
  const { systemRegistry } = getCoreConfig3(chainId);
4519
- return await readContract9(wagmiConfig, {
4361
+ return await readContract8(wagmiConfig, {
4520
4362
  address: systemRegistry,
4521
4363
  abi: systemRegistryAbi2,
4522
4364
  functionName,
@@ -4532,20 +4374,20 @@ var getAutopilotRouter = async (wagmiConfig, { chainId }) => await getAddressFro
4532
4374
 
4533
4375
  // functions/getSwapQuote.ts
4534
4376
  import { getCoreConfig as getCoreConfig4 } from "@tokemak/config";
4535
- import { ETH_TOKEN as ETH_TOKEN7, WS_TOKEN as WS_TOKEN3, WXPL_TOKEN as WXPL_TOKEN3 } from "@tokemak/tokenlist";
4377
+ import { ETH_TOKEN as ETH_TOKEN6, WS_TOKEN as WS_TOKEN2, WXPL_TOKEN as WXPL_TOKEN2 } from "@tokemak/tokenlist";
4536
4378
  import { plasma as plasma2, sonic as sonic2 } from "viem/chains";
4537
4379
  var getSwapQuote = async (config, { chainId, ...params }) => {
4538
4380
  try {
4539
4381
  if (!params.sellToken || !params.buyToken) {
4540
4382
  throw new Error("Sell token and buy token are required");
4541
4383
  }
4542
- if (params.sellToken === ETH_TOKEN7.address) {
4384
+ if (params.sellToken === ETH_TOKEN6.address) {
4543
4385
  params.sellToken = getCoreConfig4(chainId).weth;
4544
4386
  if (chainId === sonic2.id) {
4545
- params.sellToken = WS_TOKEN3.address;
4387
+ params.sellToken = WS_TOKEN2.address;
4546
4388
  }
4547
4389
  if (chainId === plasma2.id) {
4548
- params.sellToken = WXPL_TOKEN3.address;
4390
+ params.sellToken = WXPL_TOKEN2.address;
4549
4391
  }
4550
4392
  }
4551
4393
  const sellAmount = params.sellAmount.toString();
@@ -4576,7 +4418,7 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
4576
4418
  };
4577
4419
 
4578
4420
  // functions/getDynamicSwap.ts
4579
- import { getPublicClient, readContract as readContract10 } from "@wagmi/core";
4421
+ import { getPublicClient as getPublicClient2, readContract as readContract9 } from "@wagmi/core";
4580
4422
  import { autopilotRouterAbi, autopoolEthAbi as autopoolEthAbi3 } from "@tokemak/abis";
4581
4423
  import { getCoreConfig as getCoreConfig5 } from "@tokemak/config";
4582
4424
  import { getLiquidations } from "@tokemak/autopilot-swap-route-calc";
@@ -4602,7 +4444,7 @@ var getDynamicSwap = async ({
4602
4444
  let previewRedeem = 0n;
4603
4445
  let dynamicSwaps;
4604
4446
  let standardPreviewRedeem = false;
4605
- const client = await getPublicClient(config, { chainId });
4447
+ const client = await getPublicClient2(config, { chainId });
4606
4448
  try {
4607
4449
  const { systemRegistry } = getCoreConfig5(chainId);
4608
4450
  client.transport.retryCount = 0;
@@ -4672,7 +4514,7 @@ var getDynamicSwap = async ({
4672
4514
  console.log(e);
4673
4515
  }
4674
4516
  }
4675
- const previewRedeemOnChain = await readContract10(config, {
4517
+ const previewRedeemOnChain = await readContract9(config, {
4676
4518
  address,
4677
4519
  abi: autopoolEthAbi3,
4678
4520
  functionName: "previewRedeem",
@@ -4692,9 +4534,9 @@ var getDynamicSwap = async ({
4692
4534
  };
4693
4535
 
4694
4536
  // functions/getAmountWithdrawn.ts
4695
- import { ETH_TOKEN as ETH_TOKEN8 } from "@tokemak/tokenlist";
4537
+ import { ETH_TOKEN as ETH_TOKEN7 } from "@tokemak/tokenlist";
4696
4538
  import { getCoreConfig as getCoreConfig6 } from "@tokemak/config";
4697
- import { readContract as readContract11 } from "@wagmi/core";
4539
+ import { readContract as readContract10 } from "@wagmi/core";
4698
4540
  import { autopoolEthAbi as autopoolEthAbi4 } from "@tokemak/abis";
4699
4541
  var getAmountWithdrawn = async ({
4700
4542
  address,
@@ -4730,11 +4572,11 @@ var getAmountWithdrawn = async ({
4730
4572
  );
4731
4573
  let minAmount = formatUnits7(minAmountWithSlippage, decimals);
4732
4574
  if (isSwap) {
4733
- if (buyToken === ETH_TOKEN8.address) {
4575
+ if (buyToken === ETH_TOKEN7.address) {
4734
4576
  const weth = getCoreConfig6(chainId).weth;
4735
4577
  buyToken = weth;
4736
4578
  }
4737
- convertedAssets = await readContract11(config, {
4579
+ convertedAssets = await readContract10(config, {
4738
4580
  address: autopool,
4739
4581
  abi: autopoolEthAbi4,
4740
4582
  functionName: "convertToAssets",
@@ -4774,7 +4616,7 @@ var getAmountWithdrawn = async ({
4774
4616
  };
4775
4617
 
4776
4618
  // functions/getAmountDeposited.ts
4777
- import { readContract as readContract12 } from "@wagmi/core";
4619
+ import { readContract as readContract11 } from "@wagmi/core";
4778
4620
  import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
4779
4621
  import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as formatEtherNum9 } from "@tokemak/utils";
4780
4622
  var getAmountDeposited = async ({
@@ -4789,7 +4631,7 @@ var getAmountDeposited = async ({
4789
4631
  if (!address || !chainId || !amount || typeof slippage !== "number") {
4790
4632
  throw new Error("Invalid parameters");
4791
4633
  }
4792
- const previewDeposit = await readContract12(config, {
4634
+ const previewDeposit = await readContract11(config, {
4793
4635
  address,
4794
4636
  abi: autopoolEthAbi5,
4795
4637
  functionName: "previewDeposit",
@@ -4813,7 +4655,7 @@ var getAmountDeposited = async ({
4813
4655
  };
4814
4656
 
4815
4657
  // functions/getBridgeFee.ts
4816
- import { readContract as readContract13 } from "@wagmi/core";
4658
+ import { readContract as readContract12 } from "@wagmi/core";
4817
4659
  import { layerZeroEndpointAbi, oftAdapterAbi } from "@tokemak/abis";
4818
4660
  import { toHex } from "viem";
4819
4661
  import { addressToBytes32 } from "@layerzerolabs/lz-v2-utilities";
@@ -4826,13 +4668,13 @@ var getBridgeFee = async (wagmiConfig, {
4826
4668
  from
4827
4669
  }) => {
4828
4670
  try {
4829
- const endpoint = await readContract13(wagmiConfig, {
4671
+ const endpoint = await readContract12(wagmiConfig, {
4830
4672
  address: destAddress,
4831
4673
  abi: oftAdapterAbi,
4832
4674
  functionName: "endpoint",
4833
4675
  chainId: destChainId
4834
4676
  });
4835
- const eid = await readContract13(wagmiConfig, {
4677
+ const eid = await readContract12(wagmiConfig, {
4836
4678
  address: endpoint,
4837
4679
  abi: layerZeroEndpointAbi,
4838
4680
  functionName: "eid",
@@ -4850,7 +4692,7 @@ var getBridgeFee = async (wagmiConfig, {
4850
4692
  composeMsg: "0x",
4851
4693
  oftCmd: "0x"
4852
4694
  };
4853
- const feeQuote = await readContract13(wagmiConfig, {
4695
+ const feeQuote = await readContract12(wagmiConfig, {
4854
4696
  address: sourceAddress,
4855
4697
  abi: oftAdapterAbi,
4856
4698
  functionName: "quoteSend",
@@ -4933,12 +4775,12 @@ import { sepolia as sepolia2 } from "viem/chains";
4933
4775
 
4934
4776
  // functions/getCurrentCycleId.ts
4935
4777
  import { accTokeV1Abi } from "@tokemak/abis";
4936
- import { readContract as readContract14 } from "@wagmi/core";
4778
+ import { readContract as readContract13 } from "@wagmi/core";
4937
4779
  var getCurrentCycleId = async (wagmiConfig, {
4938
4780
  stoke,
4939
4781
  chainId
4940
4782
  }) => {
4941
- return readContract14(wagmiConfig, {
4783
+ return readContract13(wagmiConfig, {
4942
4784
  address: stoke,
4943
4785
  abi: accTokeV1Abi,
4944
4786
  chainId,
@@ -5148,7 +4990,7 @@ import {
5148
4990
  formatTVL
5149
4991
  } from "@tokemak/utils";
5150
4992
  import { getCoreConfig as getCoreConfig8 } from "@tokemak/config";
5151
- import { getNetwork as getNetwork4 } from "@tokemak/utils";
4993
+ import { getNetwork as getNetwork2 } from "@tokemak/utils";
5152
4994
  var getChainSToke = async (wagmiConfig, {
5153
4995
  tokePrice,
5154
4996
  chainId
@@ -5181,7 +5023,7 @@ var getChainSToke = async (wagmiConfig, {
5181
5023
  tvl: formatTVL(tvl),
5182
5024
  rawTVL: tvl,
5183
5025
  currentCycle,
5184
- chain: getNetwork4(chainId),
5026
+ chain: getNetwork2(chainId),
5185
5027
  timeBeforeNextCycle: convertSecondsToRemainingTime2(
5186
5028
  secondsLeftBeforeNextCycle
5187
5029
  )
@@ -5232,8 +5074,8 @@ var getSToke = async (wagmiConfig, {
5232
5074
  import { accTokeV1Abi as accTokeV1Abi4, managerV1Abi } from "@tokemak/abis";
5233
5075
  import {
5234
5076
  getBlockNumber,
5235
- getPublicClient as getPublicClient2,
5236
- readContract as readContract15
5077
+ getPublicClient as getPublicClient3,
5078
+ readContract as readContract14
5237
5079
  } from "@wagmi/core";
5238
5080
  var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
5239
5081
  stoke,
@@ -5242,12 +5084,12 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
5242
5084
  const scanPeriodInDays = 8;
5243
5085
  const blockTime = 12;
5244
5086
  try {
5245
- const client = getPublicClient2(wagmiConfig, { chainId });
5087
+ const client = getPublicClient3(wagmiConfig, { chainId });
5246
5088
  if (!!client) {
5247
5089
  const blockNumber = await getBlockNumber(wagmiConfig, {
5248
5090
  chainId
5249
5091
  });
5250
- const manager = await readContract15(wagmiConfig, {
5092
+ const manager = await readContract14(wagmiConfig, {
5251
5093
  functionName: "manager",
5252
5094
  address: stoke,
5253
5095
  abi: accTokeV1Abi4,
@@ -5455,6 +5297,56 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
5455
5297
  };
5456
5298
  };
5457
5299
 
5300
+ // functions/getTokenPrices.ts
5301
+ import { PRICED_TOKENS as PRICED_TOKENS2 } from "@tokemak/tokenlist";
5302
+ import { TOKEMAK_PRICES_STAGING_URL } from "@tokemak/constants";
5303
+ var getTokenPrices = async () => {
5304
+ try {
5305
+ const body = {
5306
+ tokens: PRICED_TOKENS2.map((asset) => ({
5307
+ token: asset.address,
5308
+ chainId: asset.chainId,
5309
+ systemName: "gen3",
5310
+ timeoutMS: 5 * 1e3
5311
+ }))
5312
+ };
5313
+ const response = await fetch(`${TOKEMAK_PRICES_STAGING_URL}`, {
5314
+ method: "POST",
5315
+ headers: {
5316
+ "Content-Type": "application/json"
5317
+ },
5318
+ body: JSON.stringify(body)
5319
+ });
5320
+ const data = await response.json();
5321
+ const prices = PRICED_TOKENS2.reduce((acc, asset) => {
5322
+ const priceData = data.find(
5323
+ (item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
5324
+ );
5325
+ acc[asset.symbol] = priceData?.price ?? 0;
5326
+ return acc;
5327
+ }, {});
5328
+ const timestamp = Math.floor(Date.now() / 1e3);
5329
+ return {
5330
+ timestamp,
5331
+ isStale: false,
5332
+ prices: {
5333
+ ...prices,
5334
+ WETH: prices.ETH,
5335
+ WS: prices.S,
5336
+ WXPL: prices.XPL,
5337
+ WMON: prices.MON
5338
+ }
5339
+ };
5340
+ } catch (e) {
5341
+ console.error("getTokenPrices failed:", e);
5342
+ return {
5343
+ prices: void 0,
5344
+ timestamp: void 0,
5345
+ isStale: false
5346
+ };
5347
+ }
5348
+ };
5349
+
5458
5350
  // functions/getChainSubgraphStatus.ts
5459
5351
  import { getSdkByChainId as getSdkByChainId16 } from "@tokemak/graph-cli";
5460
5352
  var getChainSubgraphStatus = async (chain) => {
@@ -5512,7 +5404,7 @@ var getSubgraphStatus = async (includeTestnet = false) => {
5512
5404
  };
5513
5405
 
5514
5406
  // functions/getCycleV1.ts
5515
- import { readContract as readContract16 } from "@wagmi/core";
5407
+ import { readContract as readContract15 } from "@wagmi/core";
5516
5408
  import { managerV1Abi as managerV1Abi2 } from "@tokemak/abis";
5517
5409
  import { createPublicClient, http } from "viem";
5518
5410
  import {
@@ -5534,7 +5426,7 @@ var getCycleV1 = async (wagmiConfig, {
5534
5426
  const { managerV1 } = getMainnetConfig7();
5535
5427
  try {
5536
5428
  if (currentBlockNumber && managerV1) {
5537
- const currentCycleIndex = await readContract16(wagmiConfig, {
5429
+ const currentCycleIndex = await readContract15(wagmiConfig, {
5538
5430
  address: managerV1,
5539
5431
  abi: managerV1Abi2,
5540
5432
  functionName: "getCurrentCycleIndex",
@@ -5656,28 +5548,26 @@ import { getSdkByChainId as getSdkByChainId17 } from "@tokemak/graph-cli";
5656
5548
 
5657
5549
  // functions/getEthPriceAtBlock.ts
5658
5550
  import { getCoreConfig as getCoreConfig10 } from "@tokemak/config";
5659
- import { readContract as readContract17 } from "@wagmi/core";
5660
5551
  import { rootPriceOracleAbi } from "@tokemak/abis";
5661
- import { USDC_TOKEN as USDC_TOKEN2 } from "@tokemak/tokenlist";
5662
- var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
5552
+ import { USDC_TOKEN } from "@tokemak/tokenlist";
5553
+ var getEthPriceAtBlock = async (client, blockNumber, chainId) => {
5663
5554
  const config = getCoreConfig10(chainId);
5664
5555
  const rootPriceOracle = config.rootPriceOracle;
5665
5556
  const weth = config.weth;
5666
- const usdc = USDC_TOKEN2.extensions?.bridgeInfo?.[chainId]?.tokenAddress || USDC_TOKEN2.address;
5667
- const priceAtBlock = await readContract17(wagmiConfig, {
5557
+ const usdc = USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || USDC_TOKEN.address;
5558
+ const priceAtBlock = await client.readContract({
5668
5559
  address: rootPriceOracle,
5669
5560
  abi: rootPriceOracleAbi,
5670
5561
  functionName: "getPriceInQuote",
5671
5562
  args: [weth, usdc],
5672
- blockNumber,
5673
- chainId
5563
+ blockNumber
5674
5564
  });
5675
5565
  return priceAtBlock;
5676
5566
  };
5677
5567
 
5678
5568
  // functions/getRebalanceStats.ts
5679
5569
  import { formatEtherNum as formatEtherNum15, formatUnitsNum as formatUnitsNum8 } from "@tokemak/utils";
5680
- import { USDC_TOKEN as USDC_TOKEN3 } from "@tokemak/tokenlist";
5570
+ import { USDC_TOKEN as USDC_TOKEN2 } from "@tokemak/tokenlist";
5681
5571
  import { sonic as sonic3 } from "viem/chains";
5682
5572
  var BATCH_SIZE = 500;
5683
5573
  var fetchChainRebalances = async (chainId) => {
@@ -5698,18 +5588,18 @@ function inferBaseAssetDecimals(rebalance, chainId) {
5698
5588
  if (chainId === sonic3.id) {
5699
5589
  return rebalance.tokenOut.decimals;
5700
5590
  }
5701
- return USDC_TOKEN3.decimals;
5591
+ return USDC_TOKEN2.decimals;
5702
5592
  }
5703
- var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
5593
+ var getRebalanceValueUsd = async (rebalance, chainId, client) => {
5704
5594
  const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
5705
5595
  if (ethWei === 0n) return null;
5706
5596
  try {
5707
5597
  const price = await getEthPriceAtBlock(
5708
- wagmiConfig,
5598
+ client,
5709
5599
  BigInt(rebalance.blockNumber),
5710
5600
  chainId
5711
5601
  );
5712
- const ethUsd = Number(formatUnitsNum8(price, USDC_TOKEN3.decimals));
5602
+ const ethUsd = Number(formatUnitsNum8(price, USDC_TOKEN2.decimals));
5713
5603
  const ethAmt = Number(formatEtherNum15(ethWei));
5714
5604
  const usd = ethAmt * ethUsd;
5715
5605
  return usd;
@@ -5718,7 +5608,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
5718
5608
  return null;
5719
5609
  }
5720
5610
  };
5721
- var processRebalance = async (rebalance, chainId, wagmiConfig) => {
5611
+ var processRebalance = async (rebalance, chainId, client) => {
5722
5612
  const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
5723
5613
  const baseAssetAmount = Number(
5724
5614
  formatUnitsNum8(
@@ -5726,11 +5616,7 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
5726
5616
  baseDecimals
5727
5617
  )
5728
5618
  );
5729
- const ethPathUsd = await getRebalanceValueUsd(
5730
- rebalance,
5731
- chainId,
5732
- wagmiConfig
5733
- );
5619
+ const ethPathUsd = await getRebalanceValueUsd(rebalance, chainId, client);
5734
5620
  if (ethPathUsd != null) {
5735
5621
  return {
5736
5622
  autopool: rebalance.autopool,
@@ -5750,12 +5636,12 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
5750
5636
  valueInAsset: baseAssetAmount
5751
5637
  };
5752
5638
  };
5753
- var processRebalancesInBatches = async (rebalances, chainId, wagmiConfig) => {
5639
+ var processRebalancesInBatches = async (rebalances, chainId, client) => {
5754
5640
  const processedRebalances = [];
5755
5641
  for (let i = 0; i < rebalances.length; i += BATCH_SIZE) {
5756
5642
  const batch = rebalances.slice(i, i + BATCH_SIZE);
5757
5643
  const batchPromises = batch.map(
5758
- async (rebalance) => processRebalance(rebalance, chainId, wagmiConfig)
5644
+ async (rebalance) => processRebalance(rebalance, chainId, client)
5759
5645
  );
5760
5646
  const batchResults = await Promise.all(batchPromises);
5761
5647
  processedRebalances.push(...batchResults);
@@ -5780,18 +5666,15 @@ var calculateRebalanceStats = (rebalances) => {
5780
5666
  rebalances
5781
5667
  };
5782
5668
  };
5783
- var getRebalanceStats = async (wagmiConfig, {
5669
+ var getRebalanceStats = async (getClient, {
5784
5670
  includeTestnet = false
5785
5671
  }) => {
5786
5672
  const chains = getChainsForEnv({ includeTestnet });
5787
5673
  const rebalances = await Promise.all(
5788
5674
  chains.map(async (chain) => {
5789
5675
  const rawRebalances = await fetchChainRebalances(chain.chainId);
5790
- return processRebalancesInBatches(
5791
- rawRebalances,
5792
- chain.chainId,
5793
- wagmiConfig
5794
- );
5676
+ const client = getClient(chain.chainId);
5677
+ return processRebalancesInBatches(rawRebalances, chain.chainId, client);
5795
5678
  })
5796
5679
  );
5797
5680
  const allRebalances = rebalances.flat();
@@ -5799,6 +5682,7 @@ var getRebalanceStats = async (wagmiConfig, {
5799
5682
  };
5800
5683
 
5801
5684
  // functions/updateRebalanceStats.ts
5685
+ import { getPublicClient as getPublicClient4 } from "@wagmi/core";
5802
5686
  var updateRebalanceStats = async (wagmiConfig, {
5803
5687
  currentRebalances,
5804
5688
  includeTestnet = false
@@ -5813,10 +5697,13 @@ var updateRebalanceStats = async (wagmiConfig, {
5813
5697
  )
5814
5698
  );
5815
5699
  if (newRawRebalances.length > 0) {
5700
+ const client = getPublicClient4(wagmiConfig, {
5701
+ chainId: chain.chainId
5702
+ });
5816
5703
  return processRebalancesInBatches(
5817
5704
  newRawRebalances,
5818
5705
  chain.chainId,
5819
- wagmiConfig
5706
+ client
5820
5707
  );
5821
5708
  }
5822
5709
  return [];
@@ -5833,7 +5720,6 @@ import { getMainnetConfig as getMainnetConfig8 } from "@tokemak/config";
5833
5720
  import {
5834
5721
  convertAutoCycleToUnix,
5835
5722
  convertSecondsToRemainingTime as convertSecondsToRemainingTime4,
5836
- formatAmount,
5837
5723
  formatCurrency as formatCurrency4,
5838
5724
  formatEtherNum as formatEtherNum16
5839
5725
  } from "@tokemak/utils";
@@ -5942,7 +5828,7 @@ var getUserSAuto = async (wagmiConfig, {
5942
5828
  return {
5943
5829
  balance,
5944
5830
  balanceUSD,
5945
- balanceExcludingWithdrawal: hasBalance ? formatAmount(formatEther5(balanceExcludingWithdrawal)) : "0.00",
5831
+ balanceExcludingWithdrawal: hasBalance ? formatEther5(balanceExcludingWithdrawal) : "0.00",
5946
5832
  balanceExcludingWithdrawalUsd,
5947
5833
  hasBalanceExcludingWithdrawal,
5948
5834
  timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime4(
@@ -6172,20 +6058,20 @@ var getUserMerklRewards = async (address) => {
6172
6058
 
6173
6059
  // functions/getUserEthAutoLPRewards.ts
6174
6060
  import { getAddress as getAddress5 } from "viem";
6175
- import { formatAmount as formatAmount2, formatUnitsNum as formatUnitsNum9 } from "@tokemak/utils";
6061
+ import { formatAmount, formatUnitsNum as formatUnitsNum9 } from "@tokemak/utils";
6176
6062
  import {
6177
- TOKE_TOKEN as TOKE_TOKEN4
6063
+ TOKE_TOKEN as TOKE_TOKEN3
6178
6064
  } from "@tokemak/tokenlist";
6179
6065
  var getUserEthAutoLPRewards = async (address) => {
6180
6066
  const rewards = await getUserMerklRewards(address);
6181
6067
  const autoTokenRewards = rewards?.rewards?.filter(
6182
- (reward) => getAddress5(reward.token.address) === getAddress5(TOKE_TOKEN4.address)
6068
+ (reward) => getAddress5(reward.token.address) === getAddress5(TOKE_TOKEN3.address)
6183
6069
  );
6184
6070
  const autoRewards = autoTokenRewards?.[0];
6185
6071
  const amount = autoRewards?.amount;
6186
6072
  const claimed = autoRewards?.claimed;
6187
6073
  const claimable = Number(amount) - Number(claimed);
6188
- const formattedClaimable = formatAmount2(
6074
+ const formattedClaimable = formatAmount(
6189
6075
  formatUnitsNum9(BigInt(claimable || 0), 18)
6190
6076
  );
6191
6077
  const users = [];
@@ -6330,12 +6216,10 @@ var getCombinedRewards = async () => {
6330
6216
  };
6331
6217
  export {
6332
6218
  AutopoolCategory,
6333
- BASE_ASSETS,
6334
6219
  BATCH_SIZE,
6335
6220
  ETH_BASE_ASSETS,
6336
6221
  EUR_BASE_ASSETS,
6337
6222
  MessageStatus,
6338
- PRICED_TOKENS,
6339
6223
  USD_BASE_ASSETS,
6340
6224
  aggregateSTokeRewardsDayData,
6341
6225
  arraysToObject,