@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.js
CHANGED
|
@@ -24,8 +24,11 @@ __export(index_exports, {
|
|
|
24
24
|
BATCH_SIZE: () => BATCH_SIZE,
|
|
25
25
|
ETH_BASE_ASSETS: () => ETH_BASE_ASSETS,
|
|
26
26
|
EUR_BASE_ASSETS: () => EUR_BASE_ASSETS,
|
|
27
|
-
|
|
27
|
+
GET_USER_POSITIONS: () => GET_USER_POSITIONS,
|
|
28
|
+
GET_V4_POOL_TVL: () => GET_V4_POOL_TVL,
|
|
29
|
+
GRAPH_V4_SUBGRAPH_PROXY_PATH: () => GRAPH_V4_SUBGRAPH_PROXY_PATH,
|
|
28
30
|
USD_BASE_ASSETS: () => USD_BASE_ASSETS,
|
|
31
|
+
V4_SUBGRAPH_IDS: () => V4_SUBGRAPH_IDS,
|
|
29
32
|
aggregateSTokeRewardsDayData: () => aggregateSTokeRewardsDayData,
|
|
30
33
|
arraysToObject: () => arraysToObject,
|
|
31
34
|
calculateRebalanceStats: () => calculateRebalanceStats,
|
|
@@ -42,7 +45,6 @@ __export(index_exports, {
|
|
|
42
45
|
findClosestTimestampEntry: () => findClosestTimestampEntry,
|
|
43
46
|
formatDateRange: () => formatDateRange,
|
|
44
47
|
getAddressFromSystemRegistry: () => getAddressFromSystemRegistry,
|
|
45
|
-
getAllowance: () => getAllowance,
|
|
46
48
|
getAmountDeposited: () => getAmountDeposited,
|
|
47
49
|
getAmountWithdrawn: () => getAmountWithdrawn,
|
|
48
50
|
getAutopilotRouter: () => getAutopilotRouter,
|
|
@@ -56,61 +58,44 @@ __export(index_exports, {
|
|
|
56
58
|
getAutopoolUserHistory: () => getAutopoolUserHistory,
|
|
57
59
|
getAutopools: () => getAutopools,
|
|
58
60
|
getAutopoolsHistory: () => getAutopoolsHistory,
|
|
59
|
-
getAutopoolsRebalances: () => getAutopoolsRebalances,
|
|
60
61
|
getBlobData: () => getBlobData,
|
|
61
62
|
getBlobHistoricalTokenPrices: () => getBlobHistoricalTokenPrices,
|
|
62
63
|
getBridgeFee: () => getBridgeFee,
|
|
63
64
|
getChainAutopools: () => getChainAutopools,
|
|
64
65
|
getChainAutopoolsApr: () => getChainAutopoolsApr,
|
|
65
|
-
getChainCycleRolloverBlockNumber: () => getChainCycleRolloverBlockNumber,
|
|
66
|
-
getChainSToke: () => getChainSToke,
|
|
67
|
-
getChainSTokeRewards: () => getChainSTokeRewards,
|
|
68
66
|
getChainSubgraphStatus: () => getChainSubgraphStatus,
|
|
69
67
|
getChainUserActivity: () => getChainUserActivity,
|
|
70
68
|
getChainUserAutopools: () => getChainUserAutopools,
|
|
71
|
-
getChainUserSToke: () => getChainUserSToke,
|
|
72
|
-
getChainUserSTokeRewards: () => getChainUserSTokeRewards,
|
|
73
69
|
getChainsForEnv: () => getChainsForEnv,
|
|
74
|
-
getCombinedRewards: () => getCombinedRewards,
|
|
75
70
|
getCurrentCycleId: () => getCurrentCycleId,
|
|
76
|
-
getCurveLP: () => getCurveLP,
|
|
77
|
-
getCycleV1: () => getCycleV1,
|
|
78
71
|
getDefillamaPoolApr: () => getDefillamaPoolApr,
|
|
79
72
|
getDefillamaPrice: () => getDefillamaPrice,
|
|
73
|
+
getDeprecatedAutopools: () => getDeprecatedAutopools,
|
|
80
74
|
getDynamicSwap: () => getDynamicSwap,
|
|
81
75
|
getEthAutoLP: () => getEthAutoLP,
|
|
82
|
-
getEthPrice: () => getEthPrice,
|
|
83
76
|
getEthPriceAtBlock: () => getEthPriceAtBlock,
|
|
84
77
|
getExchangeNames: () => getExchangeNames,
|
|
85
78
|
getGenStratAprs: () => getGenStratAprs,
|
|
86
79
|
getHistoricalTokenPrices: () => getHistoricalTokenPrices,
|
|
87
|
-
getLayerzeroStatus: () => getLayerzeroStatus,
|
|
88
80
|
getMerklCreatorApr: () => getMerklCreatorApr,
|
|
89
81
|
getMerklPoolApr: () => getMerklPoolApr,
|
|
90
|
-
getMutlipleAutopoolRebalances: () => getMutlipleAutopoolRebalances,
|
|
91
82
|
getPoolStats: () => getPoolStats,
|
|
92
83
|
getPoolsAndDestinations: () => getPoolsAndDestinations,
|
|
93
|
-
getProtocolStats: () => getProtocolStats,
|
|
94
84
|
getRebalanceStats: () => getRebalanceStats,
|
|
95
85
|
getRebalanceValueUsd: () => getRebalanceValueUsd,
|
|
96
86
|
getRewardsPayloadV1: () => getRewardsPayloadV1,
|
|
97
87
|
getSAuto: () => getSAuto,
|
|
98
88
|
getSAutoApr: () => getSAutoApr,
|
|
99
89
|
getSAutoRewards: () => getSAutoRewards,
|
|
100
|
-
getSToke: () => getSToke,
|
|
101
90
|
getSTokeChainsForEnv: () => getSTokeChainsForEnv,
|
|
102
|
-
getSTokeRewards: () => getSTokeRewards,
|
|
103
91
|
getSubgraphStatus: () => getSubgraphStatus,
|
|
104
|
-
getSushiLP: () => getSushiLP,
|
|
105
92
|
getSwapQuote: () => getSwapQuote,
|
|
106
93
|
getSystemConfig: () => getSystemConfig,
|
|
107
94
|
getTimestampDaysFromStart: () => getTimestampDaysFromStart,
|
|
108
95
|
getTokePrice: () => getTokePrice,
|
|
109
|
-
getTokenList: () => getTokenList,
|
|
110
96
|
getTokenPrice: () => getTokenPrice,
|
|
111
97
|
getTokenPrices: () => getTokenPrices,
|
|
112
98
|
getTopAutopoolHolders: () => getTopAutopoolHolders,
|
|
113
|
-
getUniV4Pool: () => getUniV4Pool,
|
|
114
99
|
getUniV4PoolById: () => getUniV4PoolById,
|
|
115
100
|
getUserActivity: () => getUserActivity,
|
|
116
101
|
getUserAutoEthRewards: () => getUserAutoEthRewards,
|
|
@@ -118,19 +103,17 @@ __export(index_exports, {
|
|
|
118
103
|
getUserAutopools: () => getUserAutopools,
|
|
119
104
|
getUserAutopoolsHistory: () => getUserAutopoolsHistory,
|
|
120
105
|
getUserAutopoolsRewards: () => getUserAutopoolsRewards,
|
|
121
|
-
getUserCurveLP: () => getUserCurveLP,
|
|
122
106
|
getUserEthAutoLP: () => getUserEthAutoLP,
|
|
123
107
|
getUserEthAutoLPRewards: () => getUserEthAutoLPRewards,
|
|
124
108
|
getUserMerklRewards: () => getUserMerklRewards,
|
|
125
109
|
getUserRewardsV1: () => getUserRewardsV1,
|
|
126
110
|
getUserSAuto: () => getUserSAuto,
|
|
127
111
|
getUserSAutoRewards: () => getUserSAutoRewards,
|
|
128
|
-
getUserSToke: () => getUserSToke,
|
|
129
|
-
getUserSushiLP: () => getUserSushiLP,
|
|
130
112
|
getUserTokenBalances: () => getUserTokenBalances,
|
|
131
113
|
getUserUniV4Positions: () => getUserUniV4Positions,
|
|
132
114
|
getUserUniV4PositionsById: () => getUserUniV4PositionsById,
|
|
133
|
-
|
|
115
|
+
getV4PoolTvlFromSubgraph: () => getV4PoolTvlFromSubgraph,
|
|
116
|
+
getV4SubgraphUrl: () => getV4SubgraphUrl,
|
|
134
117
|
mergeArrays: () => mergeArrays,
|
|
135
118
|
mergeArraysWithKey: () => mergeArraysWithKey,
|
|
136
119
|
mergeStringArrays: () => mergeStringArrays,
|
|
@@ -140,8 +123,7 @@ __export(index_exports, {
|
|
|
140
123
|
processRebalance: () => processRebalance,
|
|
141
124
|
processRebalancesInBatches: () => processRebalancesInBatches,
|
|
142
125
|
systemRegistryFunctionNames: () => systemRegistryFunctionNames,
|
|
143
|
-
updateRebalanceStats: () => updateRebalanceStats
|
|
144
|
-
waitForMessageReceived: () => waitForMessageReceived
|
|
126
|
+
updateRebalanceStats: () => updateRebalanceStats
|
|
145
127
|
});
|
|
146
128
|
module.exports = __toCommonJS(index_exports);
|
|
147
129
|
|
|
@@ -164,8 +146,8 @@ var getBlobData = async (blobName) => {
|
|
|
164
146
|
}
|
|
165
147
|
};
|
|
166
148
|
|
|
167
|
-
// functions/
|
|
168
|
-
var
|
|
149
|
+
// functions/getTokePrice.ts
|
|
150
|
+
var import_tokenlist = require("@tokemak/tokenlist");
|
|
169
151
|
|
|
170
152
|
// functions/getTokenPrice.ts
|
|
171
153
|
var import_constants = require("@tokemak/constants");
|
|
@@ -238,27 +220,7 @@ async function getTokenPriceFallback(tokenSymbol) {
|
|
|
238
220
|
}
|
|
239
221
|
}
|
|
240
222
|
|
|
241
|
-
// functions/getEthPrice.ts
|
|
242
|
-
var getEthPrice = async () => {
|
|
243
|
-
try {
|
|
244
|
-
return await getTokenPrice({
|
|
245
|
-
chainId: import_chains.sepolia.id,
|
|
246
|
-
tokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
|
|
247
|
-
});
|
|
248
|
-
} catch (error) {
|
|
249
|
-
console.warn("Primary price fetch failed. Attempting fallback...", error);
|
|
250
|
-
try {
|
|
251
|
-
const fallbackPrice = await getTokenPriceFallback("eth");
|
|
252
|
-
return fallbackPrice;
|
|
253
|
-
} catch (fallbackError) {
|
|
254
|
-
console.error("Fallback fetch also failed:", fallbackError);
|
|
255
|
-
return 0;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
|
|
260
223
|
// functions/getTokePrice.ts
|
|
261
|
-
var import_tokenlist = require("@tokemak/tokenlist");
|
|
262
224
|
var getTokePrice = async () => {
|
|
263
225
|
try {
|
|
264
226
|
return await getTokenPrice({ tokenAddress: import_tokenlist.TOKE_TOKEN.address });
|
|
@@ -442,12 +404,16 @@ function mergeStringArrays(keys, values) {
|
|
|
442
404
|
|
|
443
405
|
// utils/getChainsForEnv.ts
|
|
444
406
|
var import_constants2 = require("@tokemak/constants");
|
|
407
|
+
var import_config = require("@tokemak/config");
|
|
445
408
|
function getChainsForEnv({
|
|
446
|
-
includeTestnet = false
|
|
409
|
+
includeTestnet = false,
|
|
410
|
+
status = "all"
|
|
447
411
|
}) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return
|
|
412
|
+
const base2 = includeTestnet ? [...import_constants2.SUPPORTED_DEV_CHAINS] : [...import_constants2.SUPPORTED_PROD_CHAINS];
|
|
413
|
+
if (status === "all") return base2;
|
|
414
|
+
return base2.filter(
|
|
415
|
+
(chain) => status === "sunset" ? (0, import_config.isSunsetChain)(chain.chainId) : !(0, import_config.isSunsetChain)(chain.chainId)
|
|
416
|
+
);
|
|
451
417
|
}
|
|
452
418
|
|
|
453
419
|
// utils/fetchChainDataMap.ts
|
|
@@ -726,18 +692,24 @@ var getChainAutopoolsApr = async (chainId) => {
|
|
|
726
692
|
// functions/getChainAutopools.ts
|
|
727
693
|
var import_tokenlist3 = require("@tokemak/tokenlist");
|
|
728
694
|
var import_graph_cli = require("@tokemak/graph-cli");
|
|
729
|
-
var
|
|
695
|
+
var import_chains = require("viem/chains");
|
|
730
696
|
|
|
731
697
|
// functions/getPoolsAndDestinations.ts
|
|
732
|
-
var
|
|
698
|
+
var import_config2 = require("@tokemak/config");
|
|
733
699
|
var import_abis = require("@tokemak/abis");
|
|
734
|
-
var getPoolsAndDestinations = async (client, {
|
|
700
|
+
var getPoolsAndDestinations = async (client, {
|
|
701
|
+
chainId,
|
|
702
|
+
account,
|
|
703
|
+
blockNumber
|
|
704
|
+
}) => {
|
|
735
705
|
try {
|
|
736
|
-
const { lens } = (0,
|
|
706
|
+
const { lens } = (0, import_config2.getCoreConfig)(chainId);
|
|
737
707
|
const { autoPools, destinations } = await client.readContract({
|
|
738
708
|
address: lens,
|
|
739
709
|
abi: import_abis.lensAbi,
|
|
740
|
-
functionName: "getPoolsAndDestinations"
|
|
710
|
+
functionName: "getPoolsAndDestinations",
|
|
711
|
+
account,
|
|
712
|
+
blockNumber
|
|
741
713
|
});
|
|
742
714
|
const autopoolsAndDestinations = mergeArraysWithKey(
|
|
743
715
|
autoPools,
|
|
@@ -754,7 +726,9 @@ var getPoolsAndDestinations = async (client, { chainId }) => {
|
|
|
754
726
|
var import_constants6 = require("@tokemak/constants");
|
|
755
727
|
var getChainAutopools = async (client, {
|
|
756
728
|
chainId,
|
|
757
|
-
prices
|
|
729
|
+
prices,
|
|
730
|
+
account,
|
|
731
|
+
blockNumber
|
|
758
732
|
}) => {
|
|
759
733
|
const { GetVaultAddeds, GetAutopoolsInactiveDestinations } = (0, import_graph_cli.getSdkByChainId)(chainId);
|
|
760
734
|
try {
|
|
@@ -767,7 +741,9 @@ var getChainAutopools = async (client, {
|
|
|
767
741
|
chainId
|
|
768
742
|
});
|
|
769
743
|
const autopoolsAndDestinations = await getPoolsAndDestinations(client, {
|
|
770
|
-
chainId
|
|
744
|
+
chainId,
|
|
745
|
+
account,
|
|
746
|
+
blockNumber
|
|
771
747
|
});
|
|
772
748
|
if (!autopoolsAndDestinations) {
|
|
773
749
|
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
@@ -871,7 +847,7 @@ var getChainAutopools = async (client, {
|
|
|
871
847
|
const exchangeName = exchange.name.toLowerCase();
|
|
872
848
|
let exchangeInfo = exchange;
|
|
873
849
|
const value = exchangeValues[exchangeName];
|
|
874
|
-
if (chainId ===
|
|
850
|
+
if (chainId === import_chains.sonic.id) {
|
|
875
851
|
if (exchangeName === "balancerv3" || exchangeName === "balancer") {
|
|
876
852
|
exchangeInfo = import_tokenlist3.BEETS_PROTOCOL;
|
|
877
853
|
}
|
|
@@ -1149,14 +1125,15 @@ var getChainAutopools = async (client, {
|
|
|
1149
1125
|
};
|
|
1150
1126
|
|
|
1151
1127
|
// functions/getAutopools.ts
|
|
1152
|
-
var
|
|
1128
|
+
var import_config3 = require("@tokemak/config");
|
|
1153
1129
|
var import_viem3 = require("viem");
|
|
1154
1130
|
var getAutopools = async (wagmiConfig, {
|
|
1155
1131
|
prices,
|
|
1156
|
-
includeTestnet = false
|
|
1132
|
+
includeTestnet = false,
|
|
1133
|
+
status = "all"
|
|
1157
1134
|
}) => {
|
|
1158
1135
|
try {
|
|
1159
|
-
const chains = getChainsForEnv({ includeTestnet });
|
|
1136
|
+
const chains = getChainsForEnv({ includeTestnet, status });
|
|
1160
1137
|
const autopools = (await Promise.all(
|
|
1161
1138
|
chains.map((chain) => {
|
|
1162
1139
|
const chainId = chain?.chainId;
|
|
@@ -1173,7 +1150,7 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1173
1150
|
return sortedAutopoolsByTimestamp;
|
|
1174
1151
|
} else {
|
|
1175
1152
|
return sortedAutopoolsByTimestamp.filter((pool) => {
|
|
1176
|
-
return
|
|
1153
|
+
return import_config3.AUTOPOOLS_WHITELIST_PROD.includes((0, import_viem3.getAddress)(pool.poolAddress));
|
|
1177
1154
|
});
|
|
1178
1155
|
}
|
|
1179
1156
|
} catch (e) {
|
|
@@ -1181,6 +1158,12 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1181
1158
|
}
|
|
1182
1159
|
};
|
|
1183
1160
|
|
|
1161
|
+
// functions/getDeprecatedAutopools.ts
|
|
1162
|
+
var getDeprecatedAutopools = (wagmiConfig, {
|
|
1163
|
+
prices,
|
|
1164
|
+
includeTestnet = false
|
|
1165
|
+
}) => getAutopools(wagmiConfig, { prices, includeTestnet, status: "sunset" });
|
|
1166
|
+
|
|
1184
1167
|
// functions/getAutopoolRebalances.ts
|
|
1185
1168
|
var import_graph_cli2 = require("@tokemak/graph-cli");
|
|
1186
1169
|
var getAutopoolRebalances = async (id, chainId = 1, options) => {
|
|
@@ -1200,23 +1183,14 @@ var getAutopoolRebalances = async (id, chainId = 1, options) => {
|
|
|
1200
1183
|
}));
|
|
1201
1184
|
};
|
|
1202
1185
|
|
|
1203
|
-
// functions/getAutopoolsRebalances.ts
|
|
1204
|
-
var import_graph_cli3 = require("@tokemak/graph-cli");
|
|
1205
|
-
var getAutopoolsRebalances = async (chainId = 1) => {
|
|
1206
|
-
const { GetAutopoolsRebalances } = (0, import_graph_cli3.getSdkByChainId)(chainId);
|
|
1207
|
-
const { autopools } = await GetAutopoolsRebalances();
|
|
1208
|
-
const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
|
|
1209
|
-
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
1210
|
-
};
|
|
1211
|
-
|
|
1212
1186
|
// functions/getAutopoolDayData.ts
|
|
1213
1187
|
var import_viem4 = require("viem");
|
|
1214
1188
|
var import_utils8 = require("@tokemak/utils");
|
|
1215
1189
|
var import_constants7 = require("@tokemak/constants");
|
|
1216
|
-
var
|
|
1190
|
+
var import_graph_cli3 = require("@tokemak/graph-cli");
|
|
1217
1191
|
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_constants7.TOKEMAK_LAUNCH_TIMESTAMP) => {
|
|
1218
1192
|
try {
|
|
1219
|
-
const { GetAutopoolDayData } = (0,
|
|
1193
|
+
const { GetAutopoolDayData } = (0, import_graph_cli3.getSdkByChainId)(chainId);
|
|
1220
1194
|
const { autopoolDayDatas } = await GetAutopoolDayData({
|
|
1221
1195
|
address,
|
|
1222
1196
|
timestamp: startTimestamp
|
|
@@ -1275,9 +1249,9 @@ var getAutopoolHistory = async (autopool) => {
|
|
|
1275
1249
|
var import_viem5 = require("viem");
|
|
1276
1250
|
|
|
1277
1251
|
// functions/getAutopoolsDayData.ts
|
|
1278
|
-
var
|
|
1252
|
+
var import_graph_cli4 = require("@tokemak/graph-cli");
|
|
1279
1253
|
var getAutopoolsDayData = async (chainId, timestamp) => {
|
|
1280
|
-
const { GetAutopoolsDayData } = (0,
|
|
1254
|
+
const { GetAutopoolsDayData } = (0, import_graph_cli4.getSdkByChainId)(chainId);
|
|
1281
1255
|
const PAGE_SIZE = 1e3;
|
|
1282
1256
|
let allResults = [];
|
|
1283
1257
|
let hasMore = true;
|
|
@@ -1488,7 +1462,7 @@ var getAutopoolUser = async (config, {
|
|
|
1488
1462
|
};
|
|
1489
1463
|
|
|
1490
1464
|
// functions/getAutopoolUserActivity.ts
|
|
1491
|
-
var
|
|
1465
|
+
var import_graph_cli5 = require("@tokemak/graph-cli");
|
|
1492
1466
|
var import_utils13 = require("@tokemak/utils");
|
|
1493
1467
|
var getAutopoolUserActivity = async ({
|
|
1494
1468
|
autopool,
|
|
@@ -1497,7 +1471,7 @@ var getAutopoolUserActivity = async ({
|
|
|
1497
1471
|
if (!autopool || !autopool.chain?.chainId) {
|
|
1498
1472
|
throw new Error("Autopool not found");
|
|
1499
1473
|
}
|
|
1500
|
-
const { GetUserAutopoolBalanceChangeHistory } = (0,
|
|
1474
|
+
const { GetUserAutopoolBalanceChangeHistory } = (0, import_graph_cli5.getSdkByChainId)(
|
|
1501
1475
|
autopool.chain?.chainId
|
|
1502
1476
|
);
|
|
1503
1477
|
try {
|
|
@@ -1576,17 +1550,17 @@ var getAutopoolUserActivity = async ({
|
|
|
1576
1550
|
};
|
|
1577
1551
|
|
|
1578
1552
|
// functions/getAutopoolUserHistory.ts
|
|
1579
|
-
var
|
|
1553
|
+
var import_graph_cli6 = require("@tokemak/graph-cli");
|
|
1580
1554
|
var import_constants8 = require("@tokemak/constants");
|
|
1581
|
-
var
|
|
1555
|
+
var import_chains2 = require("viem/chains");
|
|
1582
1556
|
var import_utils15 = require("@tokemak/utils");
|
|
1583
1557
|
var getAutopoolUserHistory = async ({
|
|
1584
1558
|
userAddress,
|
|
1585
1559
|
autopool,
|
|
1586
1560
|
userActivity
|
|
1587
1561
|
}) => {
|
|
1588
|
-
const { GetUserVaultDayData } = (0,
|
|
1589
|
-
autopool?.chain?.chainId ||
|
|
1562
|
+
const { GetUserVaultDayData } = (0, import_graph_cli6.getSdkByChainId)(
|
|
1563
|
+
autopool?.chain?.chainId || import_chains2.base.id
|
|
1590
1564
|
);
|
|
1591
1565
|
try {
|
|
1592
1566
|
if (userAddress) {
|
|
@@ -1672,99 +1646,59 @@ var getAutopoolUserHistory = async ({
|
|
|
1672
1646
|
}
|
|
1673
1647
|
};
|
|
1674
1648
|
|
|
1675
|
-
// functions/
|
|
1676
|
-
var
|
|
1649
|
+
// functions/getUniV4Pool.ts
|
|
1650
|
+
var import_core3 = require("@wagmi/core");
|
|
1651
|
+
var import_viem7 = require("viem");
|
|
1652
|
+
var import_chains4 = require("viem/chains");
|
|
1677
1653
|
var import_constants9 = require("@tokemak/constants");
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
console.error(e);
|
|
1654
|
+
|
|
1655
|
+
// functions/uniV4Subgraph.ts
|
|
1656
|
+
var import_chains3 = require("viem/chains");
|
|
1657
|
+
var import_graphql_request = require("graphql-request");
|
|
1658
|
+
var V4_SUBGRAPH_IDS = {
|
|
1659
|
+
[import_chains3.mainnet.id]: "DiYPVdygkfjDWhbxGSqAQxwBKmfKnkWQojqeM2rkLb3G"
|
|
1660
|
+
};
|
|
1661
|
+
var GRAPH_V4_SUBGRAPH_PROXY_PATH = "/api/uniswap/v4-subgraph";
|
|
1662
|
+
function getV4SubgraphUrl(chainId, apiKey) {
|
|
1663
|
+
const subgraphId = V4_SUBGRAPH_IDS[chainId];
|
|
1664
|
+
if (!subgraphId) return null;
|
|
1665
|
+
if (apiKey) {
|
|
1666
|
+
return `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
|
|
1692
1667
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1668
|
+
if (typeof window !== "undefined") {
|
|
1669
|
+
return `${GRAPH_V4_SUBGRAPH_PROXY_PATH}?chainId=${chainId}`;
|
|
1670
|
+
}
|
|
1671
|
+
return `https://gateway.thegraph.com/api/subgraphs/id/${subgraphId}`;
|
|
1672
|
+
}
|
|
1673
|
+
var GET_V4_POOL_TVL = import_graphql_request.gql`
|
|
1674
|
+
query GetV4Pool($id: ID!) {
|
|
1675
|
+
pool(id: $id) {
|
|
1676
|
+
id
|
|
1677
|
+
totalValueLockedToken0
|
|
1678
|
+
totalValueLockedToken1
|
|
1679
|
+
totalValueLockedUSD
|
|
1680
|
+
token0Price
|
|
1681
|
+
token1Price
|
|
1702
1682
|
}
|
|
1703
|
-
} catch (e) {
|
|
1704
|
-
console.error(e);
|
|
1705
1683
|
}
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
var import_abis3 = require("@tokemak/abis");
|
|
1711
|
-
var import_config4 = require("@tokemak/config");
|
|
1712
|
-
var import_core3 = require("@wagmi/core");
|
|
1713
|
-
var import_viem7 = require("viem");
|
|
1714
|
-
var import_chains4 = require("viem/chains");
|
|
1715
|
-
var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
1716
|
-
const { sushiPool, lpRewardsV1Url } = (0, import_config4.getMainnetConfig)();
|
|
1717
|
-
const sushiPoolContract = {
|
|
1718
|
-
address: sushiPool,
|
|
1719
|
-
abi: import_abis3.sushiPoolAbi
|
|
1720
|
-
};
|
|
1684
|
+
`;
|
|
1685
|
+
async function getV4PoolTvlFromSubgraph(poolId, chainId, apiKey) {
|
|
1686
|
+
const url = getV4SubgraphUrl(chainId, apiKey);
|
|
1687
|
+
if (!url) return null;
|
|
1721
1688
|
try {
|
|
1722
|
-
const
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
{
|
|
1727
|
-
...sushiPoolContract,
|
|
1728
|
-
functionName: "getReserves",
|
|
1729
|
-
chainId: import_chains4.mainnet.id
|
|
1730
|
-
},
|
|
1731
|
-
{
|
|
1732
|
-
...sushiPoolContract,
|
|
1733
|
-
functionName: "totalSupply",
|
|
1734
|
-
chainId: import_chains4.mainnet.id
|
|
1735
|
-
}
|
|
1736
|
-
]
|
|
1737
|
-
}
|
|
1689
|
+
const client = new import_graphql_request.GraphQLClient(url);
|
|
1690
|
+
const data = await client.request(
|
|
1691
|
+
GET_V4_POOL_TVL,
|
|
1692
|
+
{ id: poolId.toLowerCase() }
|
|
1738
1693
|
);
|
|
1739
|
-
|
|
1740
|
-
const lpRewardsData = await lpRewardsResponse.json();
|
|
1741
|
-
const sushiLPRewards = lpRewardsData.chains[0].pools.find(
|
|
1742
|
-
({ name }) => name === "SUSHI_LP"
|
|
1743
|
-
);
|
|
1744
|
-
if (reserves && totalSupply && ethPrice) {
|
|
1745
|
-
const lpReserve = reserves[1] * 2n;
|
|
1746
|
-
const tvl = Number((0, import_viem7.formatEther)(lpReserve)) * ethPrice;
|
|
1747
|
-
const valueOf1LP = tvl / Number((0, import_viem7.formatEther)(totalSupply));
|
|
1748
|
-
return {
|
|
1749
|
-
tvl,
|
|
1750
|
-
lpReserve,
|
|
1751
|
-
totalSupply,
|
|
1752
|
-
reserves,
|
|
1753
|
-
apr: sushiLPRewards?.liquidityProviderApr,
|
|
1754
|
-
weeklyTokeEmissions: sushiLPRewards?.liquidityProviderReward,
|
|
1755
|
-
valueOf1LP
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1694
|
+
return data.pool ?? null;
|
|
1758
1695
|
} catch (e) {
|
|
1759
|
-
console.
|
|
1696
|
+
console.error("Error fetching V4 pool TVL from subgraph:", e);
|
|
1697
|
+
return null;
|
|
1760
1698
|
}
|
|
1761
|
-
}
|
|
1699
|
+
}
|
|
1762
1700
|
|
|
1763
1701
|
// functions/getUniV4Pool.ts
|
|
1764
|
-
var import_core4 = require("@wagmi/core");
|
|
1765
|
-
var import_viem8 = require("viem");
|
|
1766
|
-
var import_chains5 = require("viem/chains");
|
|
1767
|
-
var import_constants10 = require("@tokemak/constants");
|
|
1768
1702
|
var stateViewAbi = [
|
|
1769
1703
|
{
|
|
1770
1704
|
inputs: [{ internalType: "PoolId", name: "poolId", type: "bytes32" }],
|
|
@@ -1810,8 +1744,8 @@ var erc20Abi2 = [
|
|
|
1810
1744
|
}
|
|
1811
1745
|
];
|
|
1812
1746
|
function computePoolId(poolKey) {
|
|
1813
|
-
return (0,
|
|
1814
|
-
(0,
|
|
1747
|
+
return (0, import_viem7.keccak256)(
|
|
1748
|
+
(0, import_viem7.encodeAbiParameters)(
|
|
1815
1749
|
[
|
|
1816
1750
|
{ type: "address", name: "currency0" },
|
|
1817
1751
|
{ type: "address", name: "currency1" },
|
|
@@ -1856,166 +1790,6 @@ function feeToTierString(fee) {
|
|
|
1856
1790
|
};
|
|
1857
1791
|
return tiers[fee] || `${fee / 1e4}%`;
|
|
1858
1792
|
}
|
|
1859
|
-
async function getUniV4Pool(wagmiConfig, {
|
|
1860
|
-
poolKey,
|
|
1861
|
-
chainId = import_chains5.mainnet.id,
|
|
1862
|
-
prices
|
|
1863
|
-
}) {
|
|
1864
|
-
const stateView = import_constants10.UNISWAP_V4_STATE_VIEW[chainId];
|
|
1865
|
-
if (!stateView) {
|
|
1866
|
-
console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
|
|
1867
|
-
return null;
|
|
1868
|
-
}
|
|
1869
|
-
const poolManager = import_constants10.UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1870
|
-
const poolId = computePoolId(poolKey);
|
|
1871
|
-
try {
|
|
1872
|
-
const [{ result: slot0 }, { result: liquidity }] = await (0, import_core4.readContracts)(
|
|
1873
|
-
wagmiConfig,
|
|
1874
|
-
{
|
|
1875
|
-
contracts: [
|
|
1876
|
-
{
|
|
1877
|
-
address: stateView,
|
|
1878
|
-
abi: stateViewAbi,
|
|
1879
|
-
functionName: "getSlot0",
|
|
1880
|
-
args: [poolId],
|
|
1881
|
-
chainId
|
|
1882
|
-
},
|
|
1883
|
-
{
|
|
1884
|
-
address: stateView,
|
|
1885
|
-
abi: stateViewAbi,
|
|
1886
|
-
functionName: "getLiquidity",
|
|
1887
|
-
args: [poolId],
|
|
1888
|
-
chainId
|
|
1889
|
-
}
|
|
1890
|
-
]
|
|
1891
|
-
}
|
|
1892
|
-
);
|
|
1893
|
-
if (!slot0) {
|
|
1894
|
-
return null;
|
|
1895
|
-
}
|
|
1896
|
-
const isToken0Native = poolKey.currency0 === "0x0000000000000000000000000000000000000000";
|
|
1897
|
-
const isToken1Native = poolKey.currency1 === "0x0000000000000000000000000000000000000000";
|
|
1898
|
-
const tokenContracts = [];
|
|
1899
|
-
if (!isToken0Native) {
|
|
1900
|
-
tokenContracts.push(
|
|
1901
|
-
{
|
|
1902
|
-
address: poolKey.currency0,
|
|
1903
|
-
abi: erc20Abi2,
|
|
1904
|
-
functionName: "decimals",
|
|
1905
|
-
chainId
|
|
1906
|
-
},
|
|
1907
|
-
{
|
|
1908
|
-
address: poolKey.currency0,
|
|
1909
|
-
abi: erc20Abi2,
|
|
1910
|
-
functionName: "symbol",
|
|
1911
|
-
chainId
|
|
1912
|
-
},
|
|
1913
|
-
{
|
|
1914
|
-
address: poolKey.currency0,
|
|
1915
|
-
abi: erc20Abi2,
|
|
1916
|
-
functionName: "balanceOf",
|
|
1917
|
-
args: [poolManager],
|
|
1918
|
-
chainId
|
|
1919
|
-
}
|
|
1920
|
-
);
|
|
1921
|
-
}
|
|
1922
|
-
if (!isToken1Native) {
|
|
1923
|
-
tokenContracts.push(
|
|
1924
|
-
{
|
|
1925
|
-
address: poolKey.currency1,
|
|
1926
|
-
abi: erc20Abi2,
|
|
1927
|
-
functionName: "decimals",
|
|
1928
|
-
chainId
|
|
1929
|
-
},
|
|
1930
|
-
{
|
|
1931
|
-
address: poolKey.currency1,
|
|
1932
|
-
abi: erc20Abi2,
|
|
1933
|
-
functionName: "symbol",
|
|
1934
|
-
chainId
|
|
1935
|
-
},
|
|
1936
|
-
{
|
|
1937
|
-
address: poolKey.currency1,
|
|
1938
|
-
abi: erc20Abi2,
|
|
1939
|
-
functionName: "balanceOf",
|
|
1940
|
-
args: [poolManager],
|
|
1941
|
-
chainId
|
|
1942
|
-
}
|
|
1943
|
-
);
|
|
1944
|
-
}
|
|
1945
|
-
const tokenResults = tokenContracts.length > 0 ? await (0, import_core4.readContracts)(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
1946
|
-
let decimals0 = 18;
|
|
1947
|
-
let symbol0 = "ETH";
|
|
1948
|
-
let balance0 = 0n;
|
|
1949
|
-
let decimals1 = 18;
|
|
1950
|
-
let symbol1 = "ETH";
|
|
1951
|
-
let balance1 = 0n;
|
|
1952
|
-
let resultIndex = 0;
|
|
1953
|
-
if (!isToken0Native) {
|
|
1954
|
-
decimals0 = tokenResults[resultIndex++]?.result ?? 18;
|
|
1955
|
-
symbol0 = tokenResults[resultIndex++]?.result ?? "TOKEN0";
|
|
1956
|
-
balance0 = tokenResults[resultIndex++]?.result ?? 0n;
|
|
1957
|
-
}
|
|
1958
|
-
if (!isToken1Native) {
|
|
1959
|
-
decimals1 = tokenResults[resultIndex++]?.result ?? 18;
|
|
1960
|
-
symbol1 = tokenResults[resultIndex++]?.result ?? "TOKEN1";
|
|
1961
|
-
balance1 = tokenResults[resultIndex++]?.result ?? 0n;
|
|
1962
|
-
}
|
|
1963
|
-
const [sqrtPriceX96, tick] = slot0;
|
|
1964
|
-
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1965
|
-
const balance0Formatted = Number((0, import_viem8.formatUnits)(balance0, decimals0));
|
|
1966
|
-
const balance1Formatted = Number((0, import_viem8.formatUnits)(balance1, decimals1));
|
|
1967
|
-
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1968
|
-
liquidity ?? 0n,
|
|
1969
|
-
sqrtPriceX96,
|
|
1970
|
-
decimals0,
|
|
1971
|
-
decimals1
|
|
1972
|
-
);
|
|
1973
|
-
const priceInverted = price > 0 ? 1 / price : 0;
|
|
1974
|
-
const tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
|
|
1975
|
-
const tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
|
|
1976
|
-
let tvlUsd;
|
|
1977
|
-
if (prices) {
|
|
1978
|
-
const price0 = prices[symbol0] || prices[poolKey.currency0.toLowerCase()];
|
|
1979
|
-
const price1 = prices[symbol1] || prices[poolKey.currency1.toLowerCase()];
|
|
1980
|
-
if (price0) {
|
|
1981
|
-
tvlUsd = tvlToken0 * price0;
|
|
1982
|
-
} else if (price1) {
|
|
1983
|
-
tvlUsd = tvlToken1 * price1;
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
return {
|
|
1987
|
-
poolId,
|
|
1988
|
-
poolKey,
|
|
1989
|
-
token0: {
|
|
1990
|
-
address: poolKey.currency0,
|
|
1991
|
-
symbol: symbol0,
|
|
1992
|
-
decimals: decimals0,
|
|
1993
|
-
balance: balance0,
|
|
1994
|
-
balanceFormatted: balance0Formatted
|
|
1995
|
-
},
|
|
1996
|
-
token1: {
|
|
1997
|
-
address: poolKey.currency1,
|
|
1998
|
-
symbol: symbol1,
|
|
1999
|
-
decimals: decimals1,
|
|
2000
|
-
balance: balance1,
|
|
2001
|
-
balanceFormatted: balance1Formatted
|
|
2002
|
-
},
|
|
2003
|
-
fee: poolKey.fee,
|
|
2004
|
-
feeTier: feeToTierString(poolKey.fee),
|
|
2005
|
-
sqrtPriceX96,
|
|
2006
|
-
tick,
|
|
2007
|
-
liquidity: liquidity ?? 0n,
|
|
2008
|
-
liquidityAmounts,
|
|
2009
|
-
price,
|
|
2010
|
-
priceInverted,
|
|
2011
|
-
tvlToken0,
|
|
2012
|
-
tvlToken1,
|
|
2013
|
-
tvlUsd
|
|
2014
|
-
};
|
|
2015
|
-
} catch (e) {
|
|
2016
|
-
return null;
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
1793
|
function createPoolKey({
|
|
2020
1794
|
tokenA,
|
|
2021
1795
|
tokenB,
|
|
@@ -2037,17 +1811,18 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2037
1811
|
currency0,
|
|
2038
1812
|
currency1,
|
|
2039
1813
|
fee,
|
|
2040
|
-
chainId =
|
|
1814
|
+
chainId = import_chains4.mainnet.id,
|
|
2041
1815
|
prices
|
|
2042
1816
|
}) {
|
|
2043
|
-
const stateView =
|
|
1817
|
+
const stateView = import_constants9.UNISWAP_V4_STATE_VIEW[chainId];
|
|
2044
1818
|
if (!stateView) {
|
|
2045
1819
|
console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
|
|
2046
1820
|
return null;
|
|
2047
1821
|
}
|
|
2048
|
-
const poolManager =
|
|
1822
|
+
const poolManager = import_constants9.UNISWAP_V4_POOL_MANAGER[chainId];
|
|
2049
1823
|
try {
|
|
2050
|
-
const
|
|
1824
|
+
const tvlPromise = getV4PoolTvlFromSubgraph(poolId, chainId);
|
|
1825
|
+
const [{ result: slot0 }, { result: liquidity }] = await (0, import_core3.readContracts)(
|
|
2051
1826
|
wagmiConfig,
|
|
2052
1827
|
{
|
|
2053
1828
|
contracts: [
|
|
@@ -2120,7 +1895,7 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2120
1895
|
}
|
|
2121
1896
|
);
|
|
2122
1897
|
}
|
|
2123
|
-
const tokenResults = tokenContracts.length > 0 ? await (0,
|
|
1898
|
+
const tokenResults = tokenContracts.length > 0 ? await (0, import_core3.readContracts)(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
2124
1899
|
let decimals0 = 18;
|
|
2125
1900
|
let symbol0 = "ETH";
|
|
2126
1901
|
let balance0 = 0n;
|
|
@@ -2140,22 +1915,43 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2140
1915
|
}
|
|
2141
1916
|
const [sqrtPriceX96, tick] = slot0;
|
|
2142
1917
|
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
2143
|
-
const balance0Formatted = Number((0, import_viem8.formatUnits)(balance0, decimals0));
|
|
2144
|
-
const balance1Formatted = Number((0, import_viem8.formatUnits)(balance1, decimals1));
|
|
2145
|
-
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
2146
|
-
liquidity ?? 0n,
|
|
2147
|
-
sqrtPriceX96,
|
|
2148
|
-
decimals0,
|
|
2149
|
-
decimals1
|
|
2150
|
-
);
|
|
2151
1918
|
const priceInverted = price > 0 ? 1 / price : 0;
|
|
2152
|
-
const
|
|
2153
|
-
const
|
|
1919
|
+
const balance0Formatted = Number((0, import_viem7.formatUnits)(balance0, decimals0));
|
|
1920
|
+
const balance1Formatted = Number((0, import_viem7.formatUnits)(balance1, decimals1));
|
|
1921
|
+
const subgraphPool = await tvlPromise;
|
|
1922
|
+
let liquidityAmounts;
|
|
1923
|
+
let tvlToken0;
|
|
1924
|
+
let tvlToken1;
|
|
2154
1925
|
let tvlUsd;
|
|
2155
|
-
if (
|
|
2156
|
-
const
|
|
2157
|
-
|
|
2158
|
-
|
|
1926
|
+
if (subgraphPool) {
|
|
1927
|
+
const amount0 = Number(subgraphPool.totalValueLockedToken0);
|
|
1928
|
+
const amount1 = Number(subgraphPool.totalValueLockedToken1);
|
|
1929
|
+
liquidityAmounts = { amount0, amount1 };
|
|
1930
|
+
tvlToken0 = amount0 + amount1 * priceInverted;
|
|
1931
|
+
tvlToken1 = amount1 + amount0 * price;
|
|
1932
|
+
const subgraphUsd = Number(subgraphPool.totalValueLockedUSD);
|
|
1933
|
+
if (Number.isFinite(subgraphUsd) && subgraphUsd > 0) {
|
|
1934
|
+
tvlUsd = subgraphUsd;
|
|
1935
|
+
} else if (prices) {
|
|
1936
|
+
const price0 = prices[symbol0] || prices[currency0.toLowerCase()];
|
|
1937
|
+
const price1 = prices[symbol1] || prices[currency1.toLowerCase()];
|
|
1938
|
+
if (price0) tvlUsd = tvlToken0 * price0;
|
|
1939
|
+
else if (price1) tvlUsd = tvlToken1 * price1;
|
|
1940
|
+
}
|
|
1941
|
+
} else {
|
|
1942
|
+
liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1943
|
+
liquidity ?? 0n,
|
|
1944
|
+
sqrtPriceX96,
|
|
1945
|
+
decimals0,
|
|
1946
|
+
decimals1
|
|
1947
|
+
);
|
|
1948
|
+
tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
|
|
1949
|
+
tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
|
|
1950
|
+
if (prices) {
|
|
1951
|
+
const price0 = prices[symbol0] || prices[currency0.toLowerCase()];
|
|
1952
|
+
const price1 = prices[symbol1] || prices[currency1.toLowerCase()];
|
|
1953
|
+
if (price0) tvlUsd = tvlToken0 * price0;
|
|
1954
|
+
else if (price1) tvlUsd = tvlToken1 * price1;
|
|
2159
1955
|
}
|
|
2160
1956
|
}
|
|
2161
1957
|
return {
|
|
@@ -2192,22 +1988,11 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2192
1988
|
}
|
|
2193
1989
|
|
|
2194
1990
|
// functions/getUserUniV4Positions.ts
|
|
2195
|
-
var
|
|
2196
|
-
var
|
|
2197
|
-
var
|
|
2198
|
-
var
|
|
2199
|
-
var
|
|
2200
|
-
var V4_SUBGRAPH_IDS = {
|
|
2201
|
-
[import_chains6.mainnet.id]: "DiYPVdygkfjDWhbxGSqAQxwBKmfKnkWQojqeM2rkLb3G"
|
|
2202
|
-
};
|
|
2203
|
-
function getV4SubgraphUrl(chainId, apiKey) {
|
|
2204
|
-
const subgraphId = V4_SUBGRAPH_IDS[chainId];
|
|
2205
|
-
if (!subgraphId) return null;
|
|
2206
|
-
if (apiKey) {
|
|
2207
|
-
return `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
|
|
2208
|
-
}
|
|
2209
|
-
return `https://gateway.thegraph.com/api/subgraphs/id/${subgraphId}`;
|
|
2210
|
-
}
|
|
1991
|
+
var import_core4 = require("@wagmi/core");
|
|
1992
|
+
var import_viem8 = require("viem");
|
|
1993
|
+
var import_chains5 = require("viem/chains");
|
|
1994
|
+
var import_graphql_request2 = require("graphql-request");
|
|
1995
|
+
var import_constants10 = require("@tokemak/constants");
|
|
2211
1996
|
var positionManagerAbi = [
|
|
2212
1997
|
{
|
|
2213
1998
|
inputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }],
|
|
@@ -2272,7 +2057,7 @@ var erc20Abi3 = [
|
|
|
2272
2057
|
type: "function"
|
|
2273
2058
|
}
|
|
2274
2059
|
];
|
|
2275
|
-
var GET_USER_POSITIONS =
|
|
2060
|
+
var GET_USER_POSITIONS = import_graphql_request2.gql`
|
|
2276
2061
|
query GetUserPositions($owner: String!) {
|
|
2277
2062
|
positions(where: { owner: $owner }) {
|
|
2278
2063
|
tokenId
|
|
@@ -2306,8 +2091,8 @@ function getTokenAmountsFromLiquidity(liquidity, sqrtPriceX96, tickLower, tickUp
|
|
|
2306
2091
|
amount1 = liquidity * (sqrtPriceX96 - sqrtPriceLower) / Q96;
|
|
2307
2092
|
}
|
|
2308
2093
|
return {
|
|
2309
|
-
amount0: Number((0,
|
|
2310
|
-
amount1: Number((0,
|
|
2094
|
+
amount0: Number((0, import_viem8.formatUnits)(amount0, token0Decimals)),
|
|
2095
|
+
amount1: Number((0, import_viem8.formatUnits)(amount1, token1Decimals))
|
|
2311
2096
|
};
|
|
2312
2097
|
}
|
|
2313
2098
|
function feeToTierString2(fee) {
|
|
@@ -2326,7 +2111,7 @@ async function getPositionTokenIdsFromSubgraph(userAddress, chainId, graphApiKey
|
|
|
2326
2111
|
return [];
|
|
2327
2112
|
}
|
|
2328
2113
|
try {
|
|
2329
|
-
const client = new
|
|
2114
|
+
const client = new import_graphql_request2.GraphQLClient(subgraphUrl);
|
|
2330
2115
|
const data = await client.request(GET_USER_POSITIONS, {
|
|
2331
2116
|
owner: userAddress.toLowerCase()
|
|
2332
2117
|
});
|
|
@@ -2344,13 +2129,13 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2344
2129
|
poolId,
|
|
2345
2130
|
currency0,
|
|
2346
2131
|
currency1,
|
|
2347
|
-
chainId =
|
|
2132
|
+
chainId = import_chains5.mainnet.id,
|
|
2348
2133
|
prices,
|
|
2349
2134
|
graphApiKey,
|
|
2350
2135
|
knownTokenIds
|
|
2351
2136
|
}) {
|
|
2352
|
-
const positionManager =
|
|
2353
|
-
const stateView =
|
|
2137
|
+
const positionManager = import_constants10.UNISWAP_V4_POSITION_MANAGER[chainId];
|
|
2138
|
+
const stateView = import_constants10.UNISWAP_V4_STATE_VIEW[chainId];
|
|
2354
2139
|
if (!positionManager || !stateView) {
|
|
2355
2140
|
console.error(`V4 contracts not found for chainId ${chainId}`);
|
|
2356
2141
|
return { positions: [], totalValueUsd: 0, totalPositions: 0 };
|
|
@@ -2360,11 +2145,10 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2360
2145
|
if (knownTokenIds && knownTokenIds.length > 0) {
|
|
2361
2146
|
tokenIds = knownTokenIds;
|
|
2362
2147
|
} else {
|
|
2363
|
-
const apiKey = graphApiKey || import_constants11.GRAPH_API_KEY;
|
|
2364
2148
|
tokenIds = await getPositionTokenIdsFromSubgraph(
|
|
2365
2149
|
userAddress,
|
|
2366
2150
|
chainId,
|
|
2367
|
-
|
|
2151
|
+
graphApiKey
|
|
2368
2152
|
);
|
|
2369
2153
|
}
|
|
2370
2154
|
if (tokenIds.length === 0) {
|
|
@@ -2386,7 +2170,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2386
2170
|
chainId
|
|
2387
2171
|
}
|
|
2388
2172
|
]);
|
|
2389
|
-
const positionResults = await (0,
|
|
2173
|
+
const positionResults = await (0, import_core4.readContracts)(wagmiConfig, {
|
|
2390
2174
|
contracts: positionInfoCalls
|
|
2391
2175
|
});
|
|
2392
2176
|
const matchingPositions = [];
|
|
@@ -2462,7 +2246,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2462
2246
|
}
|
|
2463
2247
|
] : []
|
|
2464
2248
|
];
|
|
2465
|
-
const infoResults = await (0,
|
|
2249
|
+
const infoResults = await (0, import_core4.readContracts)(wagmiConfig, {
|
|
2466
2250
|
contracts: infoCalls
|
|
2467
2251
|
});
|
|
2468
2252
|
const slot0 = infoResults[0]?.result;
|
|
@@ -2538,7 +2322,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2538
2322
|
async function getUserUniV4Positions(wagmiConfig, {
|
|
2539
2323
|
userAddress,
|
|
2540
2324
|
poolKey,
|
|
2541
|
-
chainId =
|
|
2325
|
+
chainId = import_chains5.mainnet.id,
|
|
2542
2326
|
prices,
|
|
2543
2327
|
graphApiKey,
|
|
2544
2328
|
knownTokenIds
|
|
@@ -2557,14 +2341,14 @@ async function getUserUniV4Positions(wagmiConfig, {
|
|
|
2557
2341
|
}
|
|
2558
2342
|
|
|
2559
2343
|
// functions/getDefillamaPoolApr.ts
|
|
2560
|
-
var
|
|
2344
|
+
var import_constants11 = require("@tokemak/constants");
|
|
2561
2345
|
var poolsCache = null;
|
|
2562
2346
|
var CACHE_TTL = 5 * 60 * 1e3;
|
|
2563
2347
|
async function fetchDefiLlamaPools() {
|
|
2564
2348
|
if (poolsCache && Date.now() - poolsCache.timestamp < CACHE_TTL) {
|
|
2565
2349
|
return poolsCache.data;
|
|
2566
2350
|
}
|
|
2567
|
-
const response = await fetch(
|
|
2351
|
+
const response = await fetch(import_constants11.DEFILLAMA_YIELDS_API);
|
|
2568
2352
|
if (!response.ok) {
|
|
2569
2353
|
throw new Error(`DefiLlama API request failed: ${response.statusText}`);
|
|
2570
2354
|
}
|
|
@@ -2617,9 +2401,9 @@ function clearDefillamaCache() {
|
|
|
2617
2401
|
}
|
|
2618
2402
|
|
|
2619
2403
|
// functions/getEthAutoLP.ts
|
|
2620
|
-
var
|
|
2404
|
+
var import_chains6 = require("viem/chains");
|
|
2621
2405
|
var import_tokenlist4 = require("@tokemak/tokenlist");
|
|
2622
|
-
var
|
|
2406
|
+
var import_constants12 = require("@tokemak/constants");
|
|
2623
2407
|
|
|
2624
2408
|
// functions/getMerklCreatorApr.ts
|
|
2625
2409
|
var import_api = require("@merkl/api");
|
|
@@ -2668,11 +2452,11 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2668
2452
|
const currency0 = import_tokenlist4.ETH_TOKEN.address;
|
|
2669
2453
|
const currency1 = import_tokenlist4.AUTO_TOKEN.address;
|
|
2670
2454
|
const poolData = await getUniV4PoolById(wagmiConfig, {
|
|
2671
|
-
poolId:
|
|
2455
|
+
poolId: import_constants12.ETH_AUTO_V4_POOL_ID,
|
|
2672
2456
|
currency0,
|
|
2673
2457
|
currency1,
|
|
2674
|
-
fee:
|
|
2675
|
-
chainId:
|
|
2458
|
+
fee: import_constants12.ETH_AUTO_FEE_TIER,
|
|
2459
|
+
chainId: import_chains6.mainnet.id,
|
|
2676
2460
|
prices
|
|
2677
2461
|
});
|
|
2678
2462
|
if (!poolData) {
|
|
@@ -2681,8 +2465,8 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2681
2465
|
let apr = void 0;
|
|
2682
2466
|
try {
|
|
2683
2467
|
const aprResult = await getMerklCreatorApr({
|
|
2684
|
-
creatorAddress:
|
|
2685
|
-
identifier:
|
|
2468
|
+
creatorAddress: import_constants12.MERKL_CREATOR_ADDRESS,
|
|
2469
|
+
identifier: import_constants12.UNI_V4_POOL_ID
|
|
2686
2470
|
});
|
|
2687
2471
|
apr = aprResult?.totalApr;
|
|
2688
2472
|
} catch (error) {
|
|
@@ -2695,12 +2479,12 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2695
2479
|
}
|
|
2696
2480
|
|
|
2697
2481
|
// functions/getUserEthAutoLP.ts
|
|
2698
|
-
var
|
|
2482
|
+
var import_chains7 = require("viem/chains");
|
|
2699
2483
|
var import_tokenlist5 = require("@tokemak/tokenlist");
|
|
2700
|
-
var
|
|
2484
|
+
var import_constants13 = require("@tokemak/constants");
|
|
2701
2485
|
async function getUserEthAutoLP(wagmiConfig, {
|
|
2702
2486
|
userAddress,
|
|
2703
|
-
chainId =
|
|
2487
|
+
chainId = import_chains7.mainnet.id,
|
|
2704
2488
|
prices,
|
|
2705
2489
|
graphApiKey,
|
|
2706
2490
|
knownTokenIds
|
|
@@ -2709,7 +2493,7 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2709
2493
|
const currency1 = import_tokenlist5.AUTO_TOKEN.address;
|
|
2710
2494
|
return getUserUniV4PositionsById(wagmiConfig, {
|
|
2711
2495
|
userAddress,
|
|
2712
|
-
poolId:
|
|
2496
|
+
poolId: import_constants13.ETH_AUTO_V4_POOL_ID,
|
|
2713
2497
|
currency0,
|
|
2714
2498
|
currency1,
|
|
2715
2499
|
chainId,
|
|
@@ -2720,9 +2504,9 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2720
2504
|
}
|
|
2721
2505
|
|
|
2722
2506
|
// functions/getChainUserActivity.ts
|
|
2723
|
-
var
|
|
2507
|
+
var import_graph_cli7 = require("@tokemak/graph-cli");
|
|
2724
2508
|
var getChainUserActivity = async (address, chainId = 1) => {
|
|
2725
|
-
const { GetUserBalanceChangeHistory } = (0,
|
|
2509
|
+
const { GetUserBalanceChangeHistory } = (0, import_graph_cli7.getSdkByChainId)(chainId);
|
|
2726
2510
|
try {
|
|
2727
2511
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
2728
2512
|
(vars) => GetUserBalanceChangeHistory({
|
|
@@ -2809,8 +2593,8 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
|
|
|
2809
2593
|
};
|
|
2810
2594
|
|
|
2811
2595
|
// functions/getUserAutoEthRewards.ts
|
|
2812
|
-
var
|
|
2813
|
-
var
|
|
2596
|
+
var import_abis3 = require("@tokemak/abis");
|
|
2597
|
+
var import_core5 = require("@wagmi/core");
|
|
2814
2598
|
var import_utils17 = require("@tokemak/utils");
|
|
2815
2599
|
var getAutoEthRewards = async (wagmiConfig, {
|
|
2816
2600
|
account,
|
|
@@ -2820,16 +2604,16 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2820
2604
|
chainId
|
|
2821
2605
|
}) => {
|
|
2822
2606
|
try {
|
|
2823
|
-
const [, drippingHash] = await (0,
|
|
2607
|
+
const [, drippingHash] = await (0, import_core5.readContract)(wagmiConfig, {
|
|
2824
2608
|
address: rewardsHash,
|
|
2825
|
-
abi:
|
|
2609
|
+
abi: import_abis3.autoEthRewardsHashAbi,
|
|
2826
2610
|
functionName: "cycleHashes",
|
|
2827
2611
|
args: [currentCycleIndex - 306n],
|
|
2828
2612
|
chainId
|
|
2829
2613
|
});
|
|
2830
|
-
const [, lastWeekHash] = await (0,
|
|
2614
|
+
const [, lastWeekHash] = await (0, import_core5.readContract)(wagmiConfig, {
|
|
2831
2615
|
address: rewardsHash,
|
|
2832
|
-
abi:
|
|
2616
|
+
abi: import_abis3.autoEthRewardsHashAbi,
|
|
2833
2617
|
functionName: "cycleHashes",
|
|
2834
2618
|
// -1 to get the previous cycle
|
|
2835
2619
|
args: [currentCycleIndex - 306n - 1n],
|
|
@@ -2877,8 +2661,8 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
|
|
|
2877
2661
|
};
|
|
2878
2662
|
|
|
2879
2663
|
// functions/getUserRewardsV1.ts
|
|
2880
|
-
var
|
|
2881
|
-
var
|
|
2664
|
+
var import_abis4 = require("@tokemak/abis");
|
|
2665
|
+
var import_core6 = require("@wagmi/core");
|
|
2882
2666
|
var getUserRewardsV1 = async (wagmiConfig, {
|
|
2883
2667
|
address,
|
|
2884
2668
|
rewardsCycleIndex,
|
|
@@ -2888,11 +2672,11 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2888
2672
|
chainId
|
|
2889
2673
|
}) => {
|
|
2890
2674
|
try {
|
|
2891
|
-
const [latestClaimableHash, cycleRewardsHash] = await (0,
|
|
2675
|
+
const [latestClaimableHash, cycleRewardsHash] = await (0, import_core6.readContract)(
|
|
2892
2676
|
wagmiConfig,
|
|
2893
2677
|
{
|
|
2894
2678
|
address: rewardsV1Hash,
|
|
2895
|
-
abi:
|
|
2679
|
+
abi: import_abis4.rewardsV1HashAbi,
|
|
2896
2680
|
functionName: "cycleHashes",
|
|
2897
2681
|
args: [rewardsCycleIndex],
|
|
2898
2682
|
chainId
|
|
@@ -2912,9 +2696,9 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2912
2696
|
const {
|
|
2913
2697
|
payload: { chainId: payloadChainId, cycle, wallet, amount }
|
|
2914
2698
|
} = latestClaimablePayload;
|
|
2915
|
-
const claimable = await (0,
|
|
2699
|
+
const claimable = await (0, import_core6.readContract)(wagmiConfig, {
|
|
2916
2700
|
address: rewardsV1,
|
|
2917
|
-
abi:
|
|
2701
|
+
abi: import_abis4.rewardsV1Abi,
|
|
2918
2702
|
functionName: "getClaimableAmount",
|
|
2919
2703
|
args: [{ chainId: payloadChainId, cycle, wallet, amount }],
|
|
2920
2704
|
chainId
|
|
@@ -2927,126 +2711,19 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2927
2711
|
}
|
|
2928
2712
|
};
|
|
2929
2713
|
|
|
2930
|
-
// functions/getUserV1.ts
|
|
2931
|
-
var import_abis6 = require("@tokemak/abis");
|
|
2932
|
-
var import_core8 = require("@wagmi/core");
|
|
2933
|
-
var import_config5 = require("@tokemak/config");
|
|
2934
|
-
var import_chains9 = require("viem/chains");
|
|
2935
|
-
var getUserV1 = async (wagmiConfig, {
|
|
2936
|
-
currentCycleIndex,
|
|
2937
|
-
address,
|
|
2938
|
-
chainId
|
|
2939
|
-
}) => {
|
|
2940
|
-
const {
|
|
2941
|
-
stakingV1,
|
|
2942
|
-
rewardsV1Url,
|
|
2943
|
-
accTokeV1RewardsHash,
|
|
2944
|
-
rewardsV1Hash,
|
|
2945
|
-
accTokeV1Rewards,
|
|
2946
|
-
autoEthGuardedRewards,
|
|
2947
|
-
rewardsV1,
|
|
2948
|
-
missedTokeRewards
|
|
2949
|
-
} = (0, import_config5.getMainnetConfig)(import_chains9.mainnet.id);
|
|
2950
|
-
try {
|
|
2951
|
-
const userStakedTokeV1 = await (0, import_core8.readContract)(wagmiConfig, {
|
|
2952
|
-
address: stakingV1,
|
|
2953
|
-
abi: import_abis6.stakingV1Abi,
|
|
2954
|
-
functionName: "availableForWithdrawal",
|
|
2955
|
-
args: [address, 0n],
|
|
2956
|
-
chainId: import_chains9.mainnet.id
|
|
2957
|
-
});
|
|
2958
|
-
const tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
2959
|
-
address,
|
|
2960
|
-
rewardsCycleIndex: currentCycleIndex - 1n,
|
|
2961
|
-
rewardsV1,
|
|
2962
|
-
rewardsV1Url,
|
|
2963
|
-
rewardsV1Hash,
|
|
2964
|
-
chainId
|
|
2965
|
-
});
|
|
2966
|
-
const ethRewards = await getUserRewardsV1(wagmiConfig, {
|
|
2967
|
-
address,
|
|
2968
|
-
rewardsCycleIndex: 306n,
|
|
2969
|
-
rewardsV1: accTokeV1Rewards,
|
|
2970
|
-
rewardsV1Url,
|
|
2971
|
-
rewardsV1Hash: accTokeV1RewardsHash,
|
|
2972
|
-
chainId
|
|
2973
|
-
});
|
|
2974
|
-
const autoEthGuardedRewardsPayload = await getRewardsPayloadV1(
|
|
2975
|
-
"QmcJgQ42aGTsqngSBa98qxnbv2CHyk9DmSg1jDD569bnpp",
|
|
2976
|
-
address,
|
|
2977
|
-
rewardsV1Url
|
|
2978
|
-
);
|
|
2979
|
-
const payloadChainId = autoEthGuardedRewardsPayload?.payload?.chainId;
|
|
2980
|
-
const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
|
|
2981
|
-
const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
|
|
2982
|
-
const amount = autoEthGuardedRewardsPayload?.payload?.amount;
|
|
2983
|
-
const claimableAutoEth = await (0, import_core8.readContract)(wagmiConfig, {
|
|
2984
|
-
address: autoEthGuardedRewards,
|
|
2985
|
-
abi: import_abis6.rewardsV1Abi,
|
|
2986
|
-
functionName: "getClaimableAmount",
|
|
2987
|
-
args: [
|
|
2988
|
-
{
|
|
2989
|
-
chainId: payloadChainId || 0n,
|
|
2990
|
-
cycle: cycle || 0n,
|
|
2991
|
-
wallet: wallet || "0x0000000000000000000000000000000000000000",
|
|
2992
|
-
amount: amount || 0n
|
|
2993
|
-
}
|
|
2994
|
-
],
|
|
2995
|
-
chainId
|
|
2996
|
-
});
|
|
2997
|
-
const missedTokeRewardsPayload = await getRewardsPayloadV1(
|
|
2998
|
-
"QmRpVjVhFqbUTtLnQ4addEwBtvF2CC7t6rbQWYiju9nAqd",
|
|
2999
|
-
address,
|
|
3000
|
-
rewardsV1Url
|
|
3001
|
-
);
|
|
3002
|
-
let claimableMissedToke = 0n;
|
|
3003
|
-
if (missedTokeRewardsPayload) {
|
|
3004
|
-
const {
|
|
3005
|
-
payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
|
|
3006
|
-
} = missedTokeRewardsPayload;
|
|
3007
|
-
claimableMissedToke = await (0, import_core8.readContract)(wagmiConfig, {
|
|
3008
|
-
address: missedTokeRewards,
|
|
3009
|
-
abi: import_abis6.rewardsV1Abi,
|
|
3010
|
-
functionName: "getClaimableAmount",
|
|
3011
|
-
args: [
|
|
3012
|
-
{
|
|
3013
|
-
chainId: payloadChainId2,
|
|
3014
|
-
cycle: cycle2,
|
|
3015
|
-
wallet: wallet2,
|
|
3016
|
-
amount: amount2 || 0n
|
|
3017
|
-
}
|
|
3018
|
-
],
|
|
3019
|
-
chainId
|
|
3020
|
-
});
|
|
3021
|
-
}
|
|
3022
|
-
return {
|
|
3023
|
-
stakedToke: userStakedTokeV1,
|
|
3024
|
-
claimableToke: tokeRewards?.claimable,
|
|
3025
|
-
claimableEth: ethRewards?.claimable,
|
|
3026
|
-
claimableAutoEth,
|
|
3027
|
-
tokeRewardsPayload: tokeRewards?.rewardsPayload,
|
|
3028
|
-
ethRewardsPayload: ethRewards?.rewardsPayload,
|
|
3029
|
-
missedTokeRewardsPayload,
|
|
3030
|
-
autoEthGuardedRewardsPayload,
|
|
3031
|
-
claimableMissedToke
|
|
3032
|
-
};
|
|
3033
|
-
} catch (e) {
|
|
3034
|
-
}
|
|
3035
|
-
};
|
|
3036
|
-
|
|
3037
2714
|
// functions/getChainUserAutopoolsHistory.tsx
|
|
3038
|
-
var
|
|
3039
|
-
var
|
|
2715
|
+
var import_graph_cli8 = require("@tokemak/graph-cli");
|
|
2716
|
+
var import_constants14 = require("@tokemak/constants");
|
|
3040
2717
|
var getChainUserAutopoolsHistory = async ({
|
|
3041
2718
|
address,
|
|
3042
2719
|
chainId = 1
|
|
3043
2720
|
}) => {
|
|
3044
|
-
const { GetUserVaultsDayData } = (0,
|
|
2721
|
+
const { GetUserVaultsDayData } = (0, import_graph_cli8.getSdkByChainId)(chainId);
|
|
3045
2722
|
try {
|
|
3046
2723
|
if (address) {
|
|
3047
2724
|
const { userVaultDayDatas } = await GetUserVaultsDayData({
|
|
3048
2725
|
address,
|
|
3049
|
-
timestamp:
|
|
2726
|
+
timestamp: import_constants14.TOKEMAK_LAUNCH_TIMESTAMP
|
|
3050
2727
|
});
|
|
3051
2728
|
return userVaultDayDatas;
|
|
3052
2729
|
}
|
|
@@ -3061,12 +2738,12 @@ var getChainUserAutopoolsHistory = async ({
|
|
|
3061
2738
|
var import_utils21 = require("@tokemak/utils");
|
|
3062
2739
|
|
|
3063
2740
|
// functions/getTokenValueDayDatas.ts
|
|
3064
|
-
var
|
|
2741
|
+
var import_chains8 = require("viem/chains");
|
|
3065
2742
|
var import_utils18 = require("@tokemak/utils");
|
|
3066
|
-
var
|
|
3067
|
-
var
|
|
3068
|
-
var getTokenValueDayDatas = async (tokenAddress, chainId =
|
|
3069
|
-
const { GetTokenValueDayDatas } = (0,
|
|
2743
|
+
var import_viem9 = require("viem");
|
|
2744
|
+
var import_graph_cli9 = require("@tokemak/graph-cli");
|
|
2745
|
+
var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains8.mainnet.id) => {
|
|
2746
|
+
const { GetTokenValueDayDatas } = (0, import_graph_cli9.getSdkByChainId)(chainId);
|
|
3070
2747
|
try {
|
|
3071
2748
|
const { tokenValueDayDatas } = await GetTokenValueDayDatas({
|
|
3072
2749
|
tokenAddress: tokenAddress.toLowerCase()
|
|
@@ -3075,7 +2752,7 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainn
|
|
|
3075
2752
|
const date = (0, import_utils18.convertTimestampToDate)(
|
|
3076
2753
|
tokenValueDayData.lastSnapshotTimestamp
|
|
3077
2754
|
);
|
|
3078
|
-
const usdPrice = (0,
|
|
2755
|
+
const usdPrice = (0, import_viem9.formatUnits)(tokenValueDayData.priceInUsd, 8);
|
|
3079
2756
|
return {
|
|
3080
2757
|
timestamp: Number(tokenValueDayData.lastSnapshotTimestamp),
|
|
3081
2758
|
date,
|
|
@@ -3374,212 +3051,13 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3374
3051
|
return result;
|
|
3375
3052
|
};
|
|
3376
3053
|
|
|
3377
|
-
// functions/getUserSushiLP.ts
|
|
3378
|
-
var import_core9 = require("@wagmi/core");
|
|
3379
|
-
var import_abis7 = require("@tokemak/abis");
|
|
3380
|
-
var import_config6 = require("@tokemak/config");
|
|
3381
|
-
var getUserSushiLP = async (wagmiConfig, {
|
|
3382
|
-
sushiLP,
|
|
3383
|
-
currentCycleIndex,
|
|
3384
|
-
address,
|
|
3385
|
-
cycleRolloverBlockNumber,
|
|
3386
|
-
chainId
|
|
3387
|
-
}) => {
|
|
3388
|
-
const { tSushiLP, sushiPool } = (0, import_config6.getMainnetConfig)();
|
|
3389
|
-
try {
|
|
3390
|
-
if (address && currentCycleIndex && sushiLP) {
|
|
3391
|
-
const [
|
|
3392
|
-
{ result: sushiLPBalance },
|
|
3393
|
-
{ result: tSushiLPBalance },
|
|
3394
|
-
{ result: tSushiLPRequested }
|
|
3395
|
-
] = await (0, import_core9.readContracts)(wagmiConfig, {
|
|
3396
|
-
contracts: [
|
|
3397
|
-
{
|
|
3398
|
-
address: sushiPool,
|
|
3399
|
-
abi: import_abis7.sushiPoolAbi,
|
|
3400
|
-
functionName: "balanceOf",
|
|
3401
|
-
args: [address],
|
|
3402
|
-
chainId
|
|
3403
|
-
},
|
|
3404
|
-
{
|
|
3405
|
-
address: tSushiLP,
|
|
3406
|
-
abi: import_abis7.poolV1Abi,
|
|
3407
|
-
functionName: "balanceOf",
|
|
3408
|
-
args: [address],
|
|
3409
|
-
chainId
|
|
3410
|
-
},
|
|
3411
|
-
{
|
|
3412
|
-
address: tSushiLP,
|
|
3413
|
-
abi: import_abis7.poolV1Abi,
|
|
3414
|
-
functionName: "requestedWithdrawals",
|
|
3415
|
-
args: [address],
|
|
3416
|
-
chainId
|
|
3417
|
-
}
|
|
3418
|
-
]
|
|
3419
|
-
});
|
|
3420
|
-
const [
|
|
3421
|
-
{ result: startTSushiLPBalance },
|
|
3422
|
-
{ result: startTSushiLPRequested }
|
|
3423
|
-
] = await (0, import_core9.readContracts)(wagmiConfig, {
|
|
3424
|
-
contracts: [
|
|
3425
|
-
{
|
|
3426
|
-
address: tSushiLP,
|
|
3427
|
-
abi: import_abis7.poolV1Abi,
|
|
3428
|
-
functionName: "balanceOf",
|
|
3429
|
-
args: [address],
|
|
3430
|
-
chainId
|
|
3431
|
-
},
|
|
3432
|
-
{
|
|
3433
|
-
address: tSushiLP,
|
|
3434
|
-
abi: import_abis7.poolV1Abi,
|
|
3435
|
-
functionName: "requestedWithdrawals",
|
|
3436
|
-
args: [address],
|
|
3437
|
-
chainId
|
|
3438
|
-
}
|
|
3439
|
-
],
|
|
3440
|
-
blockNumber: cycleRolloverBlockNumber
|
|
3441
|
-
});
|
|
3442
|
-
const startTSushiWithdrawAmount = startTSushiLPRequested?.[1] || 0n;
|
|
3443
|
-
const yieldingBalance = (startTSushiLPBalance || 0n) - startTSushiWithdrawAmount;
|
|
3444
|
-
let balanceExcludingWithdrawal = tSushiLPBalance || 0n;
|
|
3445
|
-
const [withdrawalMinCycle, withdrawalAmount] = tSushiLPRequested || [
|
|
3446
|
-
0n,
|
|
3447
|
-
0n
|
|
3448
|
-
];
|
|
3449
|
-
if (withdrawalAmount > 0n && currentCycleIndex >= withdrawalMinCycle) {
|
|
3450
|
-
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
3451
|
-
}
|
|
3452
|
-
const shareOftSushiLP = Number(balanceExcludingWithdrawal) / Number(sushiLP.totalSupply);
|
|
3453
|
-
const tSushiLPUsd = sushiLP.tvl * shareOftSushiLP;
|
|
3454
|
-
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
3455
|
-
const hasUnlockableBalance = withdrawalMinCycle <= currentCycleIndex && withdrawalAmount > 0n;
|
|
3456
|
-
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
3457
|
-
return {
|
|
3458
|
-
sushiLPBalance,
|
|
3459
|
-
tSushiLPBalance,
|
|
3460
|
-
tSushiLPRequested,
|
|
3461
|
-
shareOftSushiLP,
|
|
3462
|
-
tSushiLPUsd,
|
|
3463
|
-
balanceExcludingWithdrawal,
|
|
3464
|
-
hasAddedTSushi: yieldingBalance < balanceExcludingWithdrawal,
|
|
3465
|
-
hasRequestedUnlock,
|
|
3466
|
-
hasUnlockableBalance,
|
|
3467
|
-
withdrawalAmount,
|
|
3468
|
-
hasBalanceExcludingWithdrawal
|
|
3469
|
-
};
|
|
3470
|
-
}
|
|
3471
|
-
} catch (e) {
|
|
3472
|
-
console.log(e);
|
|
3473
|
-
}
|
|
3474
|
-
};
|
|
3475
|
-
|
|
3476
|
-
// functions/getUserCurveLP.ts
|
|
3477
|
-
var import_core10 = require("@wagmi/core");
|
|
3478
|
-
var import_abis8 = require("@tokemak/abis");
|
|
3479
|
-
var import_config7 = require("@tokemak/config");
|
|
3480
|
-
var getUserCurveLP = async (wagmiConfig, {
|
|
3481
|
-
curveLP,
|
|
3482
|
-
address,
|
|
3483
|
-
chainId
|
|
3484
|
-
}) => {
|
|
3485
|
-
try {
|
|
3486
|
-
const { curvePool, convexRewarder } = (0, import_config7.getMainnetConfig)();
|
|
3487
|
-
if (address && curveLP && curvePool && convexRewarder) {
|
|
3488
|
-
const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await (0, import_core10.readContracts)(wagmiConfig, {
|
|
3489
|
-
contracts: [
|
|
3490
|
-
{
|
|
3491
|
-
address: curvePool,
|
|
3492
|
-
abi: import_abis8.poolV1Abi,
|
|
3493
|
-
functionName: "balanceOf",
|
|
3494
|
-
args: [address],
|
|
3495
|
-
chainId
|
|
3496
|
-
},
|
|
3497
|
-
{
|
|
3498
|
-
address: convexRewarder,
|
|
3499
|
-
abi: import_abis8.poolV1Abi,
|
|
3500
|
-
functionName: "balanceOf",
|
|
3501
|
-
args: [address],
|
|
3502
|
-
chainId
|
|
3503
|
-
}
|
|
3504
|
-
]
|
|
3505
|
-
});
|
|
3506
|
-
const shareOfCurve = Number(userCurveLPBalance || 0n) / Number(curveLP.totalSupply);
|
|
3507
|
-
const shareOfConvex = Number(userConvexLPBalance || 0n) / Number(curveLP.totalSupply);
|
|
3508
|
-
const curveLPUsd = shareOfCurve * curveLP.curveTvl;
|
|
3509
|
-
const convexLPUsd = shareOfConvex * curveLP.curveTvl;
|
|
3510
|
-
return {
|
|
3511
|
-
curveLPBalance: userCurveLPBalance,
|
|
3512
|
-
convexLPBalance: userConvexLPBalance,
|
|
3513
|
-
shareOfCurve,
|
|
3514
|
-
shareOfConvex,
|
|
3515
|
-
curveLPUsd,
|
|
3516
|
-
convexLPUsd
|
|
3517
|
-
};
|
|
3518
|
-
}
|
|
3519
|
-
} catch (e) {
|
|
3520
|
-
console.log(e);
|
|
3521
|
-
}
|
|
3522
|
-
};
|
|
3523
|
-
|
|
3524
|
-
// functions/getMultipleAutopoolRebalances.ts
|
|
3525
|
-
var import_graph_cli11 = require("@tokemak/graph-cli");
|
|
3526
|
-
var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
3527
|
-
const { GetMutlipleAutopoolRebalances } = (0, import_graph_cli11.getSdkByChainId)(chainId);
|
|
3528
|
-
const { autopools } = await GetMutlipleAutopoolRebalances({
|
|
3529
|
-
addresses: ids
|
|
3530
|
-
});
|
|
3531
|
-
const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
|
|
3532
|
-
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
3533
|
-
};
|
|
3534
|
-
|
|
3535
|
-
// functions/getSystemConfig.ts
|
|
3536
|
-
var import_core11 = require("@wagmi/core");
|
|
3537
|
-
var import_abis9 = require("@tokemak/abis");
|
|
3538
|
-
var systemRegistryFunctionNames = [
|
|
3539
|
-
"asyncSwapperRegistry",
|
|
3540
|
-
"autoPoolRouter",
|
|
3541
|
-
"autoPoolRegistry",
|
|
3542
|
-
"swapRouter",
|
|
3543
|
-
"weth"
|
|
3544
|
-
];
|
|
3545
|
-
var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
3546
|
-
const systemRegistryContract = {
|
|
3547
|
-
address: systemRegistry,
|
|
3548
|
-
abi: import_abis9.systemRegistryAbi
|
|
3549
|
-
};
|
|
3550
|
-
const systemRegistryCalls = systemRegistryFunctionNames.map(
|
|
3551
|
-
(functionName) => ({
|
|
3552
|
-
...systemRegistryContract,
|
|
3553
|
-
functionName
|
|
3554
|
-
})
|
|
3555
|
-
);
|
|
3556
|
-
try {
|
|
3557
|
-
const [
|
|
3558
|
-
{ result: asyncSwapperRegistry },
|
|
3559
|
-
{ result: autopoolRouter },
|
|
3560
|
-
{ result: autopoolRegistry },
|
|
3561
|
-
{ result: swapRouter }
|
|
3562
|
-
] = await (0, import_core11.readContracts)(wagmiConfig, {
|
|
3563
|
-
contracts: systemRegistryCalls
|
|
3564
|
-
});
|
|
3565
|
-
return {
|
|
3566
|
-
asyncSwapperRegistry,
|
|
3567
|
-
autopoolRouter,
|
|
3568
|
-
autopoolRegistry,
|
|
3569
|
-
swapRouter
|
|
3570
|
-
};
|
|
3571
|
-
} catch (e) {
|
|
3572
|
-
console.log(e);
|
|
3573
|
-
}
|
|
3574
|
-
};
|
|
3575
|
-
|
|
3576
3054
|
// functions/getChainUserAutopools.tsx
|
|
3577
|
-
var
|
|
3055
|
+
var import_graph_cli10 = require("@tokemak/graph-cli");
|
|
3578
3056
|
var getChainUserAutopools = async ({
|
|
3579
3057
|
address,
|
|
3580
3058
|
chainId = 1
|
|
3581
3059
|
}) => {
|
|
3582
|
-
const { GetUserVaultInfo } = (0,
|
|
3060
|
+
const { GetUserVaultInfo } = (0, import_graph_cli10.getSdkByChainId)(chainId);
|
|
3583
3061
|
try {
|
|
3584
3062
|
if (address) {
|
|
3585
3063
|
const { userInfo } = await GetUserVaultInfo({
|
|
@@ -3599,10 +3077,10 @@ var import_utils23 = require("@tokemak/utils");
|
|
|
3599
3077
|
var import_tokenlist7 = require("@tokemak/tokenlist");
|
|
3600
3078
|
|
|
3601
3079
|
// functions/getUserAutopool.tsx
|
|
3602
|
-
var
|
|
3603
|
-
var
|
|
3080
|
+
var import_viem10 = require("viem");
|
|
3081
|
+
var import_core7 = require("@wagmi/core");
|
|
3604
3082
|
var import_utils22 = require("@tokemak/utils");
|
|
3605
|
-
var
|
|
3083
|
+
var import_abis5 = require("@tokemak/abis");
|
|
3606
3084
|
var getUserAutopool = async (wagmiConfig, {
|
|
3607
3085
|
address,
|
|
3608
3086
|
autopool
|
|
@@ -3611,14 +3089,14 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3611
3089
|
if (autopool && address) {
|
|
3612
3090
|
const autopoolContract = {
|
|
3613
3091
|
address: autopool?.poolAddress,
|
|
3614
|
-
abi:
|
|
3092
|
+
abi: import_abis5.autopoolEthAbi,
|
|
3615
3093
|
chainId: autopool?.chain?.chainId
|
|
3616
3094
|
};
|
|
3617
3095
|
const [
|
|
3618
3096
|
{ result: autopoolRewarderContract },
|
|
3619
3097
|
{ result: pastRewarders },
|
|
3620
3098
|
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
3621
|
-
] = await (0,
|
|
3099
|
+
] = await (0, import_core7.readContracts)(wagmiConfig, {
|
|
3622
3100
|
contracts: [
|
|
3623
3101
|
{
|
|
3624
3102
|
...autopoolContract,
|
|
@@ -3643,9 +3121,9 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3643
3121
|
if (unstakedPoolSharesError) {
|
|
3644
3122
|
throw new Error("Error fetching unstaked pool shares");
|
|
3645
3123
|
}
|
|
3646
|
-
const stakedPoolShares = await (0,
|
|
3124
|
+
const stakedPoolShares = await (0, import_core7.readContract)(wagmiConfig, {
|
|
3647
3125
|
address: autopoolRewarderContract,
|
|
3648
|
-
abi:
|
|
3126
|
+
abi: import_viem10.erc20Abi,
|
|
3649
3127
|
functionName: "balanceOf",
|
|
3650
3128
|
args: [address],
|
|
3651
3129
|
chainId: autopool?.chain?.chainId
|
|
@@ -3664,12 +3142,12 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3664
3142
|
if (pastRewarders && pastRewarders?.length > 0) {
|
|
3665
3143
|
const pastRewardBalances = pastRewarders.map((rewarder) => ({
|
|
3666
3144
|
address: rewarder,
|
|
3667
|
-
abi:
|
|
3145
|
+
abi: import_viem10.erc20Abi,
|
|
3668
3146
|
functionName: "balanceOf",
|
|
3669
3147
|
args: [address],
|
|
3670
3148
|
chainId: autopool?.chain?.chainId
|
|
3671
3149
|
}));
|
|
3672
|
-
const pastRewards = await (0,
|
|
3150
|
+
const pastRewards = await (0, import_core7.readContracts)(wagmiConfig, {
|
|
3673
3151
|
contracts: pastRewardBalances
|
|
3674
3152
|
});
|
|
3675
3153
|
pastRewarderBalances = pastRewards.map(({ result }, index) => {
|
|
@@ -4120,7 +3598,7 @@ var getUserAutopools = async ({
|
|
|
4120
3598
|
};
|
|
4121
3599
|
|
|
4122
3600
|
// functions/getUserTokenBalances.ts
|
|
4123
|
-
var
|
|
3601
|
+
var import_viem11 = require("viem");
|
|
4124
3602
|
var networkToAlchemyUrl = (chainId) => {
|
|
4125
3603
|
return `https://rpc.autopool-services.com/${chainId}/ui`;
|
|
4126
3604
|
};
|
|
@@ -4149,7 +3627,7 @@ var getUserTokenBalances = async ({
|
|
|
4149
3627
|
const tokenBalances = data.result.tokenBalances.reduce(
|
|
4150
3628
|
(acc, balance) => {
|
|
4151
3629
|
if (balance.tokenBalance && BigInt(balance.tokenBalance) !== BigInt(0)) {
|
|
4152
|
-
acc[balance.contractAddress] = (0,
|
|
3630
|
+
acc[balance.contractAddress] = (0, import_viem11.hexToBigInt)(
|
|
4153
3631
|
balance.tokenBalance
|
|
4154
3632
|
);
|
|
4155
3633
|
}
|
|
@@ -4160,25 +3638,11 @@ var getUserTokenBalances = async ({
|
|
|
4160
3638
|
return tokenBalances;
|
|
4161
3639
|
};
|
|
4162
3640
|
|
|
4163
|
-
// functions/getTokenList.ts
|
|
4164
|
-
var import_tokenlist8 = require("@tokemak/tokenlist");
|
|
4165
|
-
var getTokenList = async () => {
|
|
4166
|
-
try {
|
|
4167
|
-
let url = `${import_tokenlist8.TOKEMAK_LISTS_URL}/swap_enabled.json`;
|
|
4168
|
-
const listResponse = await fetch(url);
|
|
4169
|
-
const { tokens: tokenList } = await listResponse.json();
|
|
4170
|
-
return tokenList;
|
|
4171
|
-
} catch (e) {
|
|
4172
|
-
console.log(e);
|
|
4173
|
-
return [];
|
|
4174
|
-
}
|
|
4175
|
-
};
|
|
4176
|
-
|
|
4177
3641
|
// functions/getTopAutopoolHolders.ts
|
|
4178
|
-
var
|
|
3642
|
+
var import_graph_cli11 = require("@tokemak/graph-cli");
|
|
4179
3643
|
var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
4180
3644
|
try {
|
|
4181
|
-
const { GetTopAutopoolHolders } = (0,
|
|
3645
|
+
const { GetTopAutopoolHolders } = (0, import_graph_cli11.getSdkByChainId)(chainId);
|
|
4182
3646
|
const { holders } = await GetTopAutopoolHolders({
|
|
4183
3647
|
address: autopoolAddress
|
|
4184
3648
|
});
|
|
@@ -4189,27 +3653,6 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
|
4189
3653
|
}
|
|
4190
3654
|
};
|
|
4191
3655
|
|
|
4192
|
-
// functions/getAllowance.ts
|
|
4193
|
-
var import_core13 = require("@wagmi/core");
|
|
4194
|
-
var import_viem13 = require("viem");
|
|
4195
|
-
var getAllowance = async (wagmiConfig, {
|
|
4196
|
-
token,
|
|
4197
|
-
address,
|
|
4198
|
-
spender
|
|
4199
|
-
}) => {
|
|
4200
|
-
try {
|
|
4201
|
-
const allowance = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4202
|
-
address: token,
|
|
4203
|
-
abi: import_viem13.erc20Abi,
|
|
4204
|
-
functionName: "allowance",
|
|
4205
|
-
args: [address || "0x0", spender]
|
|
4206
|
-
});
|
|
4207
|
-
return allowance;
|
|
4208
|
-
} catch (e) {
|
|
4209
|
-
console.error(e);
|
|
4210
|
-
}
|
|
4211
|
-
};
|
|
4212
|
-
|
|
4213
3656
|
// functions/getUserActivity.ts
|
|
4214
3657
|
var getUserActivity = async ({
|
|
4215
3658
|
address,
|
|
@@ -4241,21 +3684,21 @@ var getUserActivity = async ({
|
|
|
4241
3684
|
};
|
|
4242
3685
|
|
|
4243
3686
|
// functions/getUserAutopoolsRewards.ts
|
|
4244
|
-
var
|
|
3687
|
+
var import_viem12 = require("viem");
|
|
4245
3688
|
|
|
4246
3689
|
// functions/getChainUserAutopoolsRewards.ts
|
|
4247
|
-
var
|
|
4248
|
-
var
|
|
4249
|
-
var
|
|
3690
|
+
var import_config4 = require("@tokemak/config");
|
|
3691
|
+
var import_core8 = require("@wagmi/core");
|
|
3692
|
+
var import_abis6 = require("@tokemak/abis");
|
|
4250
3693
|
var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
4251
3694
|
chainId,
|
|
4252
3695
|
address
|
|
4253
3696
|
}) => {
|
|
4254
3697
|
try {
|
|
4255
|
-
const coreConfig = (0,
|
|
4256
|
-
const userRewardsInfo = await (0,
|
|
3698
|
+
const coreConfig = (0, import_config4.getCoreConfig)(chainId);
|
|
3699
|
+
const userRewardsInfo = await (0, import_core8.readContract)(wagmiConfig, {
|
|
4257
3700
|
address: coreConfig.lens,
|
|
4258
|
-
abi:
|
|
3701
|
+
abi: import_abis6.lensAbi,
|
|
4259
3702
|
functionName: "getUserRewardInfo",
|
|
4260
3703
|
args: [address],
|
|
4261
3704
|
chainId: coreConfig.id
|
|
@@ -4286,8 +3729,8 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4286
3729
|
|
|
4287
3730
|
// functions/getUserAutopoolsRewards.ts
|
|
4288
3731
|
var import_utils27 = require("@tokemak/utils");
|
|
4289
|
-
var
|
|
4290
|
-
var
|
|
3732
|
+
var import_tokenlist8 = require("@tokemak/tokenlist");
|
|
3733
|
+
var import_chains9 = require("viem/chains");
|
|
4291
3734
|
var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
4292
3735
|
address,
|
|
4293
3736
|
tokenPrices,
|
|
@@ -4310,7 +3753,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4310
3753
|
const extraRewardsArray = Object.entries(chainUserRewards).flatMap(
|
|
4311
3754
|
([autopoolAddress, rewards]) => {
|
|
4312
3755
|
const autopool = autopools.find(
|
|
4313
|
-
(autopool2) => (0,
|
|
3756
|
+
(autopool2) => (0, import_viem12.getAddress)(autopool2.poolAddress) === (0, import_viem12.getAddress)(autopoolAddress)
|
|
4314
3757
|
);
|
|
4315
3758
|
if (!autopool || !autopool.extraRewarders) {
|
|
4316
3759
|
return [];
|
|
@@ -4320,17 +3763,17 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4320
3763
|
extraRewards2.rewardToken?.id,
|
|
4321
3764
|
autopool.chain?.chainId
|
|
4322
3765
|
);
|
|
4323
|
-
const claimableAmount = rewards ? rewards[(0,
|
|
3766
|
+
const claimableAmount = rewards ? rewards[(0, import_viem12.getAddress)(extraRewards2.rewardToken?.id)] : 0n;
|
|
4324
3767
|
let price = tokenPrices[rewarderToken.symbol] || 0;
|
|
4325
3768
|
if (rewarderToken.symbol === "XSILO") {
|
|
4326
|
-
price = tokenPrices[
|
|
3769
|
+
price = tokenPrices[import_tokenlist8.SILO_TOKEN.symbol] || 0;
|
|
4327
3770
|
}
|
|
4328
3771
|
const formattedAmount = (0, import_utils27.formatUnitsNum)(
|
|
4329
3772
|
claimableAmount,
|
|
4330
3773
|
rewarderToken.decimals || 18
|
|
4331
3774
|
);
|
|
4332
3775
|
return {
|
|
4333
|
-
address: (0,
|
|
3776
|
+
address: (0, import_viem12.getAddress)(extraRewards2?.id),
|
|
4334
3777
|
chainId,
|
|
4335
3778
|
token: rewarderToken,
|
|
4336
3779
|
amount: claimableAmount,
|
|
@@ -4361,7 +3804,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4361
3804
|
([tokenSymbol, { amount, decimals }]) => {
|
|
4362
3805
|
let price = tokenPrices[tokenSymbol] || 0;
|
|
4363
3806
|
if (tokenSymbol === "XSILO") {
|
|
4364
|
-
price = tokenPrices[
|
|
3807
|
+
price = tokenPrices[import_tokenlist8.SILO_TOKEN.symbol] || 0;
|
|
4365
3808
|
}
|
|
4366
3809
|
const formattedAmount = (0, import_utils27.formatUnitsNum)(amount, decimals || 18);
|
|
4367
3810
|
tokenRewards[tokenSymbol] = {
|
|
@@ -4372,13 +3815,13 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4372
3815
|
};
|
|
4373
3816
|
}
|
|
4374
3817
|
);
|
|
4375
|
-
if (Object.keys(tokenRewards).includes("undefined") && chainId ===
|
|
3818
|
+
if (Object.keys(tokenRewards).includes("undefined") && chainId === import_chains9.plasma.id) {
|
|
4376
3819
|
const undefinedToken = tokenRewards["undefined"];
|
|
4377
3820
|
let price = tokenPrices.TOKE || 0;
|
|
4378
3821
|
tokenRewards["TOKE"] = {
|
|
4379
3822
|
...undefinedToken,
|
|
4380
3823
|
USD: undefinedToken.formattedAmount * price,
|
|
4381
|
-
logoURI:
|
|
3824
|
+
logoURI: import_tokenlist8.TOKE_TOKEN.logoURI
|
|
4382
3825
|
};
|
|
4383
3826
|
delete tokenRewards["undefined"];
|
|
4384
3827
|
}
|
|
@@ -4433,24 +3876,24 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4433
3876
|
};
|
|
4434
3877
|
|
|
4435
3878
|
// functions/getAmountWithdrawn.ts
|
|
4436
|
-
var
|
|
3879
|
+
var import_viem14 = require("viem");
|
|
4437
3880
|
var import_utils29 = require("@tokemak/utils");
|
|
4438
3881
|
|
|
4439
3882
|
// functions/getSwapQuote.ts
|
|
4440
|
-
var
|
|
3883
|
+
var import_constants15 = require("@tokemak/constants");
|
|
4441
3884
|
|
|
4442
3885
|
// functions/getAddressFromSystemRegistry.ts
|
|
4443
|
-
var
|
|
4444
|
-
var
|
|
4445
|
-
var
|
|
3886
|
+
var import_core9 = require("@wagmi/core");
|
|
3887
|
+
var import_config5 = require("@tokemak/config");
|
|
3888
|
+
var import_abis7 = require("@tokemak/abis");
|
|
4446
3889
|
var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
4447
3890
|
chainId,
|
|
4448
3891
|
functionName
|
|
4449
3892
|
}) => {
|
|
4450
|
-
const { systemRegistry } = (0,
|
|
4451
|
-
return await (0,
|
|
3893
|
+
const { systemRegistry } = (0, import_config5.getCoreConfig)(chainId);
|
|
3894
|
+
return await (0, import_core9.readContract)(wagmiConfig, {
|
|
4452
3895
|
address: systemRegistry,
|
|
4453
|
-
abi:
|
|
3896
|
+
abi: import_abis7.systemRegistryAbi,
|
|
4454
3897
|
functionName,
|
|
4455
3898
|
chainId
|
|
4456
3899
|
});
|
|
@@ -4463,26 +3906,26 @@ var getAutopilotRouter = async (wagmiConfig, { chainId }) => await getAddressFro
|
|
|
4463
3906
|
});
|
|
4464
3907
|
|
|
4465
3908
|
// functions/getSwapQuote.ts
|
|
4466
|
-
var
|
|
4467
|
-
var
|
|
4468
|
-
var
|
|
3909
|
+
var import_config6 = require("@tokemak/config");
|
|
3910
|
+
var import_tokenlist9 = require("@tokemak/tokenlist");
|
|
3911
|
+
var import_chains10 = require("viem/chains");
|
|
4469
3912
|
var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
4470
3913
|
try {
|
|
4471
3914
|
if (!params.sellToken || !params.buyToken) {
|
|
4472
3915
|
throw new Error("Sell token and buy token are required");
|
|
4473
3916
|
}
|
|
4474
|
-
if (params.sellToken ===
|
|
4475
|
-
params.sellToken = (0,
|
|
4476
|
-
if (chainId ===
|
|
4477
|
-
params.sellToken =
|
|
3917
|
+
if (params.sellToken === import_tokenlist9.ETH_TOKEN.address) {
|
|
3918
|
+
params.sellToken = (0, import_config6.getCoreConfig)(chainId).weth;
|
|
3919
|
+
if (chainId === import_chains10.sonic.id) {
|
|
3920
|
+
params.sellToken = import_tokenlist9.WS_TOKEN.address;
|
|
4478
3921
|
}
|
|
4479
|
-
if (chainId ===
|
|
4480
|
-
params.sellToken =
|
|
3922
|
+
if (chainId === import_chains10.plasma.id) {
|
|
3923
|
+
params.sellToken = import_tokenlist9.WXPL_TOKEN.address;
|
|
4481
3924
|
}
|
|
4482
3925
|
}
|
|
4483
3926
|
const sellAmount = params.sellAmount.toString();
|
|
4484
3927
|
const taker = await getAutopilotRouter(config, { chainId });
|
|
4485
|
-
const response = await fetch(
|
|
3928
|
+
const response = await fetch(import_constants15.TOKEMAK_SWAP_QUOTE_URL, {
|
|
4486
3929
|
method: "POST",
|
|
4487
3930
|
headers: {
|
|
4488
3931
|
"Content-Type": "application/json"
|
|
@@ -4508,12 +3951,12 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4508
3951
|
};
|
|
4509
3952
|
|
|
4510
3953
|
// functions/getDynamicSwap.ts
|
|
4511
|
-
var
|
|
4512
|
-
var
|
|
4513
|
-
var
|
|
3954
|
+
var import_core10 = require("@wagmi/core");
|
|
3955
|
+
var import_abis8 = require("@tokemak/abis");
|
|
3956
|
+
var import_config7 = require("@tokemak/config");
|
|
4514
3957
|
var import_autopilot_swap_route_calc = require("@tokemak/autopilot-swap-route-calc");
|
|
4515
|
-
var
|
|
4516
|
-
var
|
|
3958
|
+
var import_viem13 = require("viem");
|
|
3959
|
+
var import_constants16 = require("@tokemak/constants");
|
|
4517
3960
|
var getDynamicSwap = async ({
|
|
4518
3961
|
address,
|
|
4519
3962
|
amount,
|
|
@@ -4526,9 +3969,9 @@ var getDynamicSwap = async ({
|
|
|
4526
3969
|
let previewRedeem = 0n;
|
|
4527
3970
|
let dynamicSwaps;
|
|
4528
3971
|
let standardPreviewRedeem = false;
|
|
4529
|
-
const client = await (0,
|
|
3972
|
+
const client = await (0, import_core10.getPublicClient)(config, { chainId });
|
|
4530
3973
|
try {
|
|
4531
|
-
const { systemRegistry } = (0,
|
|
3974
|
+
const { systemRegistry } = (0, import_config7.getCoreConfig)(chainId);
|
|
4532
3975
|
client.transport.retryCount = 0;
|
|
4533
3976
|
client.transport.transports = [client.transport.transports[0]];
|
|
4534
3977
|
const liquidations = await (0, import_autopilot_swap_route_calc.getLiquidations)(
|
|
@@ -4537,7 +3980,7 @@ var getDynamicSwap = async ({
|
|
|
4537
3980
|
client.transport.transports[0].value.url,
|
|
4538
3981
|
address,
|
|
4539
3982
|
amount,
|
|
4540
|
-
|
|
3983
|
+
import_constants16.LIQUIDATION_PROBE_AMOUNT
|
|
4541
3984
|
);
|
|
4542
3985
|
if (liquidations?.liquidations?.length > 0) {
|
|
4543
3986
|
tokensToLiquidate = liquidations.liquidations;
|
|
@@ -4558,12 +4001,12 @@ var getDynamicSwap = async ({
|
|
|
4558
4001
|
chainId,
|
|
4559
4002
|
systemName: "gen3",
|
|
4560
4003
|
// slippageBps: Math.floor(slippage * 10000),
|
|
4561
|
-
slippageBps:
|
|
4004
|
+
slippageBps: import_constants16.DYNAMIC_SWAP_DEFAULT_SLIPPAGE_BPS,
|
|
4562
4005
|
tokensToLiquidate,
|
|
4563
4006
|
sellAllOnlyCompatible: true
|
|
4564
4007
|
})
|
|
4565
4008
|
};
|
|
4566
|
-
dynamicSwaps = await (await fetch(
|
|
4009
|
+
dynamicSwaps = await (await fetch(import_constants16.TOKEMAK_DYNAMIC_SWAP_ROUTES_URL, requestInit)).json();
|
|
4567
4010
|
if (dynamicSwaps?.success) {
|
|
4568
4011
|
const autopoolRouter = await getAutopilotRouter(config, { chainId });
|
|
4569
4012
|
if (!autopoolRouter) {
|
|
@@ -4572,7 +4015,7 @@ var getDynamicSwap = async ({
|
|
|
4572
4015
|
try {
|
|
4573
4016
|
await client?.simulateContract({
|
|
4574
4017
|
address: autopoolRouter,
|
|
4575
|
-
abi:
|
|
4018
|
+
abi: import_abis8.autopilotRouterAbi,
|
|
4576
4019
|
functionName: "previewRedeemWithRoutes",
|
|
4577
4020
|
args: [
|
|
4578
4021
|
address,
|
|
@@ -4584,10 +4027,10 @@ var getDynamicSwap = async ({
|
|
|
4584
4027
|
data: x.data
|
|
4585
4028
|
}))
|
|
4586
4029
|
],
|
|
4587
|
-
account: user ||
|
|
4030
|
+
account: user || import_constants16.SIMULATION_PLACEHOLDER_ADDRESS
|
|
4588
4031
|
});
|
|
4589
4032
|
} catch (e) {
|
|
4590
|
-
if (e instanceof
|
|
4033
|
+
if (e instanceof import_viem13.ContractFunctionExecutionError && e.cause instanceof import_viem13.ContractFunctionRevertedError && e.cause.data?.errorName === "PreviewRedeemWithRoutesResult") {
|
|
4591
4034
|
previewRedeem = e.cause.data?.args?.[0];
|
|
4592
4035
|
}
|
|
4593
4036
|
}
|
|
@@ -4596,13 +4039,13 @@ var getDynamicSwap = async ({
|
|
|
4596
4039
|
console.log(e);
|
|
4597
4040
|
}
|
|
4598
4041
|
}
|
|
4599
|
-
const previewRedeemOnChain = await (0,
|
|
4042
|
+
const previewRedeemOnChain = await (0, import_core10.readContract)(config, {
|
|
4600
4043
|
address,
|
|
4601
|
-
abi:
|
|
4044
|
+
abi: import_abis8.autopoolEthAbi,
|
|
4602
4045
|
functionName: "previewRedeem",
|
|
4603
4046
|
args: [amount],
|
|
4604
4047
|
chainId,
|
|
4605
|
-
account: user ||
|
|
4048
|
+
account: user || import_constants16.SIMULATION_PLACEHOLDER_ADDRESS
|
|
4606
4049
|
});
|
|
4607
4050
|
if (previewRedeemOnChain >= previewRedeem) {
|
|
4608
4051
|
standardPreviewRedeem = true;
|
|
@@ -4616,10 +4059,10 @@ var getDynamicSwap = async ({
|
|
|
4616
4059
|
};
|
|
4617
4060
|
|
|
4618
4061
|
// functions/getAmountWithdrawn.ts
|
|
4619
|
-
var
|
|
4620
|
-
var
|
|
4621
|
-
var
|
|
4622
|
-
var
|
|
4062
|
+
var import_tokenlist10 = require("@tokemak/tokenlist");
|
|
4063
|
+
var import_config8 = require("@tokemak/config");
|
|
4064
|
+
var import_core11 = require("@wagmi/core");
|
|
4065
|
+
var import_abis9 = require("@tokemak/abis");
|
|
4623
4066
|
var getAmountWithdrawn = async ({
|
|
4624
4067
|
address,
|
|
4625
4068
|
slippage,
|
|
@@ -4652,15 +4095,15 @@ var getAmountWithdrawn = async ({
|
|
|
4652
4095
|
dynamicSwap?.previewRedeem,
|
|
4653
4096
|
slippage
|
|
4654
4097
|
);
|
|
4655
|
-
let minAmount = (0,
|
|
4098
|
+
let minAmount = (0, import_viem14.formatUnits)(minAmountWithSlippage, decimals);
|
|
4656
4099
|
if (isSwap) {
|
|
4657
|
-
if (buyToken ===
|
|
4658
|
-
const weth = (0,
|
|
4100
|
+
if (buyToken === import_tokenlist10.ETH_TOKEN.address) {
|
|
4101
|
+
const weth = (0, import_config8.getCoreConfig)(chainId).weth;
|
|
4659
4102
|
buyToken = weth;
|
|
4660
4103
|
}
|
|
4661
|
-
convertedAssets = await (0,
|
|
4104
|
+
convertedAssets = await (0, import_core11.readContract)(config, {
|
|
4662
4105
|
address: autopool,
|
|
4663
|
-
abi:
|
|
4106
|
+
abi: import_abis9.autopoolEthAbi,
|
|
4664
4107
|
functionName: "convertToAssets",
|
|
4665
4108
|
args: [amount],
|
|
4666
4109
|
chainId
|
|
@@ -4678,7 +4121,7 @@ var getAmountWithdrawn = async ({
|
|
|
4678
4121
|
sellAll: true
|
|
4679
4122
|
});
|
|
4680
4123
|
if (quote) {
|
|
4681
|
-
minAmount = (0,
|
|
4124
|
+
minAmount = (0, import_viem14.formatUnits)(BigInt(quote?.minBuyAmount), decimals);
|
|
4682
4125
|
} else {
|
|
4683
4126
|
throw new Error("No quote found");
|
|
4684
4127
|
}
|
|
@@ -4698,8 +4141,8 @@ var getAmountWithdrawn = async ({
|
|
|
4698
4141
|
};
|
|
4699
4142
|
|
|
4700
4143
|
// functions/getAmountDeposited.ts
|
|
4701
|
-
var
|
|
4702
|
-
var
|
|
4144
|
+
var import_core12 = require("@wagmi/core");
|
|
4145
|
+
var import_abis10 = require("@tokemak/abis");
|
|
4703
4146
|
var import_utils30 = require("@tokemak/utils");
|
|
4704
4147
|
var getAmountDeposited = async ({
|
|
4705
4148
|
address,
|
|
@@ -4713,9 +4156,9 @@ var getAmountDeposited = async ({
|
|
|
4713
4156
|
if (!address || !chainId || !amount || typeof slippage !== "number") {
|
|
4714
4157
|
throw new Error("Invalid parameters");
|
|
4715
4158
|
}
|
|
4716
|
-
const previewDeposit = await (0,
|
|
4159
|
+
const previewDeposit = await (0, import_core12.readContract)(config, {
|
|
4717
4160
|
address,
|
|
4718
|
-
abi:
|
|
4161
|
+
abi: import_abis10.autopoolEthAbi,
|
|
4719
4162
|
functionName: "previewDeposit",
|
|
4720
4163
|
args: [amount],
|
|
4721
4164
|
chainId
|
|
@@ -4737,9 +4180,9 @@ var getAmountDeposited = async ({
|
|
|
4737
4180
|
};
|
|
4738
4181
|
|
|
4739
4182
|
// functions/getBridgeFee.ts
|
|
4740
|
-
var
|
|
4741
|
-
var
|
|
4742
|
-
var
|
|
4183
|
+
var import_core13 = require("@wagmi/core");
|
|
4184
|
+
var import_abis11 = require("@tokemak/abis");
|
|
4185
|
+
var import_viem15 = require("viem");
|
|
4743
4186
|
var import_lz_v2_utilities = require("@layerzerolabs/lz-v2-utilities");
|
|
4744
4187
|
var getBridgeFee = async (wagmiConfig, {
|
|
4745
4188
|
sourceAddress,
|
|
@@ -4750,15 +4193,15 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4750
4193
|
from
|
|
4751
4194
|
}) => {
|
|
4752
4195
|
try {
|
|
4753
|
-
const endpoint = await (0,
|
|
4196
|
+
const endpoint = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4754
4197
|
address: destAddress,
|
|
4755
|
-
abi:
|
|
4198
|
+
abi: import_abis11.oftAdapterAbi,
|
|
4756
4199
|
functionName: "endpoint",
|
|
4757
4200
|
chainId: destChainId
|
|
4758
4201
|
});
|
|
4759
|
-
const eid = await (0,
|
|
4202
|
+
const eid = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4760
4203
|
address: endpoint,
|
|
4761
|
-
abi:
|
|
4204
|
+
abi: import_abis11.layerZeroEndpointAbi,
|
|
4762
4205
|
functionName: "eid",
|
|
4763
4206
|
chainId: destChainId
|
|
4764
4207
|
});
|
|
@@ -4767,16 +4210,16 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4767
4210
|
const minAmountLD = amount / factor * factor;
|
|
4768
4211
|
const sendParams = {
|
|
4769
4212
|
dstEid: eid,
|
|
4770
|
-
to: (0,
|
|
4213
|
+
to: (0, import_viem15.toHex)((0, import_lz_v2_utilities.addressToBytes32)(from)),
|
|
4771
4214
|
amountLD: amount,
|
|
4772
4215
|
minAmountLD,
|
|
4773
4216
|
extraOptions: "0x",
|
|
4774
4217
|
composeMsg: "0x",
|
|
4775
4218
|
oftCmd: "0x"
|
|
4776
4219
|
};
|
|
4777
|
-
const feeQuote = await (0,
|
|
4220
|
+
const feeQuote = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4778
4221
|
address: sourceAddress,
|
|
4779
|
-
abi:
|
|
4222
|
+
abi: import_abis11.oftAdapterAbi,
|
|
4780
4223
|
functionName: "quoteSend",
|
|
4781
4224
|
args: [sendParams, false],
|
|
4782
4225
|
chainId: sourceChainId
|
|
@@ -4787,595 +4230,35 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4787
4230
|
}
|
|
4788
4231
|
};
|
|
4789
4232
|
|
|
4790
|
-
// functions/getLayerzeroStatus.ts
|
|
4791
|
-
var MessageStatus = /* @__PURE__ */ ((MessageStatus2) => {
|
|
4792
|
-
MessageStatus2["INFLIGHT"] = "INFLIGHT";
|
|
4793
|
-
MessageStatus2["DELIVERED"] = "DELIVERED";
|
|
4794
|
-
MessageStatus2["FAILED"] = "FAILED";
|
|
4795
|
-
MessageStatus2["PAYLOAD_STORED"] = "PAYLOAD_STORED";
|
|
4796
|
-
MessageStatus2["BLOCKED"] = "BLOCKED";
|
|
4797
|
-
MessageStatus2["CONFIRMING"] = "CONFIRMING";
|
|
4798
|
-
return MessageStatus2;
|
|
4799
|
-
})(MessageStatus || {});
|
|
4800
|
-
var LAYERZERO_STATUS_URL = "https://scan.layerzero-api.com/v1/messages/tx/";
|
|
4801
|
-
var getLayerzeroStatus = async ({
|
|
4802
|
-
txHash
|
|
4803
|
-
}) => {
|
|
4804
|
-
try {
|
|
4805
|
-
const response = await fetch(`${LAYERZERO_STATUS_URL}${txHash}`);
|
|
4806
|
-
if (!response.ok) {
|
|
4807
|
-
throw new Error("Network response was not ok");
|
|
4808
|
-
}
|
|
4809
|
-
const statusData = await response.json();
|
|
4810
|
-
return statusData || void 0;
|
|
4811
|
-
} catch (e) {
|
|
4812
|
-
return {
|
|
4813
|
-
status: {
|
|
4814
|
-
name: "FAILED" /* FAILED */,
|
|
4815
|
-
message: e || "Failed to fetch layerzero status"
|
|
4816
|
-
}
|
|
4817
|
-
};
|
|
4818
|
-
}
|
|
4819
|
-
};
|
|
4820
|
-
var waitForMessageReceived = async ({
|
|
4821
|
-
txHash,
|
|
4822
|
-
interval = 3e3,
|
|
4823
|
-
timeout = 20 * 60 * 1e3
|
|
4824
|
-
}) => {
|
|
4825
|
-
const startTime = Date.now();
|
|
4826
|
-
while (Date.now() - startTime < timeout) {
|
|
4827
|
-
const status = await getLayerzeroStatus({ txHash });
|
|
4828
|
-
if (!status) {
|
|
4829
|
-
console.warn(`No status returned for txHash: ${txHash}`);
|
|
4830
|
-
} else {
|
|
4831
|
-
console.log(`Current status: ${status.status.name}`);
|
|
4832
|
-
if (status.status.name === "DELIVERED" /* DELIVERED */) {
|
|
4833
|
-
return status;
|
|
4834
|
-
} else if (["FAILED" /* FAILED */, "BLOCKED" /* BLOCKED */].includes(
|
|
4835
|
-
status.status.name
|
|
4836
|
-
)) {
|
|
4837
|
-
throw new Error(`Message failed with status: ${status.status.name}`);
|
|
4838
|
-
}
|
|
4839
|
-
}
|
|
4840
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
4841
|
-
}
|
|
4842
|
-
throw new Error(`Timeout reached after 20 minutes for message: ${txHash}`);
|
|
4843
|
-
};
|
|
4844
|
-
|
|
4845
|
-
// functions/getChainUserSToke.ts
|
|
4846
|
-
var import_abis18 = require("@tokemak/abis");
|
|
4847
|
-
var import_config13 = require("@tokemak/config");
|
|
4848
|
-
var import_utils31 = require("@tokemak/utils");
|
|
4849
|
-
var import_core21 = require("@wagmi/core");
|
|
4850
|
-
var import_viem18 = require("viem");
|
|
4851
|
-
var import_chains13 = require("viem/chains");
|
|
4852
|
-
|
|
4853
4233
|
// functions/getCurrentCycleId.ts
|
|
4854
|
-
var
|
|
4855
|
-
var
|
|
4234
|
+
var import_abis12 = require("@tokemak/abis");
|
|
4235
|
+
var import_core14 = require("@wagmi/core");
|
|
4856
4236
|
var getCurrentCycleId = async (wagmiConfig, {
|
|
4857
4237
|
stoke,
|
|
4858
4238
|
chainId
|
|
4859
4239
|
}) => {
|
|
4860
|
-
return (0,
|
|
4240
|
+
return (0, import_core14.readContract)(wagmiConfig, {
|
|
4861
4241
|
address: stoke,
|
|
4862
|
-
abi:
|
|
4242
|
+
abi: import_abis12.accTokeV1Abi,
|
|
4863
4243
|
chainId,
|
|
4864
4244
|
functionName: "getCurrentCycleID"
|
|
4865
4245
|
});
|
|
4866
4246
|
};
|
|
4867
4247
|
|
|
4868
|
-
// functions/getChainUserSToke.ts
|
|
4869
|
-
var import_graph_cli14 = require("@tokemak/graph-cli");
|
|
4870
|
-
var getChainUserSToke = async (wagmiConfig, {
|
|
4871
|
-
address,
|
|
4872
|
-
tokePrice,
|
|
4873
|
-
chainId
|
|
4874
|
-
}) => {
|
|
4875
|
-
try {
|
|
4876
|
-
const { stoke } = (0, import_config13.getCoreConfig)(chainId);
|
|
4877
|
-
const cycleIndex = await getCurrentCycleId(wagmiConfig, { chainId, stoke });
|
|
4878
|
-
if (address && cycleIndex && stoke && tokePrice) {
|
|
4879
|
-
const { GetUserSTokeBalance } = (0, import_graph_cli14.getSdkByChainId)(
|
|
4880
|
-
chainId
|
|
4881
|
-
);
|
|
4882
|
-
const { accountBalanceV1S } = await GetUserSTokeBalance({
|
|
4883
|
-
address: address.toLowerCase()
|
|
4884
|
-
});
|
|
4885
|
-
const cycleStartBalance = accountBalanceV1S[0]?.cycleStartBalance || 0n;
|
|
4886
|
-
const stokeContract = {
|
|
4887
|
-
address: stoke,
|
|
4888
|
-
abi: import_abis18.accTokeV1Abi
|
|
4889
|
-
};
|
|
4890
|
-
const [
|
|
4891
|
-
{ result: balance },
|
|
4892
|
-
{ result: depositInfoResult },
|
|
4893
|
-
{ result: withdrawalInfoResult }
|
|
4894
|
-
] = await (0, import_core21.readContracts)(wagmiConfig, {
|
|
4895
|
-
contracts: [
|
|
4896
|
-
{
|
|
4897
|
-
...stokeContract,
|
|
4898
|
-
functionName: "balanceOf",
|
|
4899
|
-
args: [address],
|
|
4900
|
-
chainId
|
|
4901
|
-
},
|
|
4902
|
-
{
|
|
4903
|
-
...stokeContract,
|
|
4904
|
-
functionName: "getDepositInfo",
|
|
4905
|
-
args: [address],
|
|
4906
|
-
chainId
|
|
4907
|
-
},
|
|
4908
|
-
{
|
|
4909
|
-
...stokeContract,
|
|
4910
|
-
functionName: "getWithdrawalInfo",
|
|
4911
|
-
args: [address],
|
|
4912
|
-
chainId
|
|
4913
|
-
}
|
|
4914
|
-
]
|
|
4915
|
-
});
|
|
4916
|
-
if (withdrawalInfoResult && depositInfoResult && balance && cycleStartBalance) {
|
|
4917
|
-
const [depositLockCycle, depositLockDuration, depositAmount] = depositInfoResult;
|
|
4918
|
-
const [withdrawalMinCycle, withdrawalAmount] = withdrawalInfoResult;
|
|
4919
|
-
const rolloverDepositAmount = !!cycleStartBalance?.cycleStartBalance && cycleStartBalance?.cycleStartBalance > 0 ? BigInt(cycleStartBalance.cycleStartBalance) : 0n;
|
|
4920
|
-
let balanceExcludingWithdrawal = balance;
|
|
4921
|
-
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
4922
|
-
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
4923
|
-
}
|
|
4924
|
-
const withdrawalAmountUsd = (0, import_utils31.formatCurrency)(
|
|
4925
|
-
(0, import_utils31.formatEtherNum)(withdrawalAmount) * tokePrice
|
|
4926
|
-
);
|
|
4927
|
-
const lockDuration = Number(depositLockDuration);
|
|
4928
|
-
const lockCycle = Number(depositLockCycle);
|
|
4929
|
-
const lockStart = lockCycle + 1;
|
|
4930
|
-
const firstLockEnd = lockDuration + 1 + lockCycle;
|
|
4931
|
-
const currentCycle = Number(cycleIndex);
|
|
4932
|
-
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
4933
|
-
const lockRenew = (
|
|
4934
|
-
// if has done a renewal since start
|
|
4935
|
-
currentCycle - lockStart > lockDuration ? (
|
|
4936
|
-
// if during the lockRenew cycle add lock duration to show the right timeline
|
|
4937
|
-
currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement
|
|
4938
|
-
) : (
|
|
4939
|
-
// if during the lockRenew cycle add lock duration to show the right timeline
|
|
4940
|
-
currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd
|
|
4941
|
-
)
|
|
4942
|
-
);
|
|
4943
|
-
const withdrawAvailable = lockRenew - 1;
|
|
4944
|
-
const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
|
|
4945
|
-
const addedLockedToke = depositAmount - rolloverDepositAmount;
|
|
4946
|
-
const balanceUSD = (0, import_utils31.formatCurrency)(
|
|
4947
|
-
Number((0, import_viem18.formatEther)(balanceExcludingWithdrawal)) * tokePrice
|
|
4948
|
-
);
|
|
4949
|
-
const balanceExcludingWithdrawalUsd = (0, import_utils31.formatCurrency)(
|
|
4950
|
-
(0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
|
|
4951
|
-
);
|
|
4952
|
-
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
4953
|
-
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
4954
|
-
const unlockRequestPeriodStartUnix = (0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
|
|
4955
|
-
const unlockRequestPeriodEndUnix = (0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
|
|
4956
|
-
const hasBalance = balance > 0n;
|
|
4957
|
-
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
4958
|
-
const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
|
|
4959
|
-
let cyclesInAMonth = 4;
|
|
4960
|
-
let lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
4961
|
-
if (chainId === import_chains13.sepolia.id) {
|
|
4962
|
-
lockDurationInMonths = lockDuration - 1;
|
|
4963
|
-
}
|
|
4964
|
-
const unlockPeriodDateRangeArray = [
|
|
4965
|
-
new Date((0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
|
|
4966
|
-
new Date((0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
|
|
4967
|
-
];
|
|
4968
|
-
const {
|
|
4969
|
-
unlockPeriodDateRange,
|
|
4970
|
-
unlockPeriodStartFullDate,
|
|
4971
|
-
unlockRenewalFullDate,
|
|
4972
|
-
unlockPeriodStartDate,
|
|
4973
|
-
unlockRenewalDate
|
|
4974
|
-
} = formatDateRange(
|
|
4975
|
-
unlockPeriodDateRangeArray,
|
|
4976
|
-
chainId === import_chains13.sepolia.id ? "time" : "date"
|
|
4977
|
-
);
|
|
4978
|
-
const totalActiveUserCredits = (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
4979
|
-
const totalUserCredits = (0, import_utils31.formatEtherNum)(balance) * lockDurationInMonths;
|
|
4980
|
-
return {
|
|
4981
|
-
balance,
|
|
4982
|
-
balanceUSD,
|
|
4983
|
-
balanceExcludingWithdrawal: hasBalance ? (0, import_viem18.formatEther)(balanceExcludingWithdrawal) : "0.00",
|
|
4984
|
-
balanceExcludingWithdrawalUsd,
|
|
4985
|
-
hasBalanceExcludingWithdrawal,
|
|
4986
|
-
timeLeftBeforeUnlockRequestAvailable: (0, import_utils31.convertSecondsToRemainingTime)(
|
|
4987
|
-
unlockRequestPeriodStartUnix
|
|
4988
|
-
),
|
|
4989
|
-
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils31.convertSecondsToRemainingTime)(
|
|
4990
|
-
unlockRequestPeriodEndUnix
|
|
4991
|
-
),
|
|
4992
|
-
withdrawalAmount,
|
|
4993
|
-
withdrawalAmountUsd,
|
|
4994
|
-
hasUnlockableBalance,
|
|
4995
|
-
isUnlockRequestAvailable,
|
|
4996
|
-
hasRequestedUnlock,
|
|
4997
|
-
hasAddedLockedToke,
|
|
4998
|
-
addedLockedToke,
|
|
4999
|
-
unlockPeriodDateRange,
|
|
5000
|
-
unlockPeriodStartFullDate,
|
|
5001
|
-
unlockRenewalFullDate,
|
|
5002
|
-
unlockPeriodStartDate,
|
|
5003
|
-
unlockRenewalDate,
|
|
5004
|
-
lockDurationInMonths,
|
|
5005
|
-
boost: lockDuration,
|
|
5006
|
-
points: (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
5007
|
-
totalActiveCredits: totalActiveUserCredits,
|
|
5008
|
-
totalCredits: totalUserCredits
|
|
5009
|
-
};
|
|
5010
|
-
}
|
|
5011
|
-
}
|
|
5012
|
-
} catch (error) {
|
|
5013
|
-
console.error(error);
|
|
5014
|
-
}
|
|
5015
|
-
};
|
|
5016
|
-
|
|
5017
|
-
// functions/getUserSToke.ts
|
|
5018
|
-
var import_utils33 = require("@tokemak/utils");
|
|
5019
|
-
var getUserSToke = async (wagmiConfig, {
|
|
5020
|
-
address,
|
|
5021
|
-
tokePrice,
|
|
5022
|
-
includeTestnet = false
|
|
5023
|
-
}) => {
|
|
5024
|
-
try {
|
|
5025
|
-
if (!address) {
|
|
5026
|
-
throw new Error("Address not found");
|
|
5027
|
-
}
|
|
5028
|
-
if (!tokePrice) {
|
|
5029
|
-
throw new Error("Toke price not found");
|
|
5030
|
-
}
|
|
5031
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5032
|
-
const userSToke = await fetchChainDataMap(chains, async (chain) => {
|
|
5033
|
-
return getChainUserSToke(wagmiConfig, {
|
|
5034
|
-
address,
|
|
5035
|
-
tokePrice,
|
|
5036
|
-
chainId: chain.chainId
|
|
5037
|
-
});
|
|
5038
|
-
});
|
|
5039
|
-
const totalBalanceRaw = Object.values(userSToke).reduce((acc, item) => {
|
|
5040
|
-
if (item && item.balance) {
|
|
5041
|
-
return acc + item.balance;
|
|
5042
|
-
}
|
|
5043
|
-
return acc;
|
|
5044
|
-
}, 0n);
|
|
5045
|
-
const totalBalance = (0, import_utils33.formatEtherNum)(totalBalanceRaw || 0n);
|
|
5046
|
-
const totalBalanceUsd = (0, import_utils33.formatCurrency)(totalBalance * tokePrice);
|
|
5047
|
-
const hasBalance = totalBalance > 0;
|
|
5048
|
-
return {
|
|
5049
|
-
chains: { ...userSToke },
|
|
5050
|
-
totalBalance,
|
|
5051
|
-
totalBalanceUsd,
|
|
5052
|
-
hasBalance
|
|
5053
|
-
};
|
|
5054
|
-
} catch (e) {
|
|
5055
|
-
console.error(e);
|
|
5056
|
-
}
|
|
5057
|
-
};
|
|
5058
|
-
|
|
5059
|
-
// functions/getChainSToke.ts
|
|
5060
|
-
var import_viem19 = require("viem");
|
|
5061
|
-
var import_core22 = require("@wagmi/core");
|
|
5062
|
-
var import_abis19 = require("@tokemak/abis");
|
|
5063
|
-
var import_utils35 = require("@tokemak/utils");
|
|
5064
|
-
var import_config14 = require("@tokemak/config");
|
|
5065
|
-
var import_utils36 = require("@tokemak/utils");
|
|
5066
|
-
var getChainSToke = async (wagmiConfig, {
|
|
5067
|
-
tokePrice,
|
|
5068
|
-
chainId
|
|
5069
|
-
}) => {
|
|
5070
|
-
try {
|
|
5071
|
-
const { stoke } = (0, import_config14.getCoreConfig)(chainId);
|
|
5072
|
-
const baseConfig = {
|
|
5073
|
-
address: stoke,
|
|
5074
|
-
abi: import_abis19.accTokeV1Abi,
|
|
5075
|
-
chainId
|
|
5076
|
-
};
|
|
5077
|
-
if (stoke && tokePrice) {
|
|
5078
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await (0, import_core22.readContracts)(wagmiConfig, {
|
|
5079
|
-
contracts: [
|
|
5080
|
-
{
|
|
5081
|
-
...baseConfig,
|
|
5082
|
-
functionName: "totalSupply"
|
|
5083
|
-
},
|
|
5084
|
-
{
|
|
5085
|
-
...baseConfig,
|
|
5086
|
-
functionName: "getCurrentCycleID"
|
|
5087
|
-
}
|
|
5088
|
-
]
|
|
5089
|
-
});
|
|
5090
|
-
const tvl = Number((0, import_viem19.formatEther)(totalSupply || 0n)) * tokePrice;
|
|
5091
|
-
const secondsLeftBeforeNextCycle = (0, import_utils35.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
|
|
5092
|
-
return {
|
|
5093
|
-
rawTotalSupply: totalSupply,
|
|
5094
|
-
totalSupply: (0, import_utils35.formatLargeNumber)((0, import_viem19.formatEther)(totalSupply || 0n)),
|
|
5095
|
-
tvl: (0, import_utils35.formatTVL)(tvl),
|
|
5096
|
-
rawTVL: tvl,
|
|
5097
|
-
currentCycle,
|
|
5098
|
-
chain: (0, import_utils36.getNetwork)(chainId),
|
|
5099
|
-
timeBeforeNextCycle: (0, import_utils35.convertSecondsToRemainingTime)(
|
|
5100
|
-
secondsLeftBeforeNextCycle
|
|
5101
|
-
)
|
|
5102
|
-
};
|
|
5103
|
-
}
|
|
5104
|
-
} catch (error) {
|
|
5105
|
-
console.error(error);
|
|
5106
|
-
}
|
|
5107
|
-
};
|
|
5108
|
-
|
|
5109
|
-
// functions/getSToke.ts
|
|
5110
|
-
var import_utils37 = require("@tokemak/utils");
|
|
5111
|
-
var import_viem20 = require("viem");
|
|
5112
|
-
var getSToke = async (wagmiConfig, {
|
|
5113
|
-
tokePrice,
|
|
5114
|
-
includeTestnet = false
|
|
5115
|
-
}) => {
|
|
5116
|
-
try {
|
|
5117
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5118
|
-
const sToke = await fetchChainDataMap(chains, async (chain) => {
|
|
5119
|
-
return getChainSToke(wagmiConfig, {
|
|
5120
|
-
tokePrice,
|
|
5121
|
-
chainId: chain.chainId
|
|
5122
|
-
});
|
|
5123
|
-
});
|
|
5124
|
-
const totalSupplyBigInt = Object.values(sToke).reduce((acc, item) => {
|
|
5125
|
-
if (item && item.rawTotalSupply) {
|
|
5126
|
-
return acc + item.rawTotalSupply;
|
|
5127
|
-
}
|
|
5128
|
-
return acc;
|
|
5129
|
-
}, 0n);
|
|
5130
|
-
const totalSupply = (0, import_utils37.formatLargeNumber)((0, import_viem20.formatEther)(totalSupplyBigInt || 0n));
|
|
5131
|
-
let tvlNum = Object.values(sToke).reduce((acc, item) => {
|
|
5132
|
-
if (item && item.rawTVL) {
|
|
5133
|
-
return acc + item.rawTVL;
|
|
5134
|
-
}
|
|
5135
|
-
return acc;
|
|
5136
|
-
}, 0);
|
|
5137
|
-
const tvl = (0, import_utils37.formatTVL)(tvlNum);
|
|
5138
|
-
return { totalSupply, rawTotalSupply: totalSupplyBigInt, tvl, rawTVL: tvlNum, chains: { ...sToke } };
|
|
5139
|
-
} catch (e) {
|
|
5140
|
-
console.error(e);
|
|
5141
|
-
throw e;
|
|
5142
|
-
}
|
|
5143
|
-
};
|
|
5144
|
-
|
|
5145
|
-
// functions/getChainCycleRolloverBlockNumber.ts
|
|
5146
|
-
var import_abis20 = require("@tokemak/abis");
|
|
5147
|
-
var import_core23 = require("@wagmi/core");
|
|
5148
|
-
var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
5149
|
-
stoke,
|
|
5150
|
-
chainId
|
|
5151
|
-
}) => {
|
|
5152
|
-
const scanPeriodInDays = 8;
|
|
5153
|
-
const blockTime = 12;
|
|
5154
|
-
try {
|
|
5155
|
-
const client = (0, import_core23.getPublicClient)(wagmiConfig, { chainId });
|
|
5156
|
-
if (!!client) {
|
|
5157
|
-
const blockNumber = await (0, import_core23.getBlockNumber)(wagmiConfig, {
|
|
5158
|
-
chainId
|
|
5159
|
-
});
|
|
5160
|
-
const manager = await (0, import_core23.readContract)(wagmiConfig, {
|
|
5161
|
-
functionName: "manager",
|
|
5162
|
-
address: stoke,
|
|
5163
|
-
abi: import_abis20.accTokeV1Abi,
|
|
5164
|
-
chainId
|
|
5165
|
-
});
|
|
5166
|
-
if (!manager) {
|
|
5167
|
-
throw new Error("Manager contract not found");
|
|
5168
|
-
}
|
|
5169
|
-
const filter = await client.createContractEventFilter({
|
|
5170
|
-
address: manager,
|
|
5171
|
-
fromBlock: BigInt(
|
|
5172
|
-
Math.floor(
|
|
5173
|
-
Number(blockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
5174
|
-
)
|
|
5175
|
-
),
|
|
5176
|
-
abi: import_abis20.managerV1Abi,
|
|
5177
|
-
eventName: "CycleRolloverComplete"
|
|
5178
|
-
});
|
|
5179
|
-
const rolloverEvents = await client.getFilterLogs({ filter });
|
|
5180
|
-
const cycleRolloverBlockNumber = client.chain.id === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || blockNumber;
|
|
5181
|
-
return cycleRolloverBlockNumber;
|
|
5182
|
-
}
|
|
5183
|
-
} catch (error) {
|
|
5184
|
-
console.error(error);
|
|
5185
|
-
}
|
|
5186
|
-
};
|
|
5187
|
-
|
|
5188
|
-
// functions/getChainSTokeRewards.ts
|
|
5189
|
-
var import_config15 = require("@tokemak/config");
|
|
5190
|
-
var import_viem21 = require("viem");
|
|
5191
|
-
var import_utils39 = require("@tokemak/utils");
|
|
5192
|
-
var import_graph_cli15 = require("@tokemak/graph-cli");
|
|
5193
|
-
var getChainSTokeRewards = async ({
|
|
5194
|
-
chainId
|
|
5195
|
-
}) => {
|
|
5196
|
-
try {
|
|
5197
|
-
const { GetSTokeRewards } = (0, import_graph_cli15.getSdkByChainId)(chainId);
|
|
5198
|
-
const { poolRewardsBalances } = await GetSTokeRewards();
|
|
5199
|
-
const allPoolRewardsBalanceDayDatas = await paginateQuery(
|
|
5200
|
-
GetSTokeRewards,
|
|
5201
|
-
"poolRewardsBalanceDayDatas"
|
|
5202
|
-
);
|
|
5203
|
-
const autopools = {};
|
|
5204
|
-
let totalEarnings = 0;
|
|
5205
|
-
let totalEarningsUsd = 0;
|
|
5206
|
-
let minApr = null;
|
|
5207
|
-
let maxApr = null;
|
|
5208
|
-
for (const pool of poolRewardsBalances) {
|
|
5209
|
-
const whitelistedPools = import_config15.AUTOPOOLS_WHITELIST_PROD.map(
|
|
5210
|
-
(address) => address.toLowerCase()
|
|
5211
|
-
);
|
|
5212
|
-
if (!whitelistedPools.includes(pool.id.toLowerCase())) {
|
|
5213
|
-
continue;
|
|
5214
|
-
}
|
|
5215
|
-
const convertedBalance = (0, import_utils39.formatEtherNum)(pool.balance);
|
|
5216
|
-
const convertedBalanceUSD = Number((0, import_viem21.formatUnits)(pool.balanceUSD, 8));
|
|
5217
|
-
const convertedApr = (0, import_utils39.formatEtherNum)(pool.currentAprPerCredit);
|
|
5218
|
-
if (minApr === null || convertedApr < minApr) {
|
|
5219
|
-
minApr = convertedApr;
|
|
5220
|
-
}
|
|
5221
|
-
if (maxApr === null || convertedApr > maxApr) {
|
|
5222
|
-
maxApr = convertedApr;
|
|
5223
|
-
}
|
|
5224
|
-
autopools[pool.id] = {
|
|
5225
|
-
balance: convertedBalance,
|
|
5226
|
-
balanceUSD: convertedBalanceUSD,
|
|
5227
|
-
currentAprPerCredit: convertedApr
|
|
5228
|
-
};
|
|
5229
|
-
totalEarnings += convertedBalance;
|
|
5230
|
-
totalEarningsUsd += convertedBalanceUSD;
|
|
5231
|
-
}
|
|
5232
|
-
const activeDayDatas = allPoolRewardsBalanceDayDatas.filter(
|
|
5233
|
-
(item) => item.balance !== "0"
|
|
5234
|
-
);
|
|
5235
|
-
const historicalRewards = aggregateSTokeRewardsDayData(activeDayDatas);
|
|
5236
|
-
const aprRange = [(minApr ?? 0) * 4, (maxApr ?? 0) * 16];
|
|
5237
|
-
return {
|
|
5238
|
-
autopools,
|
|
5239
|
-
totalEarnings,
|
|
5240
|
-
totalEarningsUsd,
|
|
5241
|
-
historicalRewards,
|
|
5242
|
-
aprRange
|
|
5243
|
-
};
|
|
5244
|
-
} catch (e) {
|
|
5245
|
-
console.log("Error fetching rewards payload:", e);
|
|
5246
|
-
return null;
|
|
5247
|
-
}
|
|
5248
|
-
};
|
|
5249
|
-
|
|
5250
|
-
// functions/getSTokeRewards.ts
|
|
5251
|
-
var getSTokeRewards = async ({
|
|
5252
|
-
includeTestnet = false
|
|
5253
|
-
}) => {
|
|
5254
|
-
try {
|
|
5255
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5256
|
-
const sTokeRewards = await fetchChainDataMap(chains, async (chain) => {
|
|
5257
|
-
return getChainSTokeRewards({
|
|
5258
|
-
chainId: chain.chainId
|
|
5259
|
-
});
|
|
5260
|
-
});
|
|
5261
|
-
const totalEarnings = Object.values(sTokeRewards).reduce((acc, item) => {
|
|
5262
|
-
if (item && item.totalEarnings) {
|
|
5263
|
-
return acc + item.totalEarnings;
|
|
5264
|
-
}
|
|
5265
|
-
return acc;
|
|
5266
|
-
}, 0);
|
|
5267
|
-
const totalEarningsUsd = Object.values(sTokeRewards).reduce((acc, item) => {
|
|
5268
|
-
if (item && item.totalEarnings) {
|
|
5269
|
-
return acc + item.totalEarningsUsd;
|
|
5270
|
-
}
|
|
5271
|
-
return acc;
|
|
5272
|
-
}, 0);
|
|
5273
|
-
const allChainsDailyData = Object.values(sTokeRewards).flatMap(
|
|
5274
|
-
(chainResult) => chainResult?.historicalRewards || []
|
|
5275
|
-
);
|
|
5276
|
-
const historicalRewardsAllChains = aggregateSTokeRewardsDayData(allChainsDailyData);
|
|
5277
|
-
return {
|
|
5278
|
-
chains: { ...sTokeRewards },
|
|
5279
|
-
totalEarnings,
|
|
5280
|
-
totalEarningsUsd,
|
|
5281
|
-
historicalRewards: historicalRewardsAllChains
|
|
5282
|
-
};
|
|
5283
|
-
} catch (e) {
|
|
5284
|
-
console.error(e);
|
|
5285
|
-
throw e;
|
|
5286
|
-
}
|
|
5287
|
-
};
|
|
5288
|
-
|
|
5289
|
-
// functions/getChainUserSTokeRewards.ts
|
|
5290
|
-
var import_config16 = require("@tokemak/config");
|
|
5291
|
-
var import_utils42 = require("@tokemak/utils");
|
|
5292
|
-
var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
5293
|
-
address,
|
|
5294
|
-
chainId,
|
|
5295
|
-
tokePrice
|
|
5296
|
-
}) => {
|
|
5297
|
-
const { rewardsV1Url, stokeRewardsHash, stokeRewards } = (0, import_config16.getMainnetConfig)(1);
|
|
5298
|
-
const { stoke } = (0, import_config16.getCoreConfig)(chainId);
|
|
5299
|
-
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
5300
|
-
stoke,
|
|
5301
|
-
chainId
|
|
5302
|
-
});
|
|
5303
|
-
let tokeRewards;
|
|
5304
|
-
try {
|
|
5305
|
-
tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
5306
|
-
address,
|
|
5307
|
-
rewardsCycleIndex: currentCycle,
|
|
5308
|
-
rewardsV1: stokeRewards,
|
|
5309
|
-
rewardsV1Url,
|
|
5310
|
-
rewardsV1Hash: stokeRewardsHash,
|
|
5311
|
-
chainId
|
|
5312
|
-
});
|
|
5313
|
-
if (!tokeRewards?.rewardsPayload) {
|
|
5314
|
-
throw new Error("No rewards payload found");
|
|
5315
|
-
}
|
|
5316
|
-
} catch (error) {
|
|
5317
|
-
console.error(
|
|
5318
|
-
`Error calling getUserRewardsV1 with cycle ${currentCycle}:`,
|
|
5319
|
-
error
|
|
5320
|
-
);
|
|
5321
|
-
try {
|
|
5322
|
-
console.log("Falling back to previous cycle index...");
|
|
5323
|
-
tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
5324
|
-
address,
|
|
5325
|
-
rewardsCycleIndex: currentCycle - 1n,
|
|
5326
|
-
rewardsV1: stokeRewards,
|
|
5327
|
-
rewardsV1Url,
|
|
5328
|
-
rewardsV1Hash: stokeRewardsHash,
|
|
5329
|
-
chainId
|
|
5330
|
-
});
|
|
5331
|
-
if (!tokeRewards?.rewardsPayload) {
|
|
5332
|
-
throw new Error("No rewards payload found (fallback cycle).");
|
|
5333
|
-
}
|
|
5334
|
-
} catch (fallbackError) {
|
|
5335
|
-
console.error(
|
|
5336
|
-
`Error calling getUserRewardsV1 with cycle ${currentCycle - 1n}:`,
|
|
5337
|
-
fallbackError
|
|
5338
|
-
);
|
|
5339
|
-
throw fallbackError;
|
|
5340
|
-
}
|
|
5341
|
-
}
|
|
5342
|
-
const claimableNum = (0, import_utils42.formatEtherNum)(tokeRewards?.claimable || 0n);
|
|
5343
|
-
const claimableUsd = tokePrice * claimableNum;
|
|
5344
|
-
const hasClaimable = claimableNum > 0n;
|
|
5345
|
-
const pendingRewards = (0, import_utils42.formatEtherNum)(
|
|
5346
|
-
tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5347
|
-
);
|
|
5348
|
-
const pendingRewardsUsd = tokePrice * pendingRewards;
|
|
5349
|
-
const totalRewardsReceived = (0, import_utils42.formatEtherNum)(
|
|
5350
|
-
tokeRewards.rewardsPayload.payload.amount || 0n
|
|
5351
|
-
);
|
|
5352
|
-
const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
|
|
5353
|
-
return {
|
|
5354
|
-
claimableUsd,
|
|
5355
|
-
claimableNum,
|
|
5356
|
-
hasClaimable,
|
|
5357
|
-
pendingRewards,
|
|
5358
|
-
pendingRewardsUsd,
|
|
5359
|
-
totalRewardsReceived,
|
|
5360
|
-
totalRewardsReceivedUsd,
|
|
5361
|
-
...tokeRewards
|
|
5362
|
-
};
|
|
5363
|
-
};
|
|
5364
|
-
|
|
5365
4248
|
// functions/getTokenPrices.ts
|
|
5366
|
-
var
|
|
5367
|
-
var
|
|
4249
|
+
var import_tokenlist11 = require("@tokemak/tokenlist");
|
|
4250
|
+
var import_constants17 = require("@tokemak/constants");
|
|
5368
4251
|
var getTokenPrices = async () => {
|
|
5369
4252
|
try {
|
|
5370
4253
|
const body = {
|
|
5371
|
-
tokens:
|
|
4254
|
+
tokens: import_tokenlist11.PRICED_TOKENS.map((asset) => ({
|
|
5372
4255
|
token: asset.address,
|
|
5373
4256
|
chainId: asset.chainId,
|
|
5374
4257
|
systemName: "gen3",
|
|
5375
4258
|
timeoutMS: 5 * 1e3
|
|
5376
4259
|
}))
|
|
5377
4260
|
};
|
|
5378
|
-
const response = await fetch(`${
|
|
4261
|
+
const response = await fetch(`${import_constants17.TOKEMAK_PRICES_STAGING_URL}`, {
|
|
5379
4262
|
method: "POST",
|
|
5380
4263
|
headers: {
|
|
5381
4264
|
"Content-Type": "application/json"
|
|
@@ -5383,7 +4266,7 @@ var getTokenPrices = async () => {
|
|
|
5383
4266
|
body: JSON.stringify(body)
|
|
5384
4267
|
});
|
|
5385
4268
|
const data = await response.json();
|
|
5386
|
-
const prices =
|
|
4269
|
+
const prices = import_tokenlist11.PRICED_TOKENS.reduce((acc, asset) => {
|
|
5387
4270
|
const priceData = data.find(
|
|
5388
4271
|
(item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
|
|
5389
4272
|
);
|
|
@@ -5413,11 +4296,11 @@ var getTokenPrices = async () => {
|
|
|
5413
4296
|
};
|
|
5414
4297
|
|
|
5415
4298
|
// functions/getChainSubgraphStatus.ts
|
|
5416
|
-
var
|
|
4299
|
+
var import_graph_cli12 = require("@tokemak/graph-cli");
|
|
5417
4300
|
var getChainSubgraphStatus = async (chain) => {
|
|
5418
4301
|
const currentTimestamp = Math.floor(Date.now() / 1e3);
|
|
5419
4302
|
try {
|
|
5420
|
-
const { GetLatestSubgraphTimestamp } = (0,
|
|
4303
|
+
const { GetLatestSubgraphTimestamp } = (0, import_graph_cli12.getSdkByChainId)(
|
|
5421
4304
|
chain.chainId
|
|
5422
4305
|
);
|
|
5423
4306
|
const { _meta } = await GetLatestSubgraphTimestamp();
|
|
@@ -5468,172 +4351,36 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5468
4351
|
return { isOutOfSync, errorMessage };
|
|
5469
4352
|
};
|
|
5470
4353
|
|
|
5471
|
-
// functions/getCycleV1.ts
|
|
5472
|
-
var import_core24 = require("@wagmi/core");
|
|
5473
|
-
var import_abis21 = require("@tokemak/abis");
|
|
5474
|
-
var import_viem22 = require("viem");
|
|
5475
|
-
var import_utils44 = require("@tokemak/utils");
|
|
5476
|
-
var import_config17 = require("@tokemak/config");
|
|
5477
|
-
var import_chains14 = require("viem/chains");
|
|
5478
|
-
var publicClient = (0, import_viem22.createPublicClient)({
|
|
5479
|
-
chain: import_chains14.mainnet,
|
|
5480
|
-
transport: (0, import_viem22.http)("https://mainnet.infura.io/v3/2BtQ5D1QEPHvwgZwKwnZC7WQVhr")
|
|
5481
|
-
});
|
|
5482
|
-
var getCycleV1 = async (wagmiConfig, {
|
|
5483
|
-
currentBlockNumber,
|
|
5484
|
-
chainId
|
|
5485
|
-
}) => {
|
|
5486
|
-
const scanPeriodInDays = 8;
|
|
5487
|
-
const blockTime = 12;
|
|
5488
|
-
const { managerV1 } = (0, import_config17.getMainnetConfig)();
|
|
5489
|
-
try {
|
|
5490
|
-
if (currentBlockNumber && managerV1) {
|
|
5491
|
-
const currentCycleIndex = await (0, import_core24.readContract)(wagmiConfig, {
|
|
5492
|
-
address: managerV1,
|
|
5493
|
-
abi: import_abis21.managerV1Abi,
|
|
5494
|
-
functionName: "getCurrentCycleIndex",
|
|
5495
|
-
chainId
|
|
5496
|
-
});
|
|
5497
|
-
const filter = await publicClient.createContractEventFilter({
|
|
5498
|
-
address: managerV1,
|
|
5499
|
-
fromBlock: BigInt(
|
|
5500
|
-
Math.floor(
|
|
5501
|
-
Number(currentBlockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
5502
|
-
)
|
|
5503
|
-
),
|
|
5504
|
-
abi: import_abis21.managerV1Abi,
|
|
5505
|
-
eventName: "CycleRolloverComplete"
|
|
5506
|
-
});
|
|
5507
|
-
const rolloverEvents = await publicClient.getFilterLogs({ filter });
|
|
5508
|
-
const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
|
|
5509
|
-
const secondsLeftBeforeNextCycle = (0, import_utils44.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
|
|
5510
|
-
return {
|
|
5511
|
-
currentCycleIndex,
|
|
5512
|
-
cycleRolloverBlockNumber,
|
|
5513
|
-
timeBeforeNextCycle: (0, import_utils44.convertSecondsToRemainingTime)(
|
|
5514
|
-
secondsLeftBeforeNextCycle
|
|
5515
|
-
)
|
|
5516
|
-
};
|
|
5517
|
-
}
|
|
5518
|
-
} catch (error) {
|
|
5519
|
-
console.error(error);
|
|
5520
|
-
}
|
|
5521
|
-
};
|
|
5522
|
-
|
|
5523
|
-
// functions/getProtocolStats.ts
|
|
5524
|
-
var import_utils45 = require("@tokemak/utils");
|
|
5525
|
-
var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
5526
|
-
try {
|
|
5527
|
-
if (!autopools || !stoke || !sushiLP) {
|
|
5528
|
-
throw new Error("Missing required data");
|
|
5529
|
-
}
|
|
5530
|
-
const autopoolTVL = autopools?.reduce((acc, pool) => acc + pool.tvl, 0) || 0;
|
|
5531
|
-
const categories = autopools?.reduce((acc, pool) => {
|
|
5532
|
-
if (!acc[pool.category]) {
|
|
5533
|
-
if (pool.category === "eth" /* ETH */) {
|
|
5534
|
-
acc[pool.category] = { tvl: 0, supply: 0 };
|
|
5535
|
-
} else {
|
|
5536
|
-
acc[pool.category] = { tvl: 0 };
|
|
5537
|
-
}
|
|
5538
|
-
}
|
|
5539
|
-
acc[pool.category].tvl += pool.tvl;
|
|
5540
|
-
if (pool.category === "eth" /* ETH */) {
|
|
5541
|
-
if (pool.totalAssets) {
|
|
5542
|
-
const ethAmt = pool.totalAssets.ETH;
|
|
5543
|
-
if (acc[pool.category]) {
|
|
5544
|
-
acc[pool.category].supply = (acc[pool.category].supply ?? 0) + ethAmt;
|
|
5545
|
-
}
|
|
5546
|
-
}
|
|
5547
|
-
}
|
|
5548
|
-
return acc;
|
|
5549
|
-
}, {});
|
|
5550
|
-
const formattedCategories = Object.fromEntries(
|
|
5551
|
-
Object.entries(categories).map(([key, value]) => [
|
|
5552
|
-
key,
|
|
5553
|
-
{
|
|
5554
|
-
tvl: (0, import_utils45.formatTVL)(value.tvl),
|
|
5555
|
-
supply: (0, import_utils45.formatLargeNumber)(value.supply || 0)
|
|
5556
|
-
}
|
|
5557
|
-
])
|
|
5558
|
-
);
|
|
5559
|
-
const tvl = (0, import_utils45.formatTVL)(
|
|
5560
|
-
autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0) + (EthAutoLP?.tvlUsd || 0) + (sauto?.rawTVL || 0)
|
|
5561
|
-
);
|
|
5562
|
-
const vaultAddresses = autopools?.flatMap(
|
|
5563
|
-
(pool) => pool.destinations.map((destination) => destination.vaultAddress)
|
|
5564
|
-
);
|
|
5565
|
-
const uniqueVaultAddresses = [...new Set(vaultAddresses)];
|
|
5566
|
-
const totalDestinations = uniqueVaultAddresses.length;
|
|
5567
|
-
const stakedTVL = {
|
|
5568
|
-
totalSupply: (0, import_utils45.formatLargeNumber)(
|
|
5569
|
-
(0, import_utils45.formatEtherNum)(
|
|
5570
|
-
(sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
|
|
5571
|
-
)
|
|
5572
|
-
),
|
|
5573
|
-
tvl: (0, import_utils45.formatTVL)((sauto?.rawTVL || 0) + stoke.rawTVL)
|
|
5574
|
-
};
|
|
5575
|
-
return {
|
|
5576
|
-
autopools: {
|
|
5577
|
-
tvl: (0, import_utils45.formatTVL)(autopoolTVL),
|
|
5578
|
-
tvlNum: autopoolTVL,
|
|
5579
|
-
categories: formattedCategories
|
|
5580
|
-
},
|
|
5581
|
-
stoke: {
|
|
5582
|
-
tvl: (0, import_utils45.formatTVL)(stoke.rawTVL),
|
|
5583
|
-
tvlNum: stoke.rawTVL,
|
|
5584
|
-
totalSupply: `${stoke.totalSupply} TOKE`
|
|
5585
|
-
},
|
|
5586
|
-
sushiLP: {
|
|
5587
|
-
tvl: (0, import_utils45.formatTVL)(sushiLP?.tvl || 0),
|
|
5588
|
-
totalSupply: sushiLP?.totalSupply || 0
|
|
5589
|
-
},
|
|
5590
|
-
EthAutoLP: {
|
|
5591
|
-
tvl: (0, import_utils45.formatTVL)(EthAutoLP?.tvlUsd || 0)
|
|
5592
|
-
},
|
|
5593
|
-
sauto: {
|
|
5594
|
-
tvl: (0, import_utils45.formatTVL)(sauto?.rawTVL || 0),
|
|
5595
|
-
tvlNum: sauto?.rawTVL || 0,
|
|
5596
|
-
totalSupply: `${sauto?.totalSupply} AUTO`
|
|
5597
|
-
},
|
|
5598
|
-
stakedTVL,
|
|
5599
|
-
tvl,
|
|
5600
|
-
totalDestinations
|
|
5601
|
-
};
|
|
5602
|
-
} catch (error) {
|
|
5603
|
-
console.error(error);
|
|
5604
|
-
return null;
|
|
5605
|
-
}
|
|
5606
|
-
};
|
|
5607
|
-
|
|
5608
4354
|
// functions/getRebalanceStats.ts
|
|
5609
|
-
var
|
|
4355
|
+
var import_graph_cli13 = require("@tokemak/graph-cli");
|
|
5610
4356
|
|
|
5611
4357
|
// functions/getEthPriceAtBlock.ts
|
|
5612
|
-
var
|
|
5613
|
-
var
|
|
5614
|
-
var
|
|
5615
|
-
var getEthPriceAtBlock = async (client, blockNumber, chainId) => {
|
|
5616
|
-
const config = (0,
|
|
4358
|
+
var import_config9 = require("@tokemak/config");
|
|
4359
|
+
var import_abis13 = require("@tokemak/abis");
|
|
4360
|
+
var import_tokenlist12 = require("@tokemak/tokenlist");
|
|
4361
|
+
var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
|
|
4362
|
+
const config = (0, import_config9.getCoreConfig)(chainId);
|
|
5617
4363
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5618
4364
|
const weth = config.weth;
|
|
5619
|
-
const usdc =
|
|
4365
|
+
const usdc = import_tokenlist12.USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || import_tokenlist12.USDC_TOKEN.address;
|
|
5620
4366
|
const priceAtBlock = await client.readContract({
|
|
5621
4367
|
address: rootPriceOracle,
|
|
5622
|
-
abi:
|
|
4368
|
+
abi: import_abis13.rootPriceOracleAbi,
|
|
5623
4369
|
functionName: "getPriceInQuote",
|
|
5624
4370
|
args: [weth, usdc],
|
|
5625
|
-
blockNumber
|
|
4371
|
+
blockNumber,
|
|
4372
|
+
account
|
|
5626
4373
|
});
|
|
5627
4374
|
return priceAtBlock;
|
|
5628
4375
|
};
|
|
5629
4376
|
|
|
5630
4377
|
// functions/getRebalanceStats.ts
|
|
5631
|
-
var
|
|
5632
|
-
var
|
|
5633
|
-
var
|
|
4378
|
+
var import_utils33 = require("@tokemak/utils");
|
|
4379
|
+
var import_tokenlist13 = require("@tokemak/tokenlist");
|
|
4380
|
+
var import_chains11 = require("viem/chains");
|
|
5634
4381
|
var BATCH_SIZE = 500;
|
|
5635
4382
|
var fetchChainRebalances = async (chainId) => {
|
|
5636
|
-
const { GetAllAutopoolRebalances } = (0,
|
|
4383
|
+
const { GetAllAutopoolRebalances } = (0, import_graph_cli13.getSdkByChainId)(chainId);
|
|
5637
4384
|
const allRebalances = await paginateQuery(
|
|
5638
4385
|
GetAllAutopoolRebalances,
|
|
5639
4386
|
"autopoolRebalances"
|
|
@@ -5647,22 +4394,23 @@ function inferBaseAssetDecimals(rebalance, chainId) {
|
|
|
5647
4394
|
if (BigInt(rebalance.tokenOutValueBaseAsset) === BigInt(rebalance.tokenOutValueInEth)) {
|
|
5648
4395
|
return 18;
|
|
5649
4396
|
}
|
|
5650
|
-
if (chainId ===
|
|
4397
|
+
if (chainId === import_chains11.sonic.id) {
|
|
5651
4398
|
return rebalance.tokenOut.decimals;
|
|
5652
4399
|
}
|
|
5653
|
-
return
|
|
4400
|
+
return import_tokenlist13.USDC_TOKEN.decimals;
|
|
5654
4401
|
}
|
|
5655
|
-
var getRebalanceValueUsd = async (rebalance, chainId, client) => {
|
|
4402
|
+
var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
|
|
5656
4403
|
const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
|
|
5657
4404
|
if (ethWei === 0n) return null;
|
|
5658
4405
|
try {
|
|
5659
4406
|
const price = await getEthPriceAtBlock(
|
|
5660
4407
|
client,
|
|
5661
4408
|
BigInt(rebalance.blockNumber),
|
|
5662
|
-
chainId
|
|
4409
|
+
chainId,
|
|
4410
|
+
account
|
|
5663
4411
|
);
|
|
5664
|
-
const ethUsd = Number((0,
|
|
5665
|
-
const ethAmt = Number((0,
|
|
4412
|
+
const ethUsd = Number((0, import_utils33.formatUnitsNum)(price, import_tokenlist13.USDC_TOKEN.decimals));
|
|
4413
|
+
const ethAmt = Number((0, import_utils33.formatEtherNum)(ethWei));
|
|
5666
4414
|
const usd = ethAmt * ethUsd;
|
|
5667
4415
|
return usd;
|
|
5668
4416
|
} catch (e) {
|
|
@@ -5670,15 +4418,20 @@ var getRebalanceValueUsd = async (rebalance, chainId, client) => {
|
|
|
5670
4418
|
return null;
|
|
5671
4419
|
}
|
|
5672
4420
|
};
|
|
5673
|
-
var processRebalance = async (rebalance, chainId, client) => {
|
|
4421
|
+
var processRebalance = async (rebalance, chainId, client, account) => {
|
|
5674
4422
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5675
4423
|
const baseAssetAmount = Number(
|
|
5676
|
-
(0,
|
|
4424
|
+
(0, import_utils33.formatUnitsNum)(
|
|
5677
4425
|
BigInt(rebalance.tokenOutValueBaseAsset || "0"),
|
|
5678
4426
|
baseDecimals
|
|
5679
4427
|
)
|
|
5680
4428
|
);
|
|
5681
|
-
const ethPathUsd = await getRebalanceValueUsd(
|
|
4429
|
+
const ethPathUsd = await getRebalanceValueUsd(
|
|
4430
|
+
rebalance,
|
|
4431
|
+
chainId,
|
|
4432
|
+
client,
|
|
4433
|
+
account
|
|
4434
|
+
);
|
|
5682
4435
|
if (ethPathUsd != null) {
|
|
5683
4436
|
return {
|
|
5684
4437
|
autopool: rebalance.autopool,
|
|
@@ -5698,12 +4451,12 @@ var processRebalance = async (rebalance, chainId, client) => {
|
|
|
5698
4451
|
valueInAsset: baseAssetAmount
|
|
5699
4452
|
};
|
|
5700
4453
|
};
|
|
5701
|
-
var processRebalancesInBatches = async (rebalances, chainId, client) => {
|
|
4454
|
+
var processRebalancesInBatches = async (rebalances, chainId, client, account) => {
|
|
5702
4455
|
const processedRebalances = [];
|
|
5703
4456
|
for (let i = 0; i < rebalances.length; i += BATCH_SIZE) {
|
|
5704
4457
|
const batch = rebalances.slice(i, i + BATCH_SIZE);
|
|
5705
4458
|
const batchPromises = batch.map(
|
|
5706
|
-
async (rebalance) => processRebalance(rebalance, chainId, client)
|
|
4459
|
+
async (rebalance) => processRebalance(rebalance, chainId, client, account)
|
|
5707
4460
|
);
|
|
5708
4461
|
const batchResults = await Promise.all(batchPromises);
|
|
5709
4462
|
processedRebalances.push(...batchResults);
|
|
@@ -5729,14 +4482,20 @@ var calculateRebalanceStats = (rebalances) => {
|
|
|
5729
4482
|
};
|
|
5730
4483
|
};
|
|
5731
4484
|
var getRebalanceStats = async (getClient, {
|
|
5732
|
-
includeTestnet = false
|
|
4485
|
+
includeTestnet = false,
|
|
4486
|
+
account
|
|
5733
4487
|
}) => {
|
|
5734
4488
|
const chains = getChainsForEnv({ includeTestnet });
|
|
5735
4489
|
const rebalances = await Promise.all(
|
|
5736
4490
|
chains.map(async (chain) => {
|
|
5737
4491
|
const rawRebalances = await fetchChainRebalances(chain.chainId);
|
|
5738
4492
|
const client = getClient(chain.chainId);
|
|
5739
|
-
return processRebalancesInBatches(
|
|
4493
|
+
return processRebalancesInBatches(
|
|
4494
|
+
rawRebalances,
|
|
4495
|
+
chain.chainId,
|
|
4496
|
+
client,
|
|
4497
|
+
account
|
|
4498
|
+
);
|
|
5740
4499
|
})
|
|
5741
4500
|
);
|
|
5742
4501
|
const allRebalances = rebalances.flat();
|
|
@@ -5744,7 +4503,7 @@ var getRebalanceStats = async (getClient, {
|
|
|
5744
4503
|
};
|
|
5745
4504
|
|
|
5746
4505
|
// functions/updateRebalanceStats.ts
|
|
5747
|
-
var
|
|
4506
|
+
var import_core15 = require("@wagmi/core");
|
|
5748
4507
|
var updateRebalanceStats = async (wagmiConfig, {
|
|
5749
4508
|
currentRebalances,
|
|
5750
4509
|
includeTestnet = false
|
|
@@ -5759,7 +4518,7 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5759
4518
|
)
|
|
5760
4519
|
);
|
|
5761
4520
|
if (newRawRebalances.length > 0) {
|
|
5762
|
-
const client = (0,
|
|
4521
|
+
const client = (0, import_core15.getPublicClient)(wagmiConfig, {
|
|
5763
4522
|
chainId: chain.chainId
|
|
5764
4523
|
});
|
|
5765
4524
|
return processRebalancesInBatches(
|
|
@@ -5777,12 +4536,12 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5777
4536
|
};
|
|
5778
4537
|
|
|
5779
4538
|
// functions/getUserSAuto.ts
|
|
5780
|
-
var
|
|
5781
|
-
var
|
|
5782
|
-
var
|
|
5783
|
-
var
|
|
5784
|
-
var
|
|
5785
|
-
var
|
|
4539
|
+
var import_abis14 = require("@tokemak/abis");
|
|
4540
|
+
var import_config10 = require("@tokemak/config");
|
|
4541
|
+
var import_utils35 = require("@tokemak/utils");
|
|
4542
|
+
var import_core16 = require("@wagmi/core");
|
|
4543
|
+
var import_viem16 = require("viem");
|
|
4544
|
+
var import_chains12 = require("viem/chains");
|
|
5786
4545
|
var getUserSAuto = async (wagmiConfig, {
|
|
5787
4546
|
address,
|
|
5788
4547
|
autoPrice
|
|
@@ -5794,18 +4553,18 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5794
4553
|
if (!autoPrice) {
|
|
5795
4554
|
throw new Error("Auto price not found");
|
|
5796
4555
|
}
|
|
5797
|
-
const { sAuto } = (0,
|
|
5798
|
-
const chainId =
|
|
4556
|
+
const { sAuto } = (0, import_config10.getMainnetConfig)();
|
|
4557
|
+
const chainId = import_chains12.mainnet.id;
|
|
5799
4558
|
const sAutoContract = {
|
|
5800
4559
|
address: sAuto,
|
|
5801
|
-
abi:
|
|
4560
|
+
abi: import_abis14.sAutoAbi
|
|
5802
4561
|
};
|
|
5803
4562
|
const [
|
|
5804
4563
|
{ result: balance },
|
|
5805
4564
|
{ result: depositInfoResult },
|
|
5806
4565
|
{ result: withdrawalInfoResult },
|
|
5807
4566
|
{ result: cycleIndex }
|
|
5808
|
-
] = await (0,
|
|
4567
|
+
] = await (0, import_core16.readContracts)(wagmiConfig, {
|
|
5809
4568
|
contracts: [
|
|
5810
4569
|
{
|
|
5811
4570
|
...sAutoContract,
|
|
@@ -5841,8 +4600,8 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5841
4600
|
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
5842
4601
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
5843
4602
|
}
|
|
5844
|
-
const withdrawalAmountUsd = (0,
|
|
5845
|
-
(0,
|
|
4603
|
+
const withdrawalAmountUsd = (0, import_utils35.formatCurrency)(
|
|
4604
|
+
(0, import_utils35.formatEtherNum)(withdrawalAmount) * autoPrice
|
|
5846
4605
|
);
|
|
5847
4606
|
const lockDuration = Number(depositLockDuration);
|
|
5848
4607
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -5852,24 +4611,24 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5852
4611
|
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
5853
4612
|
const lockRenew = currentCycle - lockStart > lockDuration ? currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement : currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd;
|
|
5854
4613
|
const withdrawAvailable = lockRenew - 1;
|
|
5855
|
-
const balanceUSD = (0,
|
|
5856
|
-
Number((0,
|
|
4614
|
+
const balanceUSD = (0, import_utils35.formatCurrency)(
|
|
4615
|
+
Number((0, import_viem16.formatEther)(balanceExcludingWithdrawal)) * autoPrice
|
|
5857
4616
|
);
|
|
5858
|
-
const balanceExcludingWithdrawalUsd = (0,
|
|
5859
|
-
(0,
|
|
4617
|
+
const balanceExcludingWithdrawalUsd = (0, import_utils35.formatCurrency)(
|
|
4618
|
+
(0, import_utils35.formatEtherNum)(balanceExcludingWithdrawal) * autoPrice
|
|
5860
4619
|
);
|
|
5861
4620
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
5862
4621
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
5863
|
-
const unlockRequestPeriodStartUnix = (0,
|
|
5864
|
-
const unlockRequestPeriodEndUnix = (0,
|
|
4622
|
+
const unlockRequestPeriodStartUnix = (0, import_utils35.convertAutoCycleToUnix)(withdrawAvailable) - Date.now() / 1e3;
|
|
4623
|
+
const unlockRequestPeriodEndUnix = (0, import_utils35.convertAutoCycleToUnix)(lockRenew) - Date.now() / 1e3;
|
|
5865
4624
|
const hasBalance = balance > 0n;
|
|
5866
4625
|
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
5867
4626
|
const hasUnlockableBalance = withdrawalMinCycle <= BigInt(currentCycle) && withdrawalAmount > 0n;
|
|
5868
4627
|
const cyclesInAMonth = 4;
|
|
5869
4628
|
const lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
5870
4629
|
const unlockPeriodDateRangeArray = [
|
|
5871
|
-
new Date((0,
|
|
5872
|
-
new Date((0,
|
|
4630
|
+
new Date((0, import_utils35.convertAutoCycleToUnix)(withdrawAvailable) * 1e3),
|
|
4631
|
+
new Date((0, import_utils35.convertAutoCycleToUnix)(lockRenew) * 1e3)
|
|
5873
4632
|
];
|
|
5874
4633
|
const {
|
|
5875
4634
|
unlockPeriodDateRange,
|
|
@@ -5878,20 +4637,20 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5878
4637
|
unlockPeriodStartDate,
|
|
5879
4638
|
unlockRenewalDate
|
|
5880
4639
|
} = formatDateRange(unlockPeriodDateRangeArray, "date");
|
|
5881
|
-
const totalActiveUserCredits = (0,
|
|
5882
|
-
const totalUserCredits = (0,
|
|
4640
|
+
const totalActiveUserCredits = (0, import_utils35.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
4641
|
+
const totalUserCredits = (0, import_utils35.formatEtherNum)(balance) * lockDurationInMonths;
|
|
5883
4642
|
const hasAddedLockedAuto = depositAmount > 0n;
|
|
5884
4643
|
const addedLockedAuto = depositAmount;
|
|
5885
4644
|
return {
|
|
5886
4645
|
balance,
|
|
5887
4646
|
balanceUSD,
|
|
5888
|
-
balanceExcludingWithdrawal: hasBalance ? (0,
|
|
4647
|
+
balanceExcludingWithdrawal: hasBalance ? (0, import_viem16.formatEther)(balanceExcludingWithdrawal) : "0.00",
|
|
5889
4648
|
balanceExcludingWithdrawalUsd,
|
|
5890
4649
|
hasBalanceExcludingWithdrawal,
|
|
5891
|
-
timeLeftBeforeUnlockRequestAvailable: (0,
|
|
4650
|
+
timeLeftBeforeUnlockRequestAvailable: (0, import_utils35.convertSecondsToRemainingTime)(
|
|
5892
4651
|
unlockRequestPeriodStartUnix
|
|
5893
4652
|
),
|
|
5894
|
-
timeLeftBeforeUnlockRequestUnavailable: (0,
|
|
4653
|
+
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils35.convertSecondsToRemainingTime)(
|
|
5895
4654
|
unlockRequestPeriodEndUnix
|
|
5896
4655
|
),
|
|
5897
4656
|
withdrawalAmount,
|
|
@@ -5908,7 +4667,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5908
4667
|
unlockRenewalDate,
|
|
5909
4668
|
lockDurationInMonths,
|
|
5910
4669
|
boost: lockDuration,
|
|
5911
|
-
points: (0,
|
|
4670
|
+
points: (0, import_utils35.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
5912
4671
|
totalActiveCredits: totalActiveUserCredits,
|
|
5913
4672
|
totalCredits: totalUserCredits,
|
|
5914
4673
|
hasBalance
|
|
@@ -5920,25 +4679,25 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5920
4679
|
};
|
|
5921
4680
|
|
|
5922
4681
|
// functions/getSAuto.ts
|
|
5923
|
-
var
|
|
5924
|
-
var
|
|
5925
|
-
var
|
|
5926
|
-
var
|
|
5927
|
-
var
|
|
5928
|
-
var
|
|
4682
|
+
var import_viem17 = require("viem");
|
|
4683
|
+
var import_core17 = require("@wagmi/core");
|
|
4684
|
+
var import_abis15 = require("@tokemak/abis");
|
|
4685
|
+
var import_utils37 = require("@tokemak/utils");
|
|
4686
|
+
var import_config11 = require("@tokemak/config");
|
|
4687
|
+
var import_chains13 = require("viem/chains");
|
|
5929
4688
|
var getSAuto = async (wagmiConfig, {
|
|
5930
4689
|
autoPrice
|
|
5931
4690
|
}) => {
|
|
5932
4691
|
try {
|
|
5933
|
-
const { sAuto } = (0,
|
|
5934
|
-
const chainId =
|
|
4692
|
+
const { sAuto } = (0, import_config11.getMainnetConfig)();
|
|
4693
|
+
const chainId = import_chains13.mainnet.id;
|
|
5935
4694
|
const baseConfig = {
|
|
5936
4695
|
address: sAuto,
|
|
5937
|
-
abi:
|
|
4696
|
+
abi: import_abis15.sAutoAbi,
|
|
5938
4697
|
chainId
|
|
5939
4698
|
};
|
|
5940
4699
|
if (sAuto && autoPrice) {
|
|
5941
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await (0,
|
|
4700
|
+
const [{ result: totalSupply }, { result: currentCycle }] = await (0, import_core17.readContracts)(wagmiConfig, {
|
|
5942
4701
|
contracts: [
|
|
5943
4702
|
{
|
|
5944
4703
|
...baseConfig,
|
|
@@ -5950,15 +4709,15 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5950
4709
|
}
|
|
5951
4710
|
]
|
|
5952
4711
|
});
|
|
5953
|
-
const tvl = Number((0,
|
|
5954
|
-
const secondsLeftBeforeNextCycle = (0,
|
|
4712
|
+
const tvl = Number((0, import_viem17.formatEther)(totalSupply || 0n)) * autoPrice;
|
|
4713
|
+
const secondsLeftBeforeNextCycle = (0, import_utils37.convertAutoCycleToUnix)(Number(currentCycle) + 1) - Date.now() / 1e3;
|
|
5955
4714
|
return {
|
|
5956
4715
|
rawTotalSupply: totalSupply,
|
|
5957
|
-
totalSupply: (0,
|
|
5958
|
-
tvl: (0,
|
|
4716
|
+
totalSupply: (0, import_utils37.formatLargeNumber)((0, import_viem17.formatEther)(totalSupply || 0n)),
|
|
4717
|
+
tvl: (0, import_utils37.formatTVL)(tvl),
|
|
5959
4718
|
rawTVL: tvl,
|
|
5960
4719
|
currentCycle,
|
|
5961
|
-
timeBeforeNextCycle: (0,
|
|
4720
|
+
timeBeforeNextCycle: (0, import_utils37.convertSecondsToRemainingTime)(
|
|
5962
4721
|
secondsLeftBeforeNextCycle
|
|
5963
4722
|
)
|
|
5964
4723
|
};
|
|
@@ -5969,34 +4728,34 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5969
4728
|
};
|
|
5970
4729
|
|
|
5971
4730
|
// functions/getSAutoRewards.ts
|
|
5972
|
-
var
|
|
5973
|
-
var
|
|
5974
|
-
var
|
|
5975
|
-
var
|
|
4731
|
+
var import_viem18 = require("viem");
|
|
4732
|
+
var import_utils38 = require("@tokemak/utils");
|
|
4733
|
+
var import_graph_cli14 = require("@tokemak/graph-cli");
|
|
4734
|
+
var import_chains14 = require("viem/chains");
|
|
5976
4735
|
var getSAutoRewards = async () => {
|
|
5977
4736
|
try {
|
|
5978
|
-
const { GetSAutoRewards } = (0,
|
|
4737
|
+
const { GetSAutoRewards } = (0, import_graph_cli14.getSdkByChainId)(import_chains14.mainnet.id);
|
|
5979
4738
|
const { globalRewardsBalances } = await GetSAutoRewards();
|
|
5980
4739
|
const allGlobalRewardsBalanceDayDatas = await paginateQuery(
|
|
5981
4740
|
GetSAutoRewards,
|
|
5982
4741
|
"globalRewardsBalanceDayDatas"
|
|
5983
4742
|
);
|
|
5984
4743
|
const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
|
|
5985
|
-
return acc + (0,
|
|
4744
|
+
return acc + (0, import_utils38.formatEtherNum)(balance.balance);
|
|
5986
4745
|
}, 0);
|
|
5987
4746
|
const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
|
|
5988
|
-
return acc + Number((0,
|
|
4747
|
+
return acc + Number((0, import_viem18.formatUnits)(balance.balanceUSD, 8));
|
|
5989
4748
|
}, 0);
|
|
5990
4749
|
const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
|
|
5991
4750
|
(dayData) => ({
|
|
5992
4751
|
timestamp: String(dayData.timestamp),
|
|
5993
|
-
balance: (0,
|
|
5994
|
-
balanceUSD: Number((0,
|
|
5995
|
-
earned: (0,
|
|
5996
|
-
earnedUSD: Number((0,
|
|
5997
|
-
dayAprPerCredit: (0,
|
|
5998
|
-
formattedDate: (0,
|
|
5999
|
-
(0,
|
|
4752
|
+
balance: (0, import_utils38.formatEtherNum)(dayData.balance),
|
|
4753
|
+
balanceUSD: Number((0, import_viem18.formatUnits)(dayData.balanceUSD, 8)),
|
|
4754
|
+
earned: (0, import_utils38.formatEtherNum)(dayData.earned),
|
|
4755
|
+
earnedUSD: Number((0, import_viem18.formatUnits)(dayData.earnedUSD, 8)),
|
|
4756
|
+
dayAprPerCredit: (0, import_utils38.formatEtherNum)(dayData.dayAprPerCredit),
|
|
4757
|
+
formattedDate: (0, import_utils38.formatDateToReadable)(
|
|
4758
|
+
(0, import_utils38.convertTimestampToDate)(Number(dayData.timestamp))
|
|
6000
4759
|
)
|
|
6001
4760
|
})
|
|
6002
4761
|
);
|
|
@@ -6012,10 +4771,10 @@ var getSAutoRewards = async () => {
|
|
|
6012
4771
|
};
|
|
6013
4772
|
|
|
6014
4773
|
// functions/getUserSAutoRewards.ts
|
|
6015
|
-
var
|
|
6016
|
-
var
|
|
4774
|
+
var import_config12 = require("@tokemak/config");
|
|
4775
|
+
var import_utils40 = require("@tokemak/utils");
|
|
6017
4776
|
var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
6018
|
-
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = (0,
|
|
4777
|
+
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = (0, import_config12.getMainnetConfig)();
|
|
6019
4778
|
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
6020
4779
|
stoke: sAuto,
|
|
6021
4780
|
chainId: 1
|
|
@@ -6059,19 +4818,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
|
6059
4818
|
return null;
|
|
6060
4819
|
}
|
|
6061
4820
|
}
|
|
6062
|
-
const claimableNum = (0,
|
|
4821
|
+
const claimableNum = (0, import_utils40.formatEtherNum)(autoRewards?.claimable || 0n);
|
|
6063
4822
|
const claimableUsd = autoPrice * claimableNum;
|
|
6064
4823
|
const hasClaimable = claimableNum > 0;
|
|
6065
|
-
let pendingRewards = (0,
|
|
4824
|
+
let pendingRewards = (0, import_utils40.formatEtherNum)(
|
|
6066
4825
|
autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
6067
4826
|
);
|
|
6068
4827
|
if (currentCycle === 4242n) {
|
|
6069
|
-
pendingRewards = (0,
|
|
4828
|
+
pendingRewards = (0, import_utils40.formatEtherNum)(
|
|
6070
4829
|
autoRewards?.rewardsPayload.payload.amount || 0n
|
|
6071
4830
|
);
|
|
6072
4831
|
}
|
|
6073
4832
|
const pendingRewardsUsd = autoPrice * pendingRewards;
|
|
6074
|
-
const totalRewardsReceived = (0,
|
|
4833
|
+
const totalRewardsReceived = (0, import_utils40.formatEtherNum)(
|
|
6075
4834
|
autoRewards.rewardsPayload.payload.amount || 0n
|
|
6076
4835
|
);
|
|
6077
4836
|
const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
|
|
@@ -6105,20 +4864,20 @@ var getUserMerklRewards = async (address) => {
|
|
|
6105
4864
|
};
|
|
6106
4865
|
|
|
6107
4866
|
// functions/getUserEthAutoLPRewards.ts
|
|
6108
|
-
var
|
|
6109
|
-
var
|
|
6110
|
-
var
|
|
4867
|
+
var import_viem19 = require("viem");
|
|
4868
|
+
var import_utils41 = require("@tokemak/utils");
|
|
4869
|
+
var import_tokenlist14 = require("@tokemak/tokenlist");
|
|
6111
4870
|
var getUserEthAutoLPRewards = async (address) => {
|
|
6112
4871
|
const rewards = await getUserMerklRewards(address);
|
|
6113
4872
|
const autoTokenRewards = rewards?.rewards?.filter(
|
|
6114
|
-
(reward) => (0,
|
|
4873
|
+
(reward) => (0, import_viem19.getAddress)(reward.token.address) === (0, import_viem19.getAddress)(import_tokenlist14.TOKE_TOKEN.address)
|
|
6115
4874
|
);
|
|
6116
4875
|
const autoRewards = autoTokenRewards?.[0];
|
|
6117
4876
|
const amount = autoRewards?.amount;
|
|
6118
4877
|
const claimed = autoRewards?.claimed;
|
|
6119
4878
|
const claimable = Number(amount) - Number(claimed);
|
|
6120
|
-
const formattedClaimable = (0,
|
|
6121
|
-
(0,
|
|
4879
|
+
const formattedClaimable = (0, import_utils41.formatAmount)(
|
|
4880
|
+
(0, import_utils41.formatUnitsNum)(BigInt(claimable || 0), 18)
|
|
6122
4881
|
);
|
|
6123
4882
|
const users = [];
|
|
6124
4883
|
const tokens = [];
|
|
@@ -6170,12 +4929,12 @@ async function getMerklPoolApr({
|
|
|
6170
4929
|
}
|
|
6171
4930
|
|
|
6172
4931
|
// functions/getSAutoApr.ts
|
|
6173
|
-
var
|
|
6174
|
-
var
|
|
6175
|
-
var
|
|
4932
|
+
var import_graph_cli15 = require("@tokemak/graph-cli");
|
|
4933
|
+
var import_chains15 = require("viem/chains");
|
|
4934
|
+
var import_utils42 = require("@tokemak/utils");
|
|
6176
4935
|
var getSAutoApr = async () => {
|
|
6177
4936
|
try {
|
|
6178
|
-
const { GetSAutoApr } = (0,
|
|
4937
|
+
const { GetSAutoApr } = (0, import_graph_cli15.getSdkByChainId)(import_chains15.mainnet.id);
|
|
6179
4938
|
const { globalRewardsBalances } = await GetSAutoApr();
|
|
6180
4939
|
if (!globalRewardsBalances || globalRewardsBalances.length === 0) {
|
|
6181
4940
|
return {
|
|
@@ -6191,12 +4950,12 @@ var getSAutoApr = async () => {
|
|
|
6191
4950
|
aprFormatted: void 0
|
|
6192
4951
|
};
|
|
6193
4952
|
}
|
|
6194
|
-
const aprPerCredit = (0,
|
|
4953
|
+
const aprPerCredit = (0, import_utils42.formatEtherNum)(rawApr);
|
|
6195
4954
|
const lockDuration = 16;
|
|
6196
4955
|
const apr = aprPerCredit * lockDuration;
|
|
6197
4956
|
return {
|
|
6198
4957
|
apr,
|
|
6199
|
-
aprFormatted: (0,
|
|
4958
|
+
aprFormatted: (0, import_utils42.formatPercent)(apr)
|
|
6200
4959
|
};
|
|
6201
4960
|
} catch (error) {
|
|
6202
4961
|
console.error("Error fetching sAUTO APR:", error);
|
|
@@ -6207,58 +4966,45 @@ var getSAutoApr = async () => {
|
|
|
6207
4966
|
}
|
|
6208
4967
|
};
|
|
6209
4968
|
|
|
6210
|
-
// functions/
|
|
6211
|
-
var
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
}
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
}
|
|
6241
|
-
if (!dateByTs.has(ts)) dateByTs.set(ts, item.formattedDate);
|
|
6242
|
-
}
|
|
6243
|
-
const allTimestamps = Array.from(
|
|
6244
|
-
/* @__PURE__ */ new Set([...stokeByTs.keys(), ...sAutoByTs.keys()])
|
|
6245
|
-
).sort((a, b) => a - b);
|
|
6246
|
-
let lastStoke = { balance: 0, balanceUSD: 0 };
|
|
6247
|
-
let lastSAuto = { balance: 0, balanceUSD: 0 };
|
|
6248
|
-
const historicalRewards = allTimestamps.map((ts) => {
|
|
6249
|
-
if (stokeByTs.has(ts)) lastStoke = stokeByTs.get(ts);
|
|
6250
|
-
if (sAutoByTs.has(ts)) lastSAuto = sAutoByTs.get(ts);
|
|
4969
|
+
// functions/getSystemConfig.ts
|
|
4970
|
+
var import_core18 = require("@wagmi/core");
|
|
4971
|
+
var import_abis16 = require("@tokemak/abis");
|
|
4972
|
+
var systemRegistryFunctionNames = [
|
|
4973
|
+
"asyncSwapperRegistry",
|
|
4974
|
+
"autoPoolRouter",
|
|
4975
|
+
"autoPoolRegistry",
|
|
4976
|
+
"swapRouter",
|
|
4977
|
+
"weth"
|
|
4978
|
+
];
|
|
4979
|
+
var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
4980
|
+
const systemRegistryContract = {
|
|
4981
|
+
address: systemRegistry,
|
|
4982
|
+
abi: import_abis16.systemRegistryAbi
|
|
4983
|
+
};
|
|
4984
|
+
const systemRegistryCalls = systemRegistryFunctionNames.map(
|
|
4985
|
+
(functionName) => ({
|
|
4986
|
+
...systemRegistryContract,
|
|
4987
|
+
functionName
|
|
4988
|
+
})
|
|
4989
|
+
);
|
|
4990
|
+
try {
|
|
4991
|
+
const [
|
|
4992
|
+
{ result: asyncSwapperRegistry },
|
|
4993
|
+
{ result: autopoolRouter },
|
|
4994
|
+
{ result: autopoolRegistry },
|
|
4995
|
+
{ result: swapRouter }
|
|
4996
|
+
] = await (0, import_core18.readContracts)(wagmiConfig, {
|
|
4997
|
+
contracts: systemRegistryCalls
|
|
4998
|
+
});
|
|
6251
4999
|
return {
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
5000
|
+
asyncSwapperRegistry,
|
|
5001
|
+
autopoolRouter,
|
|
5002
|
+
autopoolRegistry,
|
|
5003
|
+
swapRouter
|
|
6255
5004
|
};
|
|
6256
|
-
})
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
totalEarningsUsd,
|
|
6260
|
-
historicalRewards
|
|
6261
|
-
};
|
|
5005
|
+
} catch (e) {
|
|
5006
|
+
console.log(e);
|
|
5007
|
+
}
|
|
6262
5008
|
};
|
|
6263
5009
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6264
5010
|
0 && (module.exports = {
|
|
@@ -6266,8 +5012,11 @@ var getCombinedRewards = async () => {
|
|
|
6266
5012
|
BATCH_SIZE,
|
|
6267
5013
|
ETH_BASE_ASSETS,
|
|
6268
5014
|
EUR_BASE_ASSETS,
|
|
6269
|
-
|
|
5015
|
+
GET_USER_POSITIONS,
|
|
5016
|
+
GET_V4_POOL_TVL,
|
|
5017
|
+
GRAPH_V4_SUBGRAPH_PROXY_PATH,
|
|
6270
5018
|
USD_BASE_ASSETS,
|
|
5019
|
+
V4_SUBGRAPH_IDS,
|
|
6271
5020
|
aggregateSTokeRewardsDayData,
|
|
6272
5021
|
arraysToObject,
|
|
6273
5022
|
calculateRebalanceStats,
|
|
@@ -6284,7 +5033,6 @@ var getCombinedRewards = async () => {
|
|
|
6284
5033
|
findClosestTimestampEntry,
|
|
6285
5034
|
formatDateRange,
|
|
6286
5035
|
getAddressFromSystemRegistry,
|
|
6287
|
-
getAllowance,
|
|
6288
5036
|
getAmountDeposited,
|
|
6289
5037
|
getAmountWithdrawn,
|
|
6290
5038
|
getAutopilotRouter,
|
|
@@ -6298,61 +5046,44 @@ var getCombinedRewards = async () => {
|
|
|
6298
5046
|
getAutopoolUserHistory,
|
|
6299
5047
|
getAutopools,
|
|
6300
5048
|
getAutopoolsHistory,
|
|
6301
|
-
getAutopoolsRebalances,
|
|
6302
5049
|
getBlobData,
|
|
6303
5050
|
getBlobHistoricalTokenPrices,
|
|
6304
5051
|
getBridgeFee,
|
|
6305
5052
|
getChainAutopools,
|
|
6306
5053
|
getChainAutopoolsApr,
|
|
6307
|
-
getChainCycleRolloverBlockNumber,
|
|
6308
|
-
getChainSToke,
|
|
6309
|
-
getChainSTokeRewards,
|
|
6310
5054
|
getChainSubgraphStatus,
|
|
6311
5055
|
getChainUserActivity,
|
|
6312
5056
|
getChainUserAutopools,
|
|
6313
|
-
getChainUserSToke,
|
|
6314
|
-
getChainUserSTokeRewards,
|
|
6315
5057
|
getChainsForEnv,
|
|
6316
|
-
getCombinedRewards,
|
|
6317
5058
|
getCurrentCycleId,
|
|
6318
|
-
getCurveLP,
|
|
6319
|
-
getCycleV1,
|
|
6320
5059
|
getDefillamaPoolApr,
|
|
6321
5060
|
getDefillamaPrice,
|
|
5061
|
+
getDeprecatedAutopools,
|
|
6322
5062
|
getDynamicSwap,
|
|
6323
5063
|
getEthAutoLP,
|
|
6324
|
-
getEthPrice,
|
|
6325
5064
|
getEthPriceAtBlock,
|
|
6326
5065
|
getExchangeNames,
|
|
6327
5066
|
getGenStratAprs,
|
|
6328
5067
|
getHistoricalTokenPrices,
|
|
6329
|
-
getLayerzeroStatus,
|
|
6330
5068
|
getMerklCreatorApr,
|
|
6331
5069
|
getMerklPoolApr,
|
|
6332
|
-
getMutlipleAutopoolRebalances,
|
|
6333
5070
|
getPoolStats,
|
|
6334
5071
|
getPoolsAndDestinations,
|
|
6335
|
-
getProtocolStats,
|
|
6336
5072
|
getRebalanceStats,
|
|
6337
5073
|
getRebalanceValueUsd,
|
|
6338
5074
|
getRewardsPayloadV1,
|
|
6339
5075
|
getSAuto,
|
|
6340
5076
|
getSAutoApr,
|
|
6341
5077
|
getSAutoRewards,
|
|
6342
|
-
getSToke,
|
|
6343
5078
|
getSTokeChainsForEnv,
|
|
6344
|
-
getSTokeRewards,
|
|
6345
5079
|
getSubgraphStatus,
|
|
6346
|
-
getSushiLP,
|
|
6347
5080
|
getSwapQuote,
|
|
6348
5081
|
getSystemConfig,
|
|
6349
5082
|
getTimestampDaysFromStart,
|
|
6350
5083
|
getTokePrice,
|
|
6351
|
-
getTokenList,
|
|
6352
5084
|
getTokenPrice,
|
|
6353
5085
|
getTokenPrices,
|
|
6354
5086
|
getTopAutopoolHolders,
|
|
6355
|
-
getUniV4Pool,
|
|
6356
5087
|
getUniV4PoolById,
|
|
6357
5088
|
getUserActivity,
|
|
6358
5089
|
getUserAutoEthRewards,
|
|
@@ -6360,19 +5091,17 @@ var getCombinedRewards = async () => {
|
|
|
6360
5091
|
getUserAutopools,
|
|
6361
5092
|
getUserAutopoolsHistory,
|
|
6362
5093
|
getUserAutopoolsRewards,
|
|
6363
|
-
getUserCurveLP,
|
|
6364
5094
|
getUserEthAutoLP,
|
|
6365
5095
|
getUserEthAutoLPRewards,
|
|
6366
5096
|
getUserMerklRewards,
|
|
6367
5097
|
getUserRewardsV1,
|
|
6368
5098
|
getUserSAuto,
|
|
6369
5099
|
getUserSAutoRewards,
|
|
6370
|
-
getUserSToke,
|
|
6371
|
-
getUserSushiLP,
|
|
6372
5100
|
getUserTokenBalances,
|
|
6373
5101
|
getUserUniV4Positions,
|
|
6374
5102
|
getUserUniV4PositionsById,
|
|
6375
|
-
|
|
5103
|
+
getV4PoolTvlFromSubgraph,
|
|
5104
|
+
getV4SubgraphUrl,
|
|
6376
5105
|
mergeArrays,
|
|
6377
5106
|
mergeArraysWithKey,
|
|
6378
5107
|
mergeStringArrays,
|
|
@@ -6382,6 +5111,5 @@ var getCombinedRewards = async () => {
|
|
|
6382
5111
|
processRebalance,
|
|
6383
5112
|
processRebalancesInBatches,
|
|
6384
5113
|
systemRegistryFunctionNames,
|
|
6385
|
-
updateRebalanceStats
|
|
6386
|
-
waitForMessageReceived
|
|
5114
|
+
updateRebalanceStats
|
|
6387
5115
|
});
|