@tokemak/queries 0.7.0 → 0.8.1

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 (67) hide show
  1. package/dist/functions/getAutopools.d.ts +3 -1
  2. package/dist/functions/getAutopools.d.ts.map +1 -1
  3. package/dist/functions/getDeprecatedAutopools.d.ts +347 -0
  4. package/dist/functions/getDeprecatedAutopools.d.ts.map +1 -0
  5. package/dist/functions/getEthAutoLP.d.ts +1 -1
  6. package/dist/functions/getEthAutoLP.d.ts.map +1 -1
  7. package/dist/functions/getUniV4Pool.d.ts +13 -17
  8. package/dist/functions/getUniV4Pool.d.ts.map +1 -1
  9. package/dist/functions/getUserUniV4Positions.d.ts +1 -0
  10. package/dist/functions/getUserUniV4Positions.d.ts.map +1 -1
  11. package/dist/functions/index.d.ts +3 -23
  12. package/dist/functions/index.d.ts.map +1 -1
  13. package/dist/functions/uniV4Subgraph.d.ts +45 -0
  14. package/dist/functions/uniV4Subgraph.d.ts.map +1 -0
  15. package/dist/index.js +419 -1714
  16. package/dist/index.mjs +291 -1589
  17. package/dist/safe.js +12 -8
  18. package/dist/safe.mjs +8 -4
  19. package/dist/utils/getChainsForEnv.d.ts +12 -3
  20. package/dist/utils/getChainsForEnv.d.ts.map +1 -1
  21. package/package.json +7 -7
  22. package/dist/functions/getAllowance.d.ts +0 -8
  23. package/dist/functions/getAllowance.d.ts.map +0 -1
  24. package/dist/functions/getAutopoolsRebalances.d.ts +0 -53
  25. package/dist/functions/getAutopoolsRebalances.d.ts.map +0 -1
  26. package/dist/functions/getChainCycleRolloverBlockNumber.d.ts +0 -7
  27. package/dist/functions/getChainCycleRolloverBlockNumber.d.ts.map +0 -1
  28. package/dist/functions/getChainSToke.d.ts +0 -15
  29. package/dist/functions/getChainSToke.d.ts.map +0 -1
  30. package/dist/functions/getChainSTokeRewards.d.ts +0 -16
  31. package/dist/functions/getChainSTokeRewards.d.ts.map +0 -1
  32. package/dist/functions/getChainUserSToke.d.ts +0 -33
  33. package/dist/functions/getChainUserSToke.d.ts.map +0 -1
  34. package/dist/functions/getChainUserSTokeRewards.d.ts +0 -30
  35. package/dist/functions/getChainUserSTokeRewards.d.ts.map +0 -1
  36. package/dist/functions/getCombinedRewards.d.ts +0 -11
  37. package/dist/functions/getCombinedRewards.d.ts.map +0 -1
  38. package/dist/functions/getCurveLP.d.ts +0 -3
  39. package/dist/functions/getCurveLP.d.ts.map +0 -1
  40. package/dist/functions/getCycleV1.d.ts +0 -10
  41. package/dist/functions/getCycleV1.d.ts.map +0 -1
  42. package/dist/functions/getEthPrice.d.ts +0 -2
  43. package/dist/functions/getEthPrice.d.ts.map +0 -1
  44. package/dist/functions/getLayerzeroStatus.d.ts +0 -24
  45. package/dist/functions/getLayerzeroStatus.d.ts.map +0 -1
  46. package/dist/functions/getMultipleAutopoolRebalances.d.ts +0 -54
  47. package/dist/functions/getMultipleAutopoolRebalances.d.ts.map +0 -1
  48. package/dist/functions/getProtocolStats.d.ts +0 -41
  49. package/dist/functions/getProtocolStats.d.ts.map +0 -1
  50. package/dist/functions/getSToke.d.ts +0 -23
  51. package/dist/functions/getSToke.d.ts.map +0 -1
  52. package/dist/functions/getSTokeRewards.d.ts +0 -22
  53. package/dist/functions/getSTokeRewards.d.ts.map +0 -1
  54. package/dist/functions/getSushiLP.d.ts +0 -14
  55. package/dist/functions/getSushiLP.d.ts.map +0 -1
  56. package/dist/functions/getTokenList.d.ts +0 -3
  57. package/dist/functions/getTokenList.d.ts.map +0 -1
  58. package/dist/functions/getUserCurveLP.d.ts +0 -16
  59. package/dist/functions/getUserCurveLP.d.ts.map +0 -1
  60. package/dist/functions/getUserSToke.d.ts +0 -40
  61. package/dist/functions/getUserSToke.d.ts.map +0 -1
  62. package/dist/functions/getUserSTokeRewards.d.ts +0 -38
  63. package/dist/functions/getUserSTokeRewards.d.ts.map +0 -1
  64. package/dist/functions/getUserSushiLP.d.ts +0 -23
  65. package/dist/functions/getUserSushiLP.d.ts.map +0 -1
  66. package/dist/functions/getUserV1.d.ts +0 -18
  67. package/dist/functions/getUserV1.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -17,8 +17,8 @@ var getBlobData = async (blobName) => {
17
17
  }
18
18
  };
19
19
 
20
- // functions/getEthPrice.ts
21
- import { sepolia } from "viem/chains";
20
+ // functions/getTokePrice.ts
21
+ import { TOKE_TOKEN } from "@tokemak/tokenlist";
22
22
 
23
23
  // functions/getTokenPrice.ts
24
24
  import { TOKEMAK_SWAP_PRICING_URL } from "@tokemak/constants";
@@ -91,27 +91,7 @@ async function getTokenPriceFallback(tokenSymbol) {
91
91
  }
92
92
  }
93
93
 
94
- // functions/getEthPrice.ts
95
- var getEthPrice = async () => {
96
- try {
97
- return await getTokenPrice({
98
- chainId: sepolia.id,
99
- tokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
100
- });
101
- } catch (error) {
102
- console.warn("Primary price fetch failed. Attempting fallback...", error);
103
- try {
104
- const fallbackPrice = await getTokenPriceFallback("eth");
105
- return fallbackPrice;
106
- } catch (fallbackError) {
107
- console.error("Fallback fetch also failed:", fallbackError);
108
- return 0;
109
- }
110
- }
111
- };
112
-
113
94
  // functions/getTokePrice.ts
