@tokemak/queries 0.6.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.
- package/dist/functions/getAutopools.d.ts +3 -1
- package/dist/functions/getAutopools.d.ts.map +1 -1
- package/dist/functions/getChainAutopools.d.ts +19 -17
- package/dist/functions/getChainAutopools.d.ts.map +1 -1
- package/dist/functions/getDeprecatedAutopools.d.ts +347 -0
- package/dist/functions/getDeprecatedAutopools.d.ts.map +1 -0
- package/dist/functions/getEthAutoLP.d.ts +1 -1
- package/dist/functions/getEthAutoLP.d.ts.map +1 -1
- package/dist/functions/getEthPriceAtBlock.d.ts +2 -2
- package/dist/functions/getEthPriceAtBlock.d.ts.map +1 -1
- package/dist/functions/getPoolsAndDestinations.d.ts +4 -2
- package/dist/functions/getPoolsAndDestinations.d.ts.map +1 -1
- package/dist/functions/getRebalanceStats.d.ts +5 -4
- package/dist/functions/getRebalanceStats.d.ts.map +1 -1
- package/dist/functions/getUniV4Pool.d.ts +13 -17
- package/dist/functions/getUniV4Pool.d.ts.map +1 -1
- package/dist/functions/getUserUniV4Positions.d.ts +1 -0
- package/dist/functions/getUserUniV4Positions.d.ts.map +1 -1
- package/dist/functions/index.d.ts +3 -23
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/uniV4Subgraph.d.ts +45 -0
- package/dist/functions/uniV4Subgraph.d.ts.map +1 -0
- package/dist/index.js +456 -1728
- package/dist/index.mjs +328 -1603
- package/dist/safe.js +49 -22
- package/dist/safe.mjs +45 -18
- package/dist/utils/getChainsForEnv.d.ts +12 -3
- package/dist/utils/getChainsForEnv.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/functions/getAllowance.d.ts +0 -8
- package/dist/functions/getAllowance.d.ts.map +0 -1
- package/dist/functions/getAutopoolsRebalances.d.ts +0 -53
- package/dist/functions/getAutopoolsRebalances.d.ts.map +0 -1
- package/dist/functions/getChainCycleRolloverBlockNumber.d.ts +0 -7
- package/dist/functions/getChainCycleRolloverBlockNumber.d.ts.map +0 -1
- package/dist/functions/getChainSToke.d.ts +0 -15
- package/dist/functions/getChainSToke.d.ts.map +0 -1
- package/dist/functions/getChainSTokeRewards.d.ts +0 -16
- package/dist/functions/getChainSTokeRewards.d.ts.map +0 -1
- package/dist/functions/getChainUserSToke.d.ts +0 -33
- package/dist/functions/getChainUserSToke.d.ts.map +0 -1
- package/dist/functions/getChainUserSTokeRewards.d.ts +0 -30
- package/dist/functions/getChainUserSTokeRewards.d.ts.map +0 -1
- package/dist/functions/getCombinedRewards.d.ts +0 -11
- package/dist/functions/getCombinedRewards.d.ts.map +0 -1
- package/dist/functions/getCurveLP.d.ts +0 -3
- package/dist/functions/getCurveLP.d.ts.map +0 -1
- package/dist/functions/getCycleV1.d.ts +0 -10
- package/dist/functions/getCycleV1.d.ts.map +0 -1
- package/dist/functions/getEthPrice.d.ts +0 -2
- package/dist/functions/getEthPrice.d.ts.map +0 -1
- package/dist/functions/getLayerzeroStatus.d.ts +0 -24
- package/dist/functions/getLayerzeroStatus.d.ts.map +0 -1
- package/dist/functions/getMultipleAutopoolRebalances.d.ts +0 -54
- package/dist/functions/getMultipleAutopoolRebalances.d.ts.map +0 -1
- package/dist/functions/getProtocolStats.d.ts +0 -41
- package/dist/functions/getProtocolStats.d.ts.map +0 -1
- package/dist/functions/getSToke.d.ts +0 -23
- package/dist/functions/getSToke.d.ts.map +0 -1
- package/dist/functions/getSTokeRewards.d.ts +0 -22
- package/dist/functions/getSTokeRewards.d.ts.map +0 -1
- package/dist/functions/getSushiLP.d.ts +0 -14
- package/dist/functions/getSushiLP.d.ts.map +0 -1
- package/dist/functions/getTokenList.d.ts +0 -3
- package/dist/functions/getTokenList.d.ts.map +0 -1
- package/dist/functions/getUserCurveLP.d.ts +0 -16
- package/dist/functions/getUserCurveLP.d.ts.map +0 -1
- package/dist/functions/getUserSToke.d.ts +0 -40
- package/dist/functions/getUserSToke.d.ts.map +0 -1
- package/dist/functions/getUserSTokeRewards.d.ts +0 -38
- package/dist/functions/getUserSTokeRewards.d.ts.map +0 -1
- package/dist/functions/getUserSushiLP.d.ts +0 -23
- package/dist/functions/getUserSushiLP.d.ts.map +0 -1
- package/dist/functions/getUserV1.d.ts +0 -18
- 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/
|
|
21
|
-
import {
|
|
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
|
-
|
|
305
|
-
|
|
306
|
-
return
|
|
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
|
|
@@ -610,13 +594,19 @@ import { sonic } from "viem/chains";
|
|
|
610
594
|
// functions/getPoolsAndDestinations.ts
|
|
611
595
|
import { getCoreConfig } from "@tokemak/config";
|
|
612
596
|
import { lensAbi } from "@tokemak/abis";
|
|
613
|
-
var getPoolsAndDestinations = async (client, {
|
|
597
|
+
var getPoolsAndDestinations = async (client, {
|
|
598
|
+
chainId,
|
|
599
|
+
account,
|
|
600
|
+
blockNumber
|
|
601
|
+
}) => {
|
|
614
602
|
try {
|
|
615
603
|
const { lens } = getCoreConfig(chainId);
|
|
616
604
|
const { autoPools, destinations } = await client.readContract({
|
|
617
605
|
address: lens,
|
|
618
606
|
abi: lensAbi,
|
|
619
|
-
functionName: "getPoolsAndDestinations"
|
|
607
|
+
functionName: "getPoolsAndDestinations",
|
|
608
|
+
account,
|
|
609
|
+
blockNumber
|
|
620
610
|
});
|
|
621
611
|
const autopoolsAndDestinations = mergeArraysWithKey(
|
|
622
612
|
autoPools,
|
|
@@ -638,7 +628,9 @@ import {
|
|
|
638
628
|
} from "@tokemak/constants";
|
|
639
629
|
var getChainAutopools = async (client, {
|
|
640
630
|
chainId,
|
|
641
|
-
prices
|
|
631
|
+
prices,
|
|
632
|
+
account,
|
|
633
|
+
blockNumber
|
|
642
634
|
}) => {
|
|
643
635
|
const { GetVaultAddeds, GetAutopoolsInactiveDestinations } = getSdkByChainId(chainId);
|
|
644
636
|
try {
|
|
@@ -651,7 +643,9 @@ var getChainAutopools = async (client, {
|
|
|
651
643
|
chainId
|
|
652
644
|
});
|
|
653
645
|
const autopoolsAndDestinations = await getPoolsAndDestinations(client, {
|
|
654
|
-
chainId
|
|
646
|
+
chainId,
|
|
647
|
+
account,
|
|
648
|
+
blockNumber
|
|
655
649
|
});
|
|
656
650
|
if (!autopoolsAndDestinations) {
|
|
657
651
|
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
@@ -1037,10 +1031,11 @@ import { AUTOPOOLS_WHITELIST_PROD } from "@tokemak/config";
|
|
|
1037
1031
|
import { getAddress as getAddress2 } from "viem";
|
|
1038
1032
|
var getAutopools = async (wagmiConfig, {
|
|
1039
1033
|
prices,
|
|
1040
|
-
includeTestnet = false
|
|
1034
|
+
includeTestnet = false,
|
|
1035
|
+
status = "all"
|
|
1041
1036
|
}) => {
|
|
1042
1037
|
try {
|
|
1043
|
-
const chains = getChainsForEnv({ includeTestnet });
|
|
1038
|
+
const chains = getChainsForEnv({ includeTestnet, status });
|
|
1044
1039
|
const autopools = (await Promise.all(
|
|
1045
1040
|
chains.map((chain) => {
|
|
1046
1041
|
const chainId = chain?.chainId;
|
|
@@ -1065,6 +1060,12 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1065
1060
|
}
|
|
1066
1061
|
};
|
|
1067
1062
|
|
|
1063
|
+
// functions/getDeprecatedAutopools.ts
|
|
1064
|
+
var getDeprecatedAutopools = (wagmiConfig, {
|
|
1065
|
+
prices,
|
|
1066
|
+
includeTestnet = false
|
|
1067
|
+
}) => getAutopools(wagmiConfig, { prices, includeTestnet, status: "sunset" });
|
|
1068
|
+
|
|
1068
1069
|
// functions/getAutopoolRebalances.ts
|
|
1069
1070
|
import { getSdkByChainId as getSdkByChainId2 } from "@tokemak/graph-cli";
|
|
1070
1071
|
var getAutopoolRebalances = async (id, chainId = 1, options) => {
|
|
@@ -1084,23 +1085,14 @@ var getAutopoolRebalances = async (id, chainId = 1, options) => {
|
|
|
1084
1085
|
}));
|
|
1085
1086
|
};
|
|
1086
1087
|
|
|
1087
|
-
// functions/getAutopoolsRebalances.ts
|
|
1088
|
-
import { getSdkByChainId as getSdkByChainId3 } from "@tokemak/graph-cli";
|
|
1089
|
-
var getAutopoolsRebalances = async (chainId = 1) => {
|
|
1090
|
-
const { GetAutopoolsRebalances } = getSdkByChainId3(chainId);
|
|
1091
|
-
const { autopools } = await GetAutopoolsRebalances();
|
|
1092
|
-
const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
|
|
1093
|
-
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
1094
|
-
};
|
|
1095
|
-
|
|
1096
1088
|
// functions/getAutopoolDayData.ts
|
|
1097
1089
|
import { formatUnits as formatUnits3 } from "viem";
|
|
1098
1090
|
import { formatEtherNum as formatEtherNum3 } from "@tokemak/utils";
|
|
1099
1091
|
import { TOKEMAK_LAUNCH_TIMESTAMP } from "@tokemak/constants";
|
|
1100
|
-
import { getSdkByChainId as
|
|
1092
|
+
import { getSdkByChainId as getSdkByChainId3 } from "@tokemak/graph-cli";
|
|
1101
1093
|
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_LAUNCH_TIMESTAMP) => {
|
|
1102
1094
|
try {
|
|
1103
|
-
const { GetAutopoolDayData } =
|
|
1095
|
+
const { GetAutopoolDayData } = getSdkByChainId3(chainId);
|
|
1104
1096
|
const { autopoolDayDatas } = await GetAutopoolDayData({
|
|
1105
1097
|
address,
|
|
1106
1098
|
timestamp: startTimestamp
|
|
@@ -1159,9 +1151,9 @@ var getAutopoolHistory = async (autopool) => {
|
|
|
1159
1151
|
import { getAddress as getAddress3 } from "viem";
|
|
1160
1152
|
|
|
1161
1153
|
// functions/getAutopoolsDayData.ts
|
|
1162
|
-
import { getSdkByChainId as
|
|
1154
|
+
import { getSdkByChainId as getSdkByChainId4 } from "@tokemak/graph-cli";
|
|
1163
1155
|
var getAutopoolsDayData = async (chainId, timestamp) => {
|
|
1164
|
-
const { GetAutopoolsDayData } =
|
|
1156
|
+
const { GetAutopoolsDayData } = getSdkByChainId4(chainId);
|
|
1165
1157
|
const PAGE_SIZE = 1e3;
|
|
1166
1158
|
let allResults = [];
|
|
1167
1159
|
let hasMore = true;
|
|
@@ -1376,7 +1368,7 @@ var getAutopoolUser = async (config, {
|
|
|
1376
1368
|
};
|
|
1377
1369
|
|
|
1378
1370
|
// functions/getAutopoolUserActivity.ts
|
|
1379
|
-
import { getSdkByChainId as
|
|
1371
|
+
import { getSdkByChainId as getSdkByChainId5 } from "@tokemak/graph-cli";
|
|
1380
1372
|
import { formatUnitsNum as formatUnitsNum3 } from "@tokemak/utils";
|
|
1381
1373
|
var getAutopoolUserActivity = async ({
|
|
1382
1374
|
autopool,
|
|
@@ -1385,7 +1377,7 @@ var getAutopoolUserActivity = async ({
|
|
|
1385
1377
|
if (!autopool || !autopool.chain?.chainId) {
|
|
1386
1378
|
throw new Error("Autopool not found");
|
|
1387
1379
|
}
|
|
1388
|
-
const { GetUserAutopoolBalanceChangeHistory } =
|
|
1380
|
+
const { GetUserAutopoolBalanceChangeHistory } = getSdkByChainId5(
|
|
1389
1381
|
autopool.chain?.chainId
|
|
1390
1382
|
);
|
|
1391
1383
|
try {
|
|
@@ -1464,7 +1456,7 @@ var getAutopoolUserActivity = async ({
|
|
|
1464
1456
|
};
|
|
1465
1457
|
|
|
1466
1458
|
// functions/getAutopoolUserHistory.ts
|
|
1467
|
-
import { getSdkByChainId as
|
|
1459
|
+
import { getSdkByChainId as getSdkByChainId6 } from "@tokemak/graph-cli";
|
|
1468
1460
|
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP2 } from "@tokemak/constants";
|
|
1469
1461
|
import { base } from "viem/chains";
|
|
1470
1462
|
import { formatEtherNum as formatEtherNum5, formatUnitsNum as formatUnitsNum4 } from "@tokemak/utils";
|
|
@@ -1473,7 +1465,7 @@ var getAutopoolUserHistory = async ({
|
|
|
1473
1465
|
autopool,
|
|
1474
1466
|
userActivity
|
|
1475
1467
|
}) => {
|
|
1476
|
-
const { GetUserVaultDayData } =
|
|
1468
|
+
const { GetUserVaultDayData } = getSdkByChainId6(
|
|
1477
1469
|
autopool?.chain?.chainId || base.id
|
|
1478
1470
|
);
|
|
1479
1471
|
try {
|
|
@@ -1560,102 +1552,62 @@ var getAutopoolUserHistory = async ({
|
|
|
1560
1552
|
}
|
|
1561
1553
|
};
|
|
1562
1554
|
|
|
1563
|
-
// functions/
|
|
1564
|
-
import {
|
|
1565
|
-
import {
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
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}`;
|
|
1580
1576
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
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
|
|
1590
1591
|
}
|
|
1591
|
-
} catch (e) {
|
|
1592
|
-
console.error(e);
|
|
1593
1592
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
import { sushiPoolAbi } from "@tokemak/abis";
|
|
1599
|
-
import { getMainnetConfig as getMainnetConfig2 } from "@tokemak/config";
|
|
1600
|
-
import { readContracts as readContracts2 } from "@wagmi/core";
|
|
1601
|
-
import { formatEther } from "viem";
|
|
1602
|
-
import { mainnet } from "viem/chains";
|
|
1603
|
-
var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
1604
|
-
const { sushiPool, lpRewardsV1Url } = getMainnetConfig2();
|
|
1605
|
-
const sushiPoolContract = {
|
|
1606
|
-
address: sushiPool,
|
|
1607
|
-
abi: sushiPoolAbi
|
|
1608
|
-
};
|
|
1593
|
+
`;
|
|
1594
|
+
async function getV4PoolTvlFromSubgraph(poolId, chainId, apiKey) {
|
|
1595
|
+
const url = getV4SubgraphUrl(chainId, apiKey);
|
|
1596
|
+
if (!url) return null;
|
|
1609
1597
|
try {
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
{
|
|
1615
|
-
...sushiPoolContract,
|
|
1616
|
-
functionName: "getReserves",
|
|
1617
|
-
chainId: mainnet.id
|
|
1618
|
-
},
|
|
1619
|
-
{
|
|
1620
|
-
...sushiPoolContract,
|
|
1621
|
-
functionName: "totalSupply",
|
|
1622
|
-
chainId: mainnet.id
|
|
1623
|
-
}
|
|
1624
|
-
]
|
|
1625
|
-
}
|
|
1626
|
-
);
|
|
1627
|
-
const lpRewardsResponse = await fetch(lpRewardsV1Url);
|
|
1628
|
-
const lpRewardsData = await lpRewardsResponse.json();
|
|
1629
|
-
const sushiLPRewards = lpRewardsData.chains[0].pools.find(
|
|
1630
|
-
({ 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() }
|
|
1631
1602
|
);
|
|
1632
|
-
|
|
1633
|
-
const lpReserve = reserves[1] * 2n;
|
|
1634
|
-
const tvl = Number(formatEther(lpReserve)) * ethPrice;
|
|
1635
|
-
const valueOf1LP = tvl / Number(formatEther(totalSupply));
|
|
1636
|
-
return {
|
|
1637
|
-
tvl,
|
|
1638
|
-
lpReserve,
|
|
1639
|
-
totalSupply,
|
|
1640
|
-
reserves,
|
|
1641
|
-
apr: sushiLPRewards?.liquidityProviderApr,
|
|
1642
|
-
weeklyTokeEmissions: sushiLPRewards?.liquidityProviderReward,
|
|
1643
|
-
valueOf1LP
|
|
1644
|
-
};
|
|
1645
|
-
}
|
|
1603
|
+
return data.pool ?? null;
|
|
1646
1604
|
} catch (e) {
|
|
1647
|
-
console.
|
|
1605
|
+
console.error("Error fetching V4 pool TVL from subgraph:", e);
|
|
1606
|
+
return null;
|
|
1648
1607
|
}
|
|
1649
|
-
}
|
|
1608
|
+
}
|
|
1650
1609
|
|
|
1651
1610
|
// functions/getUniV4Pool.ts
|
|
1652
|
-
import { readContracts as readContracts3 } from "@wagmi/core";
|
|
1653
|
-
import { formatUnits as formatUnits4, keccak256, encodeAbiParameters } from "viem";
|
|
1654
|
-
import { mainnet as mainnet2 } from "viem/chains";
|
|
1655
|
-
import {
|
|
1656
|
-
UNISWAP_V4_POOL_MANAGER,
|
|
1657
|
-
UNISWAP_V4_STATE_VIEW
|
|
1658
|
-
} from "@tokemak/constants";
|
|
1659
1611
|
var stateViewAbi = [
|
|
1660
1612
|
{
|
|
1661
1613
|
inputs: [{ internalType: "PoolId", name: "poolId", type: "bytes32" }],
|
|
@@ -1747,166 +1699,6 @@ function feeToTierString(fee) {
|
|
|
1747
1699
|
};
|
|
1748
1700
|
return tiers[fee] || `${fee / 1e4}%`;
|
|
1749
1701
|
}
|
|
1750
|
-
async function getUniV4Pool(wagmiConfig, {
|
|
1751
|
-
poolKey,
|
|
1752
|
-
chainId = mainnet2.id,
|
|
1753
|
-
prices
|
|
1754
|
-
}) {
|
|
1755
|
-
const stateView = UNISWAP_V4_STATE_VIEW[chainId];
|
|
1756
|
-
if (!stateView) {
|
|
1757
|
-
console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
|
|
1758
|
-
return null;
|
|
1759
|
-
}
|
|
1760
|
-
const poolManager = UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1761
|
-
const poolId = computePoolId(poolKey);
|
|
1762
|
-
try {
|
|
1763
|
-
const [{ result: slot0 }, { result: liquidity }] = await readContracts3(
|
|
1764
|
-
wagmiConfig,
|
|
1765
|
-
{
|
|
1766
|
-
contracts: [
|
|
1767
|
-
{
|
|
1768
|
-
address: stateView,
|
|
1769
|
-
abi: stateViewAbi,
|
|
1770
|
-
functionName: "getSlot0",
|
|
1771
|
-
args: [poolId],
|
|
1772
|
-
chainId
|
|
1773
|
-
},
|
|
1774
|
-
{
|
|
1775
|
-
address: stateView,
|
|
1776
|
-
abi: stateViewAbi,
|
|
1777
|
-
functionName: "getLiquidity",
|
|
1778
|
-
args: [poolId],
|
|
1779
|
-
chainId
|
|
1780
|
-
}
|
|
1781
|
-
]
|
|
1782
|
-
}
|
|
1783
|
-
);
|
|
1784
|
-
if (!slot0) {
|
|
1785
|
-
return null;
|
|
1786
|
-
}
|
|
1787
|
-
const isToken0Native = poolKey.currency0 === "0x0000000000000000000000000000000000000000";
|
|
1788
|
-
const isToken1Native = poolKey.currency1 === "0x0000000000000000000000000000000000000000";
|
|
1789
|
-
const tokenContracts = [];
|
|
1790
|
-
if (!isToken0Native) {
|
|
1791
|
-
tokenContracts.push(
|
|
1792
|
-
{
|
|
1793
|
-
address: poolKey.currency0,
|
|
1794
|
-
abi: erc20Abi2,
|
|
1795
|
-
functionName: "decimals",
|
|
1796
|
-
chainId
|
|
1797
|
-
},
|
|
1798
|
-
{
|
|
1799
|
-
address: poolKey.currency0,
|
|
1800
|
-
abi: erc20Abi2,
|
|
1801
|
-
functionName: "symbol",
|
|
1802
|
-
chainId
|
|
1803
|
-
},
|
|
1804
|
-
{
|
|
1805
|
-
address: poolKey.currency0,
|
|
1806
|
-
abi: erc20Abi2,
|
|
1807
|
-
functionName: "balanceOf",
|
|
1808
|
-
args: [poolManager],
|
|
1809
|
-
chainId
|
|
1810
|
-
}
|
|
1811
|
-
);
|
|
1812
|
-
}
|
|
1813
|
-
if (!isToken1Native) {
|
|
1814
|
-
tokenContracts.push(
|
|
1815
|
-
{
|
|
1816
|
-
address: poolKey.currency1,
|
|
1817
|
-
abi: erc20Abi2,
|
|
1818
|
-
functionName: "decimals",
|
|
1819
|
-
chainId
|
|
1820
|
-
},
|
|
1821
|
-
{
|
|
1822
|
-
address: poolKey.currency1,
|
|
1823
|
-
abi: erc20Abi2,
|
|
1824
|
-
functionName: "symbol",
|
|
1825
|
-
chainId
|
|
1826
|
-
},
|
|
1827
|
-
{
|
|
1828
|
-
address: poolKey.currency1,
|
|
1829
|
-
abi: erc20Abi2,
|
|
1830
|
-
functionName: "balanceOf",
|
|
1831
|
-
args: [poolManager],
|
|
1832
|
-
chainId
|
|
1833
|
-
}
|
|
1834
|
-
);
|
|
1835
|
-
}
|
|
1836
|
-
const tokenResults = tokenContracts.length > 0 ? await readContracts3(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
1837
|
-
let decimals0 = 18;
|
|
1838
|
-
let symbol0 = "ETH";
|
|
1839
|
-
let balance0 = 0n;
|
|
1840
|
-
let decimals1 = 18;
|
|
1841
|
-
let symbol1 = "ETH";
|
|
1842
|
-
let balance1 = 0n;
|
|
1843
|
-
let resultIndex = 0;
|
|
1844
|
-
if (!isToken0Native) {
|
|
1845
|
-
decimals0 = tokenResults[resultIndex++]?.result ?? 18;
|
|
1846
|
-
symbol0 = tokenResults[resultIndex++]?.result ?? "TOKEN0";
|
|
1847
|
-
balance0 = tokenResults[resultIndex++]?.result ?? 0n;
|
|
1848
|
-
}
|
|
1849
|
-
if (!isToken1Native) {
|
|
1850
|
-
decimals1 = tokenResults[resultIndex++]?.result ?? 18;
|
|
1851
|
-
symbol1 = tokenResults[resultIndex++]?.result ?? "TOKEN1";
|
|
1852
|
-
balance1 = tokenResults[resultIndex++]?.result ?? 0n;
|
|
1853
|
-
}
|
|
1854
|
-
const [sqrtPriceX96, tick] = slot0;
|
|
1855
|
-
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1856
|
-
const balance0Formatted = Number(formatUnits4(balance0, decimals0));
|
|
1857
|
-
const balance1Formatted = Number(formatUnits4(balance1, decimals1));
|
|
1858
|
-
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1859
|
-
liquidity ?? 0n,
|
|
1860
|
-
sqrtPriceX96,
|
|
1861
|
-
decimals0,
|
|
1862
|
-
decimals1
|
|
1863
|
-
);
|
|
1864
|
-
const priceInverted = price > 0 ? 1 / price : 0;
|
|
1865
|
-
const tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
|
|
1866
|
-
const tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
|
|
1867
|
-
let tvlUsd;
|
|
1868
|
-
if (prices) {
|
|
1869
|
-
const price0 = prices[symbol0] || prices[poolKey.currency0.toLowerCase()];
|
|
1870
|
-
const price1 = prices[symbol1] || prices[poolKey.currency1.toLowerCase()];
|
|
1871
|
-
if (price0) {
|
|
1872
|
-
tvlUsd = tvlToken0 * price0;
|
|
1873
|
-
} else if (price1) {
|
|
1874
|
-
tvlUsd = tvlToken1 * price1;
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
return {
|
|
1878
|
-
poolId,
|
|
1879
|
-
poolKey,
|
|
1880
|
-
token0: {
|
|
1881
|
-
address: poolKey.currency0,
|
|
1882
|
-
symbol: symbol0,
|
|
1883
|
-
decimals: decimals0,
|
|
1884
|
-
balance: balance0,
|
|
1885
|
-
balanceFormatted: balance0Formatted
|
|
1886
|
-
},
|
|
1887
|
-
token1: {
|
|
1888
|
-
address: poolKey.currency1,
|
|
1889
|
-
symbol: symbol1,
|
|
1890
|
-
decimals: decimals1,
|
|
1891
|
-
balance: balance1,
|
|
1892
|
-
balanceFormatted: balance1Formatted
|
|
1893
|
-
},
|
|
1894
|
-
fee: poolKey.fee,
|
|
1895
|
-
feeTier: feeToTierString(poolKey.fee),
|
|
1896
|
-
sqrtPriceX96,
|
|
1897
|
-
tick,
|
|
1898
|
-
liquidity: liquidity ?? 0n,
|
|
1899
|
-
liquidityAmounts,
|
|
1900
|
-
price,
|
|
1901
|
-
priceInverted,
|
|
1902
|
-
tvlToken0,
|
|
1903
|
-
tvlToken1,
|
|
1904
|
-
tvlUsd
|
|
1905
|
-
};
|
|
1906
|
-
} catch (e) {
|
|
1907
|
-
return null;
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
1702
|
function createPoolKey({
|
|
1911
1703
|
tokenA,
|
|
1912
1704
|
tokenB,
|
|
@@ -1938,7 +1730,8 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1938
1730
|
}
|
|
1939
1731
|
const poolManager = UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1940
1732
|
try {
|
|
1941
|
-
const
|
|
1733
|
+
const tvlPromise = getV4PoolTvlFromSubgraph(poolId, chainId);
|
|
1734
|
+
const [{ result: slot0 }, { result: liquidity }] = await readContracts2(
|
|
1942
1735
|
wagmiConfig,
|
|
1943
1736
|
{
|
|
1944
1737
|
contracts: [
|
|
@@ -2011,7 +1804,7 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2011
1804
|
}
|
|
2012
1805
|
);
|
|
2013
1806
|
}
|
|
2014
|
-
const tokenResults = tokenContracts.length > 0 ? await
|
|
1807
|
+
const tokenResults = tokenContracts.length > 0 ? await readContracts2(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
2015
1808
|
let decimals0 = 18;
|
|
2016
1809
|
let symbol0 = "ETH";
|
|
2017
1810
|
let balance0 = 0n;
|
|
@@ -2031,22 +1824,43 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2031
1824
|
}
|
|
2032
1825
|
const [sqrtPriceX96, tick] = slot0;
|
|
2033
1826
|
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1827
|
+
const priceInverted = price > 0 ? 1 / price : 0;
|
|
2034
1828
|
const balance0Formatted = Number(formatUnits4(balance0, decimals0));
|
|
2035
1829
|
const balance1Formatted = Number(formatUnits4(balance1, decimals1));
|
|
2036
|
-
const
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
decimals1
|
|
2041
|
-
);
|
|
2042
|
-
const priceInverted = price > 0 ? 1 / price : 0;
|
|
2043
|
-
const tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
|
|
2044
|
-
const tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
|
|
1830
|
+
const subgraphPool = await tvlPromise;
|
|
1831
|
+
let liquidityAmounts;
|
|
1832
|
+
let tvlToken0;
|
|
1833
|
+
let tvlToken1;
|
|
2045
1834
|
let tvlUsd;
|
|
2046
|
-
if (
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2049
|
-
|
|
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;
|
|
2050
1864
|
}
|
|
2051
1865
|
}
|
|
2052
1866
|
return {
|
|
@@ -2083,26 +1897,14 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2083
1897
|
}
|
|
2084
1898
|
|
|
2085
1899
|
// functions/getUserUniV4Positions.ts
|
|
2086
|
-
import { readContracts as
|
|
1900
|
+
import { readContracts as readContracts3 } from "@wagmi/core";
|
|
2087
1901
|
import { formatUnits as formatUnits5 } from "viem";
|
|
2088
1902
|
import { mainnet as mainnet3 } from "viem/chains";
|
|
2089
|
-
import { GraphQLClient, gql } from "graphql-request";
|
|
1903
|
+
import { GraphQLClient as GraphQLClient2, gql as gql2 } from "graphql-request";
|
|
2090
1904
|
import {
|
|
2091
1905
|
UNISWAP_V4_POSITION_MANAGER,
|
|
2092
|
-
UNISWAP_V4_STATE_VIEW as UNISWAP_V4_STATE_VIEW2
|
|
2093
|
-
GRAPH_API_KEY
|
|
1906
|
+
UNISWAP_V4_STATE_VIEW as UNISWAP_V4_STATE_VIEW2
|
|
2094
1907
|
} from "@tokemak/constants";
|
|
2095
|
-
var V4_SUBGRAPH_IDS = {
|
|
2096
|
-
[mainnet3.id]: "DiYPVdygkfjDWhbxGSqAQxwBKmfKnkWQojqeM2rkLb3G"
|
|
2097
|
-
};
|
|
2098
|
-
function getV4SubgraphUrl(chainId, apiKey) {
|
|
2099
|
-
const subgraphId = V4_SUBGRAPH_IDS[chainId];
|
|
2100
|
-
if (!subgraphId) return null;
|
|
2101
|
-
if (apiKey) {
|
|
2102
|
-
return `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
|
|
2103
|
-
}
|
|
2104
|
-
return `https://gateway.thegraph.com/api/subgraphs/id/${subgraphId}`;
|
|
2105
|
-
}
|
|
2106
1908
|
var positionManagerAbi = [
|
|
2107
1909
|
{
|
|
2108
1910
|
inputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }],
|
|
@@ -2167,7 +1969,7 @@ var erc20Abi3 = [
|
|
|
2167
1969
|
type: "function"
|
|
2168
1970
|
}
|
|
2169
1971
|
];
|
|
2170
|
-
var GET_USER_POSITIONS =
|
|
1972
|
+
var GET_USER_POSITIONS = gql2`
|
|
2171
1973
|
query GetUserPositions($owner: String!) {
|
|
2172
1974
|
positions(where: { owner: $owner }) {
|
|
2173
1975
|
tokenId
|
|
@@ -2221,7 +2023,7 @@ async function getPositionTokenIdsFromSubgraph(userAddress, chainId, graphApiKey
|
|
|
2221
2023
|
return [];
|
|
2222
2024
|
}
|
|
2223
2025
|
try {
|
|
2224
|
-
const client = new
|
|
2026
|
+
const client = new GraphQLClient2(subgraphUrl);
|
|
2225
2027
|
const data = await client.request(GET_USER_POSITIONS, {
|
|
2226
2028
|
owner: userAddress.toLowerCase()
|
|
2227
2029
|
});
|
|
@@ -2255,11 +2057,10 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2255
2057
|
if (knownTokenIds && knownTokenIds.length > 0) {
|
|
2256
2058
|
tokenIds = knownTokenIds;
|
|
2257
2059
|
} else {
|
|
2258
|
-
const apiKey = graphApiKey || GRAPH_API_KEY;
|
|
2259
2060
|
tokenIds = await getPositionTokenIdsFromSubgraph(
|
|
2260
2061
|
userAddress,
|
|
2261
2062
|
chainId,
|
|
2262
|
-
|
|
2063
|
+
graphApiKey
|
|
2263
2064
|
);
|
|
2264
2065
|
}
|
|
2265
2066
|
if (tokenIds.length === 0) {
|
|
@@ -2281,7 +2082,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2281
2082
|
chainId
|
|
2282
2083
|
}
|
|
2283
2084
|
]);
|
|
2284
|
-
const positionResults = await
|
|
2085
|
+
const positionResults = await readContracts3(wagmiConfig, {
|
|
2285
2086
|
contracts: positionInfoCalls
|
|
2286
2087
|
});
|
|
2287
2088
|
const matchingPositions = [];
|
|
@@ -2357,7 +2158,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2357
2158
|
}
|
|
2358
2159
|
] : []
|
|
2359
2160
|
];
|
|
2360
|
-
const infoResults = await
|
|
2161
|
+
const infoResults = await readContracts3(wagmiConfig, {
|
|
2361
2162
|
contracts: infoCalls
|
|
2362
2163
|
});
|
|
2363
2164
|
const slot0 = infoResults[0]?.result;
|
|
@@ -2620,9 +2421,9 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2620
2421
|
}
|
|
2621
2422
|
|
|
2622
2423
|
// functions/getChainUserActivity.ts
|
|
2623
|
-
import { getSdkByChainId as
|
|
2424
|
+
import { getSdkByChainId as getSdkByChainId7 } from "@tokemak/graph-cli";
|
|
2624
2425
|
var getChainUserActivity = async (address, chainId = 1) => {
|
|
2625
|
-
const { GetUserBalanceChangeHistory } =
|
|
2426
|
+
const { GetUserBalanceChangeHistory } = getSdkByChainId7(chainId);
|
|
2626
2427
|
try {
|
|
2627
2428
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
2628
2429
|
(vars) => GetUserBalanceChangeHistory({
|
|
@@ -2827,121 +2628,14 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2827
2628
|
}
|
|
2828
2629
|
};
|
|
2829
2630
|
|
|
2830
|
-
// functions/getUserV1.ts
|
|
2831
|
-
import { rewardsV1Abi as rewardsV1Abi2, stakingV1Abi } from "@tokemak/abis";
|
|
2832
|
-
import { readContract as readContract4 } from "@wagmi/core";
|
|
2833
|
-
import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
|
|
2834
|
-
import { mainnet as mainnet6 } from "viem/chains";
|
|
2835
|
-
var getUserV1 = async (wagmiConfig, {
|
|
2836
|
-
currentCycleIndex,
|
|
2837
|
-
address,
|
|
2838
|
-
chainId
|
|
2839
|
-
}) => {
|
|
2840
|
-
const {
|
|
2841
|
-
stakingV1,
|
|
2842
|
-
rewardsV1Url,
|
|
2843
|
-
accTokeV1RewardsHash,
|
|
2844
|
-
rewardsV1Hash,
|
|
2845
|
-
accTokeV1Rewards,
|
|
2846
|
-
autoEthGuardedRewards,
|
|
2847
|
-
rewardsV1,
|
|
2848
|
-
missedTokeRewards
|
|
2849
|
-
} = getMainnetConfig3(mainnet6.id);
|
|
2850
|
-
try {
|
|
2851
|
-
const userStakedTokeV1 = await readContract4(wagmiConfig, {
|
|
2852
|
-
address: stakingV1,
|
|
2853
|
-
abi: stakingV1Abi,
|
|
2854
|
-
functionName: "availableForWithdrawal",
|
|
2855
|
-
args: [address, 0n],
|
|
2856
|
-
chainId: mainnet6.id
|
|
2857
|
-
});
|
|
2858
|
-
const tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
2859
|
-
address,
|
|
2860
|
-
rewardsCycleIndex: currentCycleIndex - 1n,
|
|
2861
|
-
rewardsV1,
|
|
2862
|
-
rewardsV1Url,
|
|
2863
|
-
rewardsV1Hash,
|
|
2864
|
-
chainId
|
|
2865
|
-
});
|
|
2866
|
-
const ethRewards = await getUserRewardsV1(wagmiConfig, {
|
|
2867
|
-
address,
|
|
2868
|
-
rewardsCycleIndex: 306n,
|
|
2869
|
-
rewardsV1: accTokeV1Rewards,
|
|
2870
|
-
rewardsV1Url,
|
|
2871
|
-
rewardsV1Hash: accTokeV1RewardsHash,
|
|
2872
|
-
chainId
|
|
2873
|
-
});
|
|
2874
|
-
const autoEthGuardedRewardsPayload = await getRewardsPayloadV1(
|
|
2875
|
-
"QmcJgQ42aGTsqngSBa98qxnbv2CHyk9DmSg1jDD569bnpp",
|
|
2876
|
-
address,
|
|
2877
|
-
rewardsV1Url
|
|
2878
|
-
);
|
|
2879
|
-
const payloadChainId = autoEthGuardedRewardsPayload?.payload?.chainId;
|
|
2880
|
-
const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
|
|
2881
|
-
const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
|
|
2882
|
-
const amount = autoEthGuardedRewardsPayload?.payload?.amount;
|
|
2883
|
-
const claimableAutoEth = await readContract4(wagmiConfig, {
|
|
2884
|
-
address: autoEthGuardedRewards,
|
|
2885
|
-
abi: rewardsV1Abi2,
|
|
2886
|
-
functionName: "getClaimableAmount",
|
|
2887
|
-
args: [
|
|
2888
|
-
{
|
|
2889
|
-
chainId: payloadChainId || 0n,
|
|
2890
|
-
cycle: cycle || 0n,
|
|
2891
|
-
wallet: wallet || "0x0000000000000000000000000000000000000000",
|
|
2892
|
-
amount: amount || 0n
|
|
2893
|
-
}
|
|
2894
|
-
],
|
|
2895
|
-
chainId
|
|
2896
|
-
});
|
|
2897
|
-
const missedTokeRewardsPayload = await getRewardsPayloadV1(
|
|
2898
|
-
"QmRpVjVhFqbUTtLnQ4addEwBtvF2CC7t6rbQWYiju9nAqd",
|
|
2899
|
-
address,
|
|
2900
|
-
rewardsV1Url
|
|
2901
|
-
);
|
|
2902
|
-
let claimableMissedToke = 0n;
|
|
2903
|
-
if (missedTokeRewardsPayload) {
|
|
2904
|
-
const {
|
|
2905
|
-
payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
|
|
2906
|
-
} = missedTokeRewardsPayload;
|
|
2907
|
-
claimableMissedToke = await readContract4(wagmiConfig, {
|
|
2908
|
-
address: missedTokeRewards,
|
|
2909
|
-
abi: rewardsV1Abi2,
|
|
2910
|
-
functionName: "getClaimableAmount",
|
|
2911
|
-
args: [
|
|
2912
|
-
{
|
|
2913
|
-
chainId: payloadChainId2,
|
|
2914
|
-
cycle: cycle2,
|
|
2915
|
-
wallet: wallet2,
|
|
2916
|
-
amount: amount2 || 0n
|
|
2917
|
-
}
|
|
2918
|
-
],
|
|
2919
|
-
chainId
|
|
2920
|
-
});
|
|
2921
|
-
}
|
|
2922
|
-
return {
|
|
2923
|
-
stakedToke: userStakedTokeV1,
|
|
2924
|
-
claimableToke: tokeRewards?.claimable,
|
|
2925
|
-
claimableEth: ethRewards?.claimable,
|
|
2926
|
-
claimableAutoEth,
|
|
2927
|
-
tokeRewardsPayload: tokeRewards?.rewardsPayload,
|
|
2928
|
-
ethRewardsPayload: ethRewards?.rewardsPayload,
|
|
2929
|
-
missedTokeRewardsPayload,
|
|
2930
|
-
autoEthGuardedRewardsPayload,
|
|
2931
|
-
claimableMissedToke
|
|
2932
|
-
};
|
|
2933
|
-
} catch (e) {
|
|
2934
|
-
}
|
|
2935
|
-
};
|
|
2936
|
-
|
|
2937
2631
|
// functions/getChainUserAutopoolsHistory.tsx
|
|
2938
|
-
import { getSdkByChainId as
|
|
2632
|
+
import { getSdkByChainId as getSdkByChainId8 } from "@tokemak/graph-cli";
|
|
2939
2633
|
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP3 } from "@tokemak/constants";
|
|
2940
2634
|
var getChainUserAutopoolsHistory = async ({
|
|
2941
2635
|
address,
|
|
2942
2636
|
chainId = 1
|
|
2943
2637
|
}) => {
|
|
2944
|
-
const { GetUserVaultsDayData } =
|
|
2638
|
+
const { GetUserVaultsDayData } = getSdkByChainId8(chainId);
|
|
2945
2639
|
try {
|
|
2946
2640
|
if (address) {
|
|
2947
2641
|
const { userVaultDayDatas } = await GetUserVaultsDayData({
|
|
@@ -2964,12 +2658,12 @@ import {
|
|
|
2964
2658
|
} from "@tokemak/utils";
|
|
2965
2659
|
|
|
2966
2660
|
// functions/getTokenValueDayDatas.ts
|
|
2967
|
-
import { mainnet as
|
|
2661
|
+
import { mainnet as mainnet6 } from "viem/chains";
|
|
2968
2662
|
import { convertTimestampToDate as convertTimestampToDate3 } from "@tokemak/utils";
|
|
2969
2663
|
import { formatUnits as formatUnits6 } from "viem";
|
|
2970
|
-
import { getSdkByChainId as
|
|
2971
|
-
var getTokenValueDayDatas = async (tokenAddress, chainId =
|
|
2972
|
-
const { GetTokenValueDayDatas } =
|
|
2664
|
+
import { getSdkByChainId as getSdkByChainId9 } from "@tokemak/graph-cli";
|
|
2665
|
+
var getTokenValueDayDatas = async (tokenAddress, chainId = mainnet6.id) => {
|
|
2666
|
+
const { GetTokenValueDayDatas } = getSdkByChainId9(chainId);
|
|
2973
2667
|
try {
|
|
2974
2668
|
const { tokenValueDayDatas } = await GetTokenValueDayDatas({
|
|
2975
2669
|
tokenAddress: tokenAddress.toLowerCase()
|
|
@@ -3277,212 +2971,13 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3277
2971
|
return result;
|
|
3278
2972
|
};
|
|
3279
2973
|
|
|
3280
|
-
// functions/getUserSushiLP.ts
|
|
3281
|
-
import { readContracts as readContracts5 } from "@wagmi/core";
|
|
3282
|
-
import { poolV1Abi, sushiPoolAbi as sushiPoolAbi2 } from "@tokemak/abis";
|
|
3283
|
-
import { getMainnetConfig as getMainnetConfig4 } from "@tokemak/config";
|
|
3284
|
-
var getUserSushiLP = async (wagmiConfig, {
|
|
3285
|
-
sushiLP,
|
|
3286
|
-
currentCycleIndex,
|
|
3287
|
-
address,
|
|
3288
|
-
cycleRolloverBlockNumber,
|
|
3289
|
-
chainId
|
|
3290
|
-
}) => {
|
|
3291
|
-
const { tSushiLP, sushiPool } = getMainnetConfig4();
|
|
3292
|
-
try {
|
|
3293
|
-
if (address && currentCycleIndex && sushiLP) {
|
|
3294
|
-
const [
|
|
3295
|
-
{ result: sushiLPBalance },
|
|
3296
|
-
{ result: tSushiLPBalance },
|
|
3297
|
-
{ result: tSushiLPRequested }
|
|
3298
|
-
] = await readContracts5(wagmiConfig, {
|
|
3299
|
-
contracts: [
|
|
3300
|
-
{
|
|
3301
|
-
address: sushiPool,
|
|
3302
|
-
abi: sushiPoolAbi2,
|
|
3303
|
-
functionName: "balanceOf",
|
|
3304
|
-
args: [address],
|
|
3305
|
-
chainId
|
|
3306
|
-
},
|
|
3307
|
-
{
|
|
3308
|
-
address: tSushiLP,
|
|
3309
|
-
abi: poolV1Abi,
|
|
3310
|
-
functionName: "balanceOf",
|
|
3311
|
-
args: [address],
|
|
3312
|
-
chainId
|
|
3313
|
-
},
|
|
3314
|
-
{
|
|
3315
|
-
address: tSushiLP,
|
|
3316
|
-
abi: poolV1Abi,
|
|
3317
|
-
functionName: "requestedWithdrawals",
|
|
3318
|
-
args: [address],
|
|
3319
|
-
chainId
|
|
3320
|
-
}
|
|
3321
|
-
]
|
|
3322
|
-
});
|
|
3323
|
-
const [
|
|
3324
|
-
{ result: startTSushiLPBalance },
|
|
3325
|
-
{ result: startTSushiLPRequested }
|
|
3326
|
-
] = await readContracts5(wagmiConfig, {
|
|
3327
|
-
contracts: [
|
|
3328
|
-
{
|
|
3329
|
-
address: tSushiLP,
|
|
3330
|
-
abi: poolV1Abi,
|
|
3331
|
-
functionName: "balanceOf",
|
|
3332
|
-
args: [address],
|
|
3333
|
-
chainId
|
|
3334
|
-
},
|
|
3335
|
-
{
|
|
3336
|
-
address: tSushiLP,
|
|
3337
|
-
abi: poolV1Abi,
|
|
3338
|
-
functionName: "requestedWithdrawals",
|
|
3339
|
-
args: [address],
|
|
3340
|
-
chainId
|
|
3341
|
-
}
|
|
3342
|
-
],
|
|
3343
|
-
blockNumber: cycleRolloverBlockNumber
|
|
3344
|
-
});
|
|
3345
|
-
const startTSushiWithdrawAmount = startTSushiLPRequested?.[1] || 0n;
|
|
3346
|
-
const yieldingBalance = (startTSushiLPBalance || 0n) - startTSushiWithdrawAmount;
|
|
3347
|
-
let balanceExcludingWithdrawal = tSushiLPBalance || 0n;
|
|
3348
|
-
const [withdrawalMinCycle, withdrawalAmount] = tSushiLPRequested || [
|
|
3349
|
-
0n,
|
|
3350
|
-
0n
|
|
3351
|
-
];
|
|
3352
|
-
if (withdrawalAmount > 0n && currentCycleIndex >= withdrawalMinCycle) {
|
|
3353
|
-
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
3354
|
-
}
|
|
3355
|
-
const shareOftSushiLP = Number(balanceExcludingWithdrawal) / Number(sushiLP.totalSupply);
|
|
3356
|
-
const tSushiLPUsd = sushiLP.tvl * shareOftSushiLP;
|
|
3357
|
-
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
3358
|
-
const hasUnlockableBalance = withdrawalMinCycle <= currentCycleIndex && withdrawalAmount > 0n;
|
|
3359
|
-
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
3360
|
-
return {
|
|
3361
|
-
sushiLPBalance,
|
|
3362
|
-
tSushiLPBalance,
|
|
3363
|
-
tSushiLPRequested,
|
|
3364
|
-
shareOftSushiLP,
|
|
3365
|
-
tSushiLPUsd,
|
|
3366
|
-
balanceExcludingWithdrawal,
|
|
3367
|
-
hasAddedTSushi: yieldingBalance < balanceExcludingWithdrawal,
|
|
3368
|
-
hasRequestedUnlock,
|
|
3369
|
-
hasUnlockableBalance,
|
|
3370
|
-
withdrawalAmount,
|
|
3371
|
-
hasBalanceExcludingWithdrawal
|
|
3372
|
-
};
|
|
3373
|
-
}
|
|
3374
|
-
} catch (e) {
|
|
3375
|
-
console.log(e);
|
|
3376
|
-
}
|
|
3377
|
-
};
|
|
3378
|
-
|
|
3379
|
-
// functions/getUserCurveLP.ts
|
|
3380
|
-
import { readContracts as readContracts6 } from "@wagmi/core";
|
|
3381
|
-
import { poolV1Abi as poolV1Abi2 } from "@tokemak/abis";
|
|
3382
|
-
import { getMainnetConfig as getMainnetConfig5 } from "@tokemak/config";
|
|
3383
|
-
var getUserCurveLP = async (wagmiConfig, {
|
|
3384
|
-
curveLP,
|
|
3385
|
-
address,
|
|
3386
|
-
chainId
|
|
3387
|
-
}) => {
|
|
3388
|
-
try {
|
|
3389
|
-
const { curvePool, convexRewarder } = getMainnetConfig5();
|
|
3390
|
-
if (address && curveLP && curvePool && convexRewarder) {
|
|
3391
|
-
const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await readContracts6(wagmiConfig, {
|
|
3392
|
-
contracts: [
|
|
3393
|
-
{
|
|
3394
|
-
address: curvePool,
|
|
3395
|
-
abi: poolV1Abi2,
|
|
3396
|
-
functionName: "balanceOf",
|
|
3397
|
-
args: [address],
|
|
3398
|
-
chainId
|
|
3399
|
-
},
|
|
3400
|
-
{
|
|
3401
|
-
address: convexRewarder,
|
|
3402
|
-
abi: poolV1Abi2,
|
|
3403
|
-
functionName: "balanceOf",
|
|
3404
|
-
args: [address],
|
|
3405
|
-
chainId
|
|
3406
|
-
}
|
|
3407
|
-
]
|
|
3408
|
-
});
|
|
3409
|
-
const shareOfCurve = Number(userCurveLPBalance || 0n) / Number(curveLP.totalSupply);
|
|
3410
|
-
const shareOfConvex = Number(userConvexLPBalance || 0n) / Number(curveLP.totalSupply);
|
|
3411
|
-
const curveLPUsd = shareOfCurve * curveLP.curveTvl;
|
|
3412
|
-
const convexLPUsd = shareOfConvex * curveLP.curveTvl;
|
|
3413
|
-
return {
|
|
3414
|
-
curveLPBalance: userCurveLPBalance,
|
|
3415
|
-
convexLPBalance: userConvexLPBalance,
|
|
3416
|
-
shareOfCurve,
|
|
3417
|
-
shareOfConvex,
|
|
3418
|
-
curveLPUsd,
|
|
3419
|
-
convexLPUsd
|
|
3420
|
-
};
|
|
3421
|
-
}
|
|
3422
|
-
} catch (e) {
|
|
3423
|
-
console.log(e);
|
|
3424
|
-
}
|
|
3425
|
-
};
|
|
3426
|
-
|
|
3427
|
-
// functions/getMultipleAutopoolRebalances.ts
|
|
3428
|
-
import { getSdkByChainId as getSdkByChainId11 } from "@tokemak/graph-cli";
|
|
3429
|
-
var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
3430
|
-
const { GetMutlipleAutopoolRebalances } = getSdkByChainId11(chainId);
|
|
3431
|
-
const { autopools } = await GetMutlipleAutopoolRebalances({
|
|
3432
|
-
addresses: ids
|
|
3433
|
-
});
|
|
3434
|
-
const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
|
|
3435
|
-
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
3436
|
-
};
|
|
3437
|
-
|
|
3438
|
-
// functions/getSystemConfig.ts
|
|
3439
|
-
import { readContracts as readContracts7 } from "@wagmi/core";
|
|
3440
|
-
import { systemRegistryAbi } from "@tokemak/abis";
|
|
3441
|
-
var systemRegistryFunctionNames = [
|
|
3442
|
-
"asyncSwapperRegistry",
|
|
3443
|
-
"autoPoolRouter",
|
|
3444
|
-
"autoPoolRegistry",
|
|
3445
|
-
"swapRouter",
|
|
3446
|
-
"weth"
|
|
3447
|
-
];
|
|
3448
|
-
var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
3449
|
-
const systemRegistryContract = {
|
|
3450
|
-
address: systemRegistry,
|
|
3451
|
-
abi: systemRegistryAbi
|
|
3452
|
-
};
|
|
3453
|
-
const systemRegistryCalls = systemRegistryFunctionNames.map(
|
|
3454
|
-
(functionName) => ({
|
|
3455
|
-
...systemRegistryContract,
|
|
3456
|
-
functionName
|
|
3457
|
-
})
|
|
3458
|
-
);
|
|
3459
|
-
try {
|
|
3460
|
-
const [
|
|
3461
|
-
{ result: asyncSwapperRegistry },
|
|
3462
|
-
{ result: autopoolRouter },
|
|
3463
|
-
{ result: autopoolRegistry },
|
|
3464
|
-
{ result: swapRouter }
|
|
3465
|
-
] = await readContracts7(wagmiConfig, {
|
|
3466
|
-
contracts: systemRegistryCalls
|
|
3467
|
-
});
|
|
3468
|
-
return {
|
|
3469
|
-
asyncSwapperRegistry,
|
|
3470
|
-
autopoolRouter,
|
|
3471
|
-
autopoolRegistry,
|
|
3472
|
-
swapRouter
|
|
3473
|
-
};
|
|
3474
|
-
} catch (e) {
|
|
3475
|
-
console.log(e);
|
|
3476
|
-
}
|
|
3477
|
-
};
|
|
3478
|
-
|
|
3479
2974
|
// functions/getChainUserAutopools.tsx
|
|
3480
|
-
import { getSdkByChainId as
|
|
2975
|
+
import { getSdkByChainId as getSdkByChainId10 } from "@tokemak/graph-cli";
|
|
3481
2976
|
var getChainUserAutopools = async ({
|
|
3482
2977
|
address,
|
|
3483
2978
|
chainId = 1
|
|
3484
2979
|
}) => {
|
|
3485
|
-
const { GetUserVaultInfo } =
|
|
2980
|
+
const { GetUserVaultInfo } = getSdkByChainId10(chainId);
|
|
3486
2981
|
try {
|
|
3487
2982
|
if (address) {
|
|
3488
2983
|
const { userInfo } = await GetUserVaultInfo({
|
|
@@ -3507,7 +3002,7 @@ import { ETH_TOKEN as ETH_TOKEN5, PRICED_TOKENS } from "@tokemak/tokenlist";
|
|
|
3507
3002
|
|
|
3508
3003
|
// functions/getUserAutopool.tsx
|
|
3509
3004
|
import { erc20Abi as erc20Abi4 } from "viem";
|
|
3510
|
-
import { readContract as
|
|
3005
|
+
import { readContract as readContract4, readContracts as readContracts4 } from "@wagmi/core";
|
|
3511
3006
|
import { formatEtherNum as formatEtherNum7 } from "@tokemak/utils";
|
|
3512
3007
|
import { autopoolEthAbi as autopoolEthAbi2 } from "@tokemak/abis";
|
|
3513
3008
|
var getUserAutopool = async (wagmiConfig, {
|
|
@@ -3525,7 +3020,7 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3525
3020
|
{ result: autopoolRewarderContract },
|
|
3526
3021
|
{ result: pastRewarders },
|
|
3527
3022
|
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
3528
|
-
] = await
|
|
3023
|
+
] = await readContracts4(wagmiConfig, {
|
|
3529
3024
|
contracts: [
|
|
3530
3025
|
{
|
|
3531
3026
|
...autopoolContract,
|
|
@@ -3550,7 +3045,7 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3550
3045
|
if (unstakedPoolSharesError) {
|
|
3551
3046
|
throw new Error("Error fetching unstaked pool shares");
|
|
3552
3047
|
}
|
|
3553
|
-
const stakedPoolShares = await
|
|
3048
|
+
const stakedPoolShares = await readContract4(wagmiConfig, {
|
|
3554
3049
|
address: autopoolRewarderContract,
|
|
3555
3050
|
abi: erc20Abi4,
|
|
3556
3051
|
functionName: "balanceOf",
|
|
@@ -3576,7 +3071,7 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3576
3071
|
args: [address],
|
|
3577
3072
|
chainId: autopool?.chain?.chainId
|
|
3578
3073
|
}));
|
|
3579
|
-
const pastRewards = await
|
|
3074
|
+
const pastRewards = await readContracts4(wagmiConfig, {
|
|
3580
3075
|
contracts: pastRewardBalances
|
|
3581
3076
|
});
|
|
3582
3077
|
pastRewarderBalances = pastRewards.map(({ result }, index) => {
|
|
@@ -4067,25 +3562,11 @@ var getUserTokenBalances = async ({
|
|
|
4067
3562
|
return tokenBalances;
|
|
4068
3563
|
};
|
|
4069
3564
|
|
|
4070
|
-
// functions/getTokenList.ts
|
|
4071
|
-
import { TOKEMAK_LISTS_URL } from "@tokemak/tokenlist";
|
|
4072
|
-
var getTokenList = async () => {
|
|
4073
|
-
try {
|
|
4074
|
-
let url = `${TOKEMAK_LISTS_URL}/swap_enabled.json`;
|
|
4075
|
-
const listResponse = await fetch(url);
|
|
4076
|
-
const { tokens: tokenList } = await listResponse.json();
|
|
4077
|
-
return tokenList;
|
|
4078
|
-
} catch (e) {
|
|
4079
|
-
console.log(e);
|
|
4080
|
-
return [];
|
|
4081
|
-
}
|
|
4082
|
-
};
|
|
4083
|
-
|
|
4084
3565
|
// functions/getTopAutopoolHolders.ts
|
|
4085
|
-
import { getSdkByChainId as
|
|
3566
|
+
import { getSdkByChainId as getSdkByChainId11 } from "@tokemak/graph-cli";
|
|
4086
3567
|
var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
4087
3568
|
try {
|
|
4088
|
-
const { GetTopAutopoolHolders } =
|
|
3569
|
+
const { GetTopAutopoolHolders } = getSdkByChainId11(chainId);
|
|
4089
3570
|
const { holders } = await GetTopAutopoolHolders({
|
|
4090
3571
|
address: autopoolAddress
|
|
4091
3572
|
});
|
|
@@ -4096,27 +3577,6 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
|
4096
3577
|
}
|
|
4097
3578
|
};
|
|
4098
3579
|
|
|
4099
|
-
// functions/getAllowance.ts
|
|
4100
|
-
import { readContract as readContract6 } from "@wagmi/core";
|
|
4101
|
-
import { erc20Abi as erc20Abi5 } from "viem";
|
|
4102
|
-
var getAllowance = async (wagmiConfig, {
|
|
4103
|
-
token,
|
|
4104
|
-
address,
|
|
4105
|
-
spender
|
|
4106
|
-
}) => {
|
|
4107
|
-
try {
|
|
4108
|
-
const allowance = await readContract6(wagmiConfig, {
|
|
4109
|
-
address: token,
|
|
4110
|
-
abi: erc20Abi5,
|
|
4111
|
-
functionName: "allowance",
|
|
4112
|
-
args: [address || "0x0", spender]
|
|
4113
|
-
});
|
|
4114
|
-
return allowance;
|
|
4115
|
-
} catch (e) {
|
|
4116
|
-
console.error(e);
|
|
4117
|
-
}
|
|
4118
|
-
};
|
|
4119
|
-
|
|
4120
3580
|
// functions/getUserActivity.ts
|
|
4121
3581
|
var getUserActivity = async ({
|
|
4122
3582
|
address,
|
|
@@ -4152,7 +3612,7 @@ import { getAddress as getAddress4 } from "viem";
|
|
|
4152
3612
|
|
|
4153
3613
|
// functions/getChainUserAutopoolsRewards.ts
|
|
4154
3614
|
import { getCoreConfig as getCoreConfig2 } from "@tokemak/config";
|
|
4155
|
-
import { readContract as
|
|
3615
|
+
import { readContract as readContract5 } from "@wagmi/core";
|
|
4156
3616
|
import { lensAbi as lensAbi2 } from "@tokemak/abis";
|
|
4157
3617
|
var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
4158
3618
|
chainId,
|
|
@@ -4160,7 +3620,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4160
3620
|
}) => {
|
|
4161
3621
|
try {
|
|
4162
3622
|
const coreConfig = getCoreConfig2(chainId);
|
|
4163
|
-
const userRewardsInfo = await
|
|
3623
|
+
const userRewardsInfo = await readContract5(wagmiConfig, {
|
|
4164
3624
|
address: coreConfig.lens,
|
|
4165
3625
|
abi: lensAbi2,
|
|
4166
3626
|
functionName: "getUserRewardInfo",
|
|
@@ -4350,17 +3810,17 @@ import {
|
|
|
4350
3810
|
import { TOKEMAK_SWAP_QUOTE_URL } from "@tokemak/constants";
|
|
4351
3811
|
|
|
4352
3812
|
// functions/getAddressFromSystemRegistry.ts
|
|
4353
|
-
import { readContract as
|
|
3813
|
+
import { readContract as readContract6 } from "@wagmi/core";
|
|
4354
3814
|
import { getCoreConfig as getCoreConfig3 } from "@tokemak/config";
|
|
4355
|
-
import { systemRegistryAbi
|
|
3815
|
+
import { systemRegistryAbi } from "@tokemak/abis";
|
|
4356
3816
|
var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
4357
3817
|
chainId,
|
|
4358
3818
|
functionName
|
|
4359
3819
|
}) => {
|
|
4360
3820
|
const { systemRegistry } = getCoreConfig3(chainId);
|
|
4361
|
-
return await
|
|
3821
|
+
return await readContract6(wagmiConfig, {
|
|
4362
3822
|
address: systemRegistry,
|
|
4363
|
-
abi:
|
|
3823
|
+
abi: systemRegistryAbi,
|
|
4364
3824
|
functionName,
|
|
4365
3825
|
chainId
|
|
4366
3826
|
});
|
|
@@ -4418,7 +3878,7 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4418
3878
|
};
|
|
4419
3879
|
|
|
4420
3880
|
// functions/getDynamicSwap.ts
|
|
4421
|
-
import { getPublicClient as getPublicClient2, readContract as
|
|
3881
|
+
import { getPublicClient as getPublicClient2, readContract as readContract7 } from "@wagmi/core";
|
|
4422
3882
|
import { autopilotRouterAbi, autopoolEthAbi as autopoolEthAbi3 } from "@tokemak/abis";
|
|
4423
3883
|
import { getCoreConfig as getCoreConfig5 } from "@tokemak/config";
|
|
4424
3884
|
import { getLiquidations } from "@tokemak/autopilot-swap-route-calc";
|
|
@@ -4514,7 +3974,7 @@ var getDynamicSwap = async ({
|
|
|
4514
3974
|
console.log(e);
|
|
4515
3975
|
}
|
|
4516
3976
|
}
|
|
4517
|
-
const previewRedeemOnChain = await
|
|
3977
|
+
const previewRedeemOnChain = await readContract7(config, {
|
|
4518
3978
|
address,
|
|
4519
3979
|
abi: autopoolEthAbi3,
|
|
4520
3980
|
functionName: "previewRedeem",
|
|
@@ -4536,7 +3996,7 @@ var getDynamicSwap = async ({
|
|
|
4536
3996
|
// functions/getAmountWithdrawn.ts
|
|
4537
3997
|
import { ETH_TOKEN as ETH_TOKEN7 } from "@tokemak/tokenlist";
|
|
4538
3998
|
import { getCoreConfig as getCoreConfig6 } from "@tokemak/config";
|
|
4539
|
-
import { readContract as
|
|
3999
|
+
import { readContract as readContract8 } from "@wagmi/core";
|
|
4540
4000
|
import { autopoolEthAbi as autopoolEthAbi4 } from "@tokemak/abis";
|
|
4541
4001
|
var getAmountWithdrawn = async ({
|
|
4542
4002
|
address,
|
|
@@ -4576,7 +4036,7 @@ var getAmountWithdrawn = async ({
|
|
|
4576
4036
|
const weth = getCoreConfig6(chainId).weth;
|
|
4577
4037
|
buyToken = weth;
|
|
4578
4038
|
}
|
|
4579
|
-
convertedAssets = await
|
|
4039
|
+
convertedAssets = await readContract8(config, {
|
|
4580
4040
|
address: autopool,
|
|
4581
4041
|
abi: autopoolEthAbi4,
|
|
4582
4042
|
functionName: "convertToAssets",
|
|
@@ -4616,7 +4076,7 @@ var getAmountWithdrawn = async ({
|
|
|
4616
4076
|
};
|
|
4617
4077
|
|
|
4618
4078
|
// functions/getAmountDeposited.ts
|
|
4619
|
-
import { readContract as
|
|
4079
|
+
import { readContract as readContract9 } from "@wagmi/core";
|
|
4620
4080
|
import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
|
|
4621
4081
|
import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as formatEtherNum9 } from "@tokemak/utils";
|
|
4622
4082
|
var getAmountDeposited = async ({
|
|
@@ -4631,7 +4091,7 @@ var getAmountDeposited = async ({
|
|
|
4631
4091
|
if (!address || !chainId || !amount || typeof slippage !== "number") {
|
|
4632
4092
|
throw new Error("Invalid parameters");
|
|
4633
4093
|
}
|
|
4634
|
-
const previewDeposit = await
|
|
4094
|
+
const previewDeposit = await readContract9(config, {
|
|
4635
4095
|
address,
|
|
4636
4096
|
abi: autopoolEthAbi5,
|
|
4637
4097
|
functionName: "previewDeposit",
|
|
@@ -4655,7 +4115,7 @@ var getAmountDeposited = async ({
|
|
|
4655
4115
|
};
|
|
4656
4116
|
|
|
4657
4117
|
// functions/getBridgeFee.ts
|
|
4658
|
-
import { readContract as
|
|
4118
|
+
import { readContract as readContract10 } from "@wagmi/core";
|
|
4659
4119
|
import { layerZeroEndpointAbi, oftAdapterAbi } from "@tokemak/abis";
|
|
4660
4120
|
import { toHex } from "viem";
|
|
4661
4121
|
import { addressToBytes32 } from "@layerzerolabs/lz-v2-utilities";
|
|
@@ -4668,13 +4128,13 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4668
4128
|
from
|
|
4669
4129
|
}) => {
|
|
4670
4130
|
try {
|
|
4671
|
-
const endpoint = await
|
|
4131
|
+
const endpoint = await readContract10(wagmiConfig, {
|
|
4672
4132
|
address: destAddress,
|
|
4673
4133
|
abi: oftAdapterAbi,
|
|
4674
4134
|
functionName: "endpoint",
|
|
4675
4135
|
chainId: destChainId
|
|
4676
4136
|
});
|
|
4677
|
-
const eid = await
|
|
4137
|
+
const eid = await readContract10(wagmiConfig, {
|
|
4678
4138
|
address: endpoint,
|
|
4679
4139
|
abi: layerZeroEndpointAbi,
|
|
4680
4140
|
functionName: "eid",
|
|
@@ -4692,7 +4152,7 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4692
4152
|
composeMsg: "0x",
|
|
4693
4153
|
oftCmd: "0x"
|
|
4694
4154
|
};
|
|
4695
|
-
const feeQuote = await
|
|
4155
|
+
const feeQuote = await readContract10(wagmiConfig, {
|
|
4696
4156
|
address: sourceAddress,
|
|
4697
4157
|
abi: oftAdapterAbi,
|
|
4698
4158
|
functionName: "quoteSend",
|
|
@@ -4705,82 +4165,14 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4705
4165
|
}
|
|
4706
4166
|
};
|
|
4707
4167
|
|
|
4708
|
-
// functions/getLayerzeroStatus.ts
|
|
4709
|
-
var MessageStatus = /* @__PURE__ */ ((MessageStatus2) => {
|
|
4710
|
-
MessageStatus2["INFLIGHT"] = "INFLIGHT";
|
|
4711
|
-
MessageStatus2["DELIVERED"] = "DELIVERED";
|
|
4712
|
-
MessageStatus2["FAILED"] = "FAILED";
|
|
4713
|
-
MessageStatus2["PAYLOAD_STORED"] = "PAYLOAD_STORED";
|
|
4714
|
-
MessageStatus2["BLOCKED"] = "BLOCKED";
|
|
4715
|
-
MessageStatus2["CONFIRMING"] = "CONFIRMING";
|
|
4716
|
-
return MessageStatus2;
|
|
4717
|
-
})(MessageStatus || {});
|
|
4718
|
-
var LAYERZERO_STATUS_URL = "https://scan.layerzero-api.com/v1/messages/tx/";
|
|
4719
|
-
var getLayerzeroStatus = async ({
|
|
4720
|
-
txHash
|
|
4721
|
-
}) => {
|
|
4722
|
-
try {
|
|
4723
|
-
const response = await fetch(`${LAYERZERO_STATUS_URL}${txHash}`);
|
|
4724
|
-
if (!response.ok) {
|
|
4725
|
-
throw new Error("Network response was not ok");
|
|
4726
|
-
}
|
|
4727
|
-
const statusData = await response.json();
|
|
4728
|
-
return statusData || void 0;
|
|
4729
|
-
} catch (e) {
|
|
4730
|
-
return {
|
|
4731
|
-
status: {
|
|
4732
|
-
name: "FAILED" /* FAILED */,
|
|
4733
|
-
message: e || "Failed to fetch layerzero status"
|
|
4734
|
-
}
|
|
4735
|
-
};
|
|
4736
|
-
}
|
|
4737
|
-
};
|
|
4738
|
-
var waitForMessageReceived = async ({
|
|
4739
|
-
txHash,
|
|
4740
|
-
interval = 3e3,
|
|
4741
|
-
timeout = 20 * 60 * 1e3
|
|
4742
|
-
}) => {
|
|
4743
|
-
const startTime = Date.now();
|
|
4744
|
-
while (Date.now() - startTime < timeout) {
|
|
4745
|
-
const status = await getLayerzeroStatus({ txHash });
|
|
4746
|
-
if (!status) {
|
|
4747
|
-
console.warn(`No status returned for txHash: ${txHash}`);
|
|
4748
|
-
} else {
|
|
4749
|
-
console.log(`Current status: ${status.status.name}`);
|
|
4750
|
-
if (status.status.name === "DELIVERED" /* DELIVERED */) {
|
|
4751
|
-
return status;
|
|
4752
|
-
} else if (["FAILED" /* FAILED */, "BLOCKED" /* BLOCKED */].includes(
|
|
4753
|
-
status.status.name
|
|
4754
|
-
)) {
|
|
4755
|
-
throw new Error(`Message failed with status: ${status.status.name}`);
|
|
4756
|
-
}
|
|
4757
|
-
}
|
|
4758
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
4759
|
-
}
|
|
4760
|
-
throw new Error(`Timeout reached after 20 minutes for message: ${txHash}`);
|
|
4761
|
-
};
|
|
4762
|
-
|
|
4763
|
-
// functions/getChainUserSToke.ts
|
|
4764
|
-
import { accTokeV1Abi as accTokeV1Abi2 } from "@tokemak/abis";
|
|
4765
|
-
import { getCoreConfig as getCoreConfig7 } from "@tokemak/config";
|
|
4766
|
-
import {
|
|
4767
|
-
convertChainCycleToUnix as convertChainCycleToUnix2,
|
|
4768
|
-
convertSecondsToRemainingTime,
|
|
4769
|
-
formatCurrency as formatCurrency2,
|
|
4770
|
-
formatEtherNum as formatEtherNum10
|
|
4771
|
-
} from "@tokemak/utils";
|
|
4772
|
-
import { readContracts as readContracts9 } from "@wagmi/core";
|
|
4773
|
-
import { formatEther as formatEther2 } from "viem";
|
|
4774
|
-
import { sepolia as sepolia2 } from "viem/chains";
|
|
4775
|
-
|
|
4776
4168
|
// functions/getCurrentCycleId.ts
|
|
4777
4169
|
import { accTokeV1Abi } from "@tokemak/abis";
|
|
4778
|
-
import { readContract as
|
|
4170
|
+
import { readContract as readContract11 } from "@wagmi/core";
|
|
4779
4171
|
var getCurrentCycleId = async (wagmiConfig, {
|
|
4780
4172
|
stoke,
|
|
4781
4173
|
chainId
|
|
4782
4174
|
}) => {
|
|
4783
|
-
return
|
|
4175
|
+
return readContract11(wagmiConfig, {
|
|
4784
4176
|
address: stoke,
|
|
4785
4177
|
abi: accTokeV1Abi,
|
|
4786
4178
|
chainId,
|
|
@@ -4788,539 +4180,30 @@ var getCurrentCycleId = async (wagmiConfig, {
|
|
|
4788
4180
|
});
|
|
4789
4181
|
};
|
|
4790
4182
|
|
|
4791
|
-
// functions/
|
|
4792
|
-
import {
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
tokePrice,
|
|
4796
|
-
chainId
|
|
4797
|
-
}) => {
|
|
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 () => {
|
|
4798
4187
|
try {
|
|
4799
|
-
const
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
contracts: [
|
|
4819
|
-
{
|
|
4820
|
-
...stokeContract,
|
|
4821
|
-
functionName: "balanceOf",
|
|
4822
|
-
args: [address],
|
|
4823
|
-
chainId
|
|
4824
|
-
},
|
|
4825
|
-
{
|
|
4826
|
-
...stokeContract,
|
|
4827
|
-
functionName: "getDepositInfo",
|
|
4828
|
-
args: [address],
|
|
4829
|
-
chainId
|
|
4830
|
-
},
|
|
4831
|
-
{
|
|
4832
|
-
...stokeContract,
|
|
4833
|
-
functionName: "getWithdrawalInfo",
|
|
4834
|
-
args: [address],
|
|
4835
|
-
chainId
|
|
4836
|
-
}
|
|
4837
|
-
]
|
|
4838
|
-
});
|
|
4839
|
-
if (withdrawalInfoResult && depositInfoResult && balance && cycleStartBalance) {
|
|
4840
|
-
const [depositLockCycle, depositLockDuration, depositAmount] = depositInfoResult;
|
|
4841
|
-
const [withdrawalMinCycle, withdrawalAmount] = withdrawalInfoResult;
|
|
4842
|
-
const rolloverDepositAmount = !!cycleStartBalance?.cycleStartBalance && cycleStartBalance?.cycleStartBalance > 0 ? BigInt(cycleStartBalance.cycleStartBalance) : 0n;
|
|
4843
|
-
let balanceExcludingWithdrawal = balance;
|
|
4844
|
-
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
4845
|
-
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
4846
|
-
}
|
|
4847
|
-
const withdrawalAmountUsd = formatCurrency2(
|
|
4848
|
-
formatEtherNum10(withdrawalAmount) * tokePrice
|
|
4849
|
-
);
|
|
4850
|
-
const lockDuration = Number(depositLockDuration);
|
|
4851
|
-
const lockCycle = Number(depositLockCycle);
|
|
4852
|
-
const lockStart = lockCycle + 1;
|
|
4853
|
-
const firstLockEnd = lockDuration + 1 + lockCycle;
|
|
4854
|
-
const currentCycle = Number(cycleIndex);
|
|
4855
|
-
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
4856
|
-
const lockRenew = (
|
|
4857
|
-
// if has done a renewal since start
|
|
4858
|
-
currentCycle - lockStart > lockDuration ? (
|
|
4859
|
-
// if during the lockRenew cycle add lock duration to show the right timeline
|
|
4860
|
-
currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement
|
|
4861
|
-
) : (
|
|
4862
|
-
// if during the lockRenew cycle add lock duration to show the right timeline
|
|
4863
|
-
currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd
|
|
4864
|
-
)
|
|
4865
|
-
);
|
|
4866
|
-
const withdrawAvailable = lockRenew - 1;
|
|
4867
|
-
const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
|
|
4868
|
-
const addedLockedToke = depositAmount - rolloverDepositAmount;
|
|
4869
|
-
const balanceUSD = formatCurrency2(
|
|
4870
|
-
Number(formatEther2(balanceExcludingWithdrawal)) * tokePrice
|
|
4871
|
-
);
|
|
4872
|
-
const balanceExcludingWithdrawalUsd = formatCurrency2(
|
|
4873
|
-
formatEtherNum10(balanceExcludingWithdrawal) * tokePrice
|
|
4874
|
-
);
|
|
4875
|
-
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
4876
|
-
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
4877
|
-
const unlockRequestPeriodStartUnix = convertChainCycleToUnix2(withdrawAvailable, chainId) - Date.now() / 1e3;
|
|
4878
|
-
const unlockRequestPeriodEndUnix = convertChainCycleToUnix2(lockRenew, chainId) - Date.now() / 1e3;
|
|
4879
|
-
const hasBalance = balance > 0n;
|
|
4880
|
-
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
4881
|
-
const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
|
|
4882
|
-
let cyclesInAMonth = 4;
|
|
4883
|
-
let lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
4884
|
-
if (chainId === sepolia2.id) {
|
|
4885
|
-
lockDurationInMonths = lockDuration - 1;
|
|
4886
|
-
}
|
|
4887
|
-
const unlockPeriodDateRangeArray = [
|
|
4888
|
-
new Date(convertChainCycleToUnix2(withdrawAvailable, chainId) * 1e3),
|
|
4889
|
-
new Date(convertChainCycleToUnix2(lockRenew, chainId) * 1e3)
|
|
4890
|
-
];
|
|
4891
|
-
const {
|
|
4892
|
-
unlockPeriodDateRange,
|
|
4893
|
-
unlockPeriodStartFullDate,
|
|
4894
|
-
unlockRenewalFullDate,
|
|
4895
|
-
unlockPeriodStartDate,
|
|
4896
|
-
unlockRenewalDate
|
|
4897
|
-
} = formatDateRange(
|
|
4898
|
-
unlockPeriodDateRangeArray,
|
|
4899
|
-
chainId === sepolia2.id ? "time" : "date"
|
|
4900
|
-
);
|
|
4901
|
-
const totalActiveUserCredits = formatEtherNum10(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
4902
|
-
const totalUserCredits = formatEtherNum10(balance) * lockDurationInMonths;
|
|
4903
|
-
return {
|
|
4904
|
-
balance,
|
|
4905
|
-
balanceUSD,
|
|
4906
|
-
balanceExcludingWithdrawal: hasBalance ? formatEther2(balanceExcludingWithdrawal) : "0.00",
|
|
4907
|
-
balanceExcludingWithdrawalUsd,
|
|
4908
|
-
hasBalanceExcludingWithdrawal,
|
|
4909
|
-
timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime(
|
|
4910
|
-
unlockRequestPeriodStartUnix
|
|
4911
|
-
),
|
|
4912
|
-
timeLeftBeforeUnlockRequestUnavailable: convertSecondsToRemainingTime(
|
|
4913
|
-
unlockRequestPeriodEndUnix
|
|
4914
|
-
),
|
|
4915
|
-
withdrawalAmount,
|
|
4916
|
-
withdrawalAmountUsd,
|
|
4917
|
-
hasUnlockableBalance,
|
|
4918
|
-
isUnlockRequestAvailable,
|
|
4919
|
-
hasRequestedUnlock,
|
|
4920
|
-
hasAddedLockedToke,
|
|
4921
|
-
addedLockedToke,
|
|
4922
|
-
unlockPeriodDateRange,
|
|
4923
|
-
unlockPeriodStartFullDate,
|
|
4924
|
-
unlockRenewalFullDate,
|
|
4925
|
-
unlockPeriodStartDate,
|
|
4926
|
-
unlockRenewalDate,
|
|
4927
|
-
lockDurationInMonths,
|
|
4928
|
-
boost: lockDuration,
|
|
4929
|
-
points: formatEtherNum10(balanceExcludingWithdrawal) * lockDuration,
|
|
4930
|
-
totalActiveCredits: totalActiveUserCredits,
|
|
4931
|
-
totalCredits: totalUserCredits
|
|
4932
|
-
};
|
|
4933
|
-
}
|
|
4934
|
-
}
|
|
4935
|
-
} catch (error) {
|
|
4936
|
-
console.error(error);
|
|
4937
|
-
}
|
|
4938
|
-
};
|
|
4939
|
-
|
|
4940
|
-
// functions/getUserSToke.ts
|
|
4941
|
-
import { formatCurrency as formatCurrency3, formatEtherNum as formatEtherNum11 } from "@tokemak/utils";
|
|
4942
|
-
var getUserSToke = async (wagmiConfig, {
|
|
4943
|
-
address,
|
|
4944
|
-
tokePrice,
|
|
4945
|
-
includeTestnet = false
|
|
4946
|
-
}) => {
|
|
4947
|
-
try {
|
|
4948
|
-
if (!address) {
|
|
4949
|
-
throw new Error("Address not found");
|
|
4950
|
-
}
|
|
4951
|
-
if (!tokePrice) {
|
|
4952
|
-
throw new Error("Toke price not found");
|
|
4953
|
-
}
|
|
4954
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
4955
|
-
const userSToke = await fetchChainDataMap(chains, async (chain) => {
|
|
4956
|
-
return getChainUserSToke(wagmiConfig, {
|
|
4957
|
-
address,
|
|
4958
|
-
tokePrice,
|
|
4959
|
-
chainId: chain.chainId
|
|
4960
|
-
});
|
|
4961
|
-
});
|
|
4962
|
-
const totalBalanceRaw = Object.values(userSToke).reduce((acc, item) => {
|
|
4963
|
-
if (item && item.balance) {
|
|
4964
|
-
return acc + item.balance;
|
|
4965
|
-
}
|
|
4966
|
-
return acc;
|
|
4967
|
-
}, 0n);
|
|
4968
|
-
const totalBalance = formatEtherNum11(totalBalanceRaw || 0n);
|
|
4969
|
-
const totalBalanceUsd = formatCurrency3(totalBalance * tokePrice);
|
|
4970
|
-
const hasBalance = totalBalance > 0;
|
|
4971
|
-
return {
|
|
4972
|
-
chains: { ...userSToke },
|
|
4973
|
-
totalBalance,
|
|
4974
|
-
totalBalanceUsd,
|
|
4975
|
-
hasBalance
|
|
4976
|
-
};
|
|
4977
|
-
} catch (e) {
|
|
4978
|
-
console.error(e);
|
|
4979
|
-
}
|
|
4980
|
-
};
|
|
4981
|
-
|
|
4982
|
-
// functions/getChainSToke.ts
|
|
4983
|
-
import { formatEther as formatEther3 } from "viem";
|
|
4984
|
-
import { readContracts as readContracts10 } from "@wagmi/core";
|
|
4985
|
-
import { accTokeV1Abi as accTokeV1Abi3 } from "@tokemak/abis";
|
|
4986
|
-
import {
|
|
4987
|
-
convertChainCycleToUnix as convertChainCycleToUnix3,
|
|
4988
|
-
convertSecondsToRemainingTime as convertSecondsToRemainingTime2,
|
|
4989
|
-
formatLargeNumber,
|
|
4990
|
-
formatTVL
|
|
4991
|
-
} from "@tokemak/utils";
|
|
4992
|
-
import { getCoreConfig as getCoreConfig8 } from "@tokemak/config";
|
|
4993
|
-
import { getNetwork as getNetwork2 } from "@tokemak/utils";
|
|
4994
|
-
var getChainSToke = async (wagmiConfig, {
|
|
4995
|
-
tokePrice,
|
|
4996
|
-
chainId
|
|
4997
|
-
}) => {
|
|
4998
|
-
try {
|
|
4999
|
-
const { stoke } = getCoreConfig8(chainId);
|
|
5000
|
-
const baseConfig = {
|
|
5001
|
-
address: stoke,
|
|
5002
|
-
abi: accTokeV1Abi3,
|
|
5003
|
-
chainId
|
|
5004
|
-
};
|
|
5005
|
-
if (stoke && tokePrice) {
|
|
5006
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await readContracts10(wagmiConfig, {
|
|
5007
|
-
contracts: [
|
|
5008
|
-
{
|
|
5009
|
-
...baseConfig,
|
|
5010
|
-
functionName: "totalSupply"
|
|
5011
|
-
},
|
|
5012
|
-
{
|
|
5013
|
-
...baseConfig,
|
|
5014
|
-
functionName: "getCurrentCycleID"
|
|
5015
|
-
}
|
|
5016
|
-
]
|
|
5017
|
-
});
|
|
5018
|
-
const tvl = Number(formatEther3(totalSupply || 0n)) * tokePrice;
|
|
5019
|
-
const secondsLeftBeforeNextCycle = convertChainCycleToUnix3(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
|
|
5020
|
-
return {
|
|
5021
|
-
rawTotalSupply: totalSupply,
|
|
5022
|
-
totalSupply: formatLargeNumber(formatEther3(totalSupply || 0n)),
|
|
5023
|
-
tvl: formatTVL(tvl),
|
|
5024
|
-
rawTVL: tvl,
|
|
5025
|
-
currentCycle,
|
|
5026
|
-
chain: getNetwork2(chainId),
|
|
5027
|
-
timeBeforeNextCycle: convertSecondsToRemainingTime2(
|
|
5028
|
-
secondsLeftBeforeNextCycle
|
|
5029
|
-
)
|
|
5030
|
-
};
|
|
5031
|
-
}
|
|
5032
|
-
} catch (error) {
|
|
5033
|
-
console.error(error);
|
|
5034
|
-
}
|
|
5035
|
-
};
|
|
5036
|
-
|
|
5037
|
-
// functions/getSToke.ts
|
|
5038
|
-
import { formatLargeNumber as formatLargeNumber2, formatTVL as formatTVL2 } from "@tokemak/utils";
|
|
5039
|
-
import { formatEther as formatEther4 } from "viem";
|
|
5040
|
-
var getSToke = async (wagmiConfig, {
|
|
5041
|
-
tokePrice,
|
|
5042
|
-
includeTestnet = false
|
|
5043
|
-
}) => {
|
|
5044
|
-
try {
|
|
5045
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5046
|
-
const sToke = await fetchChainDataMap(chains, async (chain) => {
|
|
5047
|
-
return getChainSToke(wagmiConfig, {
|
|
5048
|
-
tokePrice,
|
|
5049
|
-
chainId: chain.chainId
|
|
5050
|
-
});
|
|
5051
|
-
});
|
|
5052
|
-
const totalSupplyBigInt = Object.values(sToke).reduce((acc, item) => {
|
|
5053
|
-
if (item && item.rawTotalSupply) {
|
|
5054
|
-
return acc + item.rawTotalSupply;
|
|
5055
|
-
}
|
|
5056
|
-
return acc;
|
|
5057
|
-
}, 0n);
|
|
5058
|
-
const totalSupply = formatLargeNumber2(formatEther4(totalSupplyBigInt || 0n));
|
|
5059
|
-
let tvlNum = Object.values(sToke).reduce((acc, item) => {
|
|
5060
|
-
if (item && item.rawTVL) {
|
|
5061
|
-
return acc + item.rawTVL;
|
|
5062
|
-
}
|
|
5063
|
-
return acc;
|
|
5064
|
-
}, 0);
|
|
5065
|
-
const tvl = formatTVL2(tvlNum);
|
|
5066
|
-
return { totalSupply, rawTotalSupply: totalSupplyBigInt, tvl, rawTVL: tvlNum, chains: { ...sToke } };
|
|
5067
|
-
} catch (e) {
|
|
5068
|
-
console.error(e);
|
|
5069
|
-
throw e;
|
|
5070
|
-
}
|
|
5071
|
-
};
|
|
5072
|
-
|
|
5073
|
-
// functions/getChainCycleRolloverBlockNumber.ts
|
|
5074
|
-
import { accTokeV1Abi as accTokeV1Abi4, managerV1Abi } from "@tokemak/abis";
|
|
5075
|
-
import {
|
|
5076
|
-
getBlockNumber,
|
|
5077
|
-
getPublicClient as getPublicClient3,
|
|
5078
|
-
readContract as readContract14
|
|
5079
|
-
} from "@wagmi/core";
|
|
5080
|
-
var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
5081
|
-
stoke,
|
|
5082
|
-
chainId
|
|
5083
|
-
}) => {
|
|
5084
|
-
const scanPeriodInDays = 8;
|
|
5085
|
-
const blockTime = 12;
|
|
5086
|
-
try {
|
|
5087
|
-
const client = getPublicClient3(wagmiConfig, { chainId });
|
|
5088
|
-
if (!!client) {
|
|
5089
|
-
const blockNumber = await getBlockNumber(wagmiConfig, {
|
|
5090
|
-
chainId
|
|
5091
|
-
});
|
|
5092
|
-
const manager = await readContract14(wagmiConfig, {
|
|
5093
|
-
functionName: "manager",
|
|
5094
|
-
address: stoke,
|
|
5095
|
-
abi: accTokeV1Abi4,
|
|
5096
|
-
chainId
|
|
5097
|
-
});
|
|
5098
|
-
if (!manager) {
|
|
5099
|
-
throw new Error("Manager contract not found");
|
|
5100
|
-
}
|
|
5101
|
-
const filter = await client.createContractEventFilter({
|
|
5102
|
-
address: manager,
|
|
5103
|
-
fromBlock: BigInt(
|
|
5104
|
-
Math.floor(
|
|
5105
|
-
Number(blockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
5106
|
-
)
|
|
5107
|
-
),
|
|
5108
|
-
abi: managerV1Abi,
|
|
5109
|
-
eventName: "CycleRolloverComplete"
|
|
5110
|
-
});
|
|
5111
|
-
const rolloverEvents = await client.getFilterLogs({ filter });
|
|
5112
|
-
const cycleRolloverBlockNumber = client.chain.id === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || blockNumber;
|
|
5113
|
-
return cycleRolloverBlockNumber;
|
|
5114
|
-
}
|
|
5115
|
-
} catch (error) {
|
|
5116
|
-
console.error(error);
|
|
5117
|
-
}
|
|
5118
|
-
};
|
|
5119
|
-
|
|
5120
|
-
// functions/getChainSTokeRewards.ts
|
|
5121
|
-
import { AUTOPOOLS_WHITELIST_PROD as AUTOPOOLS_WHITELIST_PROD2 } from "@tokemak/config";
|
|
5122
|
-
import { formatUnits as formatUnits8 } from "viem";
|
|
5123
|
-
import { formatEtherNum as formatEtherNum12 } from "@tokemak/utils";
|
|
5124
|
-
import { getSdkByChainId as getSdkByChainId15 } from "@tokemak/graph-cli";
|
|
5125
|
-
var getChainSTokeRewards = async ({
|
|
5126
|
-
chainId
|
|
5127
|
-
}) => {
|
|
5128
|
-
try {
|
|
5129
|
-
const { GetSTokeRewards } = getSdkByChainId15(chainId);
|
|
5130
|
-
const { poolRewardsBalances } = await GetSTokeRewards();
|
|
5131
|
-
const allPoolRewardsBalanceDayDatas = await paginateQuery(
|
|
5132
|
-
GetSTokeRewards,
|
|
5133
|
-
"poolRewardsBalanceDayDatas"
|
|
5134
|
-
);
|
|
5135
|
-
const autopools = {};
|
|
5136
|
-
let totalEarnings = 0;
|
|
5137
|
-
let totalEarningsUsd = 0;
|
|
5138
|
-
let minApr = null;
|
|
5139
|
-
let maxApr = null;
|
|
5140
|
-
for (const pool of poolRewardsBalances) {
|
|
5141
|
-
const whitelistedPools = AUTOPOOLS_WHITELIST_PROD2.map(
|
|
5142
|
-
(address) => address.toLowerCase()
|
|
5143
|
-
);
|
|
5144
|
-
if (!whitelistedPools.includes(pool.id.toLowerCase())) {
|
|
5145
|
-
continue;
|
|
5146
|
-
}
|
|
5147
|
-
const convertedBalance = formatEtherNum12(pool.balance);
|
|
5148
|
-
const convertedBalanceUSD = Number(formatUnits8(pool.balanceUSD, 8));
|
|
5149
|
-
const convertedApr = formatEtherNum12(pool.currentAprPerCredit);
|
|
5150
|
-
if (minApr === null || convertedApr < minApr) {
|
|
5151
|
-
minApr = convertedApr;
|
|
5152
|
-
}
|
|
5153
|
-
if (maxApr === null || convertedApr > maxApr) {
|
|
5154
|
-
maxApr = convertedApr;
|
|
5155
|
-
}
|
|
5156
|
-
autopools[pool.id] = {
|
|
5157
|
-
balance: convertedBalance,
|
|
5158
|
-
balanceUSD: convertedBalanceUSD,
|
|
5159
|
-
currentAprPerCredit: convertedApr
|
|
5160
|
-
};
|
|
5161
|
-
totalEarnings += convertedBalance;
|
|
5162
|
-
totalEarningsUsd += convertedBalanceUSD;
|
|
5163
|
-
}
|
|
5164
|
-
const activeDayDatas = allPoolRewardsBalanceDayDatas.filter(
|
|
5165
|
-
(item) => item.balance !== "0"
|
|
5166
|
-
);
|
|
5167
|
-
const historicalRewards = aggregateSTokeRewardsDayData(activeDayDatas);
|
|
5168
|
-
const aprRange = [(minApr ?? 0) * 4, (maxApr ?? 0) * 16];
|
|
5169
|
-
return {
|
|
5170
|
-
autopools,
|
|
5171
|
-
totalEarnings,
|
|
5172
|
-
totalEarningsUsd,
|
|
5173
|
-
historicalRewards,
|
|
5174
|
-
aprRange
|
|
5175
|
-
};
|
|
5176
|
-
} catch (e) {
|
|
5177
|
-
console.log("Error fetching rewards payload:", e);
|
|
5178
|
-
return null;
|
|
5179
|
-
}
|
|
5180
|
-
};
|
|
5181
|
-
|
|
5182
|
-
// functions/getSTokeRewards.ts
|
|
5183
|
-
var getSTokeRewards = async ({
|
|
5184
|
-
includeTestnet = false
|
|
5185
|
-
}) => {
|
|
5186
|
-
try {
|
|
5187
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5188
|
-
const sTokeRewards = await fetchChainDataMap(chains, async (chain) => {
|
|
5189
|
-
return getChainSTokeRewards({
|
|
5190
|
-
chainId: chain.chainId
|
|
5191
|
-
});
|
|
5192
|
-
});
|
|
5193
|
-
const totalEarnings = Object.values(sTokeRewards).reduce((acc, item) => {
|
|
5194
|
-
if (item && item.totalEarnings) {
|
|
5195
|
-
return acc + item.totalEarnings;
|
|
5196
|
-
}
|
|
5197
|
-
return acc;
|
|
5198
|
-
}, 0);
|
|
5199
|
-
const totalEarningsUsd = Object.values(sTokeRewards).reduce((acc, item) => {
|
|
5200
|
-
if (item && item.totalEarnings) {
|
|
5201
|
-
return acc + item.totalEarningsUsd;
|
|
5202
|
-
}
|
|
5203
|
-
return acc;
|
|
5204
|
-
}, 0);
|
|
5205
|
-
const allChainsDailyData = Object.values(sTokeRewards).flatMap(
|
|
5206
|
-
(chainResult) => chainResult?.historicalRewards || []
|
|
5207
|
-
);
|
|
5208
|
-
const historicalRewardsAllChains = aggregateSTokeRewardsDayData(allChainsDailyData);
|
|
5209
|
-
return {
|
|
5210
|
-
chains: { ...sTokeRewards },
|
|
5211
|
-
totalEarnings,
|
|
5212
|
-
totalEarningsUsd,
|
|
5213
|
-
historicalRewards: historicalRewardsAllChains
|
|
5214
|
-
};
|
|
5215
|
-
} catch (e) {
|
|
5216
|
-
console.error(e);
|
|
5217
|
-
throw e;
|
|
5218
|
-
}
|
|
5219
|
-
};
|
|
5220
|
-
|
|
5221
|
-
// functions/getChainUserSTokeRewards.ts
|
|
5222
|
-
import {
|
|
5223
|
-
getCoreConfig as getCoreConfig9,
|
|
5224
|
-
getMainnetConfig as getMainnetConfig6
|
|
5225
|
-
} from "@tokemak/config";
|
|
5226
|
-
import { formatEtherNum as formatEtherNum13 } from "@tokemak/utils";
|
|
5227
|
-
var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
5228
|
-
address,
|
|
5229
|
-
chainId,
|
|
5230
|
-
tokePrice
|
|
5231
|
-
}) => {
|
|
5232
|
-
const { rewardsV1Url, stokeRewardsHash, stokeRewards } = getMainnetConfig6(1);
|
|
5233
|
-
const { stoke } = getCoreConfig9(chainId);
|
|
5234
|
-
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
5235
|
-
stoke,
|
|
5236
|
-
chainId
|
|
5237
|
-
});
|
|
5238
|
-
let tokeRewards;
|
|
5239
|
-
try {
|
|
5240
|
-
tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
5241
|
-
address,
|
|
5242
|
-
rewardsCycleIndex: currentCycle,
|
|
5243
|
-
rewardsV1: stokeRewards,
|
|
5244
|
-
rewardsV1Url,
|
|
5245
|
-
rewardsV1Hash: stokeRewardsHash,
|
|
5246
|
-
chainId
|
|
5247
|
-
});
|
|
5248
|
-
if (!tokeRewards?.rewardsPayload) {
|
|
5249
|
-
throw new Error("No rewards payload found");
|
|
5250
|
-
}
|
|
5251
|
-
} catch (error) {
|
|
5252
|
-
console.error(
|
|
5253
|
-
`Error calling getUserRewardsV1 with cycle ${currentCycle}:`,
|
|
5254
|
-
error
|
|
5255
|
-
);
|
|
5256
|
-
try {
|
|
5257
|
-
console.log("Falling back to previous cycle index...");
|
|
5258
|
-
tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
5259
|
-
address,
|
|
5260
|
-
rewardsCycleIndex: currentCycle - 1n,
|
|
5261
|
-
rewardsV1: stokeRewards,
|
|
5262
|
-
rewardsV1Url,
|
|
5263
|
-
rewardsV1Hash: stokeRewardsHash,
|
|
5264
|
-
chainId
|
|
5265
|
-
});
|
|
5266
|
-
if (!tokeRewards?.rewardsPayload) {
|
|
5267
|
-
throw new Error("No rewards payload found (fallback cycle).");
|
|
5268
|
-
}
|
|
5269
|
-
} catch (fallbackError) {
|
|
5270
|
-
console.error(
|
|
5271
|
-
`Error calling getUserRewardsV1 with cycle ${currentCycle - 1n}:`,
|
|
5272
|
-
fallbackError
|
|
5273
|
-
);
|
|
5274
|
-
throw fallbackError;
|
|
5275
|
-
}
|
|
5276
|
-
}
|
|
5277
|
-
const claimableNum = formatEtherNum13(tokeRewards?.claimable || 0n);
|
|
5278
|
-
const claimableUsd = tokePrice * claimableNum;
|
|
5279
|
-
const hasClaimable = claimableNum > 0n;
|
|
5280
|
-
const pendingRewards = formatEtherNum13(
|
|
5281
|
-
tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5282
|
-
);
|
|
5283
|
-
const pendingRewardsUsd = tokePrice * pendingRewards;
|
|
5284
|
-
const totalRewardsReceived = formatEtherNum13(
|
|
5285
|
-
tokeRewards.rewardsPayload.payload.amount || 0n
|
|
5286
|
-
);
|
|
5287
|
-
const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
|
|
5288
|
-
return {
|
|
5289
|
-
claimableUsd,
|
|
5290
|
-
claimableNum,
|
|
5291
|
-
hasClaimable,
|
|
5292
|
-
pendingRewards,
|
|
5293
|
-
pendingRewardsUsd,
|
|
5294
|
-
totalRewardsReceived,
|
|
5295
|
-
totalRewardsReceivedUsd,
|
|
5296
|
-
...tokeRewards
|
|
5297
|
-
};
|
|
5298
|
-
};
|
|
5299
|
-
|
|
5300
|
-
// functions/getTokenPrices.ts
|
|
5301
|
-
import { PRICED_TOKENS as PRICED_TOKENS2 } from "@tokemak/tokenlist";
|
|
5302
|
-
import { TOKEMAK_PRICES_STAGING_URL } from "@tokemak/constants";
|
|
5303
|
-
var getTokenPrices = async () => {
|
|
5304
|
-
try {
|
|
5305
|
-
const body = {
|
|
5306
|
-
tokens: PRICED_TOKENS2.map((asset) => ({
|
|
5307
|
-
token: asset.address,
|
|
5308
|
-
chainId: asset.chainId,
|
|
5309
|
-
systemName: "gen3",
|
|
5310
|
-
timeoutMS: 5 * 1e3
|
|
5311
|
-
}))
|
|
5312
|
-
};
|
|
5313
|
-
const response = await fetch(`${TOKEMAK_PRICES_STAGING_URL}`, {
|
|
5314
|
-
method: "POST",
|
|
5315
|
-
headers: {
|
|
5316
|
-
"Content-Type": "application/json"
|
|
5317
|
-
},
|
|
5318
|
-
body: JSON.stringify(body)
|
|
5319
|
-
});
|
|
5320
|
-
const data = await response.json();
|
|
5321
|
-
const prices = PRICED_TOKENS2.reduce((acc, asset) => {
|
|
5322
|
-
const priceData = data.find(
|
|
5323
|
-
(item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
|
|
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
|
|
5324
4207
|
);
|
|
5325
4208
|
acc[asset.symbol] = priceData?.price ?? 0;
|
|
5326
4209
|
return acc;
|
|
@@ -5348,11 +4231,11 @@ var getTokenPrices = async () => {
|
|
|
5348
4231
|
};
|
|
5349
4232
|
|
|
5350
4233
|
// functions/getChainSubgraphStatus.ts
|
|
5351
|
-
import { getSdkByChainId as
|
|
4234
|
+
import { getSdkByChainId as getSdkByChainId12 } from "@tokemak/graph-cli";
|
|
5352
4235
|
var getChainSubgraphStatus = async (chain) => {
|
|
5353
4236
|
const currentTimestamp = Math.floor(Date.now() / 1e3);
|
|
5354
4237
|
try {
|
|
5355
|
-
const { GetLatestSubgraphTimestamp } =
|
|
4238
|
+
const { GetLatestSubgraphTimestamp } = getSdkByChainId12(
|
|
5356
4239
|
chain.chainId
|
|
5357
4240
|
);
|
|
5358
4241
|
const { _meta } = await GetLatestSubgraphTimestamp();
|
|
@@ -5403,155 +4286,15 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5403
4286
|
return { isOutOfSync, errorMessage };
|
|
5404
4287
|
};
|
|
5405
4288
|
|
|
5406
|
-
// functions/getCycleV1.ts
|
|
5407
|
-
import { readContract as readContract15 } from "@wagmi/core";
|
|
5408
|
-
import { managerV1Abi as managerV1Abi2 } from "@tokemak/abis";
|
|
5409
|
-
import { createPublicClient, http } from "viem";
|
|
5410
|
-
import {
|
|
5411
|
-
convertChainCycleToUnix as convertChainCycleToUnix4,
|
|
5412
|
-
convertSecondsToRemainingTime as convertSecondsToRemainingTime3
|
|
5413
|
-
} from "@tokemak/utils";
|
|
5414
|
-
import { getMainnetConfig as getMainnetConfig7 } from "@tokemak/config";
|
|
5415
|
-
import { mainnet as mainnet8 } from "viem/chains";
|
|
5416
|
-
var publicClient = createPublicClient({
|
|
5417
|
-
chain: mainnet8,
|
|
5418
|
-
transport: http("https://mainnet.infura.io/v3/2BtQ5D1QEPHvwgZwKwnZC7WQVhr")
|
|
5419
|
-
});
|
|
5420
|
-
var getCycleV1 = async (wagmiConfig, {
|
|
5421
|
-
currentBlockNumber,
|
|
5422
|
-
chainId
|
|
5423
|
-
}) => {
|
|
5424
|
-
const scanPeriodInDays = 8;
|
|
5425
|
-
const blockTime = 12;
|
|
5426
|
-
const { managerV1 } = getMainnetConfig7();
|
|
5427
|
-
try {
|
|
5428
|
-
if (currentBlockNumber && managerV1) {
|
|
5429
|
-
const currentCycleIndex = await readContract15(wagmiConfig, {
|
|
5430
|
-
address: managerV1,
|
|
5431
|
-
abi: managerV1Abi2,
|
|
5432
|
-
functionName: "getCurrentCycleIndex",
|
|
5433
|
-
chainId
|
|
5434
|
-
});
|
|
5435
|
-
const filter = await publicClient.createContractEventFilter({
|
|
5436
|
-
address: managerV1,
|
|
5437
|
-
fromBlock: BigInt(
|
|
5438
|
-
Math.floor(
|
|
5439
|
-
Number(currentBlockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
5440
|
-
)
|
|
5441
|
-
),
|
|
5442
|
-
abi: managerV1Abi2,
|
|
5443
|
-
eventName: "CycleRolloverComplete"
|
|
5444
|
-
});
|
|
5445
|
-
const rolloverEvents = await publicClient.getFilterLogs({ filter });
|
|
5446
|
-
const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
|
|
5447
|
-
const secondsLeftBeforeNextCycle = convertChainCycleToUnix4(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
|
|
5448
|
-
return {
|
|
5449
|
-
currentCycleIndex,
|
|
5450
|
-
cycleRolloverBlockNumber,
|
|
5451
|
-
timeBeforeNextCycle: convertSecondsToRemainingTime3(
|
|
5452
|
-
secondsLeftBeforeNextCycle
|
|
5453
|
-
)
|
|
5454
|
-
};
|
|
5455
|
-
}
|
|
5456
|
-
} catch (error) {
|
|
5457
|
-
console.error(error);
|
|
5458
|
-
}
|
|
5459
|
-
};
|
|
5460
|
-
|
|
5461
|
-
// functions/getProtocolStats.ts
|
|
5462
|
-
import { formatLargeNumber as formatLargeNumber3, formatTVL as formatTVL3, formatEtherNum as formatEtherNum14 } from "@tokemak/utils";
|
|
5463
|
-
var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
5464
|
-
try {
|
|
5465
|
-
if (!autopools || !stoke || !sushiLP) {
|
|
5466
|
-
throw new Error("Missing required data");
|
|
5467
|
-
}
|
|
5468
|
-
const autopoolTVL = autopools?.reduce((acc, pool) => acc + pool.tvl, 0) || 0;
|
|
5469
|
-
const categories = autopools?.reduce((acc, pool) => {
|
|
5470
|
-
if (!acc[pool.category]) {
|
|
5471
|
-
if (pool.category === "eth" /* ETH */) {
|
|
5472
|
-
acc[pool.category] = { tvl: 0, supply: 0 };
|
|
5473
|
-
} else {
|
|
5474
|
-
acc[pool.category] = { tvl: 0 };
|
|
5475
|
-
}
|
|
5476
|
-
}
|
|
5477
|
-
acc[pool.category].tvl += pool.tvl;
|
|
5478
|
-
if (pool.category === "eth" /* ETH */) {
|
|
5479
|
-
if (pool.totalAssets) {
|
|
5480
|
-
const ethAmt = pool.totalAssets.ETH;
|
|
5481
|
-
if (acc[pool.category]) {
|
|
5482
|
-
acc[pool.category].supply = (acc[pool.category].supply ?? 0) + ethAmt;
|
|
5483
|
-
}
|
|
5484
|
-
}
|
|
5485
|
-
}
|
|
5486
|
-
return acc;
|
|
5487
|
-
}, {});
|
|
5488
|
-
const formattedCategories = Object.fromEntries(
|
|
5489
|
-
Object.entries(categories).map(([key, value]) => [
|
|
5490
|
-
key,
|
|
5491
|
-
{
|
|
5492
|
-
tvl: formatTVL3(value.tvl),
|
|
5493
|
-
supply: formatLargeNumber3(value.supply || 0)
|
|
5494
|
-
}
|
|
5495
|
-
])
|
|
5496
|
-
);
|
|
5497
|
-
const tvl = formatTVL3(
|
|
5498
|
-
autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0) + (EthAutoLP?.tvlUsd || 0) + (sauto?.rawTVL || 0)
|
|
5499
|
-
);
|
|
5500
|
-
const vaultAddresses = autopools?.flatMap(
|
|
5501
|
-
(pool) => pool.destinations.map((destination) => destination.vaultAddress)
|
|
5502
|
-
);
|
|
5503
|
-
const uniqueVaultAddresses = [...new Set(vaultAddresses)];
|
|
5504
|
-
const totalDestinations = uniqueVaultAddresses.length;
|
|
5505
|
-
const stakedTVL = {
|
|
5506
|
-
totalSupply: formatLargeNumber3(
|
|
5507
|
-
formatEtherNum14(
|
|
5508
|
-
(sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
|
|
5509
|
-
)
|
|
5510
|
-
),
|
|
5511
|
-
tvl: formatTVL3((sauto?.rawTVL || 0) + stoke.rawTVL)
|
|
5512
|
-
};
|
|
5513
|
-
return {
|
|
5514
|
-
autopools: {
|
|
5515
|
-
tvl: formatTVL3(autopoolTVL),
|
|
5516
|
-
tvlNum: autopoolTVL,
|
|
5517
|
-
categories: formattedCategories
|
|
5518
|
-
},
|
|
5519
|
-
stoke: {
|
|
5520
|
-
tvl: formatTVL3(stoke.rawTVL),
|
|
5521
|
-
tvlNum: stoke.rawTVL,
|
|
5522
|
-
totalSupply: `${stoke.totalSupply} TOKE`
|
|
5523
|
-
},
|
|
5524
|
-
sushiLP: {
|
|
5525
|
-
tvl: formatTVL3(sushiLP?.tvl || 0),
|
|
5526
|
-
totalSupply: sushiLP?.totalSupply || 0
|
|
5527
|
-
},
|
|
5528
|
-
EthAutoLP: {
|
|
5529
|
-
tvl: formatTVL3(EthAutoLP?.tvlUsd || 0)
|
|
5530
|
-
},
|
|
5531
|
-
sauto: {
|
|
5532
|
-
tvl: formatTVL3(sauto?.rawTVL || 0),
|
|
5533
|
-
tvlNum: sauto?.rawTVL || 0,
|
|
5534
|
-
totalSupply: `${sauto?.totalSupply} AUTO`
|
|
5535
|
-
},
|
|
5536
|
-
stakedTVL,
|
|
5537
|
-
tvl,
|
|
5538
|
-
totalDestinations
|
|
5539
|
-
};
|
|
5540
|
-
} catch (error) {
|
|
5541
|
-
console.error(error);
|
|
5542
|
-
return null;
|
|
5543
|
-
}
|
|
5544
|
-
};
|
|
5545
|
-
|
|
5546
4289
|
// functions/getRebalanceStats.ts
|
|
5547
|
-
import { getSdkByChainId as
|
|
4290
|
+
import { getSdkByChainId as getSdkByChainId13 } from "@tokemak/graph-cli";
|
|
5548
4291
|
|
|
5549
4292
|
// functions/getEthPriceAtBlock.ts
|
|
5550
|
-
import { getCoreConfig as
|
|
4293
|
+
import { getCoreConfig as getCoreConfig7 } from "@tokemak/config";
|
|
5551
4294
|
import { rootPriceOracleAbi } from "@tokemak/abis";
|
|
5552
4295
|
import { USDC_TOKEN } from "@tokemak/tokenlist";
|
|
5553
|
-
var getEthPriceAtBlock = async (client, blockNumber, chainId) => {
|
|
5554
|
-
const config =
|
|
4296
|
+
var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
|
|
4297
|
+
const config = getCoreConfig7(chainId);
|
|
5555
4298
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5556
4299
|
const weth = config.weth;
|
|
5557
4300
|
const usdc = USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || USDC_TOKEN.address;
|
|
@@ -5560,18 +4303,19 @@ var getEthPriceAtBlock = async (client, blockNumber, chainId) => {
|
|
|
5560
4303
|
abi: rootPriceOracleAbi,
|
|
5561
4304
|
functionName: "getPriceInQuote",
|
|
5562
4305
|
args: [weth, usdc],
|
|
5563
|
-
blockNumber
|
|
4306
|
+
blockNumber,
|
|
4307
|
+
account
|
|
5564
4308
|
});
|
|
5565
4309
|
return priceAtBlock;
|
|
5566
4310
|
};
|
|
5567
4311
|
|
|
5568
4312
|
// functions/getRebalanceStats.ts
|
|
5569
|
-
import { formatEtherNum as
|
|
4313
|
+
import { formatEtherNum as formatEtherNum10, formatUnitsNum as formatUnitsNum8 } from "@tokemak/utils";
|
|
5570
4314
|
import { USDC_TOKEN as USDC_TOKEN2 } from "@tokemak/tokenlist";
|
|
5571
4315
|
import { sonic as sonic3 } from "viem/chains";
|
|
5572
4316
|
var BATCH_SIZE = 500;
|
|
5573
4317
|
var fetchChainRebalances = async (chainId) => {
|
|
5574
|
-
const { GetAllAutopoolRebalances } =
|
|
4318
|
+
const { GetAllAutopoolRebalances } = getSdkByChainId13(chainId);
|
|
5575
4319
|
const allRebalances = await paginateQuery(
|
|
5576
4320
|
GetAllAutopoolRebalances,
|
|
5577
4321
|
"autopoolRebalances"
|
|
@@ -5590,17 +4334,18 @@ function inferBaseAssetDecimals(rebalance, chainId) {
|
|
|
5590
4334
|
}
|
|
5591
4335
|
return USDC_TOKEN2.decimals;
|
|
5592
4336
|
}
|
|
5593
|
-
var getRebalanceValueUsd = async (rebalance, chainId, client) => {
|
|
4337
|
+
var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
|
|
5594
4338
|
const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
|
|
5595
4339
|
if (ethWei === 0n) return null;
|
|
5596
4340
|
try {
|
|
5597
4341
|
const price = await getEthPriceAtBlock(
|
|
5598
4342
|
client,
|
|
5599
4343
|
BigInt(rebalance.blockNumber),
|
|
5600
|
-
chainId
|
|
4344
|
+
chainId,
|
|
4345
|
+
account
|
|
5601
4346
|
);
|
|
5602
4347
|
const ethUsd = Number(formatUnitsNum8(price, USDC_TOKEN2.decimals));
|
|
5603
|
-
const ethAmt = Number(
|
|
4348
|
+
const ethAmt = Number(formatEtherNum10(ethWei));
|
|
5604
4349
|
const usd = ethAmt * ethUsd;
|
|
5605
4350
|
return usd;
|
|
5606
4351
|
} catch (e) {
|
|
@@ -5608,7 +4353,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, client) => {
|
|
|
5608
4353
|
return null;
|
|
5609
4354
|
}
|
|
5610
4355
|
};
|
|
5611
|
-
var processRebalance = async (rebalance, chainId, client) => {
|
|
4356
|
+
var processRebalance = async (rebalance, chainId, client, account) => {
|
|
5612
4357
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5613
4358
|
const baseAssetAmount = Number(
|
|
5614
4359
|
formatUnitsNum8(
|
|
@@ -5616,7 +4361,12 @@ var processRebalance = async (rebalance, chainId, client) => {
|
|
|
5616
4361
|
baseDecimals
|
|
5617
4362
|
)
|
|
5618
4363
|
);
|
|
5619
|
-
const ethPathUsd = await getRebalanceValueUsd(
|
|
4364
|
+
const ethPathUsd = await getRebalanceValueUsd(
|
|
4365
|
+
rebalance,
|
|
4366
|
+
chainId,
|
|
4367
|
+
client,
|
|
4368
|
+
account
|
|
4369
|
+
);
|
|
5620
4370
|
if (ethPathUsd != null) {
|
|
5621
4371
|
return {
|
|
5622
4372
|
autopool: rebalance.autopool,
|
|
@@ -5636,12 +4386,12 @@ var processRebalance = async (rebalance, chainId, client) => {
|
|
|
5636
4386
|
valueInAsset: baseAssetAmount
|
|
5637
4387
|
};
|
|
5638
4388
|
};
|
|
5639
|
-
var processRebalancesInBatches = async (rebalances, chainId, client) => {
|
|
4389
|
+
var processRebalancesInBatches = async (rebalances, chainId, client, account) => {
|
|
5640
4390
|
const processedRebalances = [];
|
|
5641
4391
|
for (let i = 0; i < rebalances.length; i += BATCH_SIZE) {
|
|
5642
4392
|
const batch = rebalances.slice(i, i + BATCH_SIZE);
|
|
5643
4393
|
const batchPromises = batch.map(
|
|
5644
|
-
async (rebalance) => processRebalance(rebalance, chainId, client)
|
|
4394
|
+
async (rebalance) => processRebalance(rebalance, chainId, client, account)
|
|
5645
4395
|
);
|
|
5646
4396
|
const batchResults = await Promise.all(batchPromises);
|
|
5647
4397
|
processedRebalances.push(...batchResults);
|
|
@@ -5667,14 +4417,20 @@ var calculateRebalanceStats = (rebalances) => {
|
|
|
5667
4417
|
};
|
|
5668
4418
|
};
|
|
5669
4419
|
var getRebalanceStats = async (getClient, {
|
|
5670
|
-
includeTestnet = false
|
|
4420
|
+
includeTestnet = false,
|
|
4421
|
+
account
|
|
5671
4422
|
}) => {
|
|
5672
4423
|
const chains = getChainsForEnv({ includeTestnet });
|
|
5673
4424
|
const rebalances = await Promise.all(
|
|
5674
4425
|
chains.map(async (chain) => {
|
|
5675
4426
|
const rawRebalances = await fetchChainRebalances(chain.chainId);
|
|
5676
4427
|
const client = getClient(chain.chainId);
|
|
5677
|
-
return processRebalancesInBatches(
|
|
4428
|
+
return processRebalancesInBatches(
|
|
4429
|
+
rawRebalances,
|
|
4430
|
+
chain.chainId,
|
|
4431
|
+
client,
|
|
4432
|
+
account
|
|
4433
|
+
);
|
|
5678
4434
|
})
|
|
5679
4435
|
);
|
|
5680
4436
|
const allRebalances = rebalances.flat();
|
|
@@ -5682,7 +4438,7 @@ var getRebalanceStats = async (getClient, {
|
|
|
5682
4438
|
};
|
|
5683
4439
|
|
|
5684
4440
|
// functions/updateRebalanceStats.ts
|
|
5685
|
-
import { getPublicClient as
|
|
4441
|
+
import { getPublicClient as getPublicClient3 } from "@wagmi/core";
|
|
5686
4442
|
var updateRebalanceStats = async (wagmiConfig, {
|
|
5687
4443
|
currentRebalances,
|
|
5688
4444
|
includeTestnet = false
|
|
@@ -5697,7 +4453,7 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5697
4453
|
)
|
|
5698
4454
|
);
|
|
5699
4455
|
if (newRawRebalances.length > 0) {
|
|
5700
|
-
const client =
|
|
4456
|
+
const client = getPublicClient3(wagmiConfig, {
|
|
5701
4457
|
chainId: chain.chainId
|
|
5702
4458
|
});
|
|
5703
4459
|
return processRebalancesInBatches(
|
|
@@ -5716,16 +4472,16 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5716
4472
|
|
|
5717
4473
|
// functions/getUserSAuto.ts
|
|
5718
4474
|
import { sAutoAbi } from "@tokemak/abis";
|
|
5719
|
-
import { getMainnetConfig
|
|
4475
|
+
import { getMainnetConfig } from "@tokemak/config";
|
|
5720
4476
|
import {
|
|
5721
4477
|
convertAutoCycleToUnix,
|
|
5722
|
-
convertSecondsToRemainingTime
|
|
5723
|
-
formatCurrency as
|
|
5724
|
-
formatEtherNum as
|
|
4478
|
+
convertSecondsToRemainingTime,
|
|
4479
|
+
formatCurrency as formatCurrency2,
|
|
4480
|
+
formatEtherNum as formatEtherNum11
|
|
5725
4481
|
} from "@tokemak/utils";
|
|
5726
|
-
import { readContracts as
|
|
5727
|
-
import { formatEther
|
|
5728
|
-
import { mainnet as
|
|
4482
|
+
import { readContracts as readContracts5 } from "@wagmi/core";
|
|
4483
|
+
import { formatEther } from "viem";
|
|
4484
|
+
import { mainnet as mainnet7 } from "viem/chains";
|
|
5729
4485
|
var getUserSAuto = async (wagmiConfig, {
|
|
5730
4486
|
address,
|
|
5731
4487
|
autoPrice
|
|
@@ -5737,8 +4493,8 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5737
4493
|
if (!autoPrice) {
|
|
5738
4494
|
throw new Error("Auto price not found");
|
|
5739
4495
|
}
|
|
5740
|
-
const { sAuto } =
|
|
5741
|
-
const chainId =
|
|
4496
|
+
const { sAuto } = getMainnetConfig();
|
|
4497
|
+
const chainId = mainnet7.id;
|
|
5742
4498
|
const sAutoContract = {
|
|
5743
4499
|
address: sAuto,
|
|
5744
4500
|
abi: sAutoAbi
|
|
@@ -5748,7 +4504,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5748
4504
|
{ result: depositInfoResult },
|
|
5749
4505
|
{ result: withdrawalInfoResult },
|
|
5750
4506
|
{ result: cycleIndex }
|
|
5751
|
-
] = await
|
|
4507
|
+
] = await readContracts5(wagmiConfig, {
|
|
5752
4508
|
contracts: [
|
|
5753
4509
|
{
|
|
5754
4510
|
...sAutoContract,
|
|
@@ -5784,8 +4540,8 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5784
4540
|
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
5785
4541
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
5786
4542
|
}
|
|
5787
|
-
const withdrawalAmountUsd =
|
|
5788
|
-
|
|
4543
|
+
const withdrawalAmountUsd = formatCurrency2(
|
|
4544
|
+
formatEtherNum11(withdrawalAmount) * autoPrice
|
|
5789
4545
|
);
|
|
5790
4546
|
const lockDuration = Number(depositLockDuration);
|
|
5791
4547
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -5795,11 +4551,11 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5795
4551
|
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
5796
4552
|
const lockRenew = currentCycle - lockStart > lockDuration ? currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement : currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd;
|
|
5797
4553
|
const withdrawAvailable = lockRenew - 1;
|
|
5798
|
-
const balanceUSD =
|
|
5799
|
-
Number(
|
|
4554
|
+
const balanceUSD = formatCurrency2(
|
|
4555
|
+
Number(formatEther(balanceExcludingWithdrawal)) * autoPrice
|
|
5800
4556
|
);
|
|
5801
|
-
const balanceExcludingWithdrawalUsd =
|
|
5802
|
-
|
|
4557
|
+
const balanceExcludingWithdrawalUsd = formatCurrency2(
|
|
4558
|
+
formatEtherNum11(balanceExcludingWithdrawal) * autoPrice
|
|
5803
4559
|
);
|
|
5804
4560
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
5805
4561
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
@@ -5821,20 +4577,20 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5821
4577
|
unlockPeriodStartDate,
|
|
5822
4578
|
unlockRenewalDate
|
|
5823
4579
|
} = formatDateRange(unlockPeriodDateRangeArray, "date");
|
|
5824
|
-
const totalActiveUserCredits =
|
|
5825
|
-
const totalUserCredits =
|
|
4580
|
+
const totalActiveUserCredits = formatEtherNum11(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
4581
|
+
const totalUserCredits = formatEtherNum11(balance) * lockDurationInMonths;
|
|
5826
4582
|
const hasAddedLockedAuto = depositAmount > 0n;
|
|
5827
4583
|
const addedLockedAuto = depositAmount;
|
|
5828
4584
|
return {
|
|
5829
4585
|
balance,
|
|
5830
4586
|
balanceUSD,
|
|
5831
|
-
balanceExcludingWithdrawal: hasBalance ?
|
|
4587
|
+
balanceExcludingWithdrawal: hasBalance ? formatEther(balanceExcludingWithdrawal) : "0.00",
|
|
5832
4588
|
balanceExcludingWithdrawalUsd,
|
|
5833
4589
|
hasBalanceExcludingWithdrawal,
|
|
5834
|
-
timeLeftBeforeUnlockRequestAvailable:
|
|
4590
|
+
timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime(
|
|
5835
4591
|
unlockRequestPeriodStartUnix
|
|
5836
4592
|
),
|
|
5837
|
-
timeLeftBeforeUnlockRequestUnavailable:
|
|
4593
|
+
timeLeftBeforeUnlockRequestUnavailable: convertSecondsToRemainingTime(
|
|
5838
4594
|
unlockRequestPeriodEndUnix
|
|
5839
4595
|
),
|
|
5840
4596
|
withdrawalAmount,
|
|
@@ -5851,7 +4607,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5851
4607
|
unlockRenewalDate,
|
|
5852
4608
|
lockDurationInMonths,
|
|
5853
4609
|
boost: lockDuration,
|
|
5854
|
-
points:
|
|
4610
|
+
points: formatEtherNum11(balanceExcludingWithdrawal) * lockDuration,
|
|
5855
4611
|
totalActiveCredits: totalActiveUserCredits,
|
|
5856
4612
|
totalCredits: totalUserCredits,
|
|
5857
4613
|
hasBalance
|
|
@@ -5863,30 +4619,30 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5863
4619
|
};
|
|
5864
4620
|
|
|
5865
4621
|
// functions/getSAuto.ts
|
|
5866
|
-
import { formatEther as
|
|
5867
|
-
import { readContracts as
|
|
4622
|
+
import { formatEther as formatEther2 } from "viem";
|
|
4623
|
+
import { readContracts as readContracts6 } from "@wagmi/core";
|
|
5868
4624
|
import { sAutoAbi as sAutoAbi2 } from "@tokemak/abis";
|
|
5869
4625
|
import {
|
|
5870
4626
|
convertAutoCycleToUnix as convertAutoCycleToUnix2,
|
|
5871
|
-
convertSecondsToRemainingTime as
|
|
5872
|
-
formatLargeNumber
|
|
5873
|
-
formatTVL
|
|
4627
|
+
convertSecondsToRemainingTime as convertSecondsToRemainingTime2,
|
|
4628
|
+
formatLargeNumber,
|
|
4629
|
+
formatTVL
|
|
5874
4630
|
} from "@tokemak/utils";
|
|
5875
|
-
import { getMainnetConfig as
|
|
5876
|
-
import { mainnet as
|
|
4631
|
+
import { getMainnetConfig as getMainnetConfig2 } from "@tokemak/config";
|
|
4632
|
+
import { mainnet as mainnet8 } from "viem/chains";
|
|
5877
4633
|
var getSAuto = async (wagmiConfig, {
|
|
5878
4634
|
autoPrice
|
|
5879
4635
|
}) => {
|
|
5880
4636
|
try {
|
|
5881
|
-
const { sAuto } =
|
|
5882
|
-
const chainId =
|
|
4637
|
+
const { sAuto } = getMainnetConfig2();
|
|
4638
|
+
const chainId = mainnet8.id;
|
|
5883
4639
|
const baseConfig = {
|
|
5884
4640
|
address: sAuto,
|
|
5885
4641
|
abi: sAutoAbi2,
|
|
5886
4642
|
chainId
|
|
5887
4643
|
};
|
|
5888
4644
|
if (sAuto && autoPrice) {
|
|
5889
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await
|
|
4645
|
+
const [{ result: totalSupply }, { result: currentCycle }] = await readContracts6(wagmiConfig, {
|
|
5890
4646
|
contracts: [
|
|
5891
4647
|
{
|
|
5892
4648
|
...baseConfig,
|
|
@@ -5898,15 +4654,15 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5898
4654
|
}
|
|
5899
4655
|
]
|
|
5900
4656
|
});
|
|
5901
|
-
const tvl = Number(
|
|
4657
|
+
const tvl = Number(formatEther2(totalSupply || 0n)) * autoPrice;
|
|
5902
4658
|
const secondsLeftBeforeNextCycle = convertAutoCycleToUnix2(Number(currentCycle) + 1) - Date.now() / 1e3;
|
|
5903
4659
|
return {
|
|
5904
4660
|
rawTotalSupply: totalSupply,
|
|
5905
|
-
totalSupply:
|
|
5906
|
-
tvl:
|
|
4661
|
+
totalSupply: formatLargeNumber(formatEther2(totalSupply || 0n)),
|
|
4662
|
+
tvl: formatTVL(tvl),
|
|
5907
4663
|
rawTVL: tvl,
|
|
5908
4664
|
currentCycle,
|
|
5909
|
-
timeBeforeNextCycle:
|
|
4665
|
+
timeBeforeNextCycle: convertSecondsToRemainingTime2(
|
|
5910
4666
|
secondsLeftBeforeNextCycle
|
|
5911
4667
|
)
|
|
5912
4668
|
};
|
|
@@ -5917,36 +4673,36 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5917
4673
|
};
|
|
5918
4674
|
|
|
5919
4675
|
// functions/getSAutoRewards.ts
|
|
5920
|
-
import { formatUnits as
|
|
4676
|
+
import { formatUnits as formatUnits8 } from "viem";
|
|
5921
4677
|
import {
|
|
5922
4678
|
convertTimestampToDate as convertTimestampToDate5,
|
|
5923
4679
|
formatDateToReadable as formatDateToReadable3,
|
|
5924
|
-
formatEtherNum as
|
|
4680
|
+
formatEtherNum as formatEtherNum12
|
|
5925
4681
|
} from "@tokemak/utils";
|
|
5926
|
-
import { getSdkByChainId as
|
|
5927
|
-
import { mainnet as
|
|
4682
|
+
import { getSdkByChainId as getSdkByChainId14 } from "@tokemak/graph-cli";
|
|
4683
|
+
import { mainnet as mainnet9 } from "viem/chains";
|
|
5928
4684
|
var getSAutoRewards = async () => {
|
|
5929
4685
|
try {
|
|
5930
|
-
const { GetSAutoRewards } =
|
|
4686
|
+
const { GetSAutoRewards } = getSdkByChainId14(mainnet9.id);
|
|
5931
4687
|
const { globalRewardsBalances } = await GetSAutoRewards();
|
|
5932
4688
|
const allGlobalRewardsBalanceDayDatas = await paginateQuery(
|
|
5933
4689
|
GetSAutoRewards,
|
|
5934
4690
|
"globalRewardsBalanceDayDatas"
|
|
5935
4691
|
);
|
|
5936
4692
|
const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
|
|
5937
|
-
return acc +
|
|
4693
|
+
return acc + formatEtherNum12(balance.balance);
|
|
5938
4694
|
}, 0);
|
|
5939
4695
|
const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
|
|
5940
|
-
return acc + Number(
|
|
4696
|
+
return acc + Number(formatUnits8(balance.balanceUSD, 8));
|
|
5941
4697
|
}, 0);
|
|
5942
4698
|
const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
|
|
5943
4699
|
(dayData) => ({
|
|
5944
4700
|
timestamp: String(dayData.timestamp),
|
|
5945
|
-
balance:
|
|
5946
|
-
balanceUSD: Number(
|
|
5947
|
-
earned:
|
|
5948
|
-
earnedUSD: Number(
|
|
5949
|
-
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),
|
|
5950
4706
|
formattedDate: formatDateToReadable3(
|
|
5951
4707
|
convertTimestampToDate5(Number(dayData.timestamp))
|
|
5952
4708
|
)
|
|
@@ -5964,10 +4720,10 @@ var getSAutoRewards = async () => {
|
|
|
5964
4720
|
};
|
|
5965
4721
|
|
|
5966
4722
|
// functions/getUserSAutoRewards.ts
|
|
5967
|
-
import { getMainnetConfig as
|
|
5968
|
-
import { formatEtherNum as
|
|
4723
|
+
import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
|
|
4724
|
+
import { formatEtherNum as formatEtherNum13 } from "@tokemak/utils";
|
|
5969
4725
|
var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
5970
|
-
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } =
|
|
4726
|
+
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = getMainnetConfig3();
|
|
5971
4727
|
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
5972
4728
|
stoke: sAuto,
|
|
5973
4729
|
chainId: 1
|
|
@@ -6011,19 +4767,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
|
6011
4767
|
return null;
|
|
6012
4768
|
}
|
|
6013
4769
|
}
|
|
6014
|
-
const claimableNum =
|
|
4770
|
+
const claimableNum = formatEtherNum13(autoRewards?.claimable || 0n);
|
|
6015
4771
|
const claimableUsd = autoPrice * claimableNum;
|
|
6016
4772
|
const hasClaimable = claimableNum > 0;
|
|
6017
|
-
let pendingRewards =
|
|
4773
|
+
let pendingRewards = formatEtherNum13(
|
|
6018
4774
|
autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
6019
4775
|
);
|
|
6020
4776
|
if (currentCycle === 4242n) {
|
|
6021
|
-
pendingRewards =
|
|
4777
|
+
pendingRewards = formatEtherNum13(
|
|
6022
4778
|
autoRewards?.rewardsPayload.payload.amount || 0n
|
|
6023
4779
|
);
|
|
6024
4780
|
}
|
|
6025
4781
|
const pendingRewardsUsd = autoPrice * pendingRewards;
|
|
6026
|
-
const totalRewardsReceived =
|
|
4782
|
+
const totalRewardsReceived = formatEtherNum13(
|
|
6027
4783
|
autoRewards.rewardsPayload.payload.amount || 0n
|
|
6028
4784
|
);
|
|
6029
4785
|
const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
|
|
@@ -6124,12 +4880,12 @@ async function getMerklPoolApr({
|
|
|
6124
4880
|
}
|
|
6125
4881
|
|
|
6126
4882
|
// functions/getSAutoApr.ts
|
|
6127
|
-
import { getSdkByChainId as
|
|
6128
|
-
import { mainnet as
|
|
6129
|
-
import { formatEtherNum as
|
|
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";
|
|
6130
4886
|
var getSAutoApr = async () => {
|
|
6131
4887
|
try {
|
|
6132
|
-
const { GetSAutoApr } =
|
|
4888
|
+
const { GetSAutoApr } = getSdkByChainId15(mainnet10.id);
|
|
6133
4889
|
const { globalRewardsBalances } = await GetSAutoApr();
|
|
6134
4890
|
if (!globalRewardsBalances || globalRewardsBalances.length === 0) {
|
|
6135
4891
|
return {
|
|
@@ -6145,7 +4901,7 @@ var getSAutoApr = async () => {
|
|
|
6145
4901
|
aprFormatted: void 0
|
|
6146
4902
|
};
|
|
6147
4903
|
}
|
|
6148
|
-
const aprPerCredit =
|
|
4904
|
+
const aprPerCredit = formatEtherNum14(rawApr);
|
|
6149
4905
|
const lockDuration = 16;
|
|
6150
4906
|
const apr = aprPerCredit * lockDuration;
|
|
6151
4907
|
return {
|
|
@@ -6161,66 +4917,56 @@ var getSAutoApr = async () => {
|
|
|
6161
4917
|
}
|
|
6162
4918
|
};
|
|
6163
4919
|
|
|
6164
|
-
// functions/
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
}
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
}
|
|
6195
|
-
if (!dateByTs.has(ts)) dateByTs.set(ts, item.formattedDate);
|
|
6196
|
-
}
|
|
6197
|
-
const allTimestamps = Array.from(
|
|
6198
|
-
/* @__PURE__ */ new Set([...stokeByTs.keys(), ...sAutoByTs.keys()])
|
|
6199
|
-
).sort((a, b) => a - b);
|
|
6200
|
-
let lastStoke = { balance: 0, balanceUSD: 0 };
|
|
6201
|
-
let lastSAuto = { balance: 0, balanceUSD: 0 };
|
|
6202
|
-
const historicalRewards = allTimestamps.map((ts) => {
|
|
6203
|
-
if (stokeByTs.has(ts)) lastStoke = stokeByTs.get(ts);
|
|
6204
|
-
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
|
+
});
|
|
6205
4950
|
return {
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
4951
|
+
asyncSwapperRegistry,
|
|
4952
|
+
autopoolRouter,
|
|
4953
|
+
autopoolRegistry,
|
|
4954
|
+
swapRouter
|
|
6209
4955
|
};
|
|
6210
|
-
})
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
totalEarningsUsd,
|
|
6214
|
-
historicalRewards
|
|
6215
|
-
};
|
|
4956
|
+
} catch (e) {
|
|
4957
|
+
console.log(e);
|
|
4958
|
+
}
|
|
6216
4959
|
};
|
|
6217
4960
|
export {
|
|
6218
4961
|
AutopoolCategory,
|
|
6219
4962
|
BATCH_SIZE,
|
|
6220
4963
|
ETH_BASE_ASSETS,
|
|
6221
4964
|
EUR_BASE_ASSETS,
|
|
6222
|
-
|
|
4965
|
+
GET_USER_POSITIONS,
|
|
4966
|
+
GET_V4_POOL_TVL,
|
|
4967
|
+
GRAPH_V4_SUBGRAPH_PROXY_PATH,
|
|
6223
4968
|
USD_BASE_ASSETS,
|
|
4969
|
+
V4_SUBGRAPH_IDS,
|
|
6224
4970
|
aggregateSTokeRewardsDayData,
|
|
6225
4971
|
arraysToObject,
|
|
6226
4972
|
calculateRebalanceStats,
|
|
@@ -6237,7 +4983,6 @@ export {
|
|
|
6237
4983
|
findClosestTimestampEntry,
|
|
6238
4984
|
formatDateRange,
|
|
6239
4985
|
getAddressFromSystemRegistry,
|
|
6240
|
-
getAllowance,
|
|
6241
4986
|
getAmountDeposited,
|
|
6242
4987
|
getAmountWithdrawn,
|
|
6243
4988
|
getAutopilotRouter,
|
|
@@ -6251,61 +4996,44 @@ export {
|
|
|
6251
4996
|
getAutopoolUserHistory,
|
|
6252
4997
|
getAutopools,
|
|
6253
4998
|
getAutopoolsHistory,
|
|
6254
|
-
getAutopoolsRebalances,
|
|
6255
4999
|
getBlobData,
|
|
6256
5000
|
getBlobHistoricalTokenPrices,
|
|
6257
5001
|
getBridgeFee,
|
|
6258
5002
|
getChainAutopools,
|
|
6259
5003
|
getChainAutopoolsApr,
|
|
6260
|
-
getChainCycleRolloverBlockNumber,
|
|
6261
|
-
getChainSToke,
|
|
6262
|
-
getChainSTokeRewards,
|
|
6263
5004
|
getChainSubgraphStatus,
|
|
6264
5005
|
getChainUserActivity,
|
|
6265
5006
|
getChainUserAutopools,
|
|
6266
|
-
getChainUserSToke,
|
|
6267
|
-
getChainUserSTokeRewards,
|
|
6268
5007
|
getChainsForEnv,
|
|
6269
|
-
getCombinedRewards,
|
|
6270
5008
|
getCurrentCycleId,
|
|
6271
|
-
getCurveLP,
|
|
6272
|
-
getCycleV1,
|
|
6273
5009
|
getDefillamaPoolApr,
|
|
6274
5010
|
getDefillamaPrice,
|
|
5011
|
+
getDeprecatedAutopools,
|
|
6275
5012
|
getDynamicSwap,
|
|
6276
5013
|
getEthAutoLP,
|
|
6277
|
-
getEthPrice,
|
|
6278
5014
|
getEthPriceAtBlock,
|
|
6279
5015
|
getExchangeNames,
|
|
6280
5016
|
getGenStratAprs,
|
|
6281
5017
|
getHistoricalTokenPrices,
|
|
6282
|
-
getLayerzeroStatus,
|
|
6283
5018
|
getMerklCreatorApr,
|
|
6284
5019
|
getMerklPoolApr,
|
|
6285
|
-
getMutlipleAutopoolRebalances,
|
|
6286
5020
|
getPoolStats,
|
|
6287
5021
|
getPoolsAndDestinations,
|
|
6288
|
-
getProtocolStats,
|
|
6289
5022
|
getRebalanceStats,
|
|
6290
5023
|
getRebalanceValueUsd,
|
|
6291
5024
|
getRewardsPayloadV1,
|
|
6292
5025
|
getSAuto,
|
|
6293
5026
|
getSAutoApr,
|
|
6294
5027
|
getSAutoRewards,
|
|
6295
|
-
getSToke,
|
|
6296
5028
|
getSTokeChainsForEnv,
|
|
6297
|
-
getSTokeRewards,
|
|
6298
5029
|
getSubgraphStatus,
|
|
6299
|
-
getSushiLP,
|
|
6300
5030
|
getSwapQuote,
|
|
6301
5031
|
getSystemConfig,
|
|
6302
5032
|
getTimestampDaysFromStart,
|
|
6303
5033
|
getTokePrice,
|
|
6304
|
-
getTokenList,
|
|
6305
5034
|
getTokenPrice,
|
|
6306
5035
|
getTokenPrices,
|
|
6307
5036
|
getTopAutopoolHolders,
|
|
6308
|
-
getUniV4Pool,
|
|
6309
5037
|
getUniV4PoolById,
|
|
6310
5038
|
getUserActivity,
|
|
6311
5039
|
getUserAutoEthRewards,
|
|
@@ -6313,19 +5041,17 @@ export {
|
|
|
6313
5041
|
getUserAutopools,
|
|
6314
5042
|
getUserAutopoolsHistory,
|
|
6315
5043
|
getUserAutopoolsRewards,
|
|
6316
|
-
getUserCurveLP,
|
|
6317
5044
|
getUserEthAutoLP,
|
|
6318
5045
|
getUserEthAutoLPRewards,
|
|
6319
5046
|
getUserMerklRewards,
|
|
6320
5047
|
getUserRewardsV1,
|
|
6321
5048
|
getUserSAuto,
|
|
6322
5049
|
getUserSAutoRewards,
|
|
6323
|
-
getUserSToke,
|
|
6324
|
-
getUserSushiLP,
|
|
6325
5050
|
getUserTokenBalances,
|
|
6326
5051
|
getUserUniV4Positions,
|
|
6327
5052
|
getUserUniV4PositionsById,
|
|
6328
|
-
|
|
5053
|
+
getV4PoolTvlFromSubgraph,
|
|
5054
|
+
getV4SubgraphUrl,
|
|
6329
5055
|
mergeArrays,
|
|
6330
5056
|
mergeArraysWithKey,
|
|
6331
5057
|
mergeStringArrays,
|
|
@@ -6335,6 +5061,5 @@ export {
|
|
|
6335
5061
|
processRebalance,
|
|
6336
5062
|
processRebalancesInBatches,
|
|
6337
5063
|
systemRegistryFunctionNames,
|
|
6338
|
-
updateRebalanceStats
|
|
6339
|
-
waitForMessageReceived
|
|
5064
|
+
updateRebalanceStats
|
|
6340
5065
|
};
|