114
- import { TOKE_TOKEN } from "@tokemak/tokenlist";
115
95
  var getTokePrice = async () => {
116
96
  try {
117
97
  return await getTokenPrice({ tokenAddress: TOKE_TOKEN.address });
@@ -298,12 +278,16 @@ import {
298
278
  SUPPORTED_DEV_CHAINS,
299
279
  SUPPORTED_PROD_CHAINS
300
280
  } from "@tokemak/constants";
281
+ import { isSunsetChain } from "@tokemak/config";
301
282
  function getChainsForEnv({
302
- includeTestnet = false
283
+ includeTestnet = false,
284
+ status = "all"
303
285
  }) {
304
- let chains;
305
- chains = includeTestnet ? [...SUPPORTED_DEV_CHAINS] : [...SUPPORTED_PROD_CHAINS];
306
- return chains;
286
+ const base2 = includeTestnet ? [...SUPPORTED_DEV_CHAINS] : [...SUPPORTED_PROD_CHAINS];
287
+ if (status === "all") return base2;
288
+ return base2.filter(
289
+ (chain) => status === "sunset" ? isSunsetChain(chain.chainId) : !isSunsetChain(chain.chainId)
290
+ );
307
291
  }
308
292
 
309
293
  // utils/fetchChainDataMap.ts
@@ -1047,10 +1031,11 @@ import { AUTOPOOLS_WHITELIST_PROD } from "@tokemak/config";
1047
1031
  import { getAddress as getAddress2 } from "viem";
1048
1032
  var getAutopools = async (wagmiConfig, {
1049
1033
  prices,
1050
- includeTestnet = false
1034
+ includeTestnet = false,
1035
+ status = "all"
1051
1036
  }) => {
1052
1037
  try {
1053
- const chains = getChainsForEnv({ includeTestnet });
1038
+ const chains = getChainsForEnv({ includeTestnet, status });
1054
1039
  const autopools = (await Promise.all(
1055
1040
  chains.map((chain) => {
1056
1041
  const chainId = chain?.chainId;
@@ -1075,6 +1060,12 @@ var getAutopools = async (wagmiConfig, {
1075
1060
  }
1076
1061
  };
1077
1062
 
1063
+ // functions/getDeprecatedAutopools.ts
1064
+ var getDeprecatedAutopools = (wagmiConfig, {
1065
+ prices,
1066
+ includeTestnet = false
1067
+ }) => getAutopools(wagmiConfig, { prices, includeTestnet, status: "sunset" });
1068
+
1078
1069
  // functions/getAutopoolRebalances.ts
1079
1070
  import { getSdkByChainId as getSdkByChainId2 } from "@tokemak/graph-cli";
1080
1071
  var getAutopoolRebalances = async (id, chainId = 1, options) => {
@@ -1094,23 +1085,14 @@ var getAutopoolRebalances = async (id, chainId = 1, options) => {
1094
1085
  }));
1095
1086
  };
1096
1087
 
1097
- // functions/getAutopoolsRebalances.ts
1098
- import { getSdkByChainId as getSdkByChainId3 } from "@tokemak/graph-cli";
1099
- var getAutopoolsRebalances = async (chainId = 1) => {
1100
- const { GetAutopoolsRebalances } = getSdkByChainId3(chainId);
1101
- const { autopools } = await GetAutopoolsRebalances();
1102
- const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
1103
- return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
1104
- };
1105
-
1106
1088
  // functions/getAutopoolDayData.ts
1107
1089
  import { formatUnits as formatUnits3 } from "viem";
1108
1090
  import { formatEtherNum as formatEtherNum3 } from "@tokemak/utils";
1109
1091
  import { TOKEMAK_LAUNCH_TIMESTAMP } from "@tokemak/constants";
1110
- import { getSdkByChainId as getSdkByChainId4 } from "@tokemak/graph-cli";
1092
+ import { getSdkByChainId as getSdkByChainId3 } from "@tokemak/graph-cli";
1111
1093
  var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_LAUNCH_TIMESTAMP) => {
1112
1094
  try {
1113
- const { GetAutopoolDayData } = getSdkByChainId4(chainId);
1095
+ const { GetAutopoolDayData } = getSdkByChainId3(chainId);
1114
1096
  const { autopoolDayDatas } = await GetAutopoolDayData({
1115
1097
  address,
1116
1098
  timestamp: startTimestamp
@@ -1169,9 +1151,9 @@ var getAutopoolHistory = async (autopool) => {
1169
1151
  import { getAddress as getAddress3 } from "viem";
1170
1152
 
1171
1153
  // functions/getAutopoolsDayData.ts
1172
- import { getSdkByChainId as getSdkByChainId5 } from "@tokemak/graph-cli";
1154
+ import { getSdkByChainId as getSdkByChainId4 } from "@tokemak/graph-cli";
1173
1155
  var getAutopoolsDayData = async (chainId, timestamp) => {
1174
- const { GetAutopoolsDayData } = getSdkByChainId5(chainId);
1156
+ const { GetAutopoolsDayData } = getSdkByChainId4(chainId);
1175
1157
  const PAGE_SIZE = 1e3;
1176
1158
  let allResults = [];
1177
1159
  let hasMore = true;
@@ -1386,7 +1368,7 @@ var getAutopoolUser = async (config, {
1386
1368
  };
1387
1369
 
1388
1370
  // functions/getAutopoolUserActivity.ts
1389
- import { getSdkByChainId as getSdkByChainId6 } from "@tokemak/graph-cli";
1371
+ import { getSdkByChainId as getSdkByChainId5 } from "@tokemak/graph-cli";
1390
1372
  import { formatUnitsNum as formatUnitsNum3 } from "@tokemak/utils";
1391
1373
  var getAutopoolUserActivity = async ({
1392
1374
  autopool,
@@ -1395,7 +1377,7 @@ var getAutopoolUserActivity = async ({
1395
1377
  if (!autopool || !autopool.chain?.chainId) {
1396
1378
  throw new Error("Autopool not found");
1397
1379
  }
1398
- const { GetUserAutopoolBalanceChangeHistory } = getSdkByChainId6(
1380
+ const { GetUserAutopoolBalanceChangeHistory } = getSdkByChainId5(
1399
1381
  autopool.chain?.chainId
1400
1382
  );
1401
1383
  try {
@@ -1474,7 +1456,7 @@ var getAutopoolUserActivity = async ({
1474
1456
  };
1475
1457
 
1476
1458
  // functions/getAutopoolUserHistory.ts
1477
- import { getSdkByChainId as getSdkByChainId7 } from "@tokemak/graph-cli";
1459
+ import { getSdkByChainId as getSdkByChainId6 } from "@tokemak/graph-cli";
1478
1460
  import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP2 } from "@tokemak/constants";
1479
1461
  import { base } from "viem/chains";
1480
1462
  import { formatEtherNum as formatEtherNum5, formatUnitsNum as formatUnitsNum4 } from "@tokemak/utils";
@@ -1483,7 +1465,7 @@ var getAutopoolUserHistory = async ({
1483
1465
  autopool,
1484
1466
  userActivity
1485
1467
  }) => {
1486
- const { GetUserVaultDayData } = getSdkByChainId7(
1468
+ const { GetUserVaultDayData } = getSdkByChainId6(
1487
1469
  autopool?.chain?.chainId || base.id
1488
1470
  );
1489
1471
  try {
@@ -1570,102 +1552,62 @@ var getAutopoolUserHistory = async ({
1570
1552
  }
1571
1553
  };
1572
1554
 
1573
- // functions/getCurveLP.ts
1574
- import { getMainnetConfig } from "@tokemak/config";
1575
- import { CURVE_API_URL, TOKE_CURVE_POOL_ID } from "@tokemak/constants";
1576
- var getCurveLP = async () => {
1577
- let curveData;
1578
- const { curveRewardsUrl } = getMainnetConfig();
1579
- try {
1580
- const curveRewardsResponse = await fetch(curveRewardsUrl);
1581
- const curveRewardsData = await curveRewardsResponse.json();
1582
- curveData = {
1583
- ...curveRewardsData,
1584
- // placeholder if other request fails
1585
- totalSupply: 0n,
1586
- apr: (curveRewardsData?.crvApy + curveRewardsData?.crvBoost) / 100
1587
- };
1588
- } catch (e) {
1589
- console.error(e);
1555
+ // functions/getUniV4Pool.ts
1556
+ import { readContracts as readContracts2 } from "@wagmi/core";
1557
+ import { formatUnits as formatUnits4, keccak256, encodeAbiParameters } from "viem";
1558
+ import { mainnet as mainnet2 } from "viem/chains";
1559
+ import {
1560
+ UNISWAP_V4_POOL_MANAGER,
1561
+ UNISWAP_V4_STATE_VIEW
1562
+ } from "@tokemak/constants";
1563
+
1564
+ // functions/uniV4Subgraph.ts
1565
+ import { mainnet } from "viem/chains";
1566
+ import { GraphQLClient, gql } from "graphql-request";
1567
+ var V4_SUBGRAPH_IDS = {
1568
+ [mainnet.id]: "DiYPVdygkfjDWhbxGSqAQxwBKmfKnkWQojqeM2rkLb3G"
1569
+ };
1570
+ var GRAPH_V4_SUBGRAPH_PROXY_PATH = "/api/uniswap/v4-subgraph";
1571
+ function getV4SubgraphUrl(chainId, apiKey) {
1572
+ const subgraphId = V4_SUBGRAPH_IDS[chainId];
1573
+ if (!subgraphId) return null;
1574
+ if (apiKey) {
1575
+ return `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
1590
1576
  }
1591
- try {
1592
- const curvePoolsResponse = await fetch(CURVE_API_URL);
1593
- const curvePoolsData = await curvePoolsResponse.json();
1594
- const curveTOKEPool = curvePoolsData?.data?.poolData.find(
1595
- (pool) => pool.id === TOKE_CURVE_POOL_ID
1596
- );
1597
- if (curveData) {
1598
- curveData.curveTvl = curveTOKEPool?.usdTotal;
1599
- curveData.totalSupply = BigInt(curveTOKEPool?.totalSupply);
1577
+ if (typeof window !== "undefined") {
1578
+ return `${GRAPH_V4_SUBGRAPH_PROXY_PATH}?chainId=${chainId}`;
1579
+ }
1580
+ return `https://gateway.thegraph.com/api/subgraphs/id/${subgraphId}`;
1581
+ }
1582
+ var GET_V4_POOL_TVL = gql`
1583
+ query GetV4Pool($id: ID!) {
1584
+ pool(id: $id) {
1585
+ id
1586
+ totalValueLockedToken0
1587
+ totalValueLockedToken1
1588
+ totalValueLockedUSD
1589
+ token0Price
1590
+ token1Price
1600
1591
  }
1601
- } catch (e) {
1602
- console.error(e);
1603
1592
  }
1604
- return curveData;
1605
- };
1606
-
1607
- // functions/getSushiLP.ts
1608
- import { sushiPoolAbi } from "@tokemak/abis";
1609
- import { getMainnetConfig as getMainnetConfig2 } from "@tokemak/config";
1610
- import { readContracts as readContracts2 } from "@wagmi/core";
1611
- import { formatEther } from "viem";
1612
- import { mainnet } from "viem/chains";
1613
- var getSushiLP = async (wagmiConfig, { ethPrice }) => {
1614
- const { sushiPool, lpRewardsV1Url } = getMainnetConfig2();
1615
- const sushiPoolContract = {
1616
- address: sushiPool,
1617
- abi: sushiPoolAbi
1618
- };
1593
+ `;
1594
+ async function getV4PoolTvlFromSubgraph(poolId, chainId, apiKey) {
1595
+ const url = getV4SubgraphUrl(chainId, apiKey);
1596
+ if (!url) return null;
1619
1597
  try {
1620
- const [{ result: reserves }, { result: totalSupply }] = await readContracts2(
1621
- wagmiConfig,
1622
- {
1623
- contracts: [
1624
- {
1625
- ...sushiPoolContract,
1626
- functionName: "getReserves",
1627
- chainId: mainnet.id
1628
- },
1629
- {
1630
- ...sushiPoolContract,
1631
- functionName: "totalSupply",
1632
- chainId: mainnet.id
1633
- }
1634
- ]
1635
- }
1636
- );
1637
- const lpRewardsResponse = await fetch(lpRewardsV1Url);
1638
- const lpRewardsData = await lpRewardsResponse.json();
1639
- const sushiLPRewards = lpRewardsData.chains[0].pools.find(
1640
- ({ name }) => name === "SUSHI_LP"
1598
+ const client = new GraphQLClient(url);
1599
+ const data = await client.request(
1600
+ GET_V4_POOL_TVL,
1601
+ { id: poolId.toLowerCase() }
1641
1602
  );
1642
- if (reserves && totalSupply && ethPrice) {
1643
- const lpReserve = reserves[1] * 2n;
1644
- const tvl = Number(formatEther(lpReserve)) * ethPrice;
1645
- const valueOf1LP = tvl / Number(formatEther(totalSupply));
1646
- return {
1647
- tvl,
1648
- lpReserve,
1649
- totalSupply,
1650
- reserves,
1651
- apr: sushiLPRewards?.liquidityProviderApr,
1652
- weeklyTokeEmissions: sushiLPRewards?.liquidityProviderReward,
1653
- valueOf1LP
1654
- };
1655
- }
1603
+ return data.pool ?? null;
1656
1604
  } catch (e) {
1657
- console.log(e);
1605
+ console.error("Error fetching V4 pool TVL from subgraph:", e);
1606
+ return null;
1658
1607
  }
1659
- };
1608
+ }
1660
1609
 
1661
1610
  // functions/getUniV4Pool.ts
1662
- import { readContracts as readContracts3 } from "@wagmi/core";
1663
- import { formatUnits as formatUnits4, keccak256, encodeAbiParameters } from "viem";
1664
- import { mainnet as mainnet2 } from "viem/chains";
1665
- import {
1666
- UNISWAP_V4_POOL_MANAGER,
1667
- UNISWAP_V4_STATE_VIEW
1668
- } from "@tokemak/constants";
1669
1611
  var stateViewAbi = [
1670
1612
  {
1671
1613
  inputs: [{ internalType: "PoolId", name: "poolId", type: "bytes32" }],
@@ -1757,166 +1699,6 @@ function feeToTierString(fee) {
1757
1699
  };
1758
1700
  return tiers[fee] || `${fee / 1e4}%`;
1759
1701
  }
1760
- async function getUniV4Pool(wagmiConfig, {
1761
- poolKey,
1762
- chainId = mainnet2.id,
1763
- prices
1764
- }) {
1765
- const stateView = UNISWAP_V4_STATE_VIEW[chainId];
1766
- if (!stateView) {
1767
- console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
1768
- return null;
1769
- }
1770
- const poolManager = UNISWAP_V4_POOL_MANAGER[chainId];
1771
- const poolId = computePoolId(poolKey);
1772
- try {
1773
- const [{ result: slot0 }, { result: liquidity }] = await readContracts3(
1774
- wagmiConfig,
1775
- {
1776
- contracts: [
1777
- {
1778
- address: stateView,
1779
- abi: stateViewAbi,
1780
- functionName: "getSlot0",
1781
- args: [poolId],
1782
- chainId
1783
- },
1784
- {
1785
- address: stateView,
1786
- abi: stateViewAbi,
1787
- functionName: "getLiquidity",
1788
- args: [poolId],
1789
- chainId
1790
- }
1791
- ]
1792
- }
1793
- );
1794
- if (!slot0) {
1795
- return null;
1796
- }
1797
- const isToken0Native = poolKey.currency0 === "0x0000000000000000000000000000000000000000";
1798
- const isToken1Native = poolKey.currency1 === "0x0000000000000000000000000000000000000000";
1799
- const tokenContracts = [];
1800
- if (!isToken0Native) {
1801
- tokenContracts.push(
1802
- {
1803
- address: poolKey.currency0,
1804
- abi: erc20Abi2,
1805
- functionName: "decimals",
1806
- chainId
1807
- },
1808
- {
1809
- address: poolKey.currency0,
1810
- abi: erc20Abi2,
1811
- functionName: "symbol",
1812
- chainId
1813
- },
1814
- {
1815
- address: poolKey.currency0,
1816
- abi: erc20Abi2,
1817
- functionName: "balanceOf",
1818
- args: [poolManager],
1819
- chainId
1820
- }
1821
- );
1822
- }
1823
- if (!isToken1Native) {
1824
- tokenContracts.push(
1825
- {
1826
- address: poolKey.currency1,
1827
- abi: erc20Abi2,
1828
- functionName: "decimals",
1829
- chainId
1830
- },
1831
- {
1832
- address: poolKey.currency1,
1833
- abi: erc20Abi2,
1834
- functionName: "symbol",
1835
- chainId
1836
- },
1837
- {
1838
- address: poolKey.currency1,
1839
- abi: erc20Abi2,
1840
- functionName: "balanceOf",
1841
- args: [poolManager],
1842
- chainId
1843
- }
1844
- );
1845
- }
1846
- const tokenResults = tokenContracts.length > 0 ? await readContracts3(wagmiConfig, { contracts: tokenContracts }) : [];
1847
- let decimals0 = 18;
1848
- let symbol0 = "ETH";
1849
- let balance0 = 0n;
1850
- let decimals1 = 18;
1851
- let symbol1 = "ETH";
1852
- let balance1 = 0n;
1853
- let resultIndex = 0;
1854
- if (!isToken0Native) {
1855
- decimals0 = tokenResults[resultIndex++]?.result ?? 18;
1856
- symbol0 = tokenResults[resultIndex++]?.result ?? "TOKEN0";
1857
- balance0 = tokenResults[resultIndex++]?.result ?? 0n;
1858
- }
1859
- if (!isToken1Native) {
1860
- decimals1 = tokenResults[resultIndex++]?.result ?? 18;
1861
- symbol1 = tokenResults[resultIndex++]?.result ?? "TOKEN1";
1862
- balance1 = tokenResults[resultIndex++]?.result ?? 0n;
1863
- }
1864
- const [sqrtPriceX96, tick] = slot0;
1865
- const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
1866
- const balance0Formatted = Number(formatUnits4(balance0, decimals0));
1867
- const balance1Formatted = Number(formatUnits4(balance1, decimals1));
1868
- const liquidityAmounts = calculateAmountsFromLiquidity(
1869
- liquidity ?? 0n,
1870
- sqrtPriceX96,
1871
- decimals0,
1872
- decimals1
1873
- );
1874
- const priceInverted = price > 0 ? 1 / price : 0;
1875
- const tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
1876
- const tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
1877
- let tvlUsd;
1878
- if (prices) {
1879
- const price0 = prices[symbol0] || prices[poolKey.currency0.toLowerCase()];
1880
- const price1 = prices[symbol1] || prices[poolKey.currency1.toLowerCase()];
1881
- if (price0) {
1882
- tvlUsd = tvlToken0 * price0;
1883
- } else if (price1) {
1884
- tvlUsd = tvlToken1 * price1;
1885
- }
1886
- }
1887
- return {
1888
- poolId,
1889
- poolKey,
1890
- token0: {
1891
- address: poolKey.currency0,
1892
- symbol: symbol0,
1893
- decimals: decimals0,
1894
- balance: balance0,
1895
- balanceFormatted: balance0Formatted
1896
- },
1897
- token1: {
1898
- address: poolKey.currency1,
1899
- symbol: symbol1,
1900
- decimals: decimals1,
1901
- balance: balance1,
1902
- balanceFormatted: balance1Formatted
1903
- },
1904
- fee: poolKey.fee,
1905
- feeTier: feeToTierString(poolKey.fee),
1906
- sqrtPriceX96,
1907
- tick,
1908
- liquidity: liquidity ?? 0n,
1909
- liquidityAmounts,
1910
- price,
1911
- priceInverted,
1912
- tvlToken0,
1913
- tvlToken1,
1914
- tvlUsd
1915
- };
1916
- } catch (e) {
1917
- return null;
1918
- }
1919
- }
1920
1702
  function createPoolKey({
1921
1703
  tokenA,
1922
1704
  tokenB,
@@ -1948,7 +1730,8 @@ async function getUniV4PoolById(wagmiConfig, {
1948
1730
  }
1949
1731
  const poolManager = UNISWAP_V4_POOL_MANAGER[chainId];
1950
1732
  try {
1951
- const [{ result: slot0 }, { result: liquidity }] = await readContracts3(
1733
+ const tvlPromise = getV4PoolTvlFromSubgraph(poolId, chainId);
1734
+ const [{ result: slot0 }, { result: liquidity }] = await readContracts2(
1952
1735
  wagmiConfig,
1953
1736
  {
1954
1737
  contracts: [
@@ -2021,7 +1804,7 @@ async function getUniV4PoolById(wagmiConfig, {
2021
1804
  }
2022
1805
  );
2023
1806
  }
2024
- const tokenResults = tokenContracts.length > 0 ? await readContracts3(wagmiConfig, { contracts: tokenContracts }) : [];
1807
+ const tokenResults = tokenContracts.length > 0 ? await readContracts2(wagmiConfig, { contracts: tokenContracts }) : [];
2025
1808
  let decimals0 = 18;
2026
1809
  let symbol0 = "ETH";
2027
1810
  let balance0 = 0n;
@@ -2041,22 +1824,43 @@ async function getUniV4PoolById(wagmiConfig, {
2041
1824
  }
2042
1825
  const [sqrtPriceX96, tick] = slot0;
2043
1826
  const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
1827
+ const priceInverted = price > 0 ? 1 / price : 0;
2044
1828
  const balance0Formatted = Number(formatUnits4(balance0, decimals0));
2045
1829
  const balance1Formatted = Number(formatUnits4(balance1, decimals1));
2046
- const liquidityAmounts = calculateAmountsFromLiquidity(
2047
- liquidity ?? 0n,
2048
- sqrtPriceX96,
2049
- decimals0,
2050
- decimals1
2051
- );
2052
- const priceInverted = price > 0 ? 1 / price : 0;
2053
- const tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
2054
- const tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
1830
+ const subgraphPool = await tvlPromise;
1831
+ let liquidityAmounts;
1832
+ let tvlToken0;
1833
+ let tvlToken1;
2055
1834
  let tvlUsd;
2056
- if (prices) {
2057
- const price0 = prices[symbol0] || prices[currency0.toLowerCase()];
2058
- if (price0) {
2059
- tvlUsd = tvlToken0 * price0;
1835
+ if (subgraphPool) {
1836
+ const amount0 = Number(subgraphPool.totalValueLockedToken0);
1837
+ const amount1 = Number(subgraphPool.totalValueLockedToken1);
1838
+ liquidityAmounts = { amount0, amount1 };
1839
+ tvlToken0 = amount0 + amount1 * priceInverted;
1840
+ tvlToken1 = amount1 + amount0 * price;
1841
+ const subgraphUsd = Number(subgraphPool.totalValueLockedUSD);
1842
+ if (Number.isFinite(subgraphUsd) && subgraphUsd > 0) {
1843
+ tvlUsd = subgraphUsd;
1844
+ } else if (prices) {
1845
+ const price0 = prices[symbol0] || prices[currency0.toLowerCase()];
1846
+ const price1 = prices[symbol1] || prices[currency1.toLowerCase()];
1847
+ if (price0) tvlUsd = tvlToken0 * price0;
1848
+ else if (price1) tvlUsd = tvlToken1 * price1;
1849
+ }
1850
+ } else {
1851
+ liquidityAmounts = calculateAmountsFromLiquidity(
1852
+ liquidity ?? 0n,
1853
+ sqrtPriceX96,
1854
+ decimals0,
1855
+ decimals1
1856
+ );
1857
+ tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
1858
+ tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
1859
+ if (prices) {
1860
+ const price0 = prices[symbol0] || prices[currency0.toLowerCase()];
1861
+ const price1 = prices[symbol1] || prices[currency1.toLowerCase()];
1862
+ if (price0) tvlUsd = tvlToken0 * price0;
1863
+ else if (price1) tvlUsd = tvlToken1 * price1;
2060
1864
  }
2061
1865
  }
2062
1866
  return {
@@ -2093,26 +1897,14 @@ async function getUniV4PoolById(wagmiConfig, {
2093
1897
  }
2094
1898
 
2095
1899
  // functions/getUserUniV4Positions.ts
2096
- import { readContracts as readContracts4 } from "@wagmi/core";
1900
+ import { readContracts as readContracts3 } from "@wagmi/core";
2097
1901
  import { formatUnits as formatUnits5 } from "viem";
2098
1902
  import { mainnet as mainnet3 } from "viem/chains";
2099
- import { GraphQLClient, gql } from "graphql-request";
1903
+ import { GraphQLClient as GraphQLClient2, gql as gql2 } from "graphql-request";
2100
1904
  import {
2101
1905
  UNISWAP_V4_POSITION_MANAGER,
2102
- UNISWAP_V4_STATE_VIEW as UNISWAP_V4_STATE_VIEW2,
2103
- GRAPH_API_KEY
1906
+ UNISWAP_V4_STATE_VIEW as UNISWAP_V4_STATE_VIEW2
2104
1907
  } from "@tokemak/constants";
2105
- var V4_SUBGRAPH_IDS = {
2106
- [mainnet3.id]: "DiYPVdygkfjDWhbxGSqAQxwBKmfKnkWQojqeM2rkLb3G"
2107
- };
2108
- function getV4SubgraphUrl(chainId, apiKey) {
2109
- const subgraphId = V4_SUBGRAPH_IDS[chainId];
2110
- if (!subgraphId) return null;
2111
- if (apiKey) {
2112
- return `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
2113
- }
2114
- return `https://gateway.thegraph.com/api/subgraphs/id/${subgraphId}`;
2115
- }
2116
1908
  var positionManagerAbi = [
2117
1909
  {
2118
1910
  inputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }],
@@ -2177,7 +1969,7 @@ var erc20Abi3 = [
2177
1969
  type: "function"
2178
1970
  }
2179
1971
  ];
2180
- var GET_USER_POSITIONS = gql`
1972
+ var GET_USER_POSITIONS = gql2`
2181
1973
  query GetUserPositions($owner: String!) {
2182
1974
  positions(where: { owner: $owner }) {
2183
1975
  tokenId
@@ -2231,7 +2023,7 @@ async function getPositionTokenIdsFromSubgraph(userAddress, chainId, graphApiKey
2231
2023
  return [];
2232
2024
  }
2233
2025
  try {
2234
- const client = new GraphQLClient(subgraphUrl);
2026
+ const client = new GraphQLClient2(subgraphUrl);
2235
2027
  const data = await client.request(GET_USER_POSITIONS, {
2236
2028
  owner: userAddress.toLowerCase()
2237
2029
  });
@@ -2265,11 +2057,10 @@ async function getUserUniV4PositionsById(wagmiConfig, {
2265
2057
  if (knownTokenIds && knownTokenIds.length > 0) {
2266
2058
  tokenIds = knownTokenIds;
2267
2059
  } else {
2268
- const apiKey = graphApiKey || GRAPH_API_KEY;
2269
2060
  tokenIds = await getPositionTokenIdsFromSubgraph(
2270
2061
  userAddress,
2271
2062
  chainId,
2272
- apiKey
2063
+ graphApiKey
2273
2064
  );
2274
2065
  }
2275
2066
  if (tokenIds.length === 0) {
@@ -2291,7 +2082,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
2291
2082
  chainId
2292
2083
  }
2293
2084
  ]);
2294
- const positionResults = await readContracts4(wagmiConfig, {
2085
+ const positionResults = await readContracts3(wagmiConfig, {
2295
2086
  contracts: positionInfoCalls
2296
2087
  });
2297
2088
  const matchingPositions = [];
@@ -2367,7 +2158,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
2367
2158
  }
2368
2159
  ] : []
2369
2160
  ];
2370
- const infoResults = await readContracts4(wagmiConfig, {
2161
+ const infoResults = await readContracts3(wagmiConfig, {
2371
2162
  contracts: infoCalls
2372
2163
  });
2373
2164
  const slot0 = infoResults[0]?.result;
@@ -2630,9 +2421,9 @@ async function getUserEthAutoLP(wagmiConfig, {
2630
2421
  }
2631
2422
 
2632
2423
  // functions/getChainUserActivity.ts
2633
- import { getSdkByChainId as getSdkByChainId8 } from "@tokemak/graph-cli";
2424
+ import { getSdkByChainId as getSdkByChainId7 } from "@tokemak/graph-cli";
2634
2425
  var getChainUserActivity = async (address, chainId = 1) => {
2635
- const { GetUserBalanceChangeHistory } = getSdkByChainId8(chainId);
2426
+ const { GetUserBalanceChangeHistory } = getSdkByChainId7(chainId);
2636
2427
  try {
2637
2428
  const userAutopoolBalanceChanges = await paginateQuery(
2638
2429
  (vars) => GetUserBalanceChangeHistory({
@@ -2837,121 +2628,14 @@ var getUserRewardsV1 = async (wagmiConfig, {
2837
2628
  }
2838
2629
  };
2839
2630
 
2840
- // functions/getUserV1.ts
2841
- import { rewardsV1Abi as rewardsV1Abi2, stakingV1Abi } from "@tokemak/abis";
2842
- import { readContract as readContract4 } from "@wagmi/core";
2843
- import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
2844
- import { mainnet as mainnet6 } from "viem/chains";
2845
- var getUserV1 = async (wagmiConfig, {
2846
- currentCycleIndex,
2847
- address,
2848
- chainId
2849
- }) => {
2850
- const {
2851
- stakingV1,
2852
- rewardsV1Url,
2853
- accTokeV1RewardsHash,
2854
- rewardsV1Hash,
2855
- accTokeV1Rewards,
2856
- autoEthGuardedRewards,
2857
- rewardsV1,
2858
- missedTokeRewards
2859
- } = getMainnetConfig3(mainnet6.id);
2860
- try {
2861
- const userStakedTokeV1 = await readContract4(wagmiConfig, {
2862
- address: stakingV1,
2863
- abi: stakingV1Abi,
2864
- functionName: "availableForWithdrawal",
2865
- args: [address, 0n],
2866
- chainId: mainnet6.id
2867
- });
2868
- const tokeRewards = await getUserRewardsV1(wagmiConfig, {
2869
- address,
2870
- rewardsCycleIndex: currentCycleIndex - 1n,
2871
- rewardsV1,
2872
- rewardsV1Url,
2873
- rewardsV1Hash,
2874
- chainId
2875
- });
2876
- const ethRewards = await getUserRewardsV1(wagmiConfig, {
2877
- address,
2878
- rewardsCycleIndex: 306n,
2879
- rewardsV1: accTokeV1Rewards,
2880
- rewardsV1Url,
2881
- rewardsV1Hash: accTokeV1RewardsHash,
2882
- chainId
2883
- });
2884
- const autoEthGuardedRewardsPayload = await getRewardsPayloadV1(
2885
- "QmcJgQ42aGTsqngSBa98qxnbv2CHyk9DmSg1jDD569bnpp",
2886
- address,
2887
- rewardsV1Url
2888
- );
2889
- const payloadChainId = autoEthGuardedRewardsPayload?.payload?.chainId;
2890
- const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
2891
- const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
2892
- const amount = autoEthGuardedRewardsPayload?.payload?.amount;
2893
- const claimableAutoEth = await readContract4(wagmiConfig, {
2894
- address: autoEthGuardedRewards,
2895
- abi: rewardsV1Abi2,
2896
- functionName: "getClaimableAmount",
2897
- args: [
2898
- {
2899
- chainId: payloadChainId || 0n,
2900
- cycle: cycle || 0n,
2901
- wallet: wallet || "0x0000000000000000000000000000000000000000",
2902
- amount: amount || 0n
2903
- }
2904
- ],
2905
- chainId
2906
- });
2907
- const missedTokeRewardsPayload = await getRewardsPayloadV1(
2908
- "QmRpVjVhFqbUTtLnQ4addEwBtvF2CC7t6rbQWYiju9nAqd",
2909
- address,
2910
- rewardsV1Url
2911
- );
2912
- let claimableMissedToke = 0n;
2913
- if (missedTokeRewardsPayload) {
2914
- const {
2915
- payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
2916
- } = missedTokeRewardsPayload;
2917
- claimableMissedToke = await readContract4(wagmiConfig, {
2918
- address: missedTokeRewards,
2919
- abi: rewardsV1Abi2,
2920
- functionName: "getClaimableAmount",
2921
- args: [
2922
- {
2923
- chainId: payloadChainId2,
2924
- cycle: cycle2,
2925
- wallet: wallet2,
2926
- amount: amount2 || 0n
2927
- }
2928
- ],
2929
- chainId
2930
- });
2931
- }
2932
- return {
2933
- stakedToke: userStakedTokeV1,
2934
- claimableToke: tokeRewards?.claimable,
2935
- claimableEth: ethRewards?.claimable,
2936
- claimableAutoEth,
2937
- tokeRewardsPayload: tokeRewards?.rewardsPayload,
2938
- ethRewardsPayload: ethRewards?.rewardsPayload,
2939
- missedTokeRewardsPayload,
2940
- autoEthGuardedRewardsPayload,
2941
- claimableMissedToke
2942
- };
2943
- } catch (e) {
2944
- }
2945
- };
2946
-
2947
2631
  // functions/getChainUserAutopoolsHistory.tsx
2948
- import { getSdkByChainId as getSdkByChainId9 } from "@tokemak/graph-cli";
2632
+ import { getSdkByChainId as getSdkByChainId8 } from "@tokemak/graph-cli";
2949
2633
  import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP3 } from "@tokemak/constants";
2950
2634
  var getChainUserAutopoolsHistory = async ({
2951
2635
  address,
2952
2636
  chainId = 1
2953
2637
  }) => {
2954
- const { GetUserVaultsDayData } = getSdkByChainId9(chainId);
2638
+ const { GetUserVaultsDayData } = getSdkByChainId8(chainId);
2955
2639
  try {
2956
2640
  if (address) {
2957
2641
  const { userVaultDayDatas } = await GetUserVaultsDayData({
@@ -2974,12 +2658,12 @@ import {
2974
2658
  } from "@tokemak/utils";
2975
2659
 
2976
2660
  // functions/getTokenValueDayDatas.ts
2977
- import { mainnet as mainnet7 } from "viem/chains";
2661
+ import { mainnet as mainnet6 } from "viem/chains";
2978
2662
  import { convertTimestampToDate as convertTimestampToDate3 } from "@tokemak/utils";
2979
2663
  import { formatUnits as formatUnits6 } from "viem";
2980
- import { getSdkByChainId as getSdkByChainId10 } from "@tokemak/graph-cli";
2981
- var getTokenValueDayDatas = async (tokenAddress, chainId = mainnet7.id) => {
2982
- const { GetTokenValueDayDatas } = getSdkByChainId10(chainId);
2664
+ import { getSdkByChainId as getSdkByChainId9 } from "@tokemak/graph-cli";
2665
+ var getTokenValueDayDatas = async (tokenAddress, chainId = mainnet6.id) => {
2666
+ const { GetTokenValueDayDatas } = getSdkByChainId9(chainId);
2983
2667
  try {
2984
2668
  const { tokenValueDayDatas } = await GetTokenValueDayDatas({
2985
2669
  tokenAddress: tokenAddress.toLowerCase()
@@ -3287,212 +2971,13 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
3287
2971
  return result;
3288
2972
  };
3289
2973
 
3290
- // functions/getUserSushiLP.ts
3291
- import { readContracts as readContracts5 } from "@wagmi/core";
3292
- import { poolV1Abi, sushiPoolAbi as sushiPoolAbi2 } from "@tokemak/abis";
3293
- import { getMainnetConfig as getMainnetConfig4 } from "@tokemak/config";
3294
- var getUserSushiLP = async (wagmiConfig, {
3295
- sushiLP,
3296
- currentCycleIndex,
3297
- address,
3298
- cycleRolloverBlockNumber,
3299
- chainId
3300
- }) => {
3301
- const { tSushiLP, sushiPool } = getMainnetConfig4();
3302
- try {
3303
- if (address && currentCycleIndex && sushiLP) {
3304
- const [
3305
- { result: sushiLPBalance },
3306
- { result: tSushiLPBalance },
3307
- { result: tSushiLPRequested }
3308
- ] = await readContracts5(wagmiConfig, {
3309
- contracts: [
3310
- {
3311
- address: sushiPool,
3312
- abi: sushiPoolAbi2,
3313
- functionName: "balanceOf",
3314
- args: [address],
3315
- chainId
3316
- },
3317
- {
3318
- address: tSushiLP,
3319
- abi: poolV1Abi,
3320
- functionName: "balanceOf",
3321
- args: [address],
3322
- chainId
3323
- },
3324
- {
3325
- address: tSushiLP,
3326
- abi: poolV1Abi,
3327
- functionName: "requestedWithdrawals",
3328
- args: [address],
3329
- chainId
3330
- }
3331
- ]
3332
- });
3333
- const [
3334
- { result: startTSushiLPBalance },
3335
- { result: startTSushiLPRequested }
3336
- ] = await readContracts5(wagmiConfig, {
3337
- contracts: [
3338
- {
3339
- address: tSushiLP,
3340
- abi: poolV1Abi,
3341
- functionName: "balanceOf",
3342
- args: [address],
3343
- chainId
3344
- },
3345
- {
3346
- address: tSushiLP,
3347
- abi: poolV1Abi,
3348
- functionName: "requestedWithdrawals",
3349
- args: [address],
3350
- chainId
3351
- }
3352
- ],
3353
- blockNumber: cycleRolloverBlockNumber
3354
- });
3355
- const startTSushiWithdrawAmount = startTSushiLPRequested?.[1] || 0n;
3356
- const yieldingBalance = (startTSushiLPBalance || 0n) - startTSushiWithdrawAmount;
3357
- let balanceExcludingWithdrawal = tSushiLPBalance || 0n;
3358
- const [withdrawalMinCycle, withdrawalAmount] = tSushiLPRequested || [
3359
- 0n,
3360
- 0n
3361
- ];
3362
- if (withdrawalAmount > 0n && currentCycleIndex >= withdrawalMinCycle) {
3363
- balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
3364
- }
3365
- const shareOftSushiLP = Number(balanceExcludingWithdrawal) / Number(sushiLP.totalSupply);
3366
- const tSushiLPUsd = sushiLP.tvl * shareOftSushiLP;
3367
- const hasRequestedUnlock = withdrawalAmount > 0n;
3368
- const hasUnlockableBalance = withdrawalMinCycle <= currentCycleIndex && withdrawalAmount > 0n;
3369
- const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
3370
- return {
3371
- sushiLPBalance,
3372
- tSushiLPBalance,
3373
- tSushiLPRequested,
3374
- shareOftSushiLP,
3375
- tSushiLPUsd,
3376
- balanceExcludingWithdrawal,
3377
- hasAddedTSushi: yieldingBalance < balanceExcludingWithdrawal,
3378
- hasRequestedUnlock,
3379
- hasUnlockableBalance,
3380
- withdrawalAmount,
3381
- hasBalanceExcludingWithdrawal
3382
- };
3383
- }
3384
- } catch (e) {
3385
- console.log(e);
3386
- }
3387
- };
3388
-
3389
- // functions/getUserCurveLP.ts
3390
- import { readContracts as readContracts6 } from "@wagmi/core";
3391
- import { poolV1Abi as poolV1Abi2 } from "@tokemak/abis";
3392
- import { getMainnetConfig as getMainnetConfig5 } from "@tokemak/config";
3393
- var getUserCurveLP = async (wagmiConfig, {
3394
- curveLP,
3395
- address,
3396
- chainId
3397
- }) => {
3398
- try {
3399
- const { curvePool, convexRewarder } = getMainnetConfig5();
3400
- if (address && curveLP && curvePool && convexRewarder) {
3401
- const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await readContracts6(wagmiConfig, {
3402
- contracts: [
3403
- {
3404
- address: curvePool,
3405
- abi: poolV1Abi2,
3406
- functionName: "balanceOf",
3407
- args: [address],
3408
- chainId
3409
- },
3410
- {
3411
- address: convexRewarder,
3412
- abi: poolV1Abi2,
3413
- functionName: "balanceOf",
3414
- args: [address],
3415
- chainId
3416
- }
3417
- ]
3418
- });
3419
- const shareOfCurve = Number(userCurveLPBalance || 0n) / Number(curveLP.totalSupply);
3420
- const shareOfConvex = Number(userConvexLPBalance || 0n) / Number(curveLP.totalSupply);
3421
- const curveLPUsd = shareOfCurve * curveLP.curveTvl;
3422
- const convexLPUsd = shareOfConvex * curveLP.curveTvl;
3423
- return {
3424
- curveLPBalance: userCurveLPBalance,
3425
- convexLPBalance: userConvexLPBalance,
3426
- shareOfCurve,
3427
- shareOfConvex,
3428
- curveLPUsd,
3429
- convexLPUsd
3430
- };
3431
- }
3432
- } catch (e) {
3433
- console.log(e);
3434
- }
3435
- };
3436
-
3437
- // functions/getMultipleAutopoolRebalances.ts
3438
- import { getSdkByChainId as getSdkByChainId11 } from "@tokemak/graph-cli";
3439
- var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
3440
- const { GetMutlipleAutopoolRebalances } = getSdkByChainId11(chainId);
3441
- const { autopools } = await GetMutlipleAutopoolRebalances({
3442
- addresses: ids
3443
- });
3444
- const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
3445
- return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
3446
- };
3447
-
3448
- // functions/getSystemConfig.ts
3449
- import { readContracts as readContracts7 } from "@wagmi/core";
3450
- import { systemRegistryAbi } from "@tokemak/abis";
3451
- var systemRegistryFunctionNames = [
3452
- "asyncSwapperRegistry",
3453
- "autoPoolRouter",
3454
- "autoPoolRegistry",
3455
- "swapRouter",
3456
- "weth"
3457
- ];
3458
- var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
3459
- const systemRegistryContract = {
3460
- address: systemRegistry,
3461
- abi: systemRegistryAbi
3462
- };
3463
- const systemRegistryCalls = systemRegistryFunctionNames.map(
3464
- (functionName) => ({
3465
- ...systemRegistryContract,
3466
- functionName
3467
- })
3468
- );
3469
- try {
3470
- const [
3471
- { result: asyncSwapperRegistry },
3472
- { result: autopoolRouter },
3473
- { result: autopoolRegistry },
3474
- { result: swapRouter }
3475
- ] = await readContracts7(wagmiConfig, {
3476
- contracts: systemRegistryCalls
3477
- });
3478
- return {
3479
- asyncSwapperRegistry,
3480
- autopoolRouter,
3481
- autopoolRegistry,
3482
- swapRouter
3483
- };
3484
- } catch (e) {
3485
- console.log(e);
3486
- }
3487
- };
3488
-
3489
2974
  // functions/getChainUserAutopools.tsx
3490
- import { getSdkByChainId as getSdkByChainId12 } from "@tokemak/graph-cli";
2975
+ import { getSdkByChainId as getSdkByChainId10 } from "@tokemak/graph-cli";
3491
2976
  var getChainUserAutopools = async ({
3492
2977
  address,
3493
2978
  chainId = 1
3494
2979
  }) => {
3495
- const { GetUserVaultInfo } = getSdkByChainId12(chainId);
2980
+ const { GetUserVaultInfo } = getSdkByChainId10(chainId);
3496
2981
  try {
3497
2982
  if (address) {
3498
2983
  const { userInfo } = await GetUserVaultInfo({
@@ -3517,7 +3002,7 @@ import { ETH_TOKEN as ETH_TOKEN5, PRICED_TOKENS } from "@tokemak/tokenlist";
3517
3002
 
3518
3003
  // functions/getUserAutopool.tsx
3519
3004
  import { erc20Abi as erc20Abi4 } from "viem";
3520
- import { readContract as readContract5, readContracts as readContracts8 } from "@wagmi/core";
3005
+ import { readContract as readContract4, readContracts as readContracts4 } from "@wagmi/core";
3521
3006
  import { formatEtherNum as formatEtherNum7 } from "@tokemak/utils";
3522
3007
  import { autopoolEthAbi as autopoolEthAbi2 } from "@tokemak/abis";
3523
3008
  var getUserAutopool = async (wagmiConfig, {
@@ -3535,7 +3020,7 @@ var getUserAutopool = async (wagmiConfig, {
3535
3020
  { result: autopoolRewarderContract },
3536
3021
  { result: pastRewarders },
3537
3022
  { result: unstakedPoolShares, error: unstakedPoolSharesError }
3538
- ] = await readContracts8(wagmiConfig, {
3023
+ ] = await readContracts4(wagmiConfig, {
3539
3024
  contracts: [
3540
3025
  {
3541
3026
  ...autopoolContract,
@@ -3560,7 +3045,7 @@ var getUserAutopool = async (wagmiConfig, {
3560
3045
  if (unstakedPoolSharesError) {
3561
3046
  throw new Error("Error fetching unstaked pool shares");
3562
3047
  }
3563
- const stakedPoolShares = await readContract5(wagmiConfig, {
3048
+ const stakedPoolShares = await readContract4(wagmiConfig, {
3564
3049
  address: autopoolRewarderContract,
3565
3050
  abi: erc20Abi4,
3566
3051
  functionName: "balanceOf",
@@ -3586,7 +3071,7 @@ var getUserAutopool = async (wagmiConfig, {
3586
3071
  args: [address],
3587
3072
  chainId: autopool?.chain?.chainId
3588
3073
  }));
3589
- const pastRewards = await readContracts8(wagmiConfig, {
3074
+ const pastRewards = await readContracts4(wagmiConfig, {
3590
3075
  contracts: pastRewardBalances
3591
3076
  });
3592
3077
  pastRewarderBalances = pastRewards.map(({ result }, index) => {
@@ -4077,25 +3562,11 @@ var getUserTokenBalances = async ({
4077
3562
  return tokenBalances;
4078
3563
  };
4079
3564
 
4080
- // functions/getTokenList.ts
4081
- import { TOKEMAK_LISTS_URL } from "@tokemak/tokenlist";
4082
- var getTokenList = async () => {
4083
- try {
4084
- let url = `${TOKEMAK_LISTS_URL}/swap_enabled.json`;
4085
- const listResponse = await fetch(url);
4086
- const { tokens: tokenList } = await listResponse.json();
4087
- return tokenList;
4088
- } catch (e) {
4089
- console.log(e);
4090
- return [];
4091
- }
4092
- };
4093
-
4094
3565
  // functions/getTopAutopoolHolders.ts
4095
- import { getSdkByChainId as getSdkByChainId13 } from "@tokemak/graph-cli";
3566
+ import { getSdkByChainId as getSdkByChainId11 } from "@tokemak/graph-cli";
4096
3567
  var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
4097
3568
  try {
4098
- const { GetTopAutopoolHolders } = getSdkByChainId13(chainId);
3569
+ const { GetTopAutopoolHolders } = getSdkByChainId11(chainId);
4099
3570
  const { holders } = await GetTopAutopoolHolders({
4100
3571
  address: autopoolAddress
4101
3572
  });
@@ -4106,27 +3577,6 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
4106
3577
  }
4107
3578
  };
4108
3579
 
4109
- // functions/getAllowance.ts
4110
- import { readContract as readContract6 } from "@wagmi/core";
4111
- import { erc20Abi as erc20Abi5 } from "viem";
4112
- var getAllowance = async (wagmiConfig, {
4113
- token,
4114
- address,
4115
- spender
4116
- }) => {
4117
- try {
4118
- const allowance = await readContract6(wagmiConfig, {
4119
- address: token,
4120
- abi: erc20Abi5,
4121
- functionName: "allowance",
4122
- args: [address || "0x0", spender]
4123
- });
4124
- return allowance;
4125
- } catch (e) {
4126
- console.error(e);
4127
- }
4128
- };
4129
-
4130
3580
  // functions/getUserActivity.ts
4131
3581
  var getUserActivity = async ({
4132
3582
  address,
@@ -4162,7 +3612,7 @@ import { getAddress as getAddress4 } from "viem";
4162
3612
 
4163
3613
  // functions/getChainUserAutopoolsRewards.ts
4164
3614
  import { getCoreConfig as getCoreConfig2 } from "@tokemak/config";
4165
- import { readContract as readContract7 } from "@wagmi/core";
3615
+ import { readContract as readContract5 } from "@wagmi/core";
4166
3616
  import { lensAbi as lensAbi2 } from "@tokemak/abis";
4167
3617
  var getChainUserAutopoolsRewards = async (wagmiConfig, {
4168
3618
  chainId,
@@ -4170,7 +3620,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
4170
3620
  }) => {
4171
3621
  try {
4172
3622
  const coreConfig = getCoreConfig2(chainId);
4173
- const userRewardsInfo = await readContract7(wagmiConfig, {
3623
+ const userRewardsInfo = await readContract5(wagmiConfig, {
4174
3624
  address: coreConfig.lens,
4175
3625
  abi: lensAbi2,
4176
3626
  functionName: "getUserRewardInfo",
@@ -4360,17 +3810,17 @@ import {
4360
3810
  import { TOKEMAK_SWAP_QUOTE_URL } from "@tokemak/constants";
4361
3811
 
4362
3812
  // functions/getAddressFromSystemRegistry.ts
4363
- import { readContract as readContract8 } from "@wagmi/core";
3813
+ import { readContract as readContract6 } from "@wagmi/core";
4364
3814
  import { getCoreConfig as getCoreConfig3 } from "@tokemak/config";
4365
- import { systemRegistryAbi as systemRegistryAbi2 } from "@tokemak/abis";
3815
+ import { systemRegistryAbi } from "@tokemak/abis";
4366
3816
  var getAddressFromSystemRegistry = async (wagmiConfig, {
4367
3817
  chainId,
4368
3818
  functionName
4369
3819
  }) => {
4370
3820
  const { systemRegistry } = getCoreConfig3(chainId);
4371
- return await readContract8(wagmiConfig, {
3821
+ return await readContract6(wagmiConfig, {
4372
3822
  address: systemRegistry,
4373
- abi: systemRegistryAbi2,
3823
+ abi: systemRegistryAbi,
4374
3824
  functionName,
4375
3825
  chainId
4376
3826
  });
@@ -4428,7 +3878,7 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
4428
3878
  };
4429
3879
 
4430
3880
  // functions/getDynamicSwap.ts
4431
- import { getPublicClient as getPublicClient2, readContract as readContract9 } from "@wagmi/core";
3881
+ import { getPublicClient as getPublicClient2, readContract as readContract7 } from "@wagmi/core";
4432
3882
  import { autopilotRouterAbi, autopoolEthAbi as autopoolEthAbi3 } from "@tokemak/abis";
4433
3883
  import { getCoreConfig as getCoreConfig5 } from "@tokemak/config";
4434
3884
  import { getLiquidations } from "@tokemak/autopilot-swap-route-calc";
@@ -4524,7 +3974,7 @@ var getDynamicSwap = async ({
4524
3974
  console.log(e);
4525
3975
  }
4526
3976
  }
4527
- const previewRedeemOnChain = await readContract9(config, {
3977
+ const previewRedeemOnChain = await readContract7(config, {
4528
3978
  address,
4529
3979
  abi: autopoolEthAbi3,
4530
3980
  functionName: "previewRedeem",
@@ -4546,7 +3996,7 @@ var getDynamicSwap = async ({
4546
3996
  // functions/getAmountWithdrawn.ts
4547
3997
  import { ETH_TOKEN as ETH_TOKEN7 } from "@tokemak/tokenlist";
4548
3998
  import { getCoreConfig as getCoreConfig6 } from "@tokemak/config";
4549
- import { readContract as readContract10 } from "@wagmi/core";
3999
+ import { readContract as readContract8 } from "@wagmi/core";
4550
4000
  import { autopoolEthAbi as autopoolEthAbi4 } from "@tokemak/abis";
4551
4001
  var getAmountWithdrawn = async ({
4552
4002
  address,
@@ -4586,7 +4036,7 @@ var getAmountWithdrawn = async ({
4586
4036
  const weth = getCoreConfig6(chainId).weth;
4587
4037
  buyToken = weth;
4588
4038
  }
4589
- convertedAssets = await readContract10(config, {
4039
+ convertedAssets = await readContract8(config, {
4590
4040
  address: autopool,
4591
4041
  abi: autopoolEthAbi4,
4592
4042
  functionName: "convertToAssets",
@@ -4626,7 +4076,7 @@ var getAmountWithdrawn = async ({
4626
4076
  };
4627
4077
 
4628
4078
  // functions/getAmountDeposited.ts
4629
- import { readContract as readContract11 } from "@wagmi/core";
4079
+ import { readContract as readContract9 } from "@wagmi/core";
4630
4080
  import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
4631
4081
  import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as formatEtherNum9 } from "@tokemak/utils";
4632
4082
  var getAmountDeposited = async ({
@@ -4641,7 +4091,7 @@ var getAmountDeposited = async ({
4641
4091
  if (!address || !chainId || !amount || typeof slippage !== "number") {
4642
4092
  throw new Error("Invalid parameters");
4643
4093
  }
4644
- const previewDeposit = await readContract11(config, {
4094
+ const previewDeposit = await readContract9(config, {
4645
4095
  address,
4646
4096
  abi: autopoolEthAbi5,
4647
4097
  functionName: "previewDeposit",
@@ -4665,7 +4115,7 @@ var getAmountDeposited = async ({
4665
4115
  };
4666
4116
 
4667
4117
  // functions/getBridgeFee.ts
4668
- import { readContract as readContract12 } from "@wagmi/core";
4118
+ import { readContract as readContract10 } from "@wagmi/core";
4669
4119
  import { layerZeroEndpointAbi, oftAdapterAbi } from "@tokemak/abis";
4670
4120
  import { toHex } from "viem";
4671
4121
  import { addressToBytes32 } from "@layerzerolabs/lz-v2-utilities";
@@ -4678,13 +4128,13 @@ var getBridgeFee = async (wagmiConfig, {
4678
4128
  from
4679
4129
  }) => {
4680
4130
  try {
4681
- const endpoint = await readContract12(wagmiConfig, {
4131
+ const endpoint = await readContract10(wagmiConfig, {
4682
4132
  address: destAddress,
4683
4133
  abi: oftAdapterAbi,
4684
4134
  functionName: "endpoint",
4685
4135
  chainId: destChainId
4686
4136
  });
4687
- const eid = await readContract12(wagmiConfig, {
4137
+ const eid = await readContract10(wagmiConfig, {
4688
4138
  address: endpoint,
4689
4139
  abi: layerZeroEndpointAbi,
4690
4140
  functionName: "eid",
@@ -4702,7 +4152,7 @@ var getBridgeFee = async (wagmiConfig, {
4702
4152
  composeMsg: "0x",
4703
4153
  oftCmd: "0x"
4704
4154
  };
4705
- const feeQuote = await readContract12(wagmiConfig, {
4155
+ const feeQuote = await readContract10(wagmiConfig, {
4706
4156
  address: sourceAddress,
4707
4157
  abi: oftAdapterAbi,
4708
4158
  functionName: "quoteSend",
@@ -4715,82 +4165,14 @@ var getBridgeFee = async (wagmiConfig, {
4715
4165
  }
4716
4166
  };
4717
4167
 
4718
- // functions/getLayerzeroStatus.ts
4719
- var MessageStatus = /* @__PURE__ */ ((MessageStatus2) => {
4720
- MessageStatus2["INFLIGHT"] = "INFLIGHT";
4721
- MessageStatus2["DELIVERED"] = "DELIVERED";
4722
- MessageStatus2["FAILED"] = "FAILED";
4723
- MessageStatus2["PAYLOAD_STORED"] = "PAYLOAD_STORED";
4724
- MessageStatus2["BLOCKED"] = "BLOCKED";
4725
- MessageStatus2["CONFIRMING"] = "CONFIRMING";
4726
- return MessageStatus2;
4727
- })(MessageStatus || {});
4728
- var LAYERZERO_STATUS_URL = "https://scan.layerzero-api.com/v1/messages/tx/";
4729
- var getLayerzeroStatus = async ({
4730
- txHash
4731
- }) => {
4732
- try {
4733
- const response = await fetch(`${LAYERZERO_STATUS_URL}${txHash}`);
4734
- if (!response.ok) {
4735
- throw new Error("Network response was not ok");
4736
- }
4737
- const statusData = await response.json();
4738
- return statusData || void 0;
4739
- } catch (e) {
4740
- return {
4741
- status: {
4742
- name: "FAILED" /* FAILED */,
4743
- message: e || "Failed to fetch layerzero status"
4744
- }
4745
- };
4746
- }
4747
- };
4748
- var waitForMessageReceived = async ({
4749
- txHash,
4750
- interval = 3e3,
4751
- timeout = 20 * 60 * 1e3
4752
- }) => {
4753
- const startTime = Date.now();
4754
- while (Date.now() - startTime < timeout) {
4755
- const status = await getLayerzeroStatus({ txHash });
4756
- if (!status) {
4757
- console.warn(`No status returned for txHash: ${txHash}`);
4758
- } else {
4759
- console.log(`Current status: ${status.status.name}`);
4760
- if (status.status.name === "DELIVERED" /* DELIVERED */) {
4761
- return status;
4762
- } else if (["FAILED" /* FAILED */, "BLOCKED" /* BLOCKED */].includes(
4763
- status.status.name
4764
- )) {
4765
- throw new Error(`Message failed with status: ${status.status.name}`);
4766
- }
4767
- }
4768
- await new Promise((resolve) => setTimeout(resolve, interval));
4769
- }
4770
- throw new Error(`Timeout reached after 20 minutes for message: ${txHash}`);
4771
- };
4772
-
4773
- // functions/getChainUserSToke.ts
4774
- import { accTokeV1Abi as accTokeV1Abi2 } from "@tokemak/abis";
4775
- import { getCoreConfig as getCoreConfig7 } from "@tokemak/config";
4776
- import {
4777
- convertChainCycleToUnix as convertChainCycleToUnix2,
4778
- convertSecondsToRemainingTime,
4779
- formatCurrency as formatCurrency2,
4780
- formatEtherNum as formatEtherNum10
4781
- } from "@tokemak/utils";
4782
- import { readContracts as readContracts9 } from "@wagmi/core";
4783
- import { formatEther as formatEther2 } from "viem";
4784
- import { sepolia as sepolia2 } from "viem/chains";
4785
-
4786
4168
  // functions/getCurrentCycleId.ts
4787
4169
  import { accTokeV1Abi } from "@tokemak/abis";
4788
- import { readContract as readContract13 } from "@wagmi/core";
4170
+ import { readContract as readContract11 } from "@wagmi/core";
4789
4171
  var getCurrentCycleId = async (wagmiConfig, {
4790
4172
  stoke,
4791
4173
  chainId
4792
4174
  }) => {
4793
- return readContract13(wagmiConfig, {
4175
+ return readContract11(wagmiConfig, {
4794
4176
  address: stoke,
4795
4177
  abi: accTokeV1Abi,
4796
4178
  chainId,
@@ -4798,539 +4180,30 @@ var getCurrentCycleId = async (wagmiConfig, {
4798
4180
  });
4799
4181
  };
4800
4182
 
4801
- // functions/getChainUserSToke.ts
4802
- import { getSdkByChainId as getSdkByChainId14 } from "@tokemak/graph-cli";
4803
- var getChainUserSToke = async (wagmiConfig, {
4804
- address,
4805
- tokePrice,
4806
- chainId
4807
- }) => {
4183
+ // functions/getTokenPrices.ts
4184
+ import { PRICED_TOKENS as PRICED_TOKENS2 } from "@tokemak/tokenlist";
4185
+ import { TOKEMAK_PRICES_STAGING_URL } from "@tokemak/constants";
4186
+ var getTokenPrices = async () => {
4808
4187
  try {
4809
- const { stoke } = getCoreConfig7(chainId);
4810
- const cycleIndex = await getCurrentCycleId(wagmiConfig, { chainId, stoke });
4811
- if (address && cycleIndex && stoke && tokePrice) {
4812
- const { GetUserSTokeBalance } = getSdkByChainId14(
4813
- chainId
4814
- );
4815
- const { accountBalanceV1S } = await GetUserSTokeBalance({
4816
- address: address.toLowerCase()
4817
- });
4818
- const cycleStartBalance = accountBalanceV1S[0]?.cycleStartBalance || 0n;
4819
- const stokeContract = {
4820
- address: stoke,
4821
- abi: accTokeV1Abi2
4822
- };
4823
- const [
4824
- { result: balance },
4825
- { result: depositInfoResult },
4826
- { result: withdrawalInfoResult }
4827
- ] = await readContracts9(wagmiConfig, {
4828
- contracts: [
4829
- {
4830
- ...stokeContract,
4831
- functionName: "balanceOf",
4832
- args: [address],
4833
- chainId
4834
- },
4835
- {
4836
- ...stokeContract,
4837
- functionName: "getDepositInfo",
4838
- args: [address],
4839
- chainId
4840
- },
4841
- {
4842
- ...stokeContract,
4843
- functionName: "getWithdrawalInfo",
4844
- args: [address],
4845
- chainId
4846
- }
4847
- ]
4848
- });
4849
- if (withdrawalInfoResult && depositInfoResult && balance && cycleStartBalance) {
4850
- const [depositLockCycle, depositLockDuration, depositAmount] = depositInfoResult;
4851
- const [withdrawalMinCycle, withdrawalAmount] = withdrawalInfoResult;
4852
- const rolloverDepositAmount = !!cycleStartBalance?.cycleStartBalance && cycleStartBalance?.cycleStartBalance > 0 ? BigInt(cycleStartBalance.cycleStartBalance) : 0n;
4853
- let balanceExcludingWithdrawal = balance;
4854
- if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
4855
- balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
4856
- }
4857
- const withdrawalAmountUsd = formatCurrency2(
4858
- formatEtherNum10(withdrawalAmount) * tokePrice
4859
- );
4860
- const lockDuration = Number(depositLockDuration);
4861
- const lockCycle = Number(depositLockCycle);
4862
- const lockStart = lockCycle + 1;
4863
- const firstLockEnd = lockDuration + 1 + lockCycle;
4864
- const currentCycle = Number(cycleIndex);
4865
- const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
4866
- const lockRenew = (
4867
- // if has done a renewal since start
4868
- currentCycle - lockStart > lockDuration ? (
4869
- // if during the lockRenew cycle add lock duration to show the right timeline
4870
- currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement
4871
- ) : (
4872
- // if during the lockRenew cycle add lock duration to show the right timeline
4873
- currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd
4874
- )
4875
- );
4876
- const withdrawAvailable = lockRenew - 1;
4877
- const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
4878
- const addedLockedToke = depositAmount - rolloverDepositAmount;
4879
- const balanceUSD = formatCurrency2(
4880
- Number(formatEther2(balanceExcludingWithdrawal)) * tokePrice
4881
- );
4882
- const balanceExcludingWithdrawalUsd = formatCurrency2(
4883
- formatEtherNum10(balanceExcludingWithdrawal) * tokePrice
4884
- );
4885
- const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
4886
- const hasRequestedUnlock = withdrawalAmount > 0n;
4887
- const unlockRequestPeriodStartUnix = convertChainCycleToUnix2(withdrawAvailable, chainId) - Date.now() / 1e3;
4888
- const unlockRequestPeriodEndUnix = convertChainCycleToUnix2(lockRenew, chainId) - Date.now() / 1e3;
4889
- const hasBalance = balance > 0n;
4890
- const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
4891
- const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
4892
- let cyclesInAMonth = 4;
4893
- let lockDurationInMonths = lockDuration / cyclesInAMonth;
4894
- if (chainId === sepolia2.id) {
4895
- lockDurationInMonths = lockDuration - 1;
4896
- }
4897
- const unlockPeriodDateRangeArray = [
4898
- new Date(convertChainCycleToUnix2(withdrawAvailable, chainId) * 1e3),
4899
- new Date(convertChainCycleToUnix2(lockRenew, chainId) * 1e3)
4900
- ];
4901
- const {
4902
- unlockPeriodDateRange,
4903
- unlockPeriodStartFullDate,
4904
- unlockRenewalFullDate,
4905
- unlockPeriodStartDate,
4906
- unlockRenewalDate
4907
- } = formatDateRange(
4908
- unlockPeriodDateRangeArray,
4909
- chainId === sepolia2.id ? "time" : "date"
4910
- );
4911
- const totalActiveUserCredits = formatEtherNum10(balanceExcludingWithdrawal) * lockDurationInMonths;
4912
- const totalUserCredits = formatEtherNum10(balance) * lockDurationInMonths;
4913
- return {
4914
- balance,
4915
- balanceUSD,
4916
- balanceExcludingWithdrawal: hasBalance ? formatEther2(balanceExcludingWithdrawal) : "0.00",
4917
- balanceExcludingWithdrawalUsd,
4918
- hasBalanceExcludingWithdrawal,
4919
- timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime(
4920
- unlockRequestPeriodStartUnix
4921
- ),
4922
- timeLeftBeforeUnlockRequestUnavailable: convertSecondsToRemainingTime(
4923
- unlockRequestPeriodEndUnix
4924
- ),
4925
- withdrawalAmount,
4926
- withdrawalAmountUsd,
4927
- hasUnlockableBalance,
4928
- isUnlockRequestAvailable,
4929
- hasRequestedUnlock,
4930
- hasAddedLockedToke,
4931
- addedLockedToke,
4932
- unlockPeriodDateRange,
4933
- unlockPeriodStartFullDate,
4934
- unlockRenewalFullDate,
4935
- unlockPeriodStartDate,
4936
- unlockRenewalDate,
4937
- lockDurationInMonths,
4938
- boost: lockDuration,
4939
- points: formatEtherNum10(balanceExcludingWithdrawal) * lockDuration,
4940
- totalActiveCredits: totalActiveUserCredits,
4941
- totalCredits: totalUserCredits
4942
- };
4943
- }
4944
- }
4945
- } catch (error) {
4946
- console.error(error);
4947
- }
4948
- };
4949
-
4950
- // functions/getUserSToke.ts
4951
- import { formatCurrency as formatCurrency3, formatEtherNum as formatEtherNum11 } from "@tokemak/utils";
4952
- var getUserSToke = async (wagmiConfig, {
4953
- address,
4954
- tokePrice,
4955
- includeTestnet = false
4956
- }) => {
4957
- try {
4958
- if (!address) {
4959
- throw new Error("Address not found");
4960
- }
4961
- if (!tokePrice) {
4962
- throw new Error("Toke price not found");
4963
- }
4964
- const chains = getSTokeChainsForEnv({ includeTestnet });
4965
- const userSToke = await fetchChainDataMap(chains, async (chain) => {
4966
- return getChainUserSToke(wagmiConfig, {
4967
- address,
4968
- tokePrice,
4969
- chainId: chain.chainId
4970
- });
4971
- });
4972
- const totalBalanceRaw = Object.values(userSToke).reduce((acc, item) => {
4973
- if (item && item.balance) {
4974
- return acc + item.balance;
4975
- }
4976
- return acc;
4977
- }, 0n);
4978
- const totalBalance = formatEtherNum11(totalBalanceRaw || 0n);
4979
- const totalBalanceUsd = formatCurrency3(totalBalance * tokePrice);
4980
- const hasBalance = totalBalance > 0;
4981
- return {
4982
- chains: { ...userSToke },
4983
- totalBalance,
4984
- totalBalanceUsd,
4985
- hasBalance
4986
- };
4987
- } catch (e) {
4988
- console.error(e);
4989
- }
4990
- };
4991
-
4992
- // functions/getChainSToke.ts
4993
- import { formatEther as formatEther3 } from "viem";
4994
- import { readContracts as readContracts10 } from "@wagmi/core";
4995
- import { accTokeV1Abi as accTokeV1Abi3 } from "@tokemak/abis";
4996
- import {
4997
- convertChainCycleToUnix as convertChainCycleToUnix3,
4998
- convertSecondsToRemainingTime as convertSecondsToRemainingTime2,
4999
- formatLargeNumber,
5000
- formatTVL
5001
- } from "@tokemak/utils";
5002
- import { getCoreConfig as getCoreConfig8 } from "@tokemak/config";
5003
- import { getNetwork as getNetwork2 } from "@tokemak/utils";
5004
- var getChainSToke = async (wagmiConfig, {
5005
- tokePrice,
5006
- chainId
5007
- }) => {
5008
- try {
5009
- const { stoke } = getCoreConfig8(chainId);
5010
- const baseConfig = {
5011
- address: stoke,
5012
- abi: accTokeV1Abi3,
5013
- chainId
5014
- };
5015
- if (stoke && tokePrice) {
5016
- const [{ result: totalSupply }, { result: currentCycle }] = await readContracts10(wagmiConfig, {
5017
- contracts: [
5018
- {
5019
- ...baseConfig,
5020
- functionName: "totalSupply"
5021
- },
5022
- {
5023
- ...baseConfig,
5024
- functionName: "getCurrentCycleID"
5025
- }
5026
- ]
5027
- });
5028
- const tvl = Number(formatEther3(totalSupply || 0n)) * tokePrice;
5029
- const secondsLeftBeforeNextCycle = convertChainCycleToUnix3(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
5030
- return {
5031
- rawTotalSupply: totalSupply,
5032
- totalSupply: formatLargeNumber(formatEther3(totalSupply || 0n)),
5033
- tvl: formatTVL(tvl),
5034
- rawTVL: tvl,
5035
- currentCycle,
5036
- chain: getNetwork2(chainId),
5037
- timeBeforeNextCycle: convertSecondsToRemainingTime2(
5038
- secondsLeftBeforeNextCycle
5039
- )
5040
- };
5041
- }
5042
- } catch (error) {
5043
- console.error(error);
5044
- }
5045
- };
5046
-
5047
- // functions/getSToke.ts
5048
- import { formatLargeNumber as formatLargeNumber2, formatTVL as formatTVL2 } from "@tokemak/utils";
5049
- import { formatEther as formatEther4 } from "viem";
5050
- var getSToke = async (wagmiConfig, {
5051
- tokePrice,
5052
- includeTestnet = false
5053
- }) => {
5054
- try {
5055
- const chains = getSTokeChainsForEnv({ includeTestnet });
5056
- const sToke = await fetchChainDataMap(chains, async (chain) => {
5057
- return getChainSToke(wagmiConfig, {
5058
- tokePrice,
5059
- chainId: chain.chainId
5060
- });
5061
- });
5062
- const totalSupplyBigInt = Object.values(sToke).reduce((acc, item) => {
5063
- if (item && item.rawTotalSupply) {
5064
- return acc + item.rawTotalSupply;
5065
- }
5066
- return acc;
5067
- }, 0n);
5068
- const totalSupply = formatLargeNumber2(formatEther4(totalSupplyBigInt || 0n));
5069
- let tvlNum = Object.values(sToke).reduce((acc, item) => {
5070
- if (item && item.rawTVL) {
5071
- return acc + item.rawTVL;
5072
- }
5073
- return acc;
5074
- }, 0);
5075
- const tvl = formatTVL2(tvlNum);
5076
- return { totalSupply, rawTotalSupply: totalSupplyBigInt, tvl, rawTVL: tvlNum, chains: { ...sToke } };
5077
- } catch (e) {
5078
- console.error(e);
5079
- throw e;
5080
- }
5081
- };
5082
-
5083
- // functions/getChainCycleRolloverBlockNumber.ts
5084
- import { accTokeV1Abi as accTokeV1Abi4, managerV1Abi } from "@tokemak/abis";
5085
- import {
5086
- getBlockNumber,
5087
- getPublicClient as getPublicClient3,
5088
- readContract as readContract14
5089
- } from "@wagmi/core";
5090
- var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
5091
- stoke,
5092
- chainId
5093
- }) => {
5094
- const scanPeriodInDays = 8;
5095
- const blockTime = 12;
5096
- try {
5097
- const client = getPublicClient3(wagmiConfig, { chainId });
5098
- if (!!client) {
5099
- const blockNumber = await getBlockNumber(wagmiConfig, {
5100
- chainId
5101
- });
5102
- const manager = await readContract14(wagmiConfig, {
5103
- functionName: "manager",
5104
- address: stoke,
5105
- abi: accTokeV1Abi4,
5106
- chainId
5107
- });
5108
- if (!manager) {
5109
- throw new Error("Manager contract not found");
5110
- }
5111
- const filter = await client.createContractEventFilter({
5112
- address: manager,
5113
- fromBlock: BigInt(
5114
- Math.floor(
5115
- Number(blockNumber) - 86400 / blockTime * scanPeriodInDays
5116
- )
5117
- ),
5118
- abi: managerV1Abi,
5119
- eventName: "CycleRolloverComplete"
5120
- });
5121
- const rolloverEvents = await client.getFilterLogs({ filter });
5122
- const cycleRolloverBlockNumber = client.chain.id === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || blockNumber;
5123
- return cycleRolloverBlockNumber;
5124
- }
5125
- } catch (error) {
5126
- console.error(error);
5127
- }
5128
- };
5129
-
5130
- // functions/getChainSTokeRewards.ts
5131
- import { AUTOPOOLS_WHITELIST_PROD as AUTOPOOLS_WHITELIST_PROD2 } from "@tokemak/config";
5132
- import { formatUnits as formatUnits8 } from "viem";
5133
- import { formatEtherNum as formatEtherNum12 } from "@tokemak/utils";
5134
- import { getSdkByChainId as getSdkByChainId15 } from "@tokemak/graph-cli";
5135
- var getChainSTokeRewards = async ({
5136
- chainId
5137
- }) => {
5138
- try {
5139
- const { GetSTokeRewards } = getSdkByChainId15(chainId);
5140
- const { poolRewardsBalances } = await GetSTokeRewards();
5141
- const allPoolRewardsBalanceDayDatas = await paginateQuery(
5142
- GetSTokeRewards,
5143
- "poolRewardsBalanceDayDatas"
5144
- );
5145
- const autopools = {};
5146
- let totalEarnings = 0;
5147
- let totalEarningsUsd = 0;
5148
- let minApr = null;
5149
- let maxApr = null;
5150
- for (const pool of poolRewardsBalances) {
5151
- const whitelistedPools = AUTOPOOLS_WHITELIST_PROD2.map(
5152
- (address) => address.toLowerCase()
5153
- );
5154
- if (!whitelistedPools.includes(pool.id.toLowerCase())) {
5155
- continue;
5156
- }
5157
- const convertedBalance = formatEtherNum12(pool.balance);
5158
- const convertedBalanceUSD = Number(formatUnits8(pool.balanceUSD, 8));
5159
- const convertedApr = formatEtherNum12(pool.currentAprPerCredit);
5160
- if (minApr === null || convertedApr < minApr) {
5161
- minApr = convertedApr;
5162
- }
5163
- if (maxApr === null || convertedApr > maxApr) {
5164
- maxApr = convertedApr;
5165
- }
5166
- autopools[pool.id] = {
5167
- balance: convertedBalance,
5168
- balanceUSD: convertedBalanceUSD,
5169
- currentAprPerCredit: convertedApr
5170
- };
5171
- totalEarnings += convertedBalance;
5172
- totalEarningsUsd += convertedBalanceUSD;
5173
- }
5174
- const activeDayDatas = allPoolRewardsBalanceDayDatas.filter(
5175
- (item) => item.balance !== "0"
5176
- );
5177
- const historicalRewards = aggregateSTokeRewardsDayData(activeDayDatas);
5178
- const aprRange = [(minApr ?? 0) * 4, (maxApr ?? 0) * 16];
5179
- return {
5180
- autopools,
5181
- totalEarnings,
5182
- totalEarningsUsd,
5183
- historicalRewards,
5184
- aprRange
5185
- };
5186
- } catch (e) {
5187
- console.log("Error fetching rewards payload:", e);
5188
- return null;
5189
- }
5190
- };
5191
-
5192
- // functions/getSTokeRewards.ts
5193
- var getSTokeRewards = async ({
5194
- includeTestnet = false
5195
- }) => {
5196
- try {
5197
- const chains = getSTokeChainsForEnv({ includeTestnet });
5198
- const sTokeRewards = await fetchChainDataMap(chains, async (chain) => {
5199
- return getChainSTokeRewards({
5200
- chainId: chain.chainId
5201
- });
5202
- });
5203
- const totalEarnings = Object.values(sTokeRewards).reduce((acc, item) => {
5204
- if (item && item.totalEarnings) {
5205
- return acc + item.totalEarnings;
5206
- }
5207
- return acc;
5208
- }, 0);
5209
- const totalEarningsUsd = Object.values(sTokeRewards).reduce((acc, item) => {
5210
- if (item && item.totalEarnings) {
5211
- return acc + item.totalEarningsUsd;
5212
- }
5213
- return acc;
5214
- }, 0);
5215
- const allChainsDailyData = Object.values(sTokeRewards).flatMap(
5216
- (chainResult) => chainResult?.historicalRewards || []
5217
- );
5218
- const historicalRewardsAllChains = aggregateSTokeRewardsDayData(allChainsDailyData);
5219
- return {
5220
- chains: { ...sTokeRewards },
5221
- totalEarnings,
5222
- totalEarningsUsd,
5223
- historicalRewards: historicalRewardsAllChains
5224
- };
5225
- } catch (e) {
5226
- console.error(e);
5227
- throw e;
5228
- }
5229
- };
5230
-
5231
- // functions/getChainUserSTokeRewards.ts
5232
- import {
5233
- getCoreConfig as getCoreConfig9,
5234
- getMainnetConfig as getMainnetConfig6
5235
- } from "@tokemak/config";
5236
- import { formatEtherNum as formatEtherNum13 } from "@tokemak/utils";
5237
- var getChainUserSTokeRewards = async (wagmiConfig, {
5238
- address,
5239
- chainId,
5240
- tokePrice
5241
- }) => {
5242
- const { rewardsV1Url, stokeRewardsHash, stokeRewards } = getMainnetConfig6(1);
5243
- const { stoke } = getCoreConfig9(chainId);
5244
- const currentCycle = await getCurrentCycleId(wagmiConfig, {
5245
- stoke,
5246
- chainId
5247
- });
5248
- let tokeRewards;
5249
- try {
5250
- tokeRewards = await getUserRewardsV1(wagmiConfig, {
5251
- address,
5252
- rewardsCycleIndex: currentCycle,
5253
- rewardsV1: stokeRewards,
5254
- rewardsV1Url,
5255
- rewardsV1Hash: stokeRewardsHash,
5256
- chainId
5257
- });
5258
- if (!tokeRewards?.rewardsPayload) {
5259
- throw new Error("No rewards payload found");
5260
- }
5261
- } catch (error) {
5262
- console.error(
5263
- `Error calling getUserRewardsV1 with cycle ${currentCycle}:`,
5264
- error
5265
- );
5266
- try {
5267
- console.log("Falling back to previous cycle index...");
5268
- tokeRewards = await getUserRewardsV1(wagmiConfig, {
5269
- address,
5270
- rewardsCycleIndex: currentCycle - 1n,
5271
- rewardsV1: stokeRewards,
5272
- rewardsV1Url,
5273
- rewardsV1Hash: stokeRewardsHash,
5274
- chainId
5275
- });
5276
- if (!tokeRewards?.rewardsPayload) {
5277
- throw new Error("No rewards payload found (fallback cycle).");
5278
- }
5279
- } catch (fallbackError) {
5280
- console.error(
5281
- `Error calling getUserRewardsV1 with cycle ${currentCycle - 1n}:`,
5282
- fallbackError
5283
- );
5284
- throw fallbackError;
5285
- }
5286
- }
5287
- const claimableNum = formatEtherNum13(tokeRewards?.claimable || 0n);
5288
- const claimableUsd = tokePrice * claimableNum;
5289
- const hasClaimable = claimableNum > 0n;
5290
- const pendingRewards = formatEtherNum13(
5291
- tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
5292
- );
5293
- const pendingRewardsUsd = tokePrice * pendingRewards;
5294
- const totalRewardsReceived = formatEtherNum13(
5295
- tokeRewards.rewardsPayload.payload.amount || 0n
5296
- );
5297
- const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
5298
- return {
5299
- claimableUsd,
5300
- claimableNum,
5301
- hasClaimable,
5302
- pendingRewards,
5303
- pendingRewardsUsd,
5304
- totalRewardsReceived,
5305
- totalRewardsReceivedUsd,
5306
- ...tokeRewards
5307
- };
5308
- };
5309
-
5310
- // functions/getTokenPrices.ts
5311
- import { PRICED_TOKENS as PRICED_TOKENS2 } from "@tokemak/tokenlist";
5312
- import { TOKEMAK_PRICES_STAGING_URL } from "@tokemak/constants";
5313
- var getTokenPrices = async () => {
5314
- try {
5315
- const body = {
5316
- tokens: PRICED_TOKENS2.map((asset) => ({
5317
- token: asset.address,
5318
- chainId: asset.chainId,
5319
- systemName: "gen3",
5320
- timeoutMS: 5 * 1e3
5321
- }))
5322
- };
5323
- const response = await fetch(`${TOKEMAK_PRICES_STAGING_URL}`, {
5324
- method: "POST",
5325
- headers: {
5326
- "Content-Type": "application/json"
5327
- },
5328
- body: JSON.stringify(body)
5329
- });
5330
- const data = await response.json();
5331
- const prices = PRICED_TOKENS2.reduce((acc, asset) => {
5332
- const priceData = data.find(
5333
- (item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
4188
+ const body = {
4189
+ tokens: PRICED_TOKENS2.map((asset) => ({
4190
+ token: asset.address,
4191
+ chainId: asset.chainId,
4192
+ systemName: "gen3",
4193
+ timeoutMS: 5 * 1e3
4194
+ }))
4195
+ };
4196
+ const response = await fetch(`${TOKEMAK_PRICES_STAGING_URL}`, {
4197
+ method: "POST",
4198
+ headers: {
4199
+ "Content-Type": "application/json"
4200
+ },
4201
+ body: JSON.stringify(body)
4202
+ });
4203
+ const data = await response.json();
4204
+ const prices = PRICED_TOKENS2.reduce((acc, asset) => {
4205
+ const priceData = data.find(
4206
+ (item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
5334
4207
  );
5335
4208
  acc[asset.symbol] = priceData?.price ?? 0;
5336
4209
  return acc;
@@ -5358,11 +4231,11 @@ var getTokenPrices = async () => {
5358
4231
  };
5359
4232
 
5360
4233
  // functions/getChainSubgraphStatus.ts
5361
- import { getSdkByChainId as getSdkByChainId16 } from "@tokemak/graph-cli";
4234
+ import { getSdkByChainId as getSdkByChainId12 } from "@tokemak/graph-cli";
5362
4235
  var getChainSubgraphStatus = async (chain) => {
5363
4236
  const currentTimestamp = Math.floor(Date.now() / 1e3);
5364
4237
  try {
5365
- const { GetLatestSubgraphTimestamp } = getSdkByChainId16(
4238
+ const { GetLatestSubgraphTimestamp } = getSdkByChainId12(
5366
4239
  chain.chainId
5367
4240
  );
5368
4241
  const { _meta } = await GetLatestSubgraphTimestamp();
@@ -5413,155 +4286,15 @@ var getSubgraphStatus = async (includeTestnet = false) => {
5413
4286
  return { isOutOfSync, errorMessage };
5414
4287
  };
5415
4288
 
5416
- // functions/getCycleV1.ts
5417
- import { readContract as readContract15 } from "@wagmi/core";
5418
- import { managerV1Abi as managerV1Abi2 } from "@tokemak/abis";
5419
- import { createPublicClient, http } from "viem";
5420
- import {
5421
- convertChainCycleToUnix as convertChainCycleToUnix4,
5422
- convertSecondsToRemainingTime as convertSecondsToRemainingTime3
5423
- } from "@tokemak/utils";
5424
- import { getMainnetConfig as getMainnetConfig7 } from "@tokemak/config";
5425
- import { mainnet as mainnet8 } from "viem/chains";
5426
- var publicClient = createPublicClient({
5427
- chain: mainnet8,
5428
- transport: http("https://mainnet.infura.io/v3/2BtQ5D1QEPHvwgZwKwnZC7WQVhr")
5429
- });
5430
- var getCycleV1 = async (wagmiConfig, {
5431
- currentBlockNumber,
5432
- chainId
5433
- }) => {
5434
- const scanPeriodInDays = 8;
5435
- const blockTime = 12;
5436
- const { managerV1 } = getMainnetConfig7();
5437
- try {
5438
- if (currentBlockNumber && managerV1) {
5439
- const currentCycleIndex = await readContract15(wagmiConfig, {
5440
- address: managerV1,
5441
- abi: managerV1Abi2,
5442
- functionName: "getCurrentCycleIndex",
5443
- chainId
5444
- });
5445
- const filter = await publicClient.createContractEventFilter({
5446
- address: managerV1,
5447
- fromBlock: BigInt(
5448
- Math.floor(
5449
- Number(currentBlockNumber) - 86400 / blockTime * scanPeriodInDays
5450
- )
5451
- ),
5452
- abi: managerV1Abi2,
5453
- eventName: "CycleRolloverComplete"
5454
- });
5455
- const rolloverEvents = await publicClient.getFilterLogs({ filter });
5456
- const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
5457
- const secondsLeftBeforeNextCycle = convertChainCycleToUnix4(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
5458
- return {
5459
- currentCycleIndex,
5460
- cycleRolloverBlockNumber,
5461
- timeBeforeNextCycle: convertSecondsToRemainingTime3(
5462
- secondsLeftBeforeNextCycle
5463
- )
5464
- };
5465
- }
5466
- } catch (error) {
5467
- console.error(error);
5468
- }
5469
- };
5470
-
5471
- // functions/getProtocolStats.ts
5472
- import { formatLargeNumber as formatLargeNumber3, formatTVL as formatTVL3, formatEtherNum as formatEtherNum14 } from "@tokemak/utils";
5473
- var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
5474
- try {
5475
- if (!autopools || !stoke || !sushiLP) {
5476
- throw new Error("Missing required data");
5477
- }
5478
- const autopoolTVL = autopools?.reduce((acc, pool) => acc + pool.tvl, 0) || 0;
5479
- const categories = autopools?.reduce((acc, pool) => {
5480
- if (!acc[pool.category]) {
5481
- if (pool.category === "eth" /* ETH */) {
5482
- acc[pool.category] = { tvl: 0, supply: 0 };
5483
- } else {
5484
- acc[pool.category] = { tvl: 0 };
5485
- }
5486
- }
5487
- acc[pool.category].tvl += pool.tvl;
5488
- if (pool.category === "eth" /* ETH */) {
5489
- if (pool.totalAssets) {
5490
- const ethAmt = pool.totalAssets.ETH;
5491
- if (acc[pool.category]) {
5492
- acc[pool.category].supply = (acc[pool.category].supply ?? 0) + ethAmt;
5493
- }
5494
- }
5495
- }
5496
- return acc;
5497
- }, {});
5498
- const formattedCategories = Object.fromEntries(
5499
- Object.entries(categories).map(([key, value]) => [
5500
- key,
5501
- {
5502
- tvl: formatTVL3(value.tvl),
5503
- supply: formatLargeNumber3(value.supply || 0)
5504
- }
5505
- ])
5506
- );
5507
- const tvl = formatTVL3(
5508
- autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0) + (EthAutoLP?.tvlUsd || 0) + (sauto?.rawTVL || 0)
5509
- );
5510
- const vaultAddresses = autopools?.flatMap(
5511
- (pool) => pool.destinations.map((destination) => destination.vaultAddress)
5512
- );
5513
- const uniqueVaultAddresses = [...new Set(vaultAddresses)];
5514
- const totalDestinations = uniqueVaultAddresses.length;
5515
- const stakedTVL = {
5516
- totalSupply: formatLargeNumber3(
5517
- formatEtherNum14(
5518
- (sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
5519
- )
5520
- ),
5521
- tvl: formatTVL3((sauto?.rawTVL || 0) + stoke.rawTVL)
5522
- };
5523
- return {
5524
- autopools: {
5525
- tvl: formatTVL3(autopoolTVL),
5526
- tvlNum: autopoolTVL,
5527
- categories: formattedCategories
5528
- },
5529
- stoke: {
5530
- tvl: formatTVL3(stoke.rawTVL),
5531
- tvlNum: stoke.rawTVL,
5532
- totalSupply: `${stoke.totalSupply} TOKE`
5533
- },
5534
- sushiLP: {
5535
- tvl: formatTVL3(sushiLP?.tvl || 0),
5536
- totalSupply: sushiLP?.totalSupply || 0
5537
- },
5538
- EthAutoLP: {
5539
- tvl: formatTVL3(EthAutoLP?.tvlUsd || 0)
5540
- },
5541
- sauto: {
5542
- tvl: formatTVL3(sauto?.rawTVL || 0),
5543
- tvlNum: sauto?.rawTVL || 0,
5544
- totalSupply: `${sauto?.totalSupply} AUTO`
5545
- },
5546
- stakedTVL,
5547
- tvl,
5548
- totalDestinations
5549
- };
5550
- } catch (error) {
5551
- console.error(error);
5552
- return null;
5553
- }
5554
- };
5555
-
5556
4289
  // functions/getRebalanceStats.ts
5557
- import { getSdkByChainId as getSdkByChainId17 } from "@tokemak/graph-cli";
4290
+ import { getSdkByChainId as getSdkByChainId13 } from "@tokemak/graph-cli";
5558
4291
 
5559
4292
  // functions/getEthPriceAtBlock.ts
5560
- import { getCoreConfig as getCoreConfig10 } from "@tokemak/config";
4293
+ import { getCoreConfig as getCoreConfig7 } from "@tokemak/config";
5561
4294
  import { rootPriceOracleAbi } from "@tokemak/abis";
5562
4295
  import { USDC_TOKEN } from "@tokemak/tokenlist";
5563
4296
  var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
5564
- const config = getCoreConfig10(chainId);
4297
+ const config = getCoreConfig7(chainId);
5565
4298
  const rootPriceOracle = config.rootPriceOracle;
5566
4299
  const weth = config.weth;
5567
4300
  const usdc = USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || USDC_TOKEN.address;
@@ -5577,12 +4310,12 @@ var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
5577
4310
  };
5578
4311
 
5579
4312
  // functions/getRebalanceStats.ts
5580
- import { formatEtherNum as formatEtherNum15, formatUnitsNum as formatUnitsNum8 } from "@tokemak/utils";
4313
+ import { formatEtherNum as formatEtherNum10, formatUnitsNum as formatUnitsNum8 } from "@tokemak/utils";
5581
4314
  import { USDC_TOKEN as USDC_TOKEN2 } from "@tokemak/tokenlist";
5582
4315
  import { sonic as sonic3 } from "viem/chains";
5583
4316
  var BATCH_SIZE = 500;
5584
4317
  var fetchChainRebalances = async (chainId) => {
5585
- const { GetAllAutopoolRebalances } = getSdkByChainId17(chainId);
4318
+ const { GetAllAutopoolRebalances } = getSdkByChainId13(chainId);
5586
4319
  const allRebalances = await paginateQuery(
5587
4320
  GetAllAutopoolRebalances,
5588
4321
  "autopoolRebalances"
@@ -5612,7 +4345,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
5612
4345
  account
5613
4346
  );
5614
4347
  const ethUsd = Number(formatUnitsNum8(price, USDC_TOKEN2.decimals));
5615
- const ethAmt = Number(formatEtherNum15(ethWei));
4348
+ const ethAmt = Number(formatEtherNum10(ethWei));
5616
4349
  const usd = ethAmt * ethUsd;
5617
4350
  return usd;
5618
4351
  } catch (e) {
@@ -5705,7 +4438,7 @@ var getRebalanceStats = async (getClient, {
5705
4438
  };
5706
4439
 
5707
4440
  // functions/updateRebalanceStats.ts
5708
- import { getPublicClient as getPublicClient4 } from "@wagmi/core";
4441
+ import { getPublicClient as getPublicClient3 } from "@wagmi/core";
5709
4442
  var updateRebalanceStats = async (wagmiConfig, {
5710
4443
  currentRebalances,
5711
4444
  includeTestnet = false
@@ -5720,7 +4453,7 @@ var updateRebalanceStats = async (wagmiConfig, {
5720
4453
  )
5721
4454
  );
5722
4455
  if (newRawRebalances.length > 0) {
5723
- const client = getPublicClient4(wagmiConfig, {
4456
+ const client = getPublicClient3(wagmiConfig, {
5724
4457
  chainId: chain.chainId
5725
4458
  });
5726
4459
  return processRebalancesInBatches(
@@ -5739,16 +4472,16 @@ var updateRebalanceStats = async (wagmiConfig, {
5739
4472
 
5740
4473
  // functions/getUserSAuto.ts
5741
4474
  import { sAutoAbi } from "@tokemak/abis";
5742
- import { getMainnetConfig as getMainnetConfig8 } from "@tokemak/config";
4475
+ import { getMainnetConfig } from "@tokemak/config";
5743
4476
  import {
5744
4477
  convertAutoCycleToUnix,
5745
- convertSecondsToRemainingTime as convertSecondsToRemainingTime4,
5746
- formatCurrency as formatCurrency4,
5747
- formatEtherNum as formatEtherNum16
4478
+ convertSecondsToRemainingTime,
4479
+ formatCurrency as formatCurrency2,
4480
+ formatEtherNum as formatEtherNum11
5748
4481
  } from "@tokemak/utils";
5749
- import { readContracts as readContracts11 } from "@wagmi/core";
5750
- import { formatEther as formatEther5 } from "viem";
5751
- import { mainnet as mainnet9 } from "viem/chains";
4482
+ import { readContracts as readContracts5 } from "@wagmi/core";
4483
+ import { formatEther } from "viem";
4484
+ import { mainnet as mainnet7 } from "viem/chains";
5752
4485
  var getUserSAuto = async (wagmiConfig, {
5753
4486
  address,
5754
4487
  autoPrice
@@ -5760,8 +4493,8 @@ var getUserSAuto = async (wagmiConfig, {
5760
4493
  if (!autoPrice) {
5761
4494
  throw new Error("Auto price not found");
5762
4495
  }
5763
- const { sAuto } = getMainnetConfig8();
5764
- const chainId = mainnet9.id;
4496
+ const { sAuto } = getMainnetConfig();
4497
+ const chainId = mainnet7.id;
5765
4498
  const sAutoContract = {
5766
4499
  address: sAuto,
5767
4500
  abi: sAutoAbi
@@ -5771,7 +4504,7 @@ var getUserSAuto = async (wagmiConfig, {
5771
4504
  { result: depositInfoResult },
5772
4505
  { result: withdrawalInfoResult },
5773
4506
  { result: cycleIndex }
5774
- ] = await readContracts11(wagmiConfig, {
4507
+ ] = await readContracts5(wagmiConfig, {
5775
4508
  contracts: [
5776
4509
  {
5777
4510
  ...sAutoContract,
@@ -5807,8 +4540,8 @@ var getUserSAuto = async (wagmiConfig, {
5807
4540
  if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
5808
4541
  balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
5809
4542
  }
5810
- const withdrawalAmountUsd = formatCurrency4(
5811
- formatEtherNum16(withdrawalAmount) * autoPrice
4543
+ const withdrawalAmountUsd = formatCurrency2(
4544
+ formatEtherNum11(withdrawalAmount) * autoPrice
5812
4545
  );
5813
4546
  const lockDuration = Number(depositLockDuration);
5814
4547
  const lockCycle = Number(depositLockCycle);
@@ -5818,11 +4551,11 @@ var getUserSAuto = async (wagmiConfig, {
5818
4551
  const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
5819
4552
  const lockRenew = currentCycle - lockStart > lockDuration ? currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement : currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd;
5820
4553
  const withdrawAvailable = lockRenew - 1;
5821
- const balanceUSD = formatCurrency4(
5822
- Number(formatEther5(balanceExcludingWithdrawal)) * autoPrice
4554
+ const balanceUSD = formatCurrency2(
4555
+ Number(formatEther(balanceExcludingWithdrawal)) * autoPrice
5823
4556
  );
5824
- const balanceExcludingWithdrawalUsd = formatCurrency4(
5825
- formatEtherNum16(balanceExcludingWithdrawal) * autoPrice
4557
+ const balanceExcludingWithdrawalUsd = formatCurrency2(
4558
+ formatEtherNum11(balanceExcludingWithdrawal) * autoPrice
5826
4559
  );
5827
4560
  const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
5828
4561
  const hasRequestedUnlock = withdrawalAmount > 0n;
@@ -5844,20 +4577,20 @@ var getUserSAuto = async (wagmiConfig, {
5844
4577
  unlockPeriodStartDate,
5845
4578
  unlockRenewalDate
5846
4579
  } = formatDateRange(unlockPeriodDateRangeArray, "date");
5847
- const totalActiveUserCredits = formatEtherNum16(balanceExcludingWithdrawal) * lockDurationInMonths;
5848
- const totalUserCredits = formatEtherNum16(balance) * lockDurationInMonths;
4580
+ const totalActiveUserCredits = formatEtherNum11(balanceExcludingWithdrawal) * lockDurationInMonths;
4581
+ const totalUserCredits = formatEtherNum11(balance) * lockDurationInMonths;
5849
4582
  const hasAddedLockedAuto = depositAmount > 0n;
5850
4583
  const addedLockedAuto = depositAmount;
5851
4584
  return {
5852
4585
  balance,
5853
4586
  balanceUSD,
5854
- balanceExcludingWithdrawal: hasBalance ? formatEther5(balanceExcludingWithdrawal) : "0.00",
4587
+ balanceExcludingWithdrawal: hasBalance ? formatEther(balanceExcludingWithdrawal) : "0.00",
5855
4588
  balanceExcludingWithdrawalUsd,
5856
4589
  hasBalanceExcludingWithdrawal,
5857
- timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime4(
4590
+ timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime(
5858
4591
  unlockRequestPeriodStartUnix
5859
4592
  ),
5860
- timeLeftBeforeUnlockRequestUnavailable: convertSecondsToRemainingTime4(
4593
+ timeLeftBeforeUnlockRequestUnavailable: convertSecondsToRemainingTime(
5861
4594
  unlockRequestPeriodEndUnix
5862
4595
  ),
5863
4596
  withdrawalAmount,
@@ -5874,7 +4607,7 @@ var getUserSAuto = async (wagmiConfig, {
5874
4607
  unlockRenewalDate,
5875
4608
  lockDurationInMonths,
5876
4609
  boost: lockDuration,
5877
- points: formatEtherNum16(balanceExcludingWithdrawal) * lockDuration,
4610
+ points: formatEtherNum11(balanceExcludingWithdrawal) * lockDuration,
5878
4611
  totalActiveCredits: totalActiveUserCredits,
5879
4612
  totalCredits: totalUserCredits,
5880
4613
  hasBalance
@@ -5886,30 +4619,30 @@ var getUserSAuto = async (wagmiConfig, {
5886
4619
  };
5887
4620
 
5888
4621
  // functions/getSAuto.ts
5889
- import { formatEther as formatEther6 } from "viem";
5890
- import { readContracts as readContracts12 } from "@wagmi/core";
4622
+ import { formatEther as formatEther2 } from "viem";
4623
+ import { readContracts as readContracts6 } from "@wagmi/core";
5891
4624
  import { sAutoAbi as sAutoAbi2 } from "@tokemak/abis";
5892
4625
  import {
5893
4626
  convertAutoCycleToUnix as convertAutoCycleToUnix2,
5894
- convertSecondsToRemainingTime as convertSecondsToRemainingTime5,
5895
- formatLargeNumber as formatLargeNumber4,
5896
- formatTVL as formatTVL4
4627
+ convertSecondsToRemainingTime as convertSecondsToRemainingTime2,
4628
+ formatLargeNumber,
4629
+ formatTVL
5897
4630
  } from "@tokemak/utils";
5898
- import { getMainnetConfig as getMainnetConfig9 } from "@tokemak/config";
5899
- import { mainnet as mainnet10 } from "viem/chains";
4631
+ import { getMainnetConfig as getMainnetConfig2 } from "@tokemak/config";
4632
+ import { mainnet as mainnet8 } from "viem/chains";
5900
4633
  var getSAuto = async (wagmiConfig, {
5901
4634
  autoPrice
5902
4635
  }) => {
5903
4636
  try {
5904
- const { sAuto } = getMainnetConfig9();
5905
- const chainId = mainnet10.id;
4637
+ const { sAuto } = getMainnetConfig2();
4638
+ const chainId = mainnet8.id;
5906
4639
  const baseConfig = {
5907
4640
  address: sAuto,
5908
4641
  abi: sAutoAbi2,
5909
4642
  chainId
5910
4643
  };
5911
4644
  if (sAuto && autoPrice) {
5912
- const [{ result: totalSupply }, { result: currentCycle }] = await readContracts12(wagmiConfig, {
4645
+ const [{ result: totalSupply }, { result: currentCycle }] = await readContracts6(wagmiConfig, {
5913
4646
  contracts: [
5914
4647
  {
5915
4648
  ...baseConfig,
@@ -5921,15 +4654,15 @@ var getSAuto = async (wagmiConfig, {
5921
4654
  }
5922
4655
  ]
5923
4656
  });
5924
- const tvl = Number(formatEther6(totalSupply || 0n)) * autoPrice;
4657
+ const tvl = Number(formatEther2(totalSupply || 0n)) * autoPrice;
5925
4658
  const secondsLeftBeforeNextCycle = convertAutoCycleToUnix2(Number(currentCycle) + 1) - Date.now() / 1e3;
5926
4659
  return {
5927
4660
  rawTotalSupply: totalSupply,
5928
- totalSupply: formatLargeNumber4(formatEther6(totalSupply || 0n)),
5929
- tvl: formatTVL4(tvl),
4661
+ totalSupply: formatLargeNumber(formatEther2(totalSupply || 0n)),
4662
+ tvl: formatTVL(tvl),
5930
4663
  rawTVL: tvl,
5931
4664
  currentCycle,
5932
- timeBeforeNextCycle: convertSecondsToRemainingTime5(
4665
+ timeBeforeNextCycle: convertSecondsToRemainingTime2(
5933
4666
  secondsLeftBeforeNextCycle
5934
4667
  )
5935
4668
  };
@@ -5940,36 +4673,36 @@ var getSAuto = async (wagmiConfig, {
5940
4673
  };
5941
4674
 
5942
4675
  // functions/getSAutoRewards.ts
5943
- import { formatUnits as formatUnits9 } from "viem";
4676
+ import { formatUnits as formatUnits8 } from "viem";
5944
4677
  import {
5945
4678
  convertTimestampToDate as convertTimestampToDate5,
5946
4679
  formatDateToReadable as formatDateToReadable3,
5947
- formatEtherNum as formatEtherNum17
4680
+ formatEtherNum as formatEtherNum12
5948
4681
  } from "@tokemak/utils";
5949
- import { getSdkByChainId as getSdkByChainId18 } from "@tokemak/graph-cli";
5950
- import { mainnet as mainnet11 } from "viem/chains";
4682
+ import { getSdkByChainId as getSdkByChainId14 } from "@tokemak/graph-cli";
4683
+ import { mainnet as mainnet9 } from "viem/chains";
5951
4684
  var getSAutoRewards = async () => {
5952
4685
  try {
5953
- const { GetSAutoRewards } = getSdkByChainId18(mainnet11.id);
4686
+ const { GetSAutoRewards } = getSdkByChainId14(mainnet9.id);
5954
4687
  const { globalRewardsBalances } = await GetSAutoRewards();
5955
4688
  const allGlobalRewardsBalanceDayDatas = await paginateQuery(
5956
4689
  GetSAutoRewards,
5957
4690
  "globalRewardsBalanceDayDatas"
5958
4691
  );
5959
4692
  const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
5960
- return acc + formatEtherNum17(balance.balance);
4693
+ return acc + formatEtherNum12(balance.balance);
5961
4694
  }, 0);
5962
4695
  const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
5963
- return acc + Number(formatUnits9(balance.balanceUSD, 8));
4696
+ return acc + Number(formatUnits8(balance.balanceUSD, 8));
5964
4697
  }, 0);
5965
4698
  const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
5966
4699
  (dayData) => ({
5967
4700
  timestamp: String(dayData.timestamp),
5968
- balance: formatEtherNum17(dayData.balance),
5969
- balanceUSD: Number(formatUnits9(dayData.balanceUSD, 8)),
5970
- earned: formatEtherNum17(dayData.earned),
5971
- earnedUSD: Number(formatUnits9(dayData.earnedUSD, 8)),
5972
- dayAprPerCredit: formatEtherNum17(dayData.dayAprPerCredit),
4701
+ balance: formatEtherNum12(dayData.balance),
4702
+ balanceUSD: Number(formatUnits8(dayData.balanceUSD, 8)),
4703
+ earned: formatEtherNum12(dayData.earned),
4704
+ earnedUSD: Number(formatUnits8(dayData.earnedUSD, 8)),
4705
+ dayAprPerCredit: formatEtherNum12(dayData.dayAprPerCredit),
5973
4706
  formattedDate: formatDateToReadable3(
5974
4707
  convertTimestampToDate5(Number(dayData.timestamp))
5975
4708
  )
@@ -5987,10 +4720,10 @@ var getSAutoRewards = async () => {
5987
4720
  };
5988
4721
 
5989
4722
  // functions/getUserSAutoRewards.ts
5990
- import { getMainnetConfig as getMainnetConfig10 } from "@tokemak/config";
5991
- import { formatEtherNum as formatEtherNum18 } from "@tokemak/utils";
4723
+ import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
4724
+ import { formatEtherNum as formatEtherNum13 } from "@tokemak/utils";
5992
4725
  var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
5993
- const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = getMainnetConfig10();
4726
+ const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = getMainnetConfig3();
5994
4727
  const currentCycle = await getCurrentCycleId(wagmiConfig, {
5995
4728
  stoke: sAuto,
5996
4729
  chainId: 1
@@ -6034,19 +4767,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
6034
4767
  return null;
6035
4768
  }
6036
4769
  }
6037
- const claimableNum = formatEtherNum18(autoRewards?.claimable || 0n);
4770
+ const claimableNum = formatEtherNum13(autoRewards?.claimable || 0n);
6038
4771
  const claimableUsd = autoPrice * claimableNum;
6039
4772
  const hasClaimable = claimableNum > 0;
6040
- let pendingRewards = formatEtherNum18(
4773
+ let pendingRewards = formatEtherNum13(
6041
4774
  autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
6042
4775
  );
6043
4776
  if (currentCycle === 4242n) {
6044
- pendingRewards = formatEtherNum18(
4777
+ pendingRewards = formatEtherNum13(
6045
4778
  autoRewards?.rewardsPayload.payload.amount || 0n
6046
4779
  );
6047
4780
  }
6048
4781
  const pendingRewardsUsd = autoPrice * pendingRewards;
6049
- const totalRewardsReceived = formatEtherNum18(
4782
+ const totalRewardsReceived = formatEtherNum13(
6050
4783
  autoRewards.rewardsPayload.payload.amount || 0n
6051
4784
  );
6052
4785
  const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
@@ -6147,12 +4880,12 @@ async function getMerklPoolApr({
6147
4880
  }
6148
4881
 
6149
4882
  // functions/getSAutoApr.ts
6150
- import { getSdkByChainId as getSdkByChainId19 } from "@tokemak/graph-cli";
6151
- import { mainnet as mainnet12 } from "viem/chains";
6152
- import { formatEtherNum as formatEtherNum19, formatPercent } from "@tokemak/utils";
4883
+ import { getSdkByChainId as getSdkByChainId15 } from "@tokemak/graph-cli";
4884
+ import { mainnet as mainnet10 } from "viem/chains";
4885
+ import { formatEtherNum as formatEtherNum14, formatPercent } from "@tokemak/utils";
6153
4886
  var getSAutoApr = async () => {
6154
4887
  try {
6155
- const { GetSAutoApr } = getSdkByChainId19(mainnet12.id);
4888
+ const { GetSAutoApr } = getSdkByChainId15(mainnet10.id);
6156
4889
  const { globalRewardsBalances } = await GetSAutoApr();
6157
4890
  if (!globalRewardsBalances || globalRewardsBalances.length === 0) {
6158
4891
  return {
@@ -6168,7 +4901,7 @@ var getSAutoApr = async () => {
6168
4901
  aprFormatted: void 0
6169
4902
  };
6170
4903
  }
6171
- const aprPerCredit = formatEtherNum19(rawApr);
4904
+ const aprPerCredit = formatEtherNum14(rawApr);
6172
4905
  const lockDuration = 16;
6173
4906
  const apr = aprPerCredit * lockDuration;
6174
4907
  return {
@@ -6184,66 +4917,56 @@ var getSAutoApr = async () => {
6184
4917
  }
6185
4918
  };
6186
4919
 
6187
- // functions/getCombinedRewards.ts
6188
- var getCombinedRewards = async () => {
6189
- const [stokeRewards, sAutoRewards] = await Promise.all([
6190
- getSTokeRewards({ includeTestnet: false }),
6191
- getSAutoRewards()
6192
- ]);
6193
- const totalEarnings = (stokeRewards?.totalEarnings || 0) + (sAutoRewards?.totalEarnings || 0);
6194
- const totalEarningsUsd = (stokeRewards?.totalEarningsUsd || 0) + (sAutoRewards?.totalEarningsUsd || 0);
6195
- const stokeByTs = /* @__PURE__ */ new Map();
6196
- const sAutoByTs = /* @__PURE__ */ new Map();
6197
- const dateByTs = /* @__PURE__ */ new Map();
6198
- for (const item of stokeRewards?.historicalRewards || []) {
6199
- const ts = Number(item.timestamp);
6200
- const existing = stokeByTs.get(ts);
6201
- if (existing) {
6202
- existing.balance += item.balance;
6203
- existing.balanceUSD += item.balanceUSD;
6204
- } else {
6205
- stokeByTs.set(ts, { balance: item.balance, balanceUSD: item.balanceUSD });
6206
- }
6207
- if (!dateByTs.has(ts)) dateByTs.set(ts, item.formattedDate);
6208
- }
6209
- for (const item of sAutoRewards?.historicalRewards || []) {
6210
- const ts = Number(item.timestamp);
6211
- const existing = sAutoByTs.get(ts);
6212
- if (existing) {
6213
- existing.balance += item.balance;
6214
- existing.balanceUSD += item.balanceUSD;
6215
- } else {
6216
- sAutoByTs.set(ts, { balance: item.balance, balanceUSD: item.balanceUSD });
6217
- }
6218
- if (!dateByTs.has(ts)) dateByTs.set(ts, item.formattedDate);
6219
- }
6220
- const allTimestamps = Array.from(
6221
- /* @__PURE__ */ new Set([...stokeByTs.keys(), ...sAutoByTs.keys()])
6222
- ).sort((a, b) => a - b);
6223
- let lastStoke = { balance: 0, balanceUSD: 0 };
6224
- let lastSAuto = { balance: 0, balanceUSD: 0 };
6225
- const historicalRewards = allTimestamps.map((ts) => {
6226
- if (stokeByTs.has(ts)) lastStoke = stokeByTs.get(ts);
6227
- if (sAutoByTs.has(ts)) lastSAuto = sAutoByTs.get(ts);
4920
+ // functions/getSystemConfig.ts
4921
+ import { readContracts as readContracts7 } from "@wagmi/core";
4922
+ import { systemRegistryAbi as systemRegistryAbi2 } from "@tokemak/abis";
4923
+ var systemRegistryFunctionNames = [
4924
+ "asyncSwapperRegistry",
4925
+ "autoPoolRouter",
4926
+ "autoPoolRegistry",
4927
+ "swapRouter",
4928
+ "weth"
4929
+ ];
4930
+ var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
4931
+ const systemRegistryContract = {
4932
+ address: systemRegistry,
4933
+ abi: systemRegistryAbi2
4934
+ };
4935
+ const systemRegistryCalls = systemRegistryFunctionNames.map(
4936
+ (functionName) => ({
4937
+ ...systemRegistryContract,
4938
+ functionName
4939
+ })
4940
+ );
4941
+ try {
4942
+ const [
4943
+ { result: asyncSwapperRegistry },
4944
+ { result: autopoolRouter },
4945
+ { result: autopoolRegistry },
4946
+ { result: swapRouter }
4947
+ ] = await readContracts7(wagmiConfig, {
4948
+ contracts: systemRegistryCalls
4949
+ });
6228
4950
  return {
6229
- balance: lastStoke.balance + lastSAuto.balance,
6230
- balanceUSD: lastStoke.balanceUSD + lastSAuto.balanceUSD,
6231
- formattedDate: dateByTs.get(ts)
4951
+ asyncSwapperRegistry,
4952
+ autopoolRouter,
4953
+ autopoolRegistry,
4954
+ swapRouter
6232
4955
  };
6233
- });
6234
- return {
6235
- totalEarnings,
6236
- totalEarningsUsd,
6237
- historicalRewards
6238
- };
4956
+ } catch (e) {
4957
+ console.log(e);
4958
+ }
6239
4959
  };
6240
4960
  export {
6241
4961
  AutopoolCategory,
6242
4962
  BATCH_SIZE,
6243
4963
  ETH_BASE_ASSETS,
6244
4964
  EUR_BASE_ASSETS,
6245
- MessageStatus,
4965
+ GET_USER_POSITIONS,
4966
+ GET_V4_POOL_TVL,
4967
+ GRAPH_V4_SUBGRAPH_PROXY_PATH,
6246
4968
  USD_BASE_ASSETS,
4969
+ V4_SUBGRAPH_IDS,
6247
4970
  aggregateSTokeRewardsDayData,
6248
4971
  arraysToObject,
6249
4972
  calculateRebalanceStats,
@@ -6260,7 +4983,6 @@ export {
6260
4983
  findClosestTimestampEntry,
6261
4984
  formatDateRange,
6262
4985
  getAddressFromSystemRegistry,
6263
- getAllowance,
6264
4986
  getAmountDeposited,
6265
4987
  getAmountWithdrawn,
6266
4988
  getAutopilotRouter,
@@ -6274,61 +4996,44 @@ export {
6274
4996
  getAutopoolUserHistory,
6275
4997
  getAutopools,
6276
4998
  getAutopoolsHistory,
6277
- getAutopoolsRebalances,
6278
4999
  getBlobData,
6279
5000
  getBlobHistoricalTokenPrices,
6280
5001
  getBridgeFee,
6281
5002
  getChainAutopools,
6282
5003
  getChainAutopoolsApr,
6283
- getChainCycleRolloverBlockNumber,
6284
- getChainSToke,
6285
- getChainSTokeRewards,
6286
5004
  getChainSubgraphStatus,
6287
5005
  getChainUserActivity,
6288
5006
  getChainUserAutopools,
6289
- getChainUserSToke,
6290
- getChainUserSTokeRewards,
6291
5007
  getChainsForEnv,
6292
- getCombinedRewards,
6293
5008
  getCurrentCycleId,
6294
- getCurveLP,
6295
- getCycleV1,
6296
5009
  getDefillamaPoolApr,
6297
5010
  getDefillamaPrice,
5011
+ getDeprecatedAutopools,
6298
5012
  getDynamicSwap,
6299
5013
  getEthAutoLP,
6300
- getEthPrice,
6301
5014
  getEthPriceAtBlock,
6302
5015
  getExchangeNames,
6303
5016
  getGenStratAprs,
6304
5017
  getHistoricalTokenPrices,
6305
- getLayerzeroStatus,
6306
5018
  getMerklCreatorApr,
6307
5019
  getMerklPoolApr,
6308
- getMutlipleAutopoolRebalances,
6309
5020
  getPoolStats,
6310
5021
  getPoolsAndDestinations,
6311
- getProtocolStats,
6312
5022
  getRebalanceStats,
6313
5023
  getRebalanceValueUsd,
6314
5024
  getRewardsPayloadV1,
6315
5025
  getSAuto,
6316
5026
  getSAutoApr,
6317
5027
  getSAutoRewards,
6318
- getSToke,
6319
5028
  getSTokeChainsForEnv,
6320
- getSTokeRewards,
6321
5029
  getSubgraphStatus,
6322
- getSushiLP,
6323
5030
  getSwapQuote,
6324
5031
  getSystemConfig,
6325
5032
  getTimestampDaysFromStart,
6326
5033
  getTokePrice,
6327
- getTokenList,
6328
5034
  getTokenPrice,
6329
5035
  getTokenPrices,
6330
5036
  getTopAutopoolHolders,
6331
- getUniV4Pool,
6332
5037
  getUniV4PoolById,
6333
5038
  getUserActivity,
6334
5039
  getUserAutoEthRewards,
@@ -6336,19 +5041,17 @@ export {
6336
5041
  getUserAutopools,
6337
5042
  getUserAutopoolsHistory,
6338
5043
  getUserAutopoolsRewards,
6339
- getUserCurveLP,
6340
5044
  getUserEthAutoLP,
6341
5045
  getUserEthAutoLPRewards,
6342
5046
  getUserMerklRewards,
6343
5047
  getUserRewardsV1,
6344
5048
  getUserSAuto,
6345
5049
  getUserSAutoRewards,
6346
- getUserSToke,
6347
- getUserSushiLP,
6348
5050
  getUserTokenBalances,
6349
5051
  getUserUniV4Positions,
6350
5052
  getUserUniV4PositionsById,
6351
- getUserV1,
5053
+ getV4PoolTvlFromSubgraph,
5054
+ getV4SubgraphUrl,
6352
5055
  mergeArrays,
6353
5056
  mergeArraysWithKey,
6354
5057
  mergeStringArrays,
@@ -6358,6 +5061,5 @@ export {
6358
5061
  processRebalance,
6359
5062
  processRebalancesInBatches,
6360
5063
  systemRegistryFunctionNames,
6361
- updateRebalanceStats,
6362
- waitForMessageReceived
5064
+ updateRebalanceStats
6363
5065
  };