@tokemak/queries 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/getAutopools.d.ts +3 -1
- package/dist/functions/getAutopools.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/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 +419 -1714
- package/dist/index.mjs +291 -1589
- package/dist/safe.js +12 -8
- package/dist/safe.mjs +8 -4
- package/dist/utils/getChainsForEnv.d.ts +12 -3
- package/dist/utils/getChainsForEnv.d.ts.map +1 -1
- package/package.json +7 -7
- 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,10 +692,10 @@ 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
700
|
var getPoolsAndDestinations = async (client, {
|
|
735
701
|
chainId,
|
|
@@ -737,7 +703,7 @@ var getPoolsAndDestinations = async (client, {
|
|
|
737
703
|
blockNumber
|
|
738
704
|
}) => {
|
|
739
705
|
try {
|
|
740
|
-
const { lens } = (0,
|
|
706
|
+
const { lens } = (0, import_config2.getCoreConfig)(chainId);
|
|
741
707
|
const { autoPools, destinations } = await client.readContract({
|
|
742
708
|
address: lens,
|
|
743
709
|
abi: import_abis.lensAbi,
|
|
@@ -881,7 +847,7 @@ var getChainAutopools = async (client, {
|
|
|
881
847
|
const exchangeName = exchange.name.toLowerCase();
|
|
882
848
|
let exchangeInfo = exchange;
|
|
883
849
|
const value = exchangeValues[exchangeName];
|
|
884
|
-
if (chainId ===
|
|
850
|
+
if (chainId === import_chains.sonic.id) {
|
|
885
851
|
if (exchangeName === "balancerv3" || exchangeName === "balancer") {
|
|
886
852
|
exchangeInfo = import_tokenlist3.BEETS_PROTOCOL;
|
|
887
853
|
}
|
|
@@ -1159,14 +1125,15 @@ var getChainAutopools = async (client, {
|
|
|
1159
1125
|
};
|
|
1160
1126
|
|
|
1161
1127
|
// functions/getAutopools.ts
|
|
1162
|
-
var
|
|
1128
|
+
var import_config3 = require("@tokemak/config");
|
|
1163
1129
|
var import_viem3 = require("viem");
|
|
1164
1130
|
var getAutopools = async (wagmiConfig, {
|
|
1165
1131
|
prices,
|
|
1166
|
-
includeTestnet = false
|
|
1132
|
+
includeTestnet = false,
|
|
1133
|
+
status = "all"
|
|
1167
1134
|
}) => {
|
|
1168
1135
|
try {
|
|
1169
|
-
const chains = getChainsForEnv({ includeTestnet });
|
|
1136
|
+
const chains = getChainsForEnv({ includeTestnet, status });
|
|
1170
1137
|
const autopools = (await Promise.all(
|
|
1171
1138
|
chains.map((chain) => {
|
|
1172
1139
|
const chainId = chain?.chainId;
|
|
@@ -1183,7 +1150,7 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1183
1150
|
return sortedAutopoolsByTimestamp;
|
|
1184
1151
|
} else {
|
|
1185
1152
|
return sortedAutopoolsByTimestamp.filter((pool) => {
|
|
1186
|
-
return
|
|
1153
|
+
return import_config3.AUTOPOOLS_WHITELIST_PROD.includes((0, import_viem3.getAddress)(pool.poolAddress));
|
|
1187
1154
|
});
|
|
1188
1155
|
}
|
|
1189
1156
|
} catch (e) {
|
|
@@ -1191,6 +1158,12 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1191
1158
|
}
|
|
1192
1159
|
};
|
|
1193
1160
|
|
|
1161
|
+
// functions/getDeprecatedAutopools.ts
|
|
1162
|
+
var getDeprecatedAutopools = (wagmiConfig, {
|
|
1163
|
+
prices,
|
|
1164
|
+
includeTestnet = false
|
|
1165
|
+
}) => getAutopools(wagmiConfig, { prices, includeTestnet, status: "sunset" });
|
|
1166
|
+
|
|
1194
1167
|
// functions/getAutopoolRebalances.ts
|
|
1195
1168
|
var import_graph_cli2 = require("@tokemak/graph-cli");
|
|
1196
1169
|
var getAutopoolRebalances = async (id, chainId = 1, options) => {
|
|
@@ -1210,23 +1183,14 @@ var getAutopoolRebalances = async (id, chainId = 1, options) => {
|
|
|
1210
1183
|
}));
|
|
1211
1184
|
};
|
|
1212
1185
|
|
|
1213
|
-
// functions/getAutopoolsRebalances.ts
|
|
1214
|
-
var import_graph_cli3 = require("@tokemak/graph-cli");
|
|
1215
|
-
var getAutopoolsRebalances = async (chainId = 1) => {
|
|
1216
|
-
const { GetAutopoolsRebalances } = (0, import_graph_cli3.getSdkByChainId)(chainId);
|
|
1217
|
-
const { autopools } = await GetAutopoolsRebalances();
|
|
1218
|
-
const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
|
|
1219
|
-
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
1220
|
-
};
|
|
1221
|
-
|
|
1222
1186
|
// functions/getAutopoolDayData.ts
|
|
1223
1187
|
var import_viem4 = require("viem");
|
|
1224
1188
|
var import_utils8 = require("@tokemak/utils");
|
|
1225
1189
|
var import_constants7 = require("@tokemak/constants");
|
|
1226
|
-
var
|
|
1190
|
+
var import_graph_cli3 = require("@tokemak/graph-cli");
|
|
1227
1191
|
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_constants7.TOKEMAK_LAUNCH_TIMESTAMP) => {
|
|
1228
1192
|
try {
|
|
1229
|
-
const { GetAutopoolDayData } = (0,
|
|
1193
|
+
const { GetAutopoolDayData } = (0, import_graph_cli3.getSdkByChainId)(chainId);
|
|
1230
1194
|
const { autopoolDayDatas } = await GetAutopoolDayData({
|
|
1231
1195
|
address,
|
|
1232
1196
|
timestamp: startTimestamp
|
|
@@ -1285,9 +1249,9 @@ var getAutopoolHistory = async (autopool) => {
|
|
|
1285
1249
|
var import_viem5 = require("viem");
|
|
1286
1250
|
|
|
1287
1251
|
// functions/getAutopoolsDayData.ts
|
|
1288
|
-
var
|
|
1252
|
+
var import_graph_cli4 = require("@tokemak/graph-cli");
|
|
1289
1253
|
var getAutopoolsDayData = async (chainId, timestamp) => {
|
|
1290
|
-
const { GetAutopoolsDayData } = (0,
|
|
1254
|
+
const { GetAutopoolsDayData } = (0, import_graph_cli4.getSdkByChainId)(chainId);
|
|
1291
1255
|
const PAGE_SIZE = 1e3;
|
|
1292
1256
|
let allResults = [];
|
|
1293
1257
|
let hasMore = true;
|
|
@@ -1498,7 +1462,7 @@ var getAutopoolUser = async (config, {
|
|
|
1498
1462
|
};
|
|
1499
1463
|
|
|
1500
1464
|
// functions/getAutopoolUserActivity.ts
|
|
1501
|
-
var
|
|
1465
|
+
var import_graph_cli5 = require("@tokemak/graph-cli");
|
|
1502
1466
|
var import_utils13 = require("@tokemak/utils");
|
|
1503
1467
|
var getAutopoolUserActivity = async ({
|
|
1504
1468
|
autopool,
|
|
@@ -1507,7 +1471,7 @@ var getAutopoolUserActivity = async ({
|
|
|
1507
1471
|
if (!autopool || !autopool.chain?.chainId) {
|
|
1508
1472
|
throw new Error("Autopool not found");
|
|
1509
1473
|
}
|
|
1510
|
-
const { GetUserAutopoolBalanceChangeHistory } = (0,
|
|
1474
|
+
const { GetUserAutopoolBalanceChangeHistory } = (0, import_graph_cli5.getSdkByChainId)(
|
|
1511
1475
|
autopool.chain?.chainId
|
|
1512
1476
|
);
|
|
1513
1477
|
try {
|
|
@@ -1586,17 +1550,17 @@ var getAutopoolUserActivity = async ({
|
|
|
1586
1550
|
};
|
|
1587
1551
|
|
|
1588
1552
|
// functions/getAutopoolUserHistory.ts
|
|
1589
|
-
var
|
|
1553
|
+
var import_graph_cli6 = require("@tokemak/graph-cli");
|
|
1590
1554
|
var import_constants8 = require("@tokemak/constants");
|
|
1591
|
-
var
|
|
1555
|
+
var import_chains2 = require("viem/chains");
|
|
1592
1556
|
var import_utils15 = require("@tokemak/utils");
|
|
1593
1557
|
var getAutopoolUserHistory = async ({
|
|
1594
1558
|
userAddress,
|
|
1595
1559
|
autopool,
|
|
1596
1560
|
userActivity
|
|
1597
1561
|
}) => {
|
|
1598
|
-
const { GetUserVaultDayData } = (0,
|
|
1599
|
-
autopool?.chain?.chainId ||
|
|
1562
|
+
const { GetUserVaultDayData } = (0, import_graph_cli6.getSdkByChainId)(
|
|
1563
|
+
autopool?.chain?.chainId || import_chains2.base.id
|
|
1600
1564
|
);
|
|
1601
1565
|
try {
|
|
1602
1566
|
if (userAddress) {
|
|
@@ -1682,99 +1646,59 @@ var getAutopoolUserHistory = async ({
|
|
|
1682
1646
|
}
|
|
1683
1647
|
};
|
|
1684
1648
|
|
|
1685
|
-
// functions/
|
|
1686
|
-
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");
|
|
1687
1653
|
var import_constants9 = require("@tokemak/constants");
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
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}`;
|
|
1702
1667
|
}
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
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
|
|
1712
1682
|
}
|
|
1713
|
-
} catch (e) {
|
|
1714
|
-
console.error(e);
|
|
1715
1683
|
}
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
var import_abis3 = require("@tokemak/abis");
|
|
1721
|
-
var import_config4 = require("@tokemak/config");
|
|
1722
|
-
var import_core3 = require("@wagmi/core");
|
|
1723
|
-
var import_viem7 = require("viem");
|
|
1724
|
-
var import_chains4 = require("viem/chains");
|
|
1725
|
-
var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
1726
|
-
const { sushiPool, lpRewardsV1Url } = (0, import_config4.getMainnetConfig)();
|
|
1727
|
-
const sushiPoolContract = {
|
|
1728
|
-
address: sushiPool,
|
|
1729
|
-
abi: import_abis3.sushiPoolAbi
|
|
1730
|
-
};
|
|
1684
|
+
`;
|
|
1685
|
+
async function getV4PoolTvlFromSubgraph(poolId, chainId, apiKey) {
|
|
1686
|
+
const url = getV4SubgraphUrl(chainId, apiKey);
|
|
1687
|
+
if (!url) return null;
|
|
1731
1688
|
try {
|
|
1732
|
-
const
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
{
|
|
1737
|
-
...sushiPoolContract,
|
|
1738
|
-
functionName: "getReserves",
|
|
1739
|
-
chainId: import_chains4.mainnet.id
|
|
1740
|
-
},
|
|
1741
|
-
{
|
|
1742
|
-
...sushiPoolContract,
|
|
1743
|
-
functionName: "totalSupply",
|
|
1744
|
-
chainId: import_chains4.mainnet.id
|
|
1745
|
-
}
|
|
1746
|
-
]
|
|
1747
|
-
}
|
|
1689
|
+
const client = new import_graphql_request.GraphQLClient(url);
|
|
1690
|
+
const data = await client.request(
|
|
1691
|
+
GET_V4_POOL_TVL,
|
|
1692
|
+
{ id: poolId.toLowerCase() }
|
|
1748
1693
|
);
|
|
1749
|
-
|
|
1750
|
-
const lpRewardsData = await lpRewardsResponse.json();
|
|
1751
|
-
const sushiLPRewards = lpRewardsData.chains[0].pools.find(
|
|
1752
|
-
({ name }) => name === "SUSHI_LP"
|
|
1753
|
-
);
|
|
1754
|
-
if (reserves && totalSupply && ethPrice) {
|
|
1755
|
-
const lpReserve = reserves[1] * 2n;
|
|
1756
|
-
const tvl = Number((0, import_viem7.formatEther)(lpReserve)) * ethPrice;
|
|
1757
|
-
const valueOf1LP = tvl / Number((0, import_viem7.formatEther)(totalSupply));
|
|
1758
|
-
return {
|
|
1759
|
-
tvl,
|
|
1760
|
-
lpReserve,
|
|
1761
|
-
totalSupply,
|
|
1762
|
-
reserves,
|
|
1763
|
-
apr: sushiLPRewards?.liquidityProviderApr,
|
|
1764
|
-
weeklyTokeEmissions: sushiLPRewards?.liquidityProviderReward,
|
|
1765
|
-
valueOf1LP
|
|
1766
|
-
};
|
|
1767
|
-
}
|
|
1694
|
+
return data.pool ?? null;
|
|
1768
1695
|
} catch (e) {
|
|
1769
|
-
console.
|
|
1696
|
+
console.error("Error fetching V4 pool TVL from subgraph:", e);
|
|
1697
|
+
return null;
|
|
1770
1698
|
}
|
|
1771
|
-
}
|
|
1699
|
+
}
|
|
1772
1700
|
|
|
1773
1701
|
// functions/getUniV4Pool.ts
|
|
1774
|
-
var import_core4 = require("@wagmi/core");
|
|
1775
|
-
var import_viem8 = require("viem");
|
|
1776
|
-
var import_chains5 = require("viem/chains");
|
|
1777
|
-
var import_constants10 = require("@tokemak/constants");
|
|
1778
1702
|
var stateViewAbi = [
|
|
1779
1703
|
{
|
|
1780
1704
|
inputs: [{ internalType: "PoolId", name: "poolId", type: "bytes32" }],
|
|
@@ -1820,8 +1744,8 @@ var erc20Abi2 = [
|
|
|
1820
1744
|
}
|
|
1821
1745
|
];
|
|
1822
1746
|
function computePoolId(poolKey) {
|
|
1823
|
-
return (0,
|
|
1824
|
-
(0,
|
|
1747
|
+
return (0, import_viem7.keccak256)(
|
|
1748
|
+
(0, import_viem7.encodeAbiParameters)(
|
|
1825
1749
|
[
|
|
1826
1750
|
{ type: "address", name: "currency0" },
|
|
1827
1751
|
{ type: "address", name: "currency1" },
|
|
@@ -1866,166 +1790,6 @@ function feeToTierString(fee) {
|
|
|
1866
1790
|
};
|
|
1867
1791
|
return tiers[fee] || `${fee / 1e4}%`;
|
|
1868
1792
|
}
|
|
1869
|
-
async function getUniV4Pool(wagmiConfig, {
|
|
1870
|
-
poolKey,
|
|
1871
|
-
chainId = import_chains5.mainnet.id,
|
|
1872
|
-
prices
|
|
1873
|
-
}) {
|
|
1874
|
-
const stateView = import_constants10.UNISWAP_V4_STATE_VIEW[chainId];
|
|
1875
|
-
if (!stateView) {
|
|
1876
|
-
console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
|
|
1877
|
-
return null;
|
|
1878
|
-
}
|
|
1879
|
-
const poolManager = import_constants10.UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1880
|
-
const poolId = computePoolId(poolKey);
|
|
1881
|
-
try {
|
|
1882
|
-
const [{ result: slot0 }, { result: liquidity }] = await (0, import_core4.readContracts)(
|
|
1883
|
-
wagmiConfig,
|
|
1884
|
-
{
|
|
1885
|
-
contracts: [
|
|
1886
|
-
{
|
|
1887
|
-
address: stateView,
|
|
1888
|
-
abi: stateViewAbi,
|
|
1889
|
-
functionName: "getSlot0",
|
|
1890
|
-
args: [poolId],
|
|
1891
|
-
chainId
|
|
1892
|
-
},
|
|
1893
|
-
{
|
|
1894
|
-
address: stateView,
|
|
1895
|
-
abi: stateViewAbi,
|
|
1896
|
-
functionName: "getLiquidity",
|
|
1897
|
-
args: [poolId],
|
|
1898
|
-
chainId
|
|
1899
|
-
}
|
|
1900
|
-
]
|
|
1901
|
-
}
|
|
1902
|
-
);
|
|
1903
|
-
if (!slot0) {
|
|
1904
|
-
return null;
|
|
1905
|
-
}
|
|
1906
|
-
const isToken0Native = poolKey.currency0 === "0x0000000000000000000000000000000000000000";
|
|
1907
|
-
const isToken1Native = poolKey.currency1 === "0x0000000000000000000000000000000000000000";
|
|
1908
|
-
const tokenContracts = [];
|
|
1909
|
-
if (!isToken0Native) {
|
|
1910
|
-
tokenContracts.push(
|
|
1911
|
-
{
|
|
1912
|
-
address: poolKey.currency0,
|
|
1913
|
-
abi: erc20Abi2,
|
|
1914
|
-
functionName: "decimals",
|
|
1915
|
-
chainId
|
|
1916
|
-
},
|
|
1917
|
-
{
|
|
1918
|
-
address: poolKey.currency0,
|
|
1919
|
-
abi: erc20Abi2,
|
|
1920
|
-
functionName: "symbol",
|
|
1921
|
-
chainId
|
|
1922
|
-
},
|
|
1923
|
-
{
|
|
1924
|
-
address: poolKey.currency0,
|
|
1925
|
-
abi: erc20Abi2,
|
|
1926
|
-
functionName: "balanceOf",
|
|
1927
|
-
args: [poolManager],
|
|
1928
|
-
chainId
|
|
1929
|
-
}
|
|
1930
|
-
);
|
|
1931
|
-
}
|
|
1932
|
-
if (!isToken1Native) {
|
|
1933
|
-
tokenContracts.push(
|
|
1934
|
-
{
|
|
1935
|
-
address: poolKey.currency1,
|
|
1936
|
-
abi: erc20Abi2,
|
|
1937
|
-
functionName: "decimals",
|
|
1938
|
-
chainId
|
|
1939
|
-
},
|
|
1940
|
-
{
|
|
1941
|
-
address: poolKey.currency1,
|
|
1942
|
-
abi: erc20Abi2,
|
|
1943
|
-
functionName: "symbol",
|
|
1944
|
-
chainId
|
|
1945
|
-
},
|
|
1946
|
-
{
|
|
1947
|
-
address: poolKey.currency1,
|
|
1948
|
-
abi: erc20Abi2,
|
|
1949
|
-
functionName: "balanceOf",
|
|
1950
|
-
args: [poolManager],
|
|
1951
|
-
chainId
|
|
1952
|
-
}
|
|
1953
|
-
);
|
|
1954
|
-
}
|
|
1955
|
-
const tokenResults = tokenContracts.length > 0 ? await (0, import_core4.readContracts)(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
1956
|
-
let decimals0 = 18;
|
|
1957
|
-
let symbol0 = "ETH";
|
|
1958
|
-
let balance0 = 0n;
|
|
1959
|
-
let decimals1 = 18;
|
|
1960
|
-
let symbol1 = "ETH";
|
|
1961
|
-
let balance1 = 0n;
|
|
1962
|
-
let resultIndex = 0;
|
|
1963
|
-
if (!isToken0Native) {
|
|
1964
|
-
decimals0 = tokenResults[resultIndex++]?.result ?? 18;
|
|
1965
|
-
symbol0 = tokenResults[resultIndex++]?.result ?? "TOKEN0";
|
|
1966
|
-
balance0 = tokenResults[resultIndex++]?.result ?? 0n;
|
|
1967
|
-
}
|
|
1968
|
-
if (!isToken1Native) {
|
|
1969
|
-
decimals1 = tokenResults[resultIndex++]?.result ?? 18;
|
|
1970
|
-
symbol1 = tokenResults[resultIndex++]?.result ?? "TOKEN1";
|
|
1971
|
-
balance1 = tokenResults[resultIndex++]?.result ?? 0n;
|
|
1972
|
-
}
|
|
1973
|
-
const [sqrtPriceX96, tick] = slot0;
|
|
1974
|
-
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1975
|
-
const balance0Formatted = Number((0, import_viem8.formatUnits)(balance0, decimals0));
|
|
1976
|
-
const balance1Formatted = Number((0, import_viem8.formatUnits)(balance1, decimals1));
|
|
1977
|
-
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1978
|
-
liquidity ?? 0n,
|
|
1979
|
-
sqrtPriceX96,
|
|
1980
|
-
decimals0,
|
|
1981
|
-
decimals1
|
|
1982
|
-
);
|
|
1983
|
-
const priceInverted = price > 0 ? 1 / price : 0;
|
|
1984
|
-
const tvlToken0 = liquidityAmounts.amount0 + liquidityAmounts.amount1 * priceInverted;
|
|
1985
|
-
const tvlToken1 = liquidityAmounts.amount1 + liquidityAmounts.amount0 * price;
|
|
1986
|
-
let tvlUsd;
|
|
1987
|
-
if (prices) {
|
|
1988
|
-
const price0 = prices[symbol0] || prices[poolKey.currency0.toLowerCase()];
|
|
1989
|
-
const price1 = prices[symbol1] || prices[poolKey.currency1.toLowerCase()];
|
|
1990
|
-
if (price0) {
|
|
1991
|
-
tvlUsd = tvlToken0 * price0;
|
|
1992
|
-
} else if (price1) {
|
|
1993
|
-
tvlUsd = tvlToken1 * price1;
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
return {
|
|
1997
|
-
poolId,
|
|
1998
|
-
poolKey,
|
|
1999
|
-
token0: {
|
|
2000
|
-
address: poolKey.currency0,
|
|
2001
|
-
symbol: symbol0,
|
|
2002
|
-
decimals: decimals0,
|
|
2003
|
-
balance: balance0,
|
|
2004
|
-
balanceFormatted: balance0Formatted
|
|
2005
|
-
},
|
|
2006
|
-
token1: {
|
|
2007
|
-
address: poolKey.currency1,
|
|
2008
|
-
symbol: symbol1,
|
|
2009
|
-
decimals: decimals1,
|
|
2010
|
-
balance: balance1,
|
|
2011
|
-
balanceFormatted: balance1Formatted
|
|
2012
|
-
},
|
|
2013
|
-
fee: poolKey.fee,
|
|
2014
|
-
feeTier: feeToTierString(poolKey.fee),
|
|
2015
|
-
sqrtPriceX96,
|
|
2016
|
-
tick,
|
|
2017
|
-
liquidity: liquidity ?? 0n,
|
|
2018
|
-
liquidityAmounts,
|
|
2019
|
-
price,
|
|
2020
|
-
priceInverted,
|
|
2021
|
-
tvlToken0,
|
|
2022
|
-
tvlToken1,
|
|
2023
|
-
tvlUsd
|
|
2024
|
-
};
|
|
2025
|
-
} catch (e) {
|
|
2026
|
-
return null;
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
1793
|
function createPoolKey({
|
|
2030
1794
|
tokenA,
|
|
2031
1795
|
tokenB,
|
|
@@ -2047,17 +1811,18 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2047
1811
|
currency0,
|
|
2048
1812
|
currency1,
|
|
2049
1813
|
fee,
|
|
2050
|
-
chainId =
|
|
1814
|
+
chainId = import_chains4.mainnet.id,
|
|
2051
1815
|
prices
|
|
2052
1816
|
}) {
|
|
2053
|
-
const stateView =
|
|
1817
|
+
const stateView = import_constants9.UNISWAP_V4_STATE_VIEW[chainId];
|
|
2054
1818
|
if (!stateView) {
|
|
2055
1819
|
console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
|
|
2056
1820
|
return null;
|
|
2057
1821
|
}
|
|
2058
|
-
const poolManager =
|
|
1822
|
+
const poolManager = import_constants9.UNISWAP_V4_POOL_MANAGER[chainId];
|
|
2059
1823
|
try {
|
|
2060
|
-
const
|
|
1824
|
+
const tvlPromise = getV4PoolTvlFromSubgraph(poolId, chainId);
|
|
1825
|
+
const [{ result: slot0 }, { result: liquidity }] = await (0, import_core3.readContracts)(
|
|
2061
1826
|
wagmiConfig,
|
|
2062
1827
|
{
|
|
2063
1828
|
contracts: [
|
|
@@ -2130,7 +1895,7 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2130
1895
|
}
|
|
2131
1896
|
);
|
|
2132
1897
|
}
|
|
2133
|
-
const tokenResults = tokenContracts.length > 0 ? await (0,
|
|
1898
|
+
const tokenResults = tokenContracts.length > 0 ? await (0, import_core3.readContracts)(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
2134
1899
|
let decimals0 = 18;
|
|
2135
1900
|
let symbol0 = "ETH";
|
|
2136
1901
|
let balance0 = 0n;
|
|
@@ -2150,22 +1915,43 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2150
1915
|
}
|
|
2151
1916
|
const [sqrtPriceX96, tick] = slot0;
|
|
2152
1917
|
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
2153
|
-
const balance0Formatted = Number((0, import_viem8.formatUnits)(balance0, decimals0));
|
|
2154
|
-
const balance1Formatted = Number((0, import_viem8.formatUnits)(balance1, decimals1));
|
|
2155
|
-
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
2156
|
-
liquidity ?? 0n,
|
|
2157
|
-
sqrtPriceX96,
|
|
2158
|
-
decimals0,
|
|
2159
|
-
decimals1
|
|
2160
|
-
);
|
|
2161
1918
|
const priceInverted = price > 0 ? 1 / price : 0;
|
|
2162
|
-
const
|
|
2163
|
-
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;
|
|
2164
1925
|
let tvlUsd;
|
|
2165
|
-
if (
|
|
2166
|
-
const
|
|
2167
|
-
|
|
2168
|
-
|
|
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;
|
|
2169
1955
|
}
|
|
2170
1956
|
}
|
|
2171
1957
|
return {
|
|
@@ -2202,22 +1988,11 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
2202
1988
|
}
|
|
2203
1989
|
|
|
2204
1990
|
// functions/getUserUniV4Positions.ts
|
|
2205
|
-
var
|
|
2206
|
-
var
|
|
2207
|
-
var
|
|
2208
|
-
var
|
|
2209
|
-
var
|
|
2210
|
-
var V4_SUBGRAPH_IDS = {
|
|
2211
|
-
[import_chains6.mainnet.id]: "DiYPVdygkfjDWhbxGSqAQxwBKmfKnkWQojqeM2rkLb3G"
|
|
2212
|
-
};
|
|
2213
|
-
function getV4SubgraphUrl(chainId, apiKey) {
|
|
2214
|
-
const subgraphId = V4_SUBGRAPH_IDS[chainId];
|
|
2215
|
-
if (!subgraphId) return null;
|
|
2216
|
-
if (apiKey) {
|
|
2217
|
-
return `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/${subgraphId}`;
|
|
2218
|
-
}
|
|
2219
|
-
return `https://gateway.thegraph.com/api/subgraphs/id/${subgraphId}`;
|
|
2220
|
-
}
|
|
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");
|
|
2221
1996
|
var positionManagerAbi = [
|
|
2222
1997
|
{
|
|
2223
1998
|
inputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }],
|
|
@@ -2282,7 +2057,7 @@ var erc20Abi3 = [
|
|
|
2282
2057
|
type: "function"
|
|
2283
2058
|
}
|
|
2284
2059
|
];
|
|
2285
|
-
var GET_USER_POSITIONS =
|
|
2060
|
+
var GET_USER_POSITIONS = import_graphql_request2.gql`
|
|
2286
2061
|
query GetUserPositions($owner: String!) {
|
|
2287
2062
|
positions(where: { owner: $owner }) {
|
|
2288
2063
|
tokenId
|
|
@@ -2316,8 +2091,8 @@ function getTokenAmountsFromLiquidity(liquidity, sqrtPriceX96, tickLower, tickUp
|
|
|
2316
2091
|
amount1 = liquidity * (sqrtPriceX96 - sqrtPriceLower) / Q96;
|
|
2317
2092
|
}
|
|
2318
2093
|
return {
|
|
2319
|
-
amount0: Number((0,
|
|
2320
|
-
amount1: Number((0,
|
|
2094
|
+
amount0: Number((0, import_viem8.formatUnits)(amount0, token0Decimals)),
|
|
2095
|
+
amount1: Number((0, import_viem8.formatUnits)(amount1, token1Decimals))
|
|
2321
2096
|
};
|
|
2322
2097
|
}
|
|
2323
2098
|
function feeToTierString2(fee) {
|
|
@@ -2336,7 +2111,7 @@ async function getPositionTokenIdsFromSubgraph(userAddress, chainId, graphApiKey
|
|
|
2336
2111
|
return [];
|
|
2337
2112
|
}
|
|
2338
2113
|
try {
|
|
2339
|
-
const client = new
|
|
2114
|
+
const client = new import_graphql_request2.GraphQLClient(subgraphUrl);
|
|
2340
2115
|
const data = await client.request(GET_USER_POSITIONS, {
|
|
2341
2116
|
owner: userAddress.toLowerCase()
|
|
2342
2117
|
});
|
|
@@ -2354,13 +2129,13 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2354
2129
|
poolId,
|
|
2355
2130
|
currency0,
|
|
2356
2131
|
currency1,
|
|
2357
|
-
chainId =
|
|
2132
|
+
chainId = import_chains5.mainnet.id,
|
|
2358
2133
|
prices,
|
|
2359
2134
|
graphApiKey,
|
|
2360
2135
|
knownTokenIds
|
|
2361
2136
|
}) {
|
|
2362
|
-
const positionManager =
|
|
2363
|
-
const stateView =
|
|
2137
|
+
const positionManager = import_constants10.UNISWAP_V4_POSITION_MANAGER[chainId];
|
|
2138
|
+
const stateView = import_constants10.UNISWAP_V4_STATE_VIEW[chainId];
|
|
2364
2139
|
if (!positionManager || !stateView) {
|
|
2365
2140
|
console.error(`V4 contracts not found for chainId ${chainId}`);
|
|
2366
2141
|
return { positions: [], totalValueUsd: 0, totalPositions: 0 };
|
|
@@ -2370,11 +2145,10 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2370
2145
|
if (knownTokenIds && knownTokenIds.length > 0) {
|
|
2371
2146
|
tokenIds = knownTokenIds;
|
|
2372
2147
|
} else {
|
|
2373
|
-
const apiKey = graphApiKey || import_constants11.GRAPH_API_KEY;
|
|
2374
2148
|
tokenIds = await getPositionTokenIdsFromSubgraph(
|
|
2375
2149
|
userAddress,
|
|
2376
2150
|
chainId,
|
|
2377
|
-
|
|
2151
|
+
graphApiKey
|
|
2378
2152
|
);
|
|
2379
2153
|
}
|
|
2380
2154
|
if (tokenIds.length === 0) {
|
|
@@ -2396,7 +2170,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2396
2170
|
chainId
|
|
2397
2171
|
}
|
|
2398
2172
|
]);
|
|
2399
|
-
const positionResults = await (0,
|
|
2173
|
+
const positionResults = await (0, import_core4.readContracts)(wagmiConfig, {
|
|
2400
2174
|
contracts: positionInfoCalls
|
|
2401
2175
|
});
|
|
2402
2176
|
const matchingPositions = [];
|
|
@@ -2472,7 +2246,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2472
2246
|
}
|
|
2473
2247
|
] : []
|
|
2474
2248
|
];
|
|
2475
|
-
const infoResults = await (0,
|
|
2249
|
+
const infoResults = await (0, import_core4.readContracts)(wagmiConfig, {
|
|
2476
2250
|
contracts: infoCalls
|
|
2477
2251
|
});
|
|
2478
2252
|
const slot0 = infoResults[0]?.result;
|
|
@@ -2548,7 +2322,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2548
2322
|
async function getUserUniV4Positions(wagmiConfig, {
|
|
2549
2323
|
userAddress,
|
|
2550
2324
|
poolKey,
|
|
2551
|
-
chainId =
|
|
2325
|
+
chainId = import_chains5.mainnet.id,
|
|
2552
2326
|
prices,
|
|
2553
2327
|
graphApiKey,
|
|
2554
2328
|
knownTokenIds
|
|
@@ -2567,14 +2341,14 @@ async function getUserUniV4Positions(wagmiConfig, {
|
|
|
2567
2341
|
}
|
|
2568
2342
|
|
|
2569
2343
|
// functions/getDefillamaPoolApr.ts
|
|
2570
|
-
var
|
|
2344
|
+
var import_constants11 = require("@tokemak/constants");
|
|
2571
2345
|
var poolsCache = null;
|
|
2572
2346
|
var CACHE_TTL = 5 * 60 * 1e3;
|
|
2573
2347
|
async function fetchDefiLlamaPools() {
|
|
2574
2348
|
if (poolsCache && Date.now() - poolsCache.timestamp < CACHE_TTL) {
|
|
2575
2349
|
return poolsCache.data;
|
|
2576
2350
|
}
|
|
2577
|
-
const response = await fetch(
|
|
2351
|
+
const response = await fetch(import_constants11.DEFILLAMA_YIELDS_API);
|
|
2578
2352
|
if (!response.ok) {
|
|
2579
2353
|
throw new Error(`DefiLlama API request failed: ${response.statusText}`);
|
|
2580
2354
|
}
|
|
@@ -2627,9 +2401,9 @@ function clearDefillamaCache() {
|
|
|
2627
2401
|
}
|
|
2628
2402
|
|
|
2629
2403
|
// functions/getEthAutoLP.ts
|
|
2630
|
-
var
|
|
2404
|
+
var import_chains6 = require("viem/chains");
|
|
2631
2405
|
var import_tokenlist4 = require("@tokemak/tokenlist");
|
|
2632
|
-
var
|
|
2406
|
+
var import_constants12 = require("@tokemak/constants");
|
|
2633
2407
|
|
|
2634
2408
|
// functions/getMerklCreatorApr.ts
|
|
2635
2409
|
var import_api = require("@merkl/api");
|
|
@@ -2678,11 +2452,11 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2678
2452
|
const currency0 = import_tokenlist4.ETH_TOKEN.address;
|
|
2679
2453
|
const currency1 = import_tokenlist4.AUTO_TOKEN.address;
|
|
2680
2454
|
const poolData = await getUniV4PoolById(wagmiConfig, {
|
|
2681
|
-
poolId:
|
|
2455
|
+
poolId: import_constants12.ETH_AUTO_V4_POOL_ID,
|
|
2682
2456
|
currency0,
|
|
2683
2457
|
currency1,
|
|
2684
|
-
fee:
|
|
2685
|
-
chainId:
|
|
2458
|
+
fee: import_constants12.ETH_AUTO_FEE_TIER,
|
|
2459
|
+
chainId: import_chains6.mainnet.id,
|
|
2686
2460
|
prices
|
|
2687
2461
|
});
|
|
2688
2462
|
if (!poolData) {
|
|
@@ -2691,8 +2465,8 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2691
2465
|
let apr = void 0;
|
|
2692
2466
|
try {
|
|
2693
2467
|
const aprResult = await getMerklCreatorApr({
|
|
2694
|
-
creatorAddress:
|
|
2695
|
-
identifier:
|
|
2468
|
+
creatorAddress: import_constants12.MERKL_CREATOR_ADDRESS,
|
|
2469
|
+
identifier: import_constants12.UNI_V4_POOL_ID
|
|
2696
2470
|
});
|
|
2697
2471
|
apr = aprResult?.totalApr;
|
|
2698
2472
|
} catch (error) {
|
|
@@ -2705,12 +2479,12 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2705
2479
|
}
|
|
2706
2480
|
|
|
2707
2481
|
// functions/getUserEthAutoLP.ts
|
|
2708
|
-
var
|
|
2482
|
+
var import_chains7 = require("viem/chains");
|
|
2709
2483
|
var import_tokenlist5 = require("@tokemak/tokenlist");
|
|
2710
|
-
var
|
|
2484
|
+
var import_constants13 = require("@tokemak/constants");
|
|
2711
2485
|
async function getUserEthAutoLP(wagmiConfig, {
|
|
2712
2486
|
userAddress,
|
|
2713
|
-
chainId =
|
|
2487
|
+
chainId = import_chains7.mainnet.id,
|
|
2714
2488
|
prices,
|
|
2715
2489
|
graphApiKey,
|
|
2716
2490
|
knownTokenIds
|
|
@@ -2719,7 +2493,7 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2719
2493
|
const currency1 = import_tokenlist5.AUTO_TOKEN.address;
|
|
2720
2494
|
return getUserUniV4PositionsById(wagmiConfig, {
|
|
2721
2495
|
userAddress,
|
|
2722
|
-
poolId:
|
|
2496
|
+
poolId: import_constants13.ETH_AUTO_V4_POOL_ID,
|
|
2723
2497
|
currency0,
|
|
2724
2498
|
currency1,
|
|
2725
2499
|
chainId,
|
|
@@ -2730,9 +2504,9 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2730
2504
|
}
|
|
2731
2505
|
|
|
2732
2506
|
// functions/getChainUserActivity.ts
|
|
2733
|
-
var
|
|
2507
|
+
var import_graph_cli7 = require("@tokemak/graph-cli");
|
|
2734
2508
|
var getChainUserActivity = async (address, chainId = 1) => {
|
|
2735
|
-
const { GetUserBalanceChangeHistory } = (0,
|
|
2509
|
+
const { GetUserBalanceChangeHistory } = (0, import_graph_cli7.getSdkByChainId)(chainId);
|
|
2736
2510
|
try {
|
|
2737
2511
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
2738
2512
|
(vars) => GetUserBalanceChangeHistory({
|
|
@@ -2819,8 +2593,8 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
|
|
|
2819
2593
|
};
|
|
2820
2594
|
|
|
2821
2595
|
// functions/getUserAutoEthRewards.ts
|
|
2822
|
-
var
|
|
2823
|
-
var
|
|
2596
|
+
var import_abis3 = require("@tokemak/abis");
|
|
2597
|
+
var import_core5 = require("@wagmi/core");
|
|
2824
2598
|
var import_utils17 = require("@tokemak/utils");
|
|
2825
2599
|
var getAutoEthRewards = async (wagmiConfig, {
|
|
2826
2600
|
account,
|
|
@@ -2830,16 +2604,16 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2830
2604
|
chainId
|
|
2831
2605
|
}) => {
|
|
2832
2606
|
try {
|
|
2833
|
-
const [, drippingHash] = await (0,
|
|
2607
|
+
const [, drippingHash] = await (0, import_core5.readContract)(wagmiConfig, {
|
|
2834
2608
|
address: rewardsHash,
|
|
2835
|
-
abi:
|
|
2609
|
+
abi: import_abis3.autoEthRewardsHashAbi,
|
|
2836
2610
|
functionName: "cycleHashes",
|
|
2837
2611
|
args: [currentCycleIndex - 306n],
|
|
2838
2612
|
chainId
|
|
2839
2613
|
});
|
|
2840
|
-
const [, lastWeekHash] = await (0,
|
|
2614
|
+
const [, lastWeekHash] = await (0, import_core5.readContract)(wagmiConfig, {
|
|
2841
2615
|
address: rewardsHash,
|
|
2842
|
-
abi:
|
|
2616
|
+
abi: import_abis3.autoEthRewardsHashAbi,
|
|
2843
2617
|
functionName: "cycleHashes",
|
|
2844
2618
|
// -1 to get the previous cycle
|
|
2845
2619
|
args: [currentCycleIndex - 306n - 1n],
|
|
@@ -2887,8 +2661,8 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
|
|
|
2887
2661
|
};
|
|
2888
2662
|
|
|
2889
2663
|
// functions/getUserRewardsV1.ts
|
|
2890
|
-
var
|
|
2891
|
-
var
|
|
2664
|
+
var import_abis4 = require("@tokemak/abis");
|
|
2665
|
+
var import_core6 = require("@wagmi/core");
|
|
2892
2666
|
var getUserRewardsV1 = async (wagmiConfig, {
|
|
2893
2667
|
address,
|
|
2894
2668
|
rewardsCycleIndex,
|
|
@@ -2898,11 +2672,11 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2898
2672
|
chainId
|
|
2899
2673
|
}) => {
|
|
2900
2674
|
try {
|
|
2901
|
-
const [latestClaimableHash, cycleRewardsHash] = await (0,
|
|
2675
|
+
const [latestClaimableHash, cycleRewardsHash] = await (0, import_core6.readContract)(
|
|
2902
2676
|
wagmiConfig,
|
|
2903
2677
|
{
|
|
2904
2678
|
address: rewardsV1Hash,
|
|
2905
|
-
abi:
|
|
2679
|
+
abi: import_abis4.rewardsV1HashAbi,
|
|
2906
2680
|
functionName: "cycleHashes",
|
|
2907
2681
|
args: [rewardsCycleIndex],
|
|
2908
2682
|
chainId
|
|
@@ -2922,9 +2696,9 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2922
2696
|
const {
|
|
2923
2697
|
payload: { chainId: payloadChainId, cycle, wallet, amount }
|
|
2924
2698
|
} = latestClaimablePayload;
|
|
2925
|
-
const claimable = await (0,
|
|
2699
|
+
const claimable = await (0, import_core6.readContract)(wagmiConfig, {
|
|
2926
2700
|
address: rewardsV1,
|
|
2927
|
-
abi:
|
|
2701
|
+
abi: import_abis4.rewardsV1Abi,
|
|
2928
2702
|
functionName: "getClaimableAmount",
|
|
2929
2703
|
args: [{ chainId: payloadChainId, cycle, wallet, amount }],
|
|
2930
2704
|
chainId
|
|
@@ -2937,126 +2711,19 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2937
2711
|
}
|
|
2938
2712
|
};
|
|
2939
2713
|
|
|
2940
|
-
// functions/getUserV1.ts
|
|
2941
|
-
var import_abis6 = require("@tokemak/abis");
|
|
2942
|
-
var import_core8 = require("@wagmi/core");
|
|
2943
|
-
var import_config5 = require("@tokemak/config");
|
|
2944
|
-
var import_chains9 = require("viem/chains");
|
|
2945
|
-
var getUserV1 = async (wagmiConfig, {
|
|
2946
|
-
currentCycleIndex,
|
|
2947
|
-
address,
|
|
2948
|
-
chainId
|
|
2949
|
-
}) => {
|
|
2950
|
-
const {
|
|
2951
|
-
stakingV1,
|
|
2952
|
-
rewardsV1Url,
|
|
2953
|
-
accTokeV1RewardsHash,
|
|
2954
|
-
rewardsV1Hash,
|
|
2955
|
-
accTokeV1Rewards,
|
|
2956
|
-
autoEthGuardedRewards,
|
|
2957
|
-
rewardsV1,
|
|
2958
|
-
missedTokeRewards
|
|
2959
|
-
} = (0, import_config5.getMainnetConfig)(import_chains9.mainnet.id);
|
|
2960
|
-
try {
|
|
2961
|
-
const userStakedTokeV1 = await (0, import_core8.readContract)(wagmiConfig, {
|
|
2962
|
-
address: stakingV1,
|
|
2963
|
-
abi: import_abis6.stakingV1Abi,
|
|
2964
|
-
functionName: "availableForWithdrawal",
|
|
2965
|
-
args: [address, 0n],
|
|
2966
|
-
chainId: import_chains9.mainnet.id
|
|
2967
|
-
});
|
|
2968
|
-
const tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
2969
|
-
address,
|
|
2970
|
-
rewardsCycleIndex: currentCycleIndex - 1n,
|
|
2971
|
-
rewardsV1,
|
|
2972
|
-
rewardsV1Url,
|
|
2973
|
-
rewardsV1Hash,
|
|
2974
|
-
chainId
|
|
2975
|
-
});
|
|
2976
|
-
const ethRewards = await getUserRewardsV1(wagmiConfig, {
|
|
2977
|
-
address,
|
|
2978
|
-
rewardsCycleIndex: 306n,
|
|
2979
|
-
rewardsV1: accTokeV1Rewards,
|
|
2980
|
-
rewardsV1Url,
|
|
2981
|
-
rewardsV1Hash: accTokeV1RewardsHash,
|
|
2982
|
-
chainId
|
|
2983
|
-
});
|
|
2984
|
-
const autoEthGuardedRewardsPayload = await getRewardsPayloadV1(
|
|
2985
|
-
"QmcJgQ42aGTsqngSBa98qxnbv2CHyk9DmSg1jDD569bnpp",
|
|
2986
|
-
address,
|
|
2987
|
-
rewardsV1Url
|
|
2988
|
-
);
|
|
2989
|
-
const payloadChainId = autoEthGuardedRewardsPayload?.payload?.chainId;
|
|
2990
|
-
const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
|
|
2991
|
-
const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
|
|
2992
|
-
const amount = autoEthGuardedRewardsPayload?.payload?.amount;
|
|
2993
|
-
const claimableAutoEth = await (0, import_core8.readContract)(wagmiConfig, {
|
|
2994
|
-
address: autoEthGuardedRewards,
|
|
2995
|
-
abi: import_abis6.rewardsV1Abi,
|
|
2996
|
-
functionName: "getClaimableAmount",
|
|
2997
|
-
args: [
|
|
2998
|
-
{
|
|
2999
|
-
chainId: payloadChainId || 0n,
|
|
3000
|
-
cycle: cycle || 0n,
|
|
3001
|
-
wallet: wallet || "0x0000000000000000000000000000000000000000",
|
|
3002
|
-
amount: amount || 0n
|
|
3003
|
-
}
|
|
3004
|
-
],
|
|
3005
|
-
chainId
|
|
3006
|
-
});
|
|
3007
|
-
const missedTokeRewardsPayload = await getRewardsPayloadV1(
|
|
3008
|
-
"QmRpVjVhFqbUTtLnQ4addEwBtvF2CC7t6rbQWYiju9nAqd",
|
|
3009
|
-
address,
|
|
3010
|
-
rewardsV1Url
|
|
3011
|
-
);
|
|
3012
|
-
let claimableMissedToke = 0n;
|
|
3013
|
-
if (missedTokeRewardsPayload) {
|
|
3014
|
-
const {
|
|
3015
|
-
payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
|
|
3016
|
-
} = missedTokeRewardsPayload;
|
|
3017
|
-
claimableMissedToke = await (0, import_core8.readContract)(wagmiConfig, {
|
|
3018
|
-
address: missedTokeRewards,
|
|
3019
|
-
abi: import_abis6.rewardsV1Abi,
|
|
3020
|
-
functionName: "getClaimableAmount",
|
|
3021
|
-
args: [
|
|
3022
|
-
{
|
|
3023
|
-
chainId: payloadChainId2,
|
|
3024
|
-
cycle: cycle2,
|
|
3025
|
-
wallet: wallet2,
|
|
3026
|
-
amount: amount2 || 0n
|
|
3027
|
-
}
|
|
3028
|
-
],
|
|
3029
|
-
chainId
|
|
3030
|
-
});
|
|
3031
|
-
}
|
|
3032
|
-
return {
|
|
3033
|
-
stakedToke: userStakedTokeV1,
|
|
3034
|
-
claimableToke: tokeRewards?.claimable,
|
|
3035
|
-
claimableEth: ethRewards?.claimable,
|
|
3036
|
-
claimableAutoEth,
|
|
3037
|
-
tokeRewardsPayload: tokeRewards?.rewardsPayload,
|
|
3038
|
-
ethRewardsPayload: ethRewards?.rewardsPayload,
|
|
3039
|
-
missedTokeRewardsPayload,
|
|
3040
|
-
autoEthGuardedRewardsPayload,
|
|
3041
|
-
claimableMissedToke
|
|
3042
|
-
};
|
|
3043
|
-
} catch (e) {
|
|
3044
|
-
}
|
|
3045
|
-
};
|
|
3046
|
-
|
|
3047
2714
|
// functions/getChainUserAutopoolsHistory.tsx
|
|
3048
|
-
var
|
|
3049
|
-
var
|
|
2715
|
+
var import_graph_cli8 = require("@tokemak/graph-cli");
|
|
2716
|
+
var import_constants14 = require("@tokemak/constants");
|
|
3050
2717
|
var getChainUserAutopoolsHistory = async ({
|
|
3051
2718
|
address,
|
|
3052
2719
|
chainId = 1
|
|
3053
2720
|
}) => {
|
|
3054
|
-
const { GetUserVaultsDayData } = (0,
|
|
2721
|
+
const { GetUserVaultsDayData } = (0, import_graph_cli8.getSdkByChainId)(chainId);
|
|
3055
2722
|
try {
|
|
3056
2723
|
if (address) {
|
|
3057
2724
|
const { userVaultDayDatas } = await GetUserVaultsDayData({
|
|
3058
2725
|
address,
|
|
3059
|
-
timestamp:
|
|
2726
|
+
timestamp: import_constants14.TOKEMAK_LAUNCH_TIMESTAMP
|
|
3060
2727
|
});
|
|
3061
2728
|
return userVaultDayDatas;
|
|
3062
2729
|
}
|
|
@@ -3071,12 +2738,12 @@ var getChainUserAutopoolsHistory = async ({
|
|
|
3071
2738
|
var import_utils21 = require("@tokemak/utils");
|
|
3072
2739
|
|
|
3073
2740
|
// functions/getTokenValueDayDatas.ts
|
|
3074
|
-
var
|
|
2741
|
+
var import_chains8 = require("viem/chains");
|
|
3075
2742
|
var import_utils18 = require("@tokemak/utils");
|
|
3076
|
-
var
|
|
3077
|
-
var
|
|
3078
|
-
var getTokenValueDayDatas = async (tokenAddress, chainId =
|
|
3079
|
-
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);
|
|
3080
2747
|
try {
|
|
3081
2748
|
const { tokenValueDayDatas } = await GetTokenValueDayDatas({
|
|
3082
2749
|
tokenAddress: tokenAddress.toLowerCase()
|
|
@@ -3085,7 +2752,7 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainn
|
|
|
3085
2752
|
const date = (0, import_utils18.convertTimestampToDate)(
|
|
3086
2753
|
tokenValueDayData.lastSnapshotTimestamp
|
|
3087
2754
|
);
|
|
3088
|
-
const usdPrice = (0,
|
|
2755
|
+
const usdPrice = (0, import_viem9.formatUnits)(tokenValueDayData.priceInUsd, 8);
|
|
3089
2756
|
return {
|
|
3090
2757
|
timestamp: Number(tokenValueDayData.lastSnapshotTimestamp),
|
|
3091
2758
|
date,
|
|
@@ -3384,212 +3051,13 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3384
3051
|
return result;
|
|
3385
3052
|
};
|
|
3386
3053
|
|
|
3387
|
-
// functions/getUserSushiLP.ts
|
|
3388
|
-
var import_core9 = require("@wagmi/core");
|
|
3389
|
-
var import_abis7 = require("@tokemak/abis");
|
|
3390
|
-
var import_config6 = require("@tokemak/config");
|
|
3391
|
-
var getUserSushiLP = async (wagmiConfig, {
|
|
3392
|
-
sushiLP,
|
|
3393
|
-
currentCycleIndex,
|
|
3394
|
-
address,
|
|
3395
|
-
cycleRolloverBlockNumber,
|
|
3396
|
-
chainId
|
|
3397
|
-
}) => {
|
|
3398
|
-
const { tSushiLP, sushiPool } = (0, import_config6.getMainnetConfig)();
|
|
3399
|
-
try {
|
|
3400
|
-
if (address && currentCycleIndex && sushiLP) {
|
|
3401
|
-
const [
|
|
3402
|
-
{ result: sushiLPBalance },
|
|
3403
|
-
{ result: tSushiLPBalance },
|
|
3404
|
-
{ result: tSushiLPRequested }
|
|
3405
|
-
] = await (0, import_core9.readContracts)(wagmiConfig, {
|
|
3406
|
-
contracts: [
|
|
3407
|
-
{
|
|
3408
|
-
address: sushiPool,
|
|
3409
|
-
abi: import_abis7.sushiPoolAbi,
|
|
3410
|
-
functionName: "balanceOf",
|
|
3411
|
-
args: [address],
|
|
3412
|
-
chainId
|
|
3413
|
-
},
|
|
3414
|
-
{
|
|
3415
|
-
address: tSushiLP,
|
|
3416
|
-
abi: import_abis7.poolV1Abi,
|
|
3417
|
-
functionName: "balanceOf",
|
|
3418
|
-
args: [address],
|
|
3419
|
-
chainId
|
|
3420
|
-
},
|
|
3421
|
-
{
|
|
3422
|
-
address: tSushiLP,
|
|
3423
|
-
abi: import_abis7.poolV1Abi,
|
|
3424
|
-
functionName: "requestedWithdrawals",
|
|
3425
|
-
args: [address],
|
|
3426
|
-
chainId
|
|
3427
|
-
}
|
|
3428
|
-
]
|
|
3429
|
-
});
|
|
3430
|
-
const [
|
|
3431
|
-
{ result: startTSushiLPBalance },
|
|
3432
|
-
{ result: startTSushiLPRequested }
|
|
3433
|
-
] = await (0, import_core9.readContracts)(wagmiConfig, {
|
|
3434
|
-
contracts: [
|
|
3435
|
-
{
|
|
3436
|
-
address: tSushiLP,
|
|
3437
|
-
abi: import_abis7.poolV1Abi,
|
|
3438
|
-
functionName: "balanceOf",
|
|
3439
|
-
args: [address],
|
|
3440
|
-
chainId
|
|
3441
|
-
},
|
|
3442
|
-
{
|
|
3443
|
-
address: tSushiLP,
|
|
3444
|
-
abi: import_abis7.poolV1Abi,
|
|
3445
|
-
functionName: "requestedWithdrawals",
|
|
3446
|
-
args: [address],
|
|
3447
|
-
chainId
|
|
3448
|
-
}
|
|
3449
|
-
],
|
|
3450
|
-
blockNumber: cycleRolloverBlockNumber
|
|
3451
|
-
});
|
|
3452
|
-
const startTSushiWithdrawAmount = startTSushiLPRequested?.[1] || 0n;
|
|
3453
|
-
const yieldingBalance = (startTSushiLPBalance || 0n) - startTSushiWithdrawAmount;
|
|
3454
|
-
let balanceExcludingWithdrawal = tSushiLPBalance || 0n;
|
|
3455
|
-
const [withdrawalMinCycle, withdrawalAmount] = tSushiLPRequested || [
|
|
3456
|
-
0n,
|
|
3457
|
-
0n
|
|
3458
|
-
];
|
|
3459
|
-
if (withdrawalAmount > 0n && currentCycleIndex >= withdrawalMinCycle) {
|
|
3460
|
-
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
3461
|
-
}
|
|
3462
|
-
const shareOftSushiLP = Number(balanceExcludingWithdrawal) / Number(sushiLP.totalSupply);
|
|
3463
|
-
const tSushiLPUsd = sushiLP.tvl * shareOftSushiLP;
|
|
3464
|
-
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
3465
|
-
const hasUnlockableBalance = withdrawalMinCycle <= currentCycleIndex && withdrawalAmount > 0n;
|
|
3466
|
-
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
3467
|
-
return {
|
|
3468
|
-
sushiLPBalance,
|
|
3469
|
-
tSushiLPBalance,
|
|
3470
|
-
tSushiLPRequested,
|
|
3471
|
-
shareOftSushiLP,
|
|
3472
|
-
tSushiLPUsd,
|
|
3473
|
-
balanceExcludingWithdrawal,
|
|
3474
|
-
hasAddedTSushi: yieldingBalance < balanceExcludingWithdrawal,
|
|
3475
|
-
hasRequestedUnlock,
|
|
3476
|
-
hasUnlockableBalance,
|
|
3477
|
-
withdrawalAmount,
|
|
3478
|
-
hasBalanceExcludingWithdrawal
|
|
3479
|
-
};
|
|
3480
|
-
}
|
|
3481
|
-
} catch (e) {
|
|
3482
|
-
console.log(e);
|
|
3483
|
-
}
|
|
3484
|
-
};
|
|
3485
|
-
|
|
3486
|
-
// functions/getUserCurveLP.ts
|
|
3487
|
-
var import_core10 = require("@wagmi/core");
|
|
3488
|
-
var import_abis8 = require("@tokemak/abis");
|
|
3489
|
-
var import_config7 = require("@tokemak/config");
|
|
3490
|
-
var getUserCurveLP = async (wagmiConfig, {
|
|
3491
|
-
curveLP,
|
|
3492
|
-
address,
|
|
3493
|
-
chainId
|
|
3494
|
-
}) => {
|
|
3495
|
-
try {
|
|
3496
|
-
const { curvePool, convexRewarder } = (0, import_config7.getMainnetConfig)();
|
|
3497
|
-
if (address && curveLP && curvePool && convexRewarder) {
|
|
3498
|
-
const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await (0, import_core10.readContracts)(wagmiConfig, {
|
|
3499
|
-
contracts: [
|
|
3500
|
-
{
|
|
3501
|
-
address: curvePool,
|
|
3502
|
-
abi: import_abis8.poolV1Abi,
|
|
3503
|
-
functionName: "balanceOf",
|
|
3504
|
-
args: [address],
|
|
3505
|
-
chainId
|
|
3506
|
-
},
|
|
3507
|
-
{
|
|
3508
|
-
address: convexRewarder,
|
|
3509
|
-
abi: import_abis8.poolV1Abi,
|
|
3510
|
-
functionName: "balanceOf",
|
|
3511
|
-
args: [address],
|
|
3512
|
-
chainId
|
|
3513
|
-
}
|
|
3514
|
-
]
|
|
3515
|
-
});
|
|
3516
|
-
const shareOfCurve = Number(userCurveLPBalance || 0n) / Number(curveLP.totalSupply);
|
|
3517
|
-
const shareOfConvex = Number(userConvexLPBalance || 0n) / Number(curveLP.totalSupply);
|
|
3518
|
-
const curveLPUsd = shareOfCurve * curveLP.curveTvl;
|
|
3519
|
-
const convexLPUsd = shareOfConvex * curveLP.curveTvl;
|
|
3520
|
-
return {
|
|
3521
|
-
curveLPBalance: userCurveLPBalance,
|
|
3522
|
-
convexLPBalance: userConvexLPBalance,
|
|
3523
|
-
shareOfCurve,
|
|
3524
|
-
shareOfConvex,
|
|
3525
|
-
curveLPUsd,
|
|
3526
|
-
convexLPUsd
|
|
3527
|
-
};
|
|
3528
|
-
}
|
|
3529
|
-
} catch (e) {
|
|
3530
|
-
console.log(e);
|
|
3531
|
-
}
|
|
3532
|
-
};
|
|
3533
|
-
|
|
3534
|
-
// functions/getMultipleAutopoolRebalances.ts
|
|
3535
|
-
var import_graph_cli11 = require("@tokemak/graph-cli");
|
|
3536
|
-
var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
3537
|
-
const { GetMutlipleAutopoolRebalances } = (0, import_graph_cli11.getSdkByChainId)(chainId);
|
|
3538
|
-
const { autopools } = await GetMutlipleAutopoolRebalances({
|
|
3539
|
-
addresses: ids
|
|
3540
|
-
});
|
|
3541
|
-
const rebalances = autopools.map(({ rebalances: rebalances2 }) => rebalances2);
|
|
3542
|
-
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
3543
|
-
};
|
|
3544
|
-
|
|
3545
|
-
// functions/getSystemConfig.ts
|
|
3546
|
-
var import_core11 = require("@wagmi/core");
|
|
3547
|
-
var import_abis9 = require("@tokemak/abis");
|
|
3548
|
-
var systemRegistryFunctionNames = [
|
|
3549
|
-
"asyncSwapperRegistry",
|
|
3550
|
-
"autoPoolRouter",
|
|
3551
|
-
"autoPoolRegistry",
|
|
3552
|
-
"swapRouter",
|
|
3553
|
-
"weth"
|
|
3554
|
-
];
|
|
3555
|
-
var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
3556
|
-
const systemRegistryContract = {
|
|
3557
|
-
address: systemRegistry,
|
|
3558
|
-
abi: import_abis9.systemRegistryAbi
|
|
3559
|
-
};
|
|
3560
|
-
const systemRegistryCalls = systemRegistryFunctionNames.map(
|
|
3561
|
-
(functionName) => ({
|
|
3562
|
-
...systemRegistryContract,
|
|
3563
|
-
functionName
|
|
3564
|
-
})
|
|
3565
|
-
);
|
|
3566
|
-
try {
|
|
3567
|
-
const [
|
|
3568
|
-
{ result: asyncSwapperRegistry },
|
|
3569
|
-
{ result: autopoolRouter },
|
|
3570
|
-
{ result: autopoolRegistry },
|
|
3571
|
-
{ result: swapRouter }
|
|
3572
|
-
] = await (0, import_core11.readContracts)(wagmiConfig, {
|
|
3573
|
-
contracts: systemRegistryCalls
|
|
3574
|
-
});
|
|
3575
|
-
return {
|
|
3576
|
-
asyncSwapperRegistry,
|
|
3577
|
-
autopoolRouter,
|
|
3578
|
-
autopoolRegistry,
|
|
3579
|
-
swapRouter
|
|
3580
|
-
};
|
|
3581
|
-
} catch (e) {
|
|
3582
|
-
console.log(e);
|
|
3583
|
-
}
|
|
3584
|
-
};
|
|
3585
|
-
|
|
3586
3054
|
// functions/getChainUserAutopools.tsx
|
|
3587
|
-
var
|
|
3055
|
+
var import_graph_cli10 = require("@tokemak/graph-cli");
|
|
3588
3056
|
var getChainUserAutopools = async ({
|
|
3589
3057
|
address,
|
|
3590
3058
|
chainId = 1
|
|
3591
3059
|
}) => {
|
|
3592
|
-
const { GetUserVaultInfo } = (0,
|
|
3060
|
+
const { GetUserVaultInfo } = (0, import_graph_cli10.getSdkByChainId)(chainId);
|
|
3593
3061
|
try {
|
|
3594
3062
|
if (address) {
|
|
3595
3063
|
const { userInfo } = await GetUserVaultInfo({
|
|
@@ -3609,10 +3077,10 @@ var import_utils23 = require("@tokemak/utils");
|
|
|
3609
3077
|
var import_tokenlist7 = require("@tokemak/tokenlist");
|
|
3610
3078
|
|
|
3611
3079
|
// functions/getUserAutopool.tsx
|
|
3612
|
-
var
|
|
3613
|
-
var
|
|
3080
|
+
var import_viem10 = require("viem");
|
|
3081
|
+
var import_core7 = require("@wagmi/core");
|
|
3614
3082
|
var import_utils22 = require("@tokemak/utils");
|
|
3615
|
-
var
|
|
3083
|
+
var import_abis5 = require("@tokemak/abis");
|
|
3616
3084
|
var getUserAutopool = async (wagmiConfig, {
|
|
3617
3085
|
address,
|
|
3618
3086
|
autopool
|
|
@@ -3621,14 +3089,14 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3621
3089
|
if (autopool && address) {
|
|
3622
3090
|
const autopoolContract = {
|
|
3623
3091
|
address: autopool?.poolAddress,
|
|
3624
|
-
abi:
|
|
3092
|
+
abi: import_abis5.autopoolEthAbi,
|
|
3625
3093
|
chainId: autopool?.chain?.chainId
|
|
3626
3094
|
};
|
|
3627
3095
|
const [
|
|
3628
3096
|
{ result: autopoolRewarderContract },
|
|
3629
3097
|
{ result: pastRewarders },
|
|
3630
3098
|
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
3631
|
-
] = await (0,
|
|
3099
|
+
] = await (0, import_core7.readContracts)(wagmiConfig, {
|
|
3632
3100
|
contracts: [
|
|
3633
3101
|
{
|
|
3634
3102
|
...autopoolContract,
|
|
@@ -3653,9 +3121,9 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3653
3121
|
if (unstakedPoolSharesError) {
|
|
3654
3122
|
throw new Error("Error fetching unstaked pool shares");
|
|
3655
3123
|
}
|
|
3656
|
-
const stakedPoolShares = await (0,
|
|
3124
|
+
const stakedPoolShares = await (0, import_core7.readContract)(wagmiConfig, {
|
|
3657
3125
|
address: autopoolRewarderContract,
|
|
3658
|
-
abi:
|
|
3126
|
+
abi: import_viem10.erc20Abi,
|
|
3659
3127
|
functionName: "balanceOf",
|
|
3660
3128
|
args: [address],
|
|
3661
3129
|
chainId: autopool?.chain?.chainId
|
|
@@ -3674,12 +3142,12 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3674
3142
|
if (pastRewarders && pastRewarders?.length > 0) {
|
|
3675
3143
|
const pastRewardBalances = pastRewarders.map((rewarder) => ({
|
|
3676
3144
|
address: rewarder,
|
|
3677
|
-
abi:
|
|
3145
|
+
abi: import_viem10.erc20Abi,
|
|
3678
3146
|
functionName: "balanceOf",
|
|
3679
3147
|
args: [address],
|
|
3680
3148
|
chainId: autopool?.chain?.chainId
|
|
3681
3149
|
}));
|
|
3682
|
-
const pastRewards = await (0,
|
|
3150
|
+
const pastRewards = await (0, import_core7.readContracts)(wagmiConfig, {
|
|
3683
3151
|
contracts: pastRewardBalances
|
|
3684
3152
|
});
|
|
3685
3153
|
pastRewarderBalances = pastRewards.map(({ result }, index) => {
|
|
@@ -4130,7 +3598,7 @@ var getUserAutopools = async ({
|
|
|
4130
3598
|
};
|
|
4131
3599
|
|
|
4132
3600
|
// functions/getUserTokenBalances.ts
|
|
4133
|
-
var
|
|
3601
|
+
var import_viem11 = require("viem");
|
|
4134
3602
|
var networkToAlchemyUrl = (chainId) => {
|
|
4135
3603
|
return `https://rpc.autopool-services.com/${chainId}/ui`;
|
|
4136
3604
|
};
|
|
@@ -4159,7 +3627,7 @@ var getUserTokenBalances = async ({
|
|
|
4159
3627
|
const tokenBalances = data.result.tokenBalances.reduce(
|
|
4160
3628
|
(acc, balance) => {
|
|
4161
3629
|
if (balance.tokenBalance && BigInt(balance.tokenBalance) !== BigInt(0)) {
|
|
4162
|
-
acc[balance.contractAddress] = (0,
|
|
3630
|
+
acc[balance.contractAddress] = (0, import_viem11.hexToBigInt)(
|
|
4163
3631
|
balance.tokenBalance
|
|
4164
3632
|
);
|
|
4165
3633
|
}
|
|
@@ -4170,25 +3638,11 @@ var getUserTokenBalances = async ({
|
|
|
4170
3638
|
return tokenBalances;
|
|
4171
3639
|
};
|
|
4172
3640
|
|
|
4173
|
-
// functions/getTokenList.ts
|
|
4174
|
-
var import_tokenlist8 = require("@tokemak/tokenlist");
|
|
4175
|
-
var getTokenList = async () => {
|
|
4176
|
-
try {
|
|
4177
|
-
let url = `${import_tokenlist8.TOKEMAK_LISTS_URL}/swap_enabled.json`;
|
|
4178
|
-
const listResponse = await fetch(url);
|
|
4179
|
-
const { tokens: tokenList } = await listResponse.json();
|
|
4180
|
-
return tokenList;
|
|
4181
|
-
} catch (e) {
|
|
4182
|
-
console.log(e);
|
|
4183
|
-
return [];
|
|
4184
|
-
}
|
|
4185
|
-
};
|
|
4186
|
-
|
|
4187
3641
|
// functions/getTopAutopoolHolders.ts
|
|
4188
|
-
var
|
|
3642
|
+
var import_graph_cli11 = require("@tokemak/graph-cli");
|
|
4189
3643
|
var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
4190
3644
|
try {
|
|
4191
|
-
const { GetTopAutopoolHolders } = (0,
|
|
3645
|
+
const { GetTopAutopoolHolders } = (0, import_graph_cli11.getSdkByChainId)(chainId);
|
|
4192
3646
|
const { holders } = await GetTopAutopoolHolders({
|
|
4193
3647
|
address: autopoolAddress
|
|
4194
3648
|
});
|
|
@@ -4199,27 +3653,6 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
|
4199
3653
|
}
|
|
4200
3654
|
};
|
|
4201
3655
|
|
|
4202
|
-
// functions/getAllowance.ts
|
|
4203
|
-
var import_core13 = require("@wagmi/core");
|
|
4204
|
-
var import_viem13 = require("viem");
|
|
4205
|
-
var getAllowance = async (wagmiConfig, {
|
|
4206
|
-
token,
|
|
4207
|
-
address,
|
|
4208
|
-
spender
|
|
4209
|
-
}) => {
|
|
4210
|
-
try {
|
|
4211
|
-
const allowance = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4212
|
-
address: token,
|
|
4213
|
-
abi: import_viem13.erc20Abi,
|
|
4214
|
-
functionName: "allowance",
|
|
4215
|
-
args: [address || "0x0", spender]
|
|
4216
|
-
});
|
|
4217
|
-
return allowance;
|
|
4218
|
-
} catch (e) {
|
|
4219
|
-
console.error(e);
|
|
4220
|
-
}
|
|
4221
|
-
};
|
|
4222
|
-
|
|
4223
3656
|
// functions/getUserActivity.ts
|
|
4224
3657
|
var getUserActivity = async ({
|
|
4225
3658
|
address,
|
|
@@ -4251,21 +3684,21 @@ var getUserActivity = async ({
|
|
|
4251
3684
|
};
|
|
4252
3685
|
|
|
4253
3686
|
// functions/getUserAutopoolsRewards.ts
|
|
4254
|
-
var
|
|
3687
|
+
var import_viem12 = require("viem");
|
|
4255
3688
|
|
|
4256
3689
|
// functions/getChainUserAutopoolsRewards.ts
|
|
4257
|
-
var
|
|
4258
|
-
var
|
|
4259
|
-
var
|
|
3690
|
+
var import_config4 = require("@tokemak/config");
|
|
3691
|
+
var import_core8 = require("@wagmi/core");
|
|
3692
|
+
var import_abis6 = require("@tokemak/abis");
|
|
4260
3693
|
var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
4261
3694
|
chainId,
|
|
4262
3695
|
address
|
|
4263
3696
|
}) => {
|
|
4264
3697
|
try {
|
|
4265
|
-
const coreConfig = (0,
|
|
4266
|
-
const userRewardsInfo = await (0,
|
|
3698
|
+
const coreConfig = (0, import_config4.getCoreConfig)(chainId);
|
|
3699
|
+
const userRewardsInfo = await (0, import_core8.readContract)(wagmiConfig, {
|
|
4267
3700
|
address: coreConfig.lens,
|
|
4268
|
-
abi:
|
|
3701
|
+
abi: import_abis6.lensAbi,
|
|
4269
3702
|
functionName: "getUserRewardInfo",
|
|
4270
3703
|
args: [address],
|
|
4271
3704
|
chainId: coreConfig.id
|
|
@@ -4296,8 +3729,8 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4296
3729
|
|
|
4297
3730
|
// functions/getUserAutopoolsRewards.ts
|
|
4298
3731
|
var import_utils27 = require("@tokemak/utils");
|
|
4299
|
-
var
|
|
4300
|
-
var
|
|
3732
|
+
var import_tokenlist8 = require("@tokemak/tokenlist");
|
|
3733
|
+
var import_chains9 = require("viem/chains");
|
|
4301
3734
|
var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
4302
3735
|
address,
|
|
4303
3736
|
tokenPrices,
|
|
@@ -4320,7 +3753,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4320
3753
|
const extraRewardsArray = Object.entries(chainUserRewards).flatMap(
|
|
4321
3754
|
([autopoolAddress, rewards]) => {
|
|
4322
3755
|
const autopool = autopools.find(
|
|
4323
|
-
(autopool2) => (0,
|
|
3756
|
+
(autopool2) => (0, import_viem12.getAddress)(autopool2.poolAddress) === (0, import_viem12.getAddress)(autopoolAddress)
|
|
4324
3757
|
);
|
|
4325
3758
|
if (!autopool || !autopool.extraRewarders) {
|
|
4326
3759
|
return [];
|
|
@@ -4330,17 +3763,17 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4330
3763
|
extraRewards2.rewardToken?.id,
|
|
4331
3764
|
autopool.chain?.chainId
|
|
4332
3765
|
);
|
|
4333
|
-
const claimableAmount = rewards ? rewards[(0,
|
|
3766
|
+
const claimableAmount = rewards ? rewards[(0, import_viem12.getAddress)(extraRewards2.rewardToken?.id)] : 0n;
|
|
4334
3767
|
let price = tokenPrices[rewarderToken.symbol] || 0;
|
|
4335
3768
|
if (rewarderToken.symbol === "XSILO") {
|
|
4336
|
-
price = tokenPrices[
|
|
3769
|
+
price = tokenPrices[import_tokenlist8.SILO_TOKEN.symbol] || 0;
|
|
4337
3770
|
}
|
|
4338
3771
|
const formattedAmount = (0, import_utils27.formatUnitsNum)(
|
|
4339
3772
|
claimableAmount,
|
|
4340
3773
|
rewarderToken.decimals || 18
|
|
4341
3774
|
);
|
|
4342
3775
|
return {
|
|
4343
|
-
address: (0,
|
|
3776
|
+
address: (0, import_viem12.getAddress)(extraRewards2?.id),
|
|
4344
3777
|
chainId,
|
|
4345
3778
|
token: rewarderToken,
|
|
4346
3779
|
amount: claimableAmount,
|
|
@@ -4371,7 +3804,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4371
3804
|
([tokenSymbol, { amount, decimals }]) => {
|
|
4372
3805
|
let price = tokenPrices[tokenSymbol] || 0;
|
|
4373
3806
|
if (tokenSymbol === "XSILO") {
|
|
4374
|
-
price = tokenPrices[
|
|
3807
|
+
price = tokenPrices[import_tokenlist8.SILO_TOKEN.symbol] || 0;
|
|
4375
3808
|
}
|
|
4376
3809
|
const formattedAmount = (0, import_utils27.formatUnitsNum)(amount, decimals || 18);
|
|
4377
3810
|
tokenRewards[tokenSymbol] = {
|
|
@@ -4382,13 +3815,13 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4382
3815
|
};
|
|
4383
3816
|
}
|
|
4384
3817
|
);
|
|
4385
|
-
if (Object.keys(tokenRewards).includes("undefined") && chainId ===
|
|
3818
|
+
if (Object.keys(tokenRewards).includes("undefined") && chainId === import_chains9.plasma.id) {
|
|
4386
3819
|
const undefinedToken = tokenRewards["undefined"];
|
|
4387
3820
|
let price = tokenPrices.TOKE || 0;
|
|
4388
3821
|
tokenRewards["TOKE"] = {
|
|
4389
3822
|
...undefinedToken,
|
|
4390
3823
|
USD: undefinedToken.formattedAmount * price,
|
|
4391
|
-
logoURI:
|
|
3824
|
+
logoURI: import_tokenlist8.TOKE_TOKEN.logoURI
|
|
4392
3825
|
};
|
|
4393
3826
|
delete tokenRewards["undefined"];
|
|
4394
3827
|
}
|
|
@@ -4443,24 +3876,24 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4443
3876
|
};
|
|
4444
3877
|
|
|
4445
3878
|
// functions/getAmountWithdrawn.ts
|
|
4446
|
-
var
|
|
3879
|
+
var import_viem14 = require("viem");
|
|
4447
3880
|
var import_utils29 = require("@tokemak/utils");
|
|
4448
3881
|
|
|
4449
3882
|
// functions/getSwapQuote.ts
|
|
4450
|
-
var
|
|
3883
|
+
var import_constants15 = require("@tokemak/constants");
|
|
4451
3884
|
|
|
4452
3885
|
// functions/getAddressFromSystemRegistry.ts
|
|
4453
|
-
var
|
|
4454
|
-
var
|
|
4455
|
-
var
|
|
3886
|
+
var import_core9 = require("@wagmi/core");
|
|
3887
|
+
var import_config5 = require("@tokemak/config");
|
|
3888
|
+
var import_abis7 = require("@tokemak/abis");
|
|
4456
3889
|
var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
4457
3890
|
chainId,
|
|
4458
3891
|
functionName
|
|
4459
3892
|
}) => {
|
|
4460
|
-
const { systemRegistry } = (0,
|
|
4461
|
-
return await (0,
|
|
3893
|
+
const { systemRegistry } = (0, import_config5.getCoreConfig)(chainId);
|
|
3894
|
+
return await (0, import_core9.readContract)(wagmiConfig, {
|
|
4462
3895
|
address: systemRegistry,
|
|
4463
|
-
abi:
|
|
3896
|
+
abi: import_abis7.systemRegistryAbi,
|
|
4464
3897
|
functionName,
|
|
4465
3898
|
chainId
|
|
4466
3899
|
});
|
|
@@ -4473,26 +3906,26 @@ var getAutopilotRouter = async (wagmiConfig, { chainId }) => await getAddressFro
|
|
|
4473
3906
|
});
|
|
4474
3907
|
|
|
4475
3908
|
// functions/getSwapQuote.ts
|
|
4476
|
-
var
|
|
4477
|
-
var
|
|
4478
|
-
var
|
|
3909
|
+
var import_config6 = require("@tokemak/config");
|
|
3910
|
+
var import_tokenlist9 = require("@tokemak/tokenlist");
|
|
3911
|
+
var import_chains10 = require("viem/chains");
|
|
4479
3912
|
var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
4480
3913
|
try {
|
|
4481
3914
|
if (!params.sellToken || !params.buyToken) {
|
|
4482
3915
|
throw new Error("Sell token and buy token are required");
|
|
4483
3916
|
}
|
|
4484
|
-
if (params.sellToken ===
|
|
4485
|
-
params.sellToken = (0,
|
|
4486
|
-
if (chainId ===
|
|
4487
|
-
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;
|
|
4488
3921
|
}
|
|
4489
|
-
if (chainId ===
|
|
4490
|
-
params.sellToken =
|
|
3922
|
+
if (chainId === import_chains10.plasma.id) {
|
|
3923
|
+
params.sellToken = import_tokenlist9.WXPL_TOKEN.address;
|
|
4491
3924
|
}
|
|
4492
3925
|
}
|
|
4493
3926
|
const sellAmount = params.sellAmount.toString();
|
|
4494
3927
|
const taker = await getAutopilotRouter(config, { chainId });
|
|
4495
|
-
const response = await fetch(
|
|
3928
|
+
const response = await fetch(import_constants15.TOKEMAK_SWAP_QUOTE_URL, {
|
|
4496
3929
|
method: "POST",
|
|
4497
3930
|
headers: {
|
|
4498
3931
|
"Content-Type": "application/json"
|
|
@@ -4518,12 +3951,12 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4518
3951
|
};
|
|
4519
3952
|
|
|
4520
3953
|
// functions/getDynamicSwap.ts
|
|
4521
|
-
var
|
|
4522
|
-
var
|
|
4523
|
-
var
|
|
3954
|
+
var import_core10 = require("@wagmi/core");
|
|
3955
|
+
var import_abis8 = require("@tokemak/abis");
|
|
3956
|
+
var import_config7 = require("@tokemak/config");
|
|
4524
3957
|
var import_autopilot_swap_route_calc = require("@tokemak/autopilot-swap-route-calc");
|
|
4525
|
-
var
|
|
4526
|
-
var
|
|
3958
|
+
var import_viem13 = require("viem");
|
|
3959
|
+
var import_constants16 = require("@tokemak/constants");
|
|
4527
3960
|
var getDynamicSwap = async ({
|
|
4528
3961
|
address,
|
|
4529
3962
|
amount,
|
|
@@ -4536,9 +3969,9 @@ var getDynamicSwap = async ({
|
|
|
4536
3969
|
let previewRedeem = 0n;
|
|
4537
3970
|
let dynamicSwaps;
|
|
4538
3971
|
let standardPreviewRedeem = false;
|
|
4539
|
-
const client = await (0,
|
|
3972
|
+
const client = await (0, import_core10.getPublicClient)(config, { chainId });
|
|
4540
3973
|
try {
|
|
4541
|
-
const { systemRegistry } = (0,
|
|
3974
|
+
const { systemRegistry } = (0, import_config7.getCoreConfig)(chainId);
|
|
4542
3975
|
client.transport.retryCount = 0;
|
|
4543
3976
|
client.transport.transports = [client.transport.transports[0]];
|
|
4544
3977
|
const liquidations = await (0, import_autopilot_swap_route_calc.getLiquidations)(
|
|
@@ -4547,7 +3980,7 @@ var getDynamicSwap = async ({
|
|
|
4547
3980
|
client.transport.transports[0].value.url,
|
|
4548
3981
|
address,
|
|
4549
3982
|
amount,
|
|
4550
|
-
|
|
3983
|
+
import_constants16.LIQUIDATION_PROBE_AMOUNT
|
|
4551
3984
|
);
|
|
4552
3985
|
if (liquidations?.liquidations?.length > 0) {
|
|
4553
3986
|
tokensToLiquidate = liquidations.liquidations;
|
|
@@ -4568,12 +4001,12 @@ var getDynamicSwap = async ({
|
|
|
4568
4001
|
chainId,
|
|
4569
4002
|
systemName: "gen3",
|
|
4570
4003
|
// slippageBps: Math.floor(slippage * 10000),
|
|
4571
|
-
slippageBps:
|
|
4004
|
+
slippageBps: import_constants16.DYNAMIC_SWAP_DEFAULT_SLIPPAGE_BPS,
|
|
4572
4005
|
tokensToLiquidate,
|
|
4573
4006
|
sellAllOnlyCompatible: true
|
|
4574
4007
|
})
|
|
4575
4008
|
};
|
|
4576
|
-
dynamicSwaps = await (await fetch(
|
|
4009
|
+
dynamicSwaps = await (await fetch(import_constants16.TOKEMAK_DYNAMIC_SWAP_ROUTES_URL, requestInit)).json();
|
|
4577
4010
|
if (dynamicSwaps?.success) {
|
|
4578
4011
|
const autopoolRouter = await getAutopilotRouter(config, { chainId });
|
|
4579
4012
|
if (!autopoolRouter) {
|
|
@@ -4582,7 +4015,7 @@ var getDynamicSwap = async ({
|
|
|
4582
4015
|
try {
|
|
4583
4016
|
await client?.simulateContract({
|
|
4584
4017
|
address: autopoolRouter,
|
|
4585
|
-
abi:
|
|
4018
|
+
abi: import_abis8.autopilotRouterAbi,
|
|
4586
4019
|
functionName: "previewRedeemWithRoutes",
|
|
4587
4020
|
args: [
|
|
4588
4021
|
address,
|
|
@@ -4594,10 +4027,10 @@ var getDynamicSwap = async ({
|
|
|
4594
4027
|
data: x.data
|
|
4595
4028
|
}))
|
|
4596
4029
|
],
|
|
4597
|
-
account: user ||
|
|
4030
|
+
account: user || import_constants16.SIMULATION_PLACEHOLDER_ADDRESS
|
|
4598
4031
|
});
|
|
4599
4032
|
} catch (e) {
|
|
4600
|
-
if (e instanceof
|
|
4033
|
+
if (e instanceof import_viem13.ContractFunctionExecutionError && e.cause instanceof import_viem13.ContractFunctionRevertedError && e.cause.data?.errorName === "PreviewRedeemWithRoutesResult") {
|
|
4601
4034
|
previewRedeem = e.cause.data?.args?.[0];
|
|
4602
4035
|
}
|
|
4603
4036
|
}
|
|
@@ -4606,13 +4039,13 @@ var getDynamicSwap = async ({
|
|
|
4606
4039
|
console.log(e);
|
|
4607
4040
|
}
|
|
4608
4041
|
}
|
|
4609
|
-
const previewRedeemOnChain = await (0,
|
|
4042
|
+
const previewRedeemOnChain = await (0, import_core10.readContract)(config, {
|
|
4610
4043
|
address,
|
|
4611
|
-
abi:
|
|
4044
|
+
abi: import_abis8.autopoolEthAbi,
|
|
4612
4045
|
functionName: "previewRedeem",
|
|
4613
4046
|
args: [amount],
|
|
4614
4047
|
chainId,
|
|
4615
|
-
account: user ||
|
|
4048
|
+
account: user || import_constants16.SIMULATION_PLACEHOLDER_ADDRESS
|
|
4616
4049
|
});
|
|
4617
4050
|
if (previewRedeemOnChain >= previewRedeem) {
|
|
4618
4051
|
standardPreviewRedeem = true;
|
|
@@ -4626,10 +4059,10 @@ var getDynamicSwap = async ({
|
|
|
4626
4059
|
};
|
|
4627
4060
|
|
|
4628
4061
|
// functions/getAmountWithdrawn.ts
|
|
4629
|
-
var
|
|
4630
|
-
var
|
|
4631
|
-
var
|
|
4632
|
-
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");
|
|
4633
4066
|
var getAmountWithdrawn = async ({
|
|
4634
4067
|
address,
|
|
4635
4068
|
slippage,
|
|
@@ -4662,15 +4095,15 @@ var getAmountWithdrawn = async ({
|
|
|
4662
4095
|
dynamicSwap?.previewRedeem,
|
|
4663
4096
|
slippage
|
|
4664
4097
|
);
|
|
4665
|
-
let minAmount = (0,
|
|
4098
|
+
let minAmount = (0, import_viem14.formatUnits)(minAmountWithSlippage, decimals);
|
|
4666
4099
|
if (isSwap) {
|
|
4667
|
-
if (buyToken ===
|
|
4668
|
-
const weth = (0,
|
|
4100
|
+
if (buyToken === import_tokenlist10.ETH_TOKEN.address) {
|
|
4101
|
+
const weth = (0, import_config8.getCoreConfig)(chainId).weth;
|
|
4669
4102
|
buyToken = weth;
|
|
4670
4103
|
}
|
|
4671
|
-
convertedAssets = await (0,
|
|
4104
|
+
convertedAssets = await (0, import_core11.readContract)(config, {
|
|
4672
4105
|
address: autopool,
|
|
4673
|
-
abi:
|
|
4106
|
+
abi: import_abis9.autopoolEthAbi,
|
|
4674
4107
|
functionName: "convertToAssets",
|
|
4675
4108
|
args: [amount],
|
|
4676
4109
|
chainId
|
|
@@ -4688,7 +4121,7 @@ var getAmountWithdrawn = async ({
|
|
|
4688
4121
|
sellAll: true
|
|
4689
4122
|
});
|
|
4690
4123
|
if (quote) {
|
|
4691
|
-
minAmount = (0,
|
|
4124
|
+
minAmount = (0, import_viem14.formatUnits)(BigInt(quote?.minBuyAmount), decimals);
|
|
4692
4125
|
} else {
|
|
4693
4126
|
throw new Error("No quote found");
|
|
4694
4127
|
}
|
|
@@ -4708,8 +4141,8 @@ var getAmountWithdrawn = async ({
|
|
|
4708
4141
|
};
|
|
4709
4142
|
|
|
4710
4143
|
// functions/getAmountDeposited.ts
|
|
4711
|
-
var
|
|
4712
|
-
var
|
|
4144
|
+
var import_core12 = require("@wagmi/core");
|
|
4145
|
+
var import_abis10 = require("@tokemak/abis");
|
|
4713
4146
|
var import_utils30 = require("@tokemak/utils");
|
|
4714
4147
|
var getAmountDeposited = async ({
|
|
4715
4148
|
address,
|
|
@@ -4723,9 +4156,9 @@ var getAmountDeposited = async ({
|
|
|
4723
4156
|
if (!address || !chainId || !amount || typeof slippage !== "number") {
|
|
4724
4157
|
throw new Error("Invalid parameters");
|
|
4725
4158
|
}
|
|
4726
|
-
const previewDeposit = await (0,
|
|
4159
|
+
const previewDeposit = await (0, import_core12.readContract)(config, {
|
|
4727
4160
|
address,
|
|
4728
|
-
abi:
|
|
4161
|
+
abi: import_abis10.autopoolEthAbi,
|
|
4729
4162
|
functionName: "previewDeposit",
|
|
4730
4163
|
args: [amount],
|
|
4731
4164
|
chainId
|
|
@@ -4747,9 +4180,9 @@ var getAmountDeposited = async ({
|
|
|
4747
4180
|
};
|
|
4748
4181
|
|
|
4749
4182
|
// functions/getBridgeFee.ts
|
|
4750
|
-
var
|
|
4751
|
-
var
|
|
4752
|
-
var
|
|
4183
|
+
var import_core13 = require("@wagmi/core");
|
|
4184
|
+
var import_abis11 = require("@tokemak/abis");
|
|
4185
|
+
var import_viem15 = require("viem");
|
|
4753
4186
|
var import_lz_v2_utilities = require("@layerzerolabs/lz-v2-utilities");
|
|
4754
4187
|
var getBridgeFee = async (wagmiConfig, {
|
|
4755
4188
|
sourceAddress,
|
|
@@ -4760,15 +4193,15 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4760
4193
|
from
|
|
4761
4194
|
}) => {
|
|
4762
4195
|
try {
|
|
4763
|
-
const endpoint = await (0,
|
|
4196
|
+
const endpoint = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4764
4197
|
address: destAddress,
|
|
4765
|
-
abi:
|
|
4198
|
+
abi: import_abis11.oftAdapterAbi,
|
|
4766
4199
|
functionName: "endpoint",
|
|
4767
4200
|
chainId: destChainId
|
|
4768
4201
|
});
|
|
4769
|
-
const eid = await (0,
|
|
4202
|
+
const eid = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4770
4203
|
address: endpoint,
|
|
4771
|
-
abi:
|
|
4204
|
+
abi: import_abis11.layerZeroEndpointAbi,
|
|
4772
4205
|
functionName: "eid",
|
|
4773
4206
|
chainId: destChainId
|
|
4774
4207
|
});
|
|
@@ -4777,16 +4210,16 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4777
4210
|
const minAmountLD = amount / factor * factor;
|
|
4778
4211
|
const sendParams = {
|
|
4779
4212
|
dstEid: eid,
|
|
4780
|
-
to: (0,
|
|
4213
|
+
to: (0, import_viem15.toHex)((0, import_lz_v2_utilities.addressToBytes32)(from)),
|
|
4781
4214
|
amountLD: amount,
|
|
4782
4215
|
minAmountLD,
|
|
4783
4216
|
extraOptions: "0x",
|
|
4784
4217
|
composeMsg: "0x",
|
|
4785
4218
|
oftCmd: "0x"
|
|
4786
4219
|
};
|
|
4787
|
-
const feeQuote = await (0,
|
|
4220
|
+
const feeQuote = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4788
4221
|
address: sourceAddress,
|
|
4789
|
-
abi:
|
|
4222
|
+
abi: import_abis11.oftAdapterAbi,
|
|
4790
4223
|
functionName: "quoteSend",
|
|
4791
4224
|
args: [sendParams, false],
|
|
4792
4225
|
chainId: sourceChainId
|
|
@@ -4797,595 +4230,35 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4797
4230
|
}
|
|
4798
4231
|
};
|
|
4799
4232
|
|
|
4800
|
-
// functions/getLayerzeroStatus.ts
|
|
4801
|
-
var MessageStatus = /* @__PURE__ */ ((MessageStatus2) => {
|
|
4802
|
-
MessageStatus2["INFLIGHT"] = "INFLIGHT";
|
|
4803
|
-
MessageStatus2["DELIVERED"] = "DELIVERED";
|
|
4804
|
-
MessageStatus2["FAILED"] = "FAILED";
|
|
4805
|
-
MessageStatus2["PAYLOAD_STORED"] = "PAYLOAD_STORED";
|
|
4806
|
-
MessageStatus2["BLOCKED"] = "BLOCKED";
|
|
4807
|
-
MessageStatus2["CONFIRMING"] = "CONFIRMING";
|
|
4808
|
-
return MessageStatus2;
|
|
4809
|
-
})(MessageStatus || {});
|
|
4810
|
-
var LAYERZERO_STATUS_URL = "https://scan.layerzero-api.com/v1/messages/tx/";
|
|
4811
|
-
var getLayerzeroStatus = async ({
|
|
4812
|
-
txHash
|
|
4813
|
-
}) => {
|
|
4814
|
-
try {
|
|
4815
|
-
const response = await fetch(`${LAYERZERO_STATUS_URL}${txHash}`);
|
|
4816
|
-
if (!response.ok) {
|
|
4817
|
-
throw new Error("Network response was not ok");
|
|
4818
|
-
}
|
|
4819
|
-
const statusData = await response.json();
|
|
4820
|
-
return statusData || void 0;
|
|
4821
|
-
} catch (e) {
|
|
4822
|
-
return {
|
|
4823
|
-
status: {
|
|
4824
|
-
name: "FAILED" /* FAILED */,
|
|
4825
|
-
message: e || "Failed to fetch layerzero status"
|
|
4826
|
-
}
|
|
4827
|
-
};
|
|
4828
|
-
}
|
|
4829
|
-
};
|
|
4830
|
-
var waitForMessageReceived = async ({
|
|
4831
|
-
txHash,
|
|
4832
|
-
interval = 3e3,
|
|
4833
|
-
timeout = 20 * 60 * 1e3
|
|
4834
|
-
}) => {
|
|
4835
|
-
const startTime = Date.now();
|
|
4836
|
-
while (Date.now() - startTime < timeout) {
|
|
4837
|
-
const status = await getLayerzeroStatus({ txHash });
|
|
4838
|
-
if (!status) {
|
|
4839
|
-
console.warn(`No status returned for txHash: ${txHash}`);
|
|
4840
|
-
} else {
|
|
4841
|
-
console.log(`Current status: ${status.status.name}`);
|
|
4842
|
-
if (status.status.name === "DELIVERED" /* DELIVERED */) {
|
|
4843
|
-
return status;
|
|
4844
|
-
} else if (["FAILED" /* FAILED */, "BLOCKED" /* BLOCKED */].includes(
|
|
4845
|
-
status.status.name
|
|
4846
|
-
)) {
|
|
4847
|
-
throw new Error(`Message failed with status: ${status.status.name}`);
|
|
4848
|
-
}
|
|
4849
|
-
}
|
|
4850
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
4851
|
-
}
|
|
4852
|
-
throw new Error(`Timeout reached after 20 minutes for message: ${txHash}`);
|
|
4853
|
-
};
|
|
4854
|
-
|
|
4855
|
-
// functions/getChainUserSToke.ts
|
|
4856
|
-
var import_abis18 = require("@tokemak/abis");
|
|
4857
|
-
var import_config13 = require("@tokemak/config");
|
|
4858
|
-
var import_utils31 = require("@tokemak/utils");
|
|
4859
|
-
var import_core21 = require("@wagmi/core");
|
|
4860
|
-
var import_viem18 = require("viem");
|
|
4861
|
-
var import_chains13 = require("viem/chains");
|
|
4862
|
-
|
|
4863
4233
|
// functions/getCurrentCycleId.ts
|
|
4864
|
-
var
|
|
4865
|
-
var
|
|
4234
|
+
var import_abis12 = require("@tokemak/abis");
|
|
4235
|
+
var import_core14 = require("@wagmi/core");
|
|
4866
4236
|
var getCurrentCycleId = async (wagmiConfig, {
|
|
4867
4237
|
stoke,
|
|
4868
4238
|
chainId
|
|
4869
4239
|
}) => {
|
|
4870
|
-
return (0,
|
|
4240
|
+
return (0, import_core14.readContract)(wagmiConfig, {
|
|
4871
4241
|
address: stoke,
|
|
4872
|
-
abi:
|
|
4242
|
+
abi: import_abis12.accTokeV1Abi,
|
|
4873
4243
|
chainId,
|
|
4874
4244
|
functionName: "getCurrentCycleID"
|
|
4875
4245
|
});
|
|
4876
4246
|
};
|
|
4877
4247
|
|
|
4878
|
-
// functions/getChainUserSToke.ts
|
|
4879
|
-
var import_graph_cli14 = require("@tokemak/graph-cli");
|
|
4880
|
-
var getChainUserSToke = async (wagmiConfig, {
|
|
4881
|
-
address,
|
|
4882
|
-
tokePrice,
|
|
4883
|
-
chainId
|
|
4884
|
-
}) => {
|
|
4885
|
-
try {
|
|
4886
|
-
const { stoke } = (0, import_config13.getCoreConfig)(chainId);
|
|
4887
|
-
const cycleIndex = await getCurrentCycleId(wagmiConfig, { chainId, stoke });
|
|
4888
|
-
if (address && cycleIndex && stoke && tokePrice) {
|
|
4889
|
-
const { GetUserSTokeBalance } = (0, import_graph_cli14.getSdkByChainId)(
|
|
4890
|
-
chainId
|
|
4891
|
-
);
|
|
4892
|
-
const { accountBalanceV1S } = await GetUserSTokeBalance({
|
|
4893
|
-
address: address.toLowerCase()
|
|
4894
|
-
});
|
|
4895
|
-
const cycleStartBalance = accountBalanceV1S[0]?.cycleStartBalance || 0n;
|
|
4896
|
-
const stokeContract = {
|
|
4897
|
-
address: stoke,
|
|
4898
|
-
abi: import_abis18.accTokeV1Abi
|
|
4899
|
-
};
|
|
4900
|
-
const [
|
|
4901
|
-
{ result: balance },
|
|
4902
|
-
{ result: depositInfoResult },
|
|
4903
|
-
{ result: withdrawalInfoResult }
|
|
4904
|
-
] = await (0, import_core21.readContracts)(wagmiConfig, {
|
|
4905
|
-
contracts: [
|
|
4906
|
-
{
|
|
4907
|
-
...stokeContract,
|
|
4908
|
-
functionName: "balanceOf",
|
|
4909
|
-
args: [address],
|
|
4910
|
-
chainId
|
|
4911
|
-
},
|
|
4912
|
-
{
|
|
4913
|
-
...stokeContract,
|
|
4914
|
-
functionName: "getDepositInfo",
|
|
4915
|
-
args: [address],
|
|
4916
|
-
chainId
|
|
4917
|
-
},
|
|
4918
|
-
{
|
|
4919
|
-
...stokeContract,
|
|
4920
|
-
functionName: "getWithdrawalInfo",
|
|
4921
|
-
args: [address],
|
|
4922
|
-
chainId
|
|
4923
|
-
}
|
|
4924
|
-
]
|
|
4925
|
-
});
|
|
4926
|
-
if (withdrawalInfoResult && depositInfoResult && balance && cycleStartBalance) {
|
|
4927
|
-
const [depositLockCycle, depositLockDuration, depositAmount] = depositInfoResult;
|
|
4928
|
-
const [withdrawalMinCycle, withdrawalAmount] = withdrawalInfoResult;
|
|
4929
|
-
const rolloverDepositAmount = !!cycleStartBalance?.cycleStartBalance && cycleStartBalance?.cycleStartBalance > 0 ? BigInt(cycleStartBalance.cycleStartBalance) : 0n;
|
|
4930
|
-
let balanceExcludingWithdrawal = balance;
|
|
4931
|
-
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
4932
|
-
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
4933
|
-
}
|
|
4934
|
-
const withdrawalAmountUsd = (0, import_utils31.formatCurrency)(
|
|
4935
|
-
(0, import_utils31.formatEtherNum)(withdrawalAmount) * tokePrice
|
|
4936
|
-
);
|
|
4937
|
-
const lockDuration = Number(depositLockDuration);
|
|
4938
|
-
const lockCycle = Number(depositLockCycle);
|
|
4939
|
-
const lockStart = lockCycle + 1;
|
|
4940
|
-
const firstLockEnd = lockDuration + 1 + lockCycle;
|
|
4941
|
-
const currentCycle = Number(cycleIndex);
|
|
4942
|
-
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
4943
|
-
const lockRenew = (
|
|
4944
|
-
// if has done a renewal since start
|
|
4945
|
-
currentCycle - lockStart > lockDuration ? (
|
|
4946
|
-
// if during the lockRenew cycle add lock duration to show the right timeline
|
|
4947
|
-
currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement
|
|
4948
|
-
) : (
|
|
4949
|
-
// if during the lockRenew cycle add lock duration to show the right timeline
|
|
4950
|
-
currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd
|
|
4951
|
-
)
|
|
4952
|
-
);
|
|
4953
|
-
const withdrawAvailable = lockRenew - 1;
|
|
4954
|
-
const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
|
|
4955
|
-
const addedLockedToke = depositAmount - rolloverDepositAmount;
|
|
4956
|
-
const balanceUSD = (0, import_utils31.formatCurrency)(
|
|
4957
|
-
Number((0, import_viem18.formatEther)(balanceExcludingWithdrawal)) * tokePrice
|
|
4958
|
-
);
|
|
4959
|
-
const balanceExcludingWithdrawalUsd = (0, import_utils31.formatCurrency)(
|
|
4960
|
-
(0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
|
|
4961
|
-
);
|
|
4962
|
-
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
4963
|
-
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
4964
|
-
const unlockRequestPeriodStartUnix = (0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
|
|
4965
|
-
const unlockRequestPeriodEndUnix = (0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
|
|
4966
|
-
const hasBalance = balance > 0n;
|
|
4967
|
-
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
4968
|
-
const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
|
|
4969
|
-
let cyclesInAMonth = 4;
|
|
4970
|
-
let lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
4971
|
-
if (chainId === import_chains13.sepolia.id) {
|
|
4972
|
-
lockDurationInMonths = lockDuration - 1;
|
|
4973
|
-
}
|
|
4974
|
-
const unlockPeriodDateRangeArray = [
|
|
4975
|
-
new Date((0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
|
|
4976
|
-
new Date((0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
|
|
4977
|
-
];
|
|
4978
|
-
const {
|
|
4979
|
-
unlockPeriodDateRange,
|
|
4980
|
-
unlockPeriodStartFullDate,
|
|
4981
|
-
unlockRenewalFullDate,
|
|
4982
|
-
unlockPeriodStartDate,
|
|
4983
|
-
unlockRenewalDate
|
|
4984
|
-
} = formatDateRange(
|
|
4985
|
-
unlockPeriodDateRangeArray,
|
|
4986
|
-
chainId === import_chains13.sepolia.id ? "time" : "date"
|
|
4987
|
-
);
|
|
4988
|
-
const totalActiveUserCredits = (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
4989
|
-
const totalUserCredits = (0, import_utils31.formatEtherNum)(balance) * lockDurationInMonths;
|
|
4990
|
-
return {
|
|
4991
|
-
balance,
|
|
4992
|
-
balanceUSD,
|
|
4993
|
-
balanceExcludingWithdrawal: hasBalance ? (0, import_viem18.formatEther)(balanceExcludingWithdrawal) : "0.00",
|
|
4994
|
-
balanceExcludingWithdrawalUsd,
|
|
4995
|
-
hasBalanceExcludingWithdrawal,
|
|
4996
|
-
timeLeftBeforeUnlockRequestAvailable: (0, import_utils31.convertSecondsToRemainingTime)(
|
|
4997
|
-
unlockRequestPeriodStartUnix
|
|
4998
|
-
),
|
|
4999
|
-
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils31.convertSecondsToRemainingTime)(
|
|
5000
|
-
unlockRequestPeriodEndUnix
|
|
5001
|
-
),
|
|
5002
|
-
withdrawalAmount,
|
|
5003
|
-
withdrawalAmountUsd,
|
|
5004
|
-
hasUnlockableBalance,
|
|
5005
|
-
isUnlockRequestAvailable,
|
|
5006
|
-
hasRequestedUnlock,
|
|
5007
|
-
hasAddedLockedToke,
|
|
5008
|
-
addedLockedToke,
|
|
5009
|
-
unlockPeriodDateRange,
|
|
5010
|
-
unlockPeriodStartFullDate,
|
|
5011
|
-
unlockRenewalFullDate,
|
|
5012
|
-
unlockPeriodStartDate,
|
|
5013
|
-
unlockRenewalDate,
|
|
5014
|
-
lockDurationInMonths,
|
|
5015
|
-
boost: lockDuration,
|
|
5016
|
-
points: (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
5017
|
-
totalActiveCredits: totalActiveUserCredits,
|
|
5018
|
-
totalCredits: totalUserCredits
|
|
5019
|
-
};
|
|
5020
|
-
}
|
|
5021
|
-
}
|
|
5022
|
-
} catch (error) {
|
|
5023
|
-
console.error(error);
|
|
5024
|
-
}
|
|
5025
|
-
};
|
|
5026
|
-
|
|
5027
|
-
// functions/getUserSToke.ts
|
|
5028
|
-
var import_utils33 = require("@tokemak/utils");
|
|
5029
|
-
var getUserSToke = async (wagmiConfig, {
|
|
5030
|
-
address,
|
|
5031
|
-
tokePrice,
|
|
5032
|
-
includeTestnet = false
|
|
5033
|
-
}) => {
|
|
5034
|
-
try {
|
|
5035
|
-
if (!address) {
|
|
5036
|
-
throw new Error("Address not found");
|
|
5037
|
-
}
|
|
5038
|
-
if (!tokePrice) {
|
|
5039
|
-
throw new Error("Toke price not found");
|
|
5040
|
-
}
|
|
5041
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5042
|
-
const userSToke = await fetchChainDataMap(chains, async (chain) => {
|
|
5043
|
-
return getChainUserSToke(wagmiConfig, {
|
|
5044
|
-
address,
|
|
5045
|
-
tokePrice,
|
|
5046
|
-
chainId: chain.chainId
|
|
5047
|
-
});
|
|
5048
|
-
});
|
|
5049
|
-
const totalBalanceRaw = Object.values(userSToke).reduce((acc, item) => {
|
|
5050
|
-
if (item && item.balance) {
|
|
5051
|
-
return acc + item.balance;
|
|
5052
|
-
}
|
|
5053
|
-
return acc;
|
|
5054
|
-
}, 0n);
|
|
5055
|
-
const totalBalance = (0, import_utils33.formatEtherNum)(totalBalanceRaw || 0n);
|
|
5056
|
-
const totalBalanceUsd = (0, import_utils33.formatCurrency)(totalBalance * tokePrice);
|
|
5057
|
-
const hasBalance = totalBalance > 0;
|
|
5058
|
-
return {
|
|
5059
|
-
chains: { ...userSToke },
|
|
5060
|
-
totalBalance,
|
|
5061
|
-
totalBalanceUsd,
|
|
5062
|
-
hasBalance
|
|
5063
|
-
};
|
|
5064
|
-
} catch (e) {
|
|
5065
|
-
console.error(e);
|
|
5066
|
-
}
|
|
5067
|
-
};
|
|
5068
|
-
|
|
5069
|
-
// functions/getChainSToke.ts
|
|
5070
|
-
var import_viem19 = require("viem");
|
|
5071
|
-
var import_core22 = require("@wagmi/core");
|
|
5072
|
-
var import_abis19 = require("@tokemak/abis");
|
|
5073
|
-
var import_utils35 = require("@tokemak/utils");
|
|
5074
|
-
var import_config14 = require("@tokemak/config");
|
|
5075
|
-
var import_utils36 = require("@tokemak/utils");
|
|
5076
|
-
var getChainSToke = async (wagmiConfig, {
|
|
5077
|
-
tokePrice,
|
|
5078
|
-
chainId
|
|
5079
|
-
}) => {
|
|
5080
|
-
try {
|
|
5081
|
-
const { stoke } = (0, import_config14.getCoreConfig)(chainId);
|
|
5082
|
-
const baseConfig = {
|
|
5083
|
-
address: stoke,
|
|
5084
|
-
abi: import_abis19.accTokeV1Abi,
|
|
5085
|
-
chainId
|
|
5086
|
-
};
|
|
5087
|
-
if (stoke && tokePrice) {
|
|
5088
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await (0, import_core22.readContracts)(wagmiConfig, {
|
|
5089
|
-
contracts: [
|
|
5090
|
-
{
|
|
5091
|
-
...baseConfig,
|
|
5092
|
-
functionName: "totalSupply"
|
|
5093
|
-
},
|
|
5094
|
-
{
|
|
5095
|
-
...baseConfig,
|
|
5096
|
-
functionName: "getCurrentCycleID"
|
|
5097
|
-
}
|
|
5098
|
-
]
|
|
5099
|
-
});
|
|
5100
|
-
const tvl = Number((0, import_viem19.formatEther)(totalSupply || 0n)) * tokePrice;
|
|
5101
|
-
const secondsLeftBeforeNextCycle = (0, import_utils35.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
|
|
5102
|
-
return {
|
|
5103
|
-
rawTotalSupply: totalSupply,
|
|
5104
|
-
totalSupply: (0, import_utils35.formatLargeNumber)((0, import_viem19.formatEther)(totalSupply || 0n)),
|
|
5105
|
-
tvl: (0, import_utils35.formatTVL)(tvl),
|
|
5106
|
-
rawTVL: tvl,
|
|
5107
|
-
currentCycle,
|
|
5108
|
-
chain: (0, import_utils36.getNetwork)(chainId),
|
|
5109
|
-
timeBeforeNextCycle: (0, import_utils35.convertSecondsToRemainingTime)(
|
|
5110
|
-
secondsLeftBeforeNextCycle
|
|
5111
|
-
)
|
|
5112
|
-
};
|
|
5113
|
-
}
|
|
5114
|
-
} catch (error) {
|
|
5115
|
-
console.error(error);
|
|
5116
|
-
}
|
|
5117
|
-
};
|
|
5118
|
-
|
|
5119
|
-
// functions/getSToke.ts
|
|
5120
|
-
var import_utils37 = require("@tokemak/utils");
|
|
5121
|
-
var import_viem20 = require("viem");
|
|
5122
|
-
var getSToke = async (wagmiConfig, {
|
|
5123
|
-
tokePrice,
|
|
5124
|
-
includeTestnet = false
|
|
5125
|
-
}) => {
|
|
5126
|
-
try {
|
|
5127
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5128
|
-
const sToke = await fetchChainDataMap(chains, async (chain) => {
|
|
5129
|
-
return getChainSToke(wagmiConfig, {
|
|
5130
|
-
tokePrice,
|
|
5131
|
-
chainId: chain.chainId
|
|
5132
|
-
});
|
|
5133
|
-
});
|
|
5134
|
-
const totalSupplyBigInt = Object.values(sToke).reduce((acc, item) => {
|
|
5135
|
-
if (item && item.rawTotalSupply) {
|
|
5136
|
-
return acc + item.rawTotalSupply;
|
|
5137
|
-
}
|
|
5138
|
-
return acc;
|
|
5139
|
-
}, 0n);
|
|
5140
|
-
const totalSupply = (0, import_utils37.formatLargeNumber)((0, import_viem20.formatEther)(totalSupplyBigInt || 0n));
|
|
5141
|
-
let tvlNum = Object.values(sToke).reduce((acc, item) => {
|
|
5142
|
-
if (item && item.rawTVL) {
|
|
5143
|
-
return acc + item.rawTVL;
|
|
5144
|
-
}
|
|
5145
|
-
return acc;
|
|
5146
|
-
}, 0);
|
|
5147
|
-
const tvl = (0, import_utils37.formatTVL)(tvlNum);
|
|
5148
|
-
return { totalSupply, rawTotalSupply: totalSupplyBigInt, tvl, rawTVL: tvlNum, chains: { ...sToke } };
|
|
5149
|
-
} catch (e) {
|
|
5150
|
-
console.error(e);
|
|
5151
|
-
throw e;
|
|
5152
|
-
}
|
|
5153
|
-
};
|
|
5154
|
-
|
|
5155
|
-
// functions/getChainCycleRolloverBlockNumber.ts
|
|
5156
|
-
var import_abis20 = require("@tokemak/abis");
|
|
5157
|
-
var import_core23 = require("@wagmi/core");
|
|
5158
|
-
var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
5159
|
-
stoke,
|
|
5160
|
-
chainId
|
|
5161
|
-
}) => {
|
|
5162
|
-
const scanPeriodInDays = 8;
|
|
5163
|
-
const blockTime = 12;
|
|
5164
|
-
try {
|
|
5165
|
-
const client = (0, import_core23.getPublicClient)(wagmiConfig, { chainId });
|
|
5166
|
-
if (!!client) {
|
|
5167
|
-
const blockNumber = await (0, import_core23.getBlockNumber)(wagmiConfig, {
|
|
5168
|
-
chainId
|
|
5169
|
-
});
|
|
5170
|
-
const manager = await (0, import_core23.readContract)(wagmiConfig, {
|
|
5171
|
-
functionName: "manager",
|
|
5172
|
-
address: stoke,
|
|
5173
|
-
abi: import_abis20.accTokeV1Abi,
|
|
5174
|
-
chainId
|
|
5175
|
-
});
|
|
5176
|
-
if (!manager) {
|
|
5177
|
-
throw new Error("Manager contract not found");
|
|
5178
|
-
}
|
|
5179
|
-
const filter = await client.createContractEventFilter({
|
|
5180
|
-
address: manager,
|
|
5181
|
-
fromBlock: BigInt(
|
|
5182
|
-
Math.floor(
|
|
5183
|
-
Number(blockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
5184
|
-
)
|
|
5185
|
-
),
|
|
5186
|
-
abi: import_abis20.managerV1Abi,
|
|
5187
|
-
eventName: "CycleRolloverComplete"
|
|
5188
|
-
});
|
|
5189
|
-
const rolloverEvents = await client.getFilterLogs({ filter });
|
|
5190
|
-
const cycleRolloverBlockNumber = client.chain.id === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || blockNumber;
|
|
5191
|
-
return cycleRolloverBlockNumber;
|
|
5192
|
-
}
|
|
5193
|
-
} catch (error) {
|
|
5194
|
-
console.error(error);
|
|
5195
|
-
}
|
|
5196
|
-
};
|
|
5197
|
-
|
|
5198
|
-
// functions/getChainSTokeRewards.ts
|
|
5199
|
-
var import_config15 = require("@tokemak/config");
|
|
5200
|
-
var import_viem21 = require("viem");
|
|
5201
|
-
var import_utils39 = require("@tokemak/utils");
|
|
5202
|
-
var import_graph_cli15 = require("@tokemak/graph-cli");
|
|
5203
|
-
var getChainSTokeRewards = async ({
|
|
5204
|
-
chainId
|
|
5205
|
-
}) => {
|
|
5206
|
-
try {
|
|
5207
|
-
const { GetSTokeRewards } = (0, import_graph_cli15.getSdkByChainId)(chainId);
|
|
5208
|
-
const { poolRewardsBalances } = await GetSTokeRewards();
|
|
5209
|
-
const allPoolRewardsBalanceDayDatas = await paginateQuery(
|
|
5210
|
-
GetSTokeRewards,
|
|
5211
|
-
"poolRewardsBalanceDayDatas"
|
|
5212
|
-
);
|
|
5213
|
-
const autopools = {};
|
|
5214
|
-
let totalEarnings = 0;
|
|
5215
|
-
let totalEarningsUsd = 0;
|
|
5216
|
-
let minApr = null;
|
|
5217
|
-
let maxApr = null;
|
|
5218
|
-
for (const pool of poolRewardsBalances) {
|
|
5219
|
-
const whitelistedPools = import_config15.AUTOPOOLS_WHITELIST_PROD.map(
|
|
5220
|
-
(address) => address.toLowerCase()
|
|
5221
|
-
);
|
|
5222
|
-
if (!whitelistedPools.includes(pool.id.toLowerCase())) {
|
|
5223
|
-
continue;
|
|
5224
|
-
}
|
|
5225
|
-
const convertedBalance = (0, import_utils39.formatEtherNum)(pool.balance);
|
|
5226
|
-
const convertedBalanceUSD = Number((0, import_viem21.formatUnits)(pool.balanceUSD, 8));
|
|
5227
|
-
const convertedApr = (0, import_utils39.formatEtherNum)(pool.currentAprPerCredit);
|
|
5228
|
-
if (minApr === null || convertedApr < minApr) {
|
|
5229
|
-
minApr = convertedApr;
|
|
5230
|
-
}
|
|
5231
|
-
if (maxApr === null || convertedApr > maxApr) {
|
|
5232
|
-
maxApr = convertedApr;
|
|
5233
|
-
}
|
|
5234
|
-
autopools[pool.id] = {
|
|
5235
|
-
balance: convertedBalance,
|
|
5236
|
-
balanceUSD: convertedBalanceUSD,
|
|
5237
|
-
currentAprPerCredit: convertedApr
|
|
5238
|
-
};
|
|
5239
|
-
totalEarnings += convertedBalance;
|
|
5240
|
-
totalEarningsUsd += convertedBalanceUSD;
|
|
5241
|
-
}
|
|
5242
|
-
const activeDayDatas = allPoolRewardsBalanceDayDatas.filter(
|
|
5243
|
-
(item) => item.balance !== "0"
|
|
5244
|
-
);
|
|
5245
|
-
const historicalRewards = aggregateSTokeRewardsDayData(activeDayDatas);
|
|
5246
|
-
const aprRange = [(minApr ?? 0) * 4, (maxApr ?? 0) * 16];
|
|
5247
|
-
return {
|
|
5248
|
-
autopools,
|
|
5249
|
-
totalEarnings,
|
|
5250
|
-
totalEarningsUsd,
|
|
5251
|
-
historicalRewards,
|
|
5252
|
-
aprRange
|
|
5253
|
-
};
|
|
5254
|
-
} catch (e) {
|
|
5255
|
-
console.log("Error fetching rewards payload:", e);
|
|
5256
|
-
return null;
|
|
5257
|
-
}
|
|
5258
|
-
};
|
|
5259
|
-
|
|
5260
|
-
// functions/getSTokeRewards.ts
|
|
5261
|
-
var getSTokeRewards = async ({
|
|
5262
|
-
includeTestnet = false
|
|
5263
|
-
}) => {
|
|
5264
|
-
try {
|
|
5265
|
-
const chains = getSTokeChainsForEnv({ includeTestnet });
|
|
5266
|
-
const sTokeRewards = await fetchChainDataMap(chains, async (chain) => {
|
|
5267
|
-
return getChainSTokeRewards({
|
|
5268
|
-
chainId: chain.chainId
|
|
5269
|
-
});
|
|
5270
|
-
});
|
|
5271
|
-
const totalEarnings = Object.values(sTokeRewards).reduce((acc, item) => {
|
|
5272
|
-
if (item && item.totalEarnings) {
|
|
5273
|
-
return acc + item.totalEarnings;
|
|
5274
|
-
}
|
|
5275
|
-
return acc;
|
|
5276
|
-
}, 0);
|
|
5277
|
-
const totalEarningsUsd = Object.values(sTokeRewards).reduce((acc, item) => {
|
|
5278
|
-
if (item && item.totalEarnings) {
|
|
5279
|
-
return acc + item.totalEarningsUsd;
|
|
5280
|
-
}
|
|
5281
|
-
return acc;
|
|
5282
|
-
}, 0);
|
|
5283
|
-
const allChainsDailyData = Object.values(sTokeRewards).flatMap(
|
|
5284
|
-
(chainResult) => chainResult?.historicalRewards || []
|
|
5285
|
-
);
|
|
5286
|
-
const historicalRewardsAllChains = aggregateSTokeRewardsDayData(allChainsDailyData);
|
|
5287
|
-
return {
|
|
5288
|
-
chains: { ...sTokeRewards },
|
|
5289
|
-
totalEarnings,
|
|
5290
|
-
totalEarningsUsd,
|
|
5291
|
-
historicalRewards: historicalRewardsAllChains
|
|
5292
|
-
};
|
|
5293
|
-
} catch (e) {
|
|
5294
|
-
console.error(e);
|
|
5295
|
-
throw e;
|
|
5296
|
-
}
|
|
5297
|
-
};
|
|
5298
|
-
|
|
5299
|
-
// functions/getChainUserSTokeRewards.ts
|
|
5300
|
-
var import_config16 = require("@tokemak/config");
|
|
5301
|
-
var import_utils42 = require("@tokemak/utils");
|
|
5302
|
-
var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
5303
|
-
address,
|
|
5304
|
-
chainId,
|
|
5305
|
-
tokePrice
|
|
5306
|
-
}) => {
|
|
5307
|
-
const { rewardsV1Url, stokeRewardsHash, stokeRewards } = (0, import_config16.getMainnetConfig)(1);
|
|
5308
|
-
const { stoke } = (0, import_config16.getCoreConfig)(chainId);
|
|
5309
|
-
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
5310
|
-
stoke,
|
|
5311
|
-
chainId
|
|
5312
|
-
});
|
|
5313
|
-
let tokeRewards;
|
|
5314
|
-
try {
|
|
5315
|
-
tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
5316
|
-
address,
|
|
5317
|
-
rewardsCycleIndex: currentCycle,
|
|
5318
|
-
rewardsV1: stokeRewards,
|
|
5319
|
-
rewardsV1Url,
|
|
5320
|
-
rewardsV1Hash: stokeRewardsHash,
|
|
5321
|
-
chainId
|
|
5322
|
-
});
|
|
5323
|
-
if (!tokeRewards?.rewardsPayload) {
|
|
5324
|
-
throw new Error("No rewards payload found");
|
|
5325
|
-
}
|
|
5326
|
-
} catch (error) {
|
|
5327
|
-
console.error(
|
|
5328
|
-
`Error calling getUserRewardsV1 with cycle ${currentCycle}:`,
|
|
5329
|
-
error
|
|
5330
|
-
);
|
|
5331
|
-
try {
|
|
5332
|
-
console.log("Falling back to previous cycle index...");
|
|
5333
|
-
tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
5334
|
-
address,
|
|
5335
|
-
rewardsCycleIndex: currentCycle - 1n,
|
|
5336
|
-
rewardsV1: stokeRewards,
|
|
5337
|
-
rewardsV1Url,
|
|
5338
|
-
rewardsV1Hash: stokeRewardsHash,
|
|
5339
|
-
chainId
|
|
5340
|
-
});
|
|
5341
|
-
if (!tokeRewards?.rewardsPayload) {
|
|
5342
|
-
throw new Error("No rewards payload found (fallback cycle).");
|
|
5343
|
-
}
|
|
5344
|
-
} catch (fallbackError) {
|
|
5345
|
-
console.error(
|
|
5346
|
-
`Error calling getUserRewardsV1 with cycle ${currentCycle - 1n}:`,
|
|
5347
|
-
fallbackError
|
|
5348
|
-
);
|
|
5349
|
-
throw fallbackError;
|
|
5350
|
-
}
|
|
5351
|
-
}
|
|
5352
|
-
const claimableNum = (0, import_utils42.formatEtherNum)(tokeRewards?.claimable || 0n);
|
|
5353
|
-
const claimableUsd = tokePrice * claimableNum;
|
|
5354
|
-
const hasClaimable = claimableNum > 0n;
|
|
5355
|
-
const pendingRewards = (0, import_utils42.formatEtherNum)(
|
|
5356
|
-
tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5357
|
-
);
|
|
5358
|
-
const pendingRewardsUsd = tokePrice * pendingRewards;
|
|
5359
|
-
const totalRewardsReceived = (0, import_utils42.formatEtherNum)(
|
|
5360
|
-
tokeRewards.rewardsPayload.payload.amount || 0n
|
|
5361
|
-
);
|
|
5362
|
-
const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
|
|
5363
|
-
return {
|
|
5364
|
-
claimableUsd,
|
|
5365
|
-
claimableNum,
|
|
5366
|
-
hasClaimable,
|
|
5367
|
-
pendingRewards,
|
|
5368
|
-
pendingRewardsUsd,
|
|
5369
|
-
totalRewardsReceived,
|
|
5370
|
-
totalRewardsReceivedUsd,
|
|
5371
|
-
...tokeRewards
|
|
5372
|
-
};
|
|
5373
|
-
};
|
|
5374
|
-
|
|
5375
4248
|
// functions/getTokenPrices.ts
|
|
5376
|
-
var
|
|
5377
|
-
var
|
|
4249
|
+
var import_tokenlist11 = require("@tokemak/tokenlist");
|
|
4250
|
+
var import_constants17 = require("@tokemak/constants");
|
|
5378
4251
|
var getTokenPrices = async () => {
|
|
5379
4252
|
try {
|
|
5380
4253
|
const body = {
|
|
5381
|
-
tokens:
|
|
4254
|
+
tokens: import_tokenlist11.PRICED_TOKENS.map((asset) => ({
|
|
5382
4255
|
token: asset.address,
|
|
5383
4256
|
chainId: asset.chainId,
|
|
5384
4257
|
systemName: "gen3",
|
|
5385
4258
|
timeoutMS: 5 * 1e3
|
|
5386
4259
|
}))
|
|
5387
4260
|
};
|
|
5388
|
-
const response = await fetch(`${
|
|
4261
|
+
const response = await fetch(`${import_constants17.TOKEMAK_PRICES_STAGING_URL}`, {
|
|
5389
4262
|
method: "POST",
|
|
5390
4263
|
headers: {
|
|
5391
4264
|
"Content-Type": "application/json"
|
|
@@ -5393,7 +4266,7 @@ var getTokenPrices = async () => {
|
|
|
5393
4266
|
body: JSON.stringify(body)
|
|
5394
4267
|
});
|
|
5395
4268
|
const data = await response.json();
|
|
5396
|
-
const prices =
|
|
4269
|
+
const prices = import_tokenlist11.PRICED_TOKENS.reduce((acc, asset) => {
|
|
5397
4270
|
const priceData = data.find(
|
|
5398
4271
|
(item) => item.token.toLowerCase() === asset.address.toLowerCase() && item.chainId === asset.chainId
|
|
5399
4272
|
);
|
|
@@ -5423,11 +4296,11 @@ var getTokenPrices = async () => {
|
|
|
5423
4296
|
};
|
|
5424
4297
|
|
|
5425
4298
|
// functions/getChainSubgraphStatus.ts
|
|
5426
|
-
var
|
|
4299
|
+
var import_graph_cli12 = require("@tokemak/graph-cli");
|
|
5427
4300
|
var getChainSubgraphStatus = async (chain) => {
|
|
5428
4301
|
const currentTimestamp = Math.floor(Date.now() / 1e3);
|
|
5429
4302
|
try {
|
|
5430
|
-
const { GetLatestSubgraphTimestamp } = (0,
|
|
4303
|
+
const { GetLatestSubgraphTimestamp } = (0, import_graph_cli12.getSdkByChainId)(
|
|
5431
4304
|
chain.chainId
|
|
5432
4305
|
);
|
|
5433
4306
|
const { _meta } = await GetLatestSubgraphTimestamp();
|
|
@@ -5478,158 +4351,21 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5478
4351
|
return { isOutOfSync, errorMessage };
|
|
5479
4352
|
};
|
|
5480
4353
|
|
|
5481
|
-
// functions/getCycleV1.ts
|
|
5482
|
-
var import_core24 = require("@wagmi/core");
|
|
5483
|
-
var import_abis21 = require("@tokemak/abis");
|
|
5484
|
-
var import_viem22 = require("viem");
|
|
5485
|
-
var import_utils44 = require("@tokemak/utils");
|
|
5486
|
-
var import_config17 = require("@tokemak/config");
|
|
5487
|
-
var import_chains14 = require("viem/chains");
|
|
5488
|
-
var publicClient = (0, import_viem22.createPublicClient)({
|
|
5489
|
-
chain: import_chains14.mainnet,
|
|
5490
|
-
transport: (0, import_viem22.http)("https://mainnet.infura.io/v3/2BtQ5D1QEPHvwgZwKwnZC7WQVhr")
|
|
5491
|
-
});
|
|
5492
|
-
var getCycleV1 = async (wagmiConfig, {
|
|
5493
|
-
currentBlockNumber,
|
|
5494
|
-
chainId
|
|
5495
|
-
}) => {
|
|
5496
|
-
const scanPeriodInDays = 8;
|
|
5497
|
-
const blockTime = 12;
|
|
5498
|
-
const { managerV1 } = (0, import_config17.getMainnetConfig)();
|
|
5499
|
-
try {
|
|
5500
|
-
if (currentBlockNumber && managerV1) {
|
|
5501
|
-
const currentCycleIndex = await (0, import_core24.readContract)(wagmiConfig, {
|
|
5502
|
-
address: managerV1,
|
|
5503
|
-
abi: import_abis21.managerV1Abi,
|
|
5504
|
-
functionName: "getCurrentCycleIndex",
|
|
5505
|
-
chainId
|
|
5506
|
-
});
|
|
5507
|
-
const filter = await publicClient.createContractEventFilter({
|
|
5508
|
-
address: managerV1,
|
|
5509
|
-
fromBlock: BigInt(
|
|
5510
|
-
Math.floor(
|
|
5511
|
-
Number(currentBlockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
5512
|
-
)
|
|
5513
|
-
),
|
|
5514
|
-
abi: import_abis21.managerV1Abi,
|
|
5515
|
-
eventName: "CycleRolloverComplete"
|
|
5516
|
-
});
|
|
5517
|
-
const rolloverEvents = await publicClient.getFilterLogs({ filter });
|
|
5518
|
-
const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
|
|
5519
|
-
const secondsLeftBeforeNextCycle = (0, import_utils44.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
|
|
5520
|
-
return {
|
|
5521
|
-
currentCycleIndex,
|
|
5522
|
-
cycleRolloverBlockNumber,
|
|
5523
|
-
timeBeforeNextCycle: (0, import_utils44.convertSecondsToRemainingTime)(
|
|
5524
|
-
secondsLeftBeforeNextCycle
|
|
5525
|
-
)
|
|
5526
|
-
};
|
|
5527
|
-
}
|
|
5528
|
-
} catch (error) {
|
|
5529
|
-
console.error(error);
|
|
5530
|
-
}
|
|
5531
|
-
};
|
|
5532
|
-
|
|
5533
|
-
// functions/getProtocolStats.ts
|
|
5534
|
-
var import_utils45 = require("@tokemak/utils");
|
|
5535
|
-
var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
5536
|
-
try {
|
|
5537
|
-
if (!autopools || !stoke || !sushiLP) {
|
|
5538
|
-
throw new Error("Missing required data");
|
|
5539
|
-
}
|
|
5540
|
-
const autopoolTVL = autopools?.reduce((acc, pool) => acc + pool.tvl, 0) || 0;
|
|
5541
|
-
const categories = autopools?.reduce((acc, pool) => {
|
|
5542
|
-
if (!acc[pool.category]) {
|
|
5543
|
-
if (pool.category === "eth" /* ETH */) {
|
|
5544
|
-
acc[pool.category] = { tvl: 0, supply: 0 };
|
|
5545
|
-
} else {
|
|
5546
|
-
acc[pool.category] = { tvl: 0 };
|
|
5547
|
-
}
|
|
5548
|
-
}
|
|
5549
|
-
acc[pool.category].tvl += pool.tvl;
|
|
5550
|
-
if (pool.category === "eth" /* ETH */) {
|
|
5551
|
-
if (pool.totalAssets) {
|
|
5552
|
-
const ethAmt = pool.totalAssets.ETH;
|
|
5553
|
-
if (acc[pool.category]) {
|
|
5554
|
-
acc[pool.category].supply = (acc[pool.category].supply ?? 0) + ethAmt;
|
|
5555
|
-
}
|
|
5556
|
-
}
|
|
5557
|
-
}
|
|
5558
|
-
return acc;
|
|
5559
|
-
}, {});
|
|
5560
|
-
const formattedCategories = Object.fromEntries(
|
|
5561
|
-
Object.entries(categories).map(([key, value]) => [
|
|
5562
|
-
key,
|
|
5563
|
-
{
|
|
5564
|
-
tvl: (0, import_utils45.formatTVL)(value.tvl),
|
|
5565
|
-
supply: (0, import_utils45.formatLargeNumber)(value.supply || 0)
|
|
5566
|
-
}
|
|
5567
|
-
])
|
|
5568
|
-
);
|
|
5569
|
-
const tvl = (0, import_utils45.formatTVL)(
|
|
5570
|
-
autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0) + (EthAutoLP?.tvlUsd || 0) + (sauto?.rawTVL || 0)
|
|
5571
|
-
);
|
|
5572
|
-
const vaultAddresses = autopools?.flatMap(
|
|
5573
|
-
(pool) => pool.destinations.map((destination) => destination.vaultAddress)
|
|
5574
|
-
);
|
|
5575
|
-
const uniqueVaultAddresses = [...new Set(vaultAddresses)];
|
|
5576
|
-
const totalDestinations = uniqueVaultAddresses.length;
|
|
5577
|
-
const stakedTVL = {
|
|
5578
|
-
totalSupply: (0, import_utils45.formatLargeNumber)(
|
|
5579
|
-
(0, import_utils45.formatEtherNum)(
|
|
5580
|
-
(sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
|
|
5581
|
-
)
|
|
5582
|
-
),
|
|
5583
|
-
tvl: (0, import_utils45.formatTVL)((sauto?.rawTVL || 0) + stoke.rawTVL)
|
|
5584
|
-
};
|
|
5585
|
-
return {
|
|
5586
|
-
autopools: {
|
|
5587
|
-
tvl: (0, import_utils45.formatTVL)(autopoolTVL),
|
|
5588
|
-
tvlNum: autopoolTVL,
|
|
5589
|
-
categories: formattedCategories
|
|
5590
|
-
},
|
|
5591
|
-
stoke: {
|
|
5592
|
-
tvl: (0, import_utils45.formatTVL)(stoke.rawTVL),
|
|
5593
|
-
tvlNum: stoke.rawTVL,
|
|
5594
|
-
totalSupply: `${stoke.totalSupply} TOKE`
|
|
5595
|
-
},
|
|
5596
|
-
sushiLP: {
|
|
5597
|
-
tvl: (0, import_utils45.formatTVL)(sushiLP?.tvl || 0),
|
|
5598
|
-
totalSupply: sushiLP?.totalSupply || 0
|
|
5599
|
-
},
|
|
5600
|
-
EthAutoLP: {
|
|
5601
|
-
tvl: (0, import_utils45.formatTVL)(EthAutoLP?.tvlUsd || 0)
|
|
5602
|
-
},
|
|
5603
|
-
sauto: {
|
|
5604
|
-
tvl: (0, import_utils45.formatTVL)(sauto?.rawTVL || 0),
|
|
5605
|
-
tvlNum: sauto?.rawTVL || 0,
|
|
5606
|
-
totalSupply: `${sauto?.totalSupply} AUTO`
|
|
5607
|
-
},
|
|
5608
|
-
stakedTVL,
|
|
5609
|
-
tvl,
|
|
5610
|
-
totalDestinations
|
|
5611
|
-
};
|
|
5612
|
-
} catch (error) {
|
|
5613
|
-
console.error(error);
|
|
5614
|
-
return null;
|
|
5615
|
-
}
|
|
5616
|
-
};
|
|
5617
|
-
|
|
5618
4354
|
// functions/getRebalanceStats.ts
|
|
5619
|
-
var
|
|
4355
|
+
var import_graph_cli13 = require("@tokemak/graph-cli");
|
|
5620
4356
|
|
|
5621
4357
|
// functions/getEthPriceAtBlock.ts
|
|
5622
|
-
var
|
|
5623
|
-
var
|
|
5624
|
-
var
|
|
4358
|
+
var import_config9 = require("@tokemak/config");
|
|
4359
|
+
var import_abis13 = require("@tokemak/abis");
|
|
4360
|
+
var import_tokenlist12 = require("@tokemak/tokenlist");
|
|
5625
4361
|
var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
|
|
5626
|
-
const config = (0,
|
|
4362
|
+
const config = (0, import_config9.getCoreConfig)(chainId);
|
|
5627
4363
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5628
4364
|
const weth = config.weth;
|
|
5629
|
-
const usdc =
|
|
4365
|
+
const usdc = import_tokenlist12.USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || import_tokenlist12.USDC_TOKEN.address;
|
|
5630
4366
|
const priceAtBlock = await client.readContract({
|
|
5631
4367
|
address: rootPriceOracle,
|
|
5632
|
-
abi:
|
|
4368
|
+
abi: import_abis13.rootPriceOracleAbi,
|
|
5633
4369
|
functionName: "getPriceInQuote",
|
|
5634
4370
|
args: [weth, usdc],
|
|
5635
4371
|
blockNumber,
|
|
@@ -5639,12 +4375,12 @@ var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
|
|
|
5639
4375
|
};
|
|
5640
4376
|
|
|
5641
4377
|
// functions/getRebalanceStats.ts
|
|
5642
|
-
var
|
|
5643
|
-
var
|
|
5644
|
-
var
|
|
4378
|
+
var import_utils33 = require("@tokemak/utils");
|
|
4379
|
+
var import_tokenlist13 = require("@tokemak/tokenlist");
|
|
4380
|
+
var import_chains11 = require("viem/chains");
|
|
5645
4381
|
var BATCH_SIZE = 500;
|
|
5646
4382
|
var fetchChainRebalances = async (chainId) => {
|
|
5647
|
-
const { GetAllAutopoolRebalances } = (0,
|
|
4383
|
+
const { GetAllAutopoolRebalances } = (0, import_graph_cli13.getSdkByChainId)(chainId);
|
|
5648
4384
|
const allRebalances = await paginateQuery(
|
|
5649
4385
|
GetAllAutopoolRebalances,
|
|
5650
4386
|
"autopoolRebalances"
|
|
@@ -5658,10 +4394,10 @@ function inferBaseAssetDecimals(rebalance, chainId) {
|
|
|
5658
4394
|
if (BigInt(rebalance.tokenOutValueBaseAsset) === BigInt(rebalance.tokenOutValueInEth)) {
|
|
5659
4395
|
return 18;
|
|
5660
4396
|
}
|
|
5661
|
-
if (chainId ===
|
|
4397
|
+
if (chainId === import_chains11.sonic.id) {
|
|
5662
4398
|
return rebalance.tokenOut.decimals;
|
|
5663
4399
|
}
|
|
5664
|
-
return
|
|
4400
|
+
return import_tokenlist13.USDC_TOKEN.decimals;
|
|
5665
4401
|
}
|
|
5666
4402
|
var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
|
|
5667
4403
|
const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
|
|
@@ -5673,8 +4409,8 @@ var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
|
|
|
5673
4409
|
chainId,
|
|
5674
4410
|
account
|
|
5675
4411
|
);
|
|
5676
|
-
const ethUsd = Number((0,
|
|
5677
|
-
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));
|
|
5678
4414
|
const usd = ethAmt * ethUsd;
|
|
5679
4415
|
return usd;
|
|
5680
4416
|
} catch (e) {
|
|
@@ -5685,7 +4421,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
|
|
|
5685
4421
|
var processRebalance = async (rebalance, chainId, client, account) => {
|
|
5686
4422
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5687
4423
|
const baseAssetAmount = Number(
|
|
5688
|
-
(0,
|
|
4424
|
+
(0, import_utils33.formatUnitsNum)(
|
|
5689
4425
|
BigInt(rebalance.tokenOutValueBaseAsset || "0"),
|
|
5690
4426
|
baseDecimals
|
|
5691
4427
|
)
|
|
@@ -5767,7 +4503,7 @@ var getRebalanceStats = async (getClient, {
|
|
|
5767
4503
|
};
|
|
5768
4504
|
|
|
5769
4505
|
// functions/updateRebalanceStats.ts
|
|
5770
|
-
var
|
|
4506
|
+
var import_core15 = require("@wagmi/core");
|
|
5771
4507
|
var updateRebalanceStats = async (wagmiConfig, {
|
|
5772
4508
|
currentRebalances,
|
|
5773
4509
|
includeTestnet = false
|
|
@@ -5782,7 +4518,7 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5782
4518
|
)
|
|
5783
4519
|
);
|
|
5784
4520
|
if (newRawRebalances.length > 0) {
|
|
5785
|
-
const client = (0,
|
|
4521
|
+
const client = (0, import_core15.getPublicClient)(wagmiConfig, {
|
|
5786
4522
|
chainId: chain.chainId
|
|
5787
4523
|
});
|
|
5788
4524
|
return processRebalancesInBatches(
|
|
@@ -5800,12 +4536,12 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5800
4536
|
};
|
|
5801
4537
|
|
|
5802
4538
|
// functions/getUserSAuto.ts
|
|
5803
|
-
var
|
|
5804
|
-
var
|
|
5805
|
-
var
|
|
5806
|
-
var
|
|
5807
|
-
var
|
|
5808
|
-
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");
|
|
5809
4545
|
var getUserSAuto = async (wagmiConfig, {
|
|
5810
4546
|
address,
|
|
5811
4547
|
autoPrice
|
|
@@ -5817,18 +4553,18 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5817
4553
|
if (!autoPrice) {
|
|
5818
4554
|
throw new Error("Auto price not found");
|
|
5819
4555
|
}
|
|
5820
|
-
const { sAuto } = (0,
|
|
5821
|
-
const chainId =
|
|
4556
|
+
const { sAuto } = (0, import_config10.getMainnetConfig)();
|
|
4557
|
+
const chainId = import_chains12.mainnet.id;
|
|
5822
4558
|
const sAutoContract = {
|
|
5823
4559
|
address: sAuto,
|
|
5824
|
-
abi:
|
|
4560
|
+
abi: import_abis14.sAutoAbi
|
|
5825
4561
|
};
|
|
5826
4562
|
const [
|
|
5827
4563
|
{ result: balance },
|
|
5828
4564
|
{ result: depositInfoResult },
|
|
5829
4565
|
{ result: withdrawalInfoResult },
|
|
5830
4566
|
{ result: cycleIndex }
|
|
5831
|
-
] = await (0,
|
|
4567
|
+
] = await (0, import_core16.readContracts)(wagmiConfig, {
|
|
5832
4568
|
contracts: [
|
|
5833
4569
|
{
|
|
5834
4570
|
...sAutoContract,
|
|
@@ -5864,8 +4600,8 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5864
4600
|
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
5865
4601
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
5866
4602
|
}
|
|
5867
|
-
const withdrawalAmountUsd = (0,
|
|
5868
|
-
(0,
|
|
4603
|
+
const withdrawalAmountUsd = (0, import_utils35.formatCurrency)(
|
|
4604
|
+
(0, import_utils35.formatEtherNum)(withdrawalAmount) * autoPrice
|
|
5869
4605
|
);
|
|
5870
4606
|
const lockDuration = Number(depositLockDuration);
|
|
5871
4607
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -5875,24 +4611,24 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5875
4611
|
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
5876
4612
|
const lockRenew = currentCycle - lockStart > lockDuration ? currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement : currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd;
|
|
5877
4613
|
const withdrawAvailable = lockRenew - 1;
|
|
5878
|
-
const balanceUSD = (0,
|
|
5879
|
-
Number((0,
|
|
4614
|
+
const balanceUSD = (0, import_utils35.formatCurrency)(
|
|
4615
|
+
Number((0, import_viem16.formatEther)(balanceExcludingWithdrawal)) * autoPrice
|
|
5880
4616
|
);
|
|
5881
|
-
const balanceExcludingWithdrawalUsd = (0,
|
|
5882
|
-
(0,
|
|
4617
|
+
const balanceExcludingWithdrawalUsd = (0, import_utils35.formatCurrency)(
|
|
4618
|
+
(0, import_utils35.formatEtherNum)(balanceExcludingWithdrawal) * autoPrice
|
|
5883
4619
|
);
|
|
5884
4620
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
5885
4621
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
5886
|
-
const unlockRequestPeriodStartUnix = (0,
|
|
5887
|
-
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;
|
|
5888
4624
|
const hasBalance = balance > 0n;
|
|
5889
4625
|
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
5890
4626
|
const hasUnlockableBalance = withdrawalMinCycle <= BigInt(currentCycle) && withdrawalAmount > 0n;
|
|
5891
4627
|
const cyclesInAMonth = 4;
|
|
5892
4628
|
const lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
5893
4629
|
const unlockPeriodDateRangeArray = [
|
|
5894
|
-
new Date((0,
|
|
5895
|
-
new Date((0,
|
|
4630
|
+
new Date((0, import_utils35.convertAutoCycleToUnix)(withdrawAvailable) * 1e3),
|
|
4631
|
+
new Date((0, import_utils35.convertAutoCycleToUnix)(lockRenew) * 1e3)
|
|
5896
4632
|
];
|
|
5897
4633
|
const {
|
|
5898
4634
|
unlockPeriodDateRange,
|
|
@@ -5901,20 +4637,20 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5901
4637
|
unlockPeriodStartDate,
|
|
5902
4638
|
unlockRenewalDate
|
|
5903
4639
|
} = formatDateRange(unlockPeriodDateRangeArray, "date");
|
|
5904
|
-
const totalActiveUserCredits = (0,
|
|
5905
|
-
const totalUserCredits = (0,
|
|
4640
|
+
const totalActiveUserCredits = (0, import_utils35.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
4641
|
+
const totalUserCredits = (0, import_utils35.formatEtherNum)(balance) * lockDurationInMonths;
|
|
5906
4642
|
const hasAddedLockedAuto = depositAmount > 0n;
|
|
5907
4643
|
const addedLockedAuto = depositAmount;
|
|
5908
4644
|
return {
|
|
5909
4645
|
balance,
|
|
5910
4646
|
balanceUSD,
|
|
5911
|
-
balanceExcludingWithdrawal: hasBalance ? (0,
|
|
4647
|
+
balanceExcludingWithdrawal: hasBalance ? (0, import_viem16.formatEther)(balanceExcludingWithdrawal) : "0.00",
|
|
5912
4648
|
balanceExcludingWithdrawalUsd,
|
|
5913
4649
|
hasBalanceExcludingWithdrawal,
|
|
5914
|
-
timeLeftBeforeUnlockRequestAvailable: (0,
|
|
4650
|
+
timeLeftBeforeUnlockRequestAvailable: (0, import_utils35.convertSecondsToRemainingTime)(
|
|
5915
4651
|
unlockRequestPeriodStartUnix
|
|
5916
4652
|
),
|
|
5917
|
-
timeLeftBeforeUnlockRequestUnavailable: (0,
|
|
4653
|
+
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils35.convertSecondsToRemainingTime)(
|
|
5918
4654
|
unlockRequestPeriodEndUnix
|
|
5919
4655
|
),
|
|
5920
4656
|
withdrawalAmount,
|
|
@@ -5931,7 +4667,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5931
4667
|
unlockRenewalDate,
|
|
5932
4668
|
lockDurationInMonths,
|
|
5933
4669
|
boost: lockDuration,
|
|
5934
|
-
points: (0,
|
|
4670
|
+
points: (0, import_utils35.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
5935
4671
|
totalActiveCredits: totalActiveUserCredits,
|
|
5936
4672
|
totalCredits: totalUserCredits,
|
|
5937
4673
|
hasBalance
|
|
@@ -5943,25 +4679,25 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5943
4679
|
};
|
|
5944
4680
|
|
|
5945
4681
|
// functions/getSAuto.ts
|
|
5946
|
-
var
|
|
5947
|
-
var
|
|
5948
|
-
var
|
|
5949
|
-
var
|
|
5950
|
-
var
|
|
5951
|
-
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");
|
|
5952
4688
|
var getSAuto = async (wagmiConfig, {
|
|
5953
4689
|
autoPrice
|
|
5954
4690
|
}) => {
|
|
5955
4691
|
try {
|
|
5956
|
-
const { sAuto } = (0,
|
|
5957
|
-
const chainId =
|
|
4692
|
+
const { sAuto } = (0, import_config11.getMainnetConfig)();
|
|
4693
|
+
const chainId = import_chains13.mainnet.id;
|
|
5958
4694
|
const baseConfig = {
|
|
5959
4695
|
address: sAuto,
|
|
5960
|
-
abi:
|
|
4696
|
+
abi: import_abis15.sAutoAbi,
|
|
5961
4697
|
chainId
|
|
5962
4698
|
};
|
|
5963
4699
|
if (sAuto && autoPrice) {
|
|
5964
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await (0,
|
|
4700
|
+
const [{ result: totalSupply }, { result: currentCycle }] = await (0, import_core17.readContracts)(wagmiConfig, {
|
|
5965
4701
|
contracts: [
|
|
5966
4702
|
{
|
|
5967
4703
|
...baseConfig,
|
|
@@ -5973,15 +4709,15 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5973
4709
|
}
|
|
5974
4710
|
]
|
|
5975
4711
|
});
|
|
5976
|
-
const tvl = Number((0,
|
|
5977
|
-
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;
|
|
5978
4714
|
return {
|
|
5979
4715
|
rawTotalSupply: totalSupply,
|
|
5980
|
-
totalSupply: (0,
|
|
5981
|
-
tvl: (0,
|
|
4716
|
+
totalSupply: (0, import_utils37.formatLargeNumber)((0, import_viem17.formatEther)(totalSupply || 0n)),
|
|
4717
|
+
tvl: (0, import_utils37.formatTVL)(tvl),
|
|
5982
4718
|
rawTVL: tvl,
|
|
5983
4719
|
currentCycle,
|
|
5984
|
-
timeBeforeNextCycle: (0,
|
|
4720
|
+
timeBeforeNextCycle: (0, import_utils37.convertSecondsToRemainingTime)(
|
|
5985
4721
|
secondsLeftBeforeNextCycle
|
|
5986
4722
|
)
|
|
5987
4723
|
};
|
|
@@ -5992,34 +4728,34 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5992
4728
|
};
|
|
5993
4729
|
|
|
5994
4730
|
// functions/getSAutoRewards.ts
|
|
5995
|
-
var
|
|
5996
|
-
var
|
|
5997
|
-
var
|
|
5998
|
-
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");
|
|
5999
4735
|
var getSAutoRewards = async () => {
|
|
6000
4736
|
try {
|
|
6001
|
-
const { GetSAutoRewards } = (0,
|
|
4737
|
+
const { GetSAutoRewards } = (0, import_graph_cli14.getSdkByChainId)(import_chains14.mainnet.id);
|
|
6002
4738
|
const { globalRewardsBalances } = await GetSAutoRewards();
|
|
6003
4739
|
const allGlobalRewardsBalanceDayDatas = await paginateQuery(
|
|
6004
4740
|
GetSAutoRewards,
|
|
6005
4741
|
"globalRewardsBalanceDayDatas"
|
|
6006
4742
|
);
|
|
6007
4743
|
const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
|
|
6008
|
-
return acc + (0,
|
|
4744
|
+
return acc + (0, import_utils38.formatEtherNum)(balance.balance);
|
|
6009
4745
|
}, 0);
|
|
6010
4746
|
const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
|
|
6011
|
-
return acc + Number((0,
|
|
4747
|
+
return acc + Number((0, import_viem18.formatUnits)(balance.balanceUSD, 8));
|
|
6012
4748
|
}, 0);
|
|
6013
4749
|
const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
|
|
6014
4750
|
(dayData) => ({
|
|
6015
4751
|
timestamp: String(dayData.timestamp),
|
|
6016
|
-
balance: (0,
|
|
6017
|
-
balanceUSD: Number((0,
|
|
6018
|
-
earned: (0,
|
|
6019
|
-
earnedUSD: Number((0,
|
|
6020
|
-
dayAprPerCredit: (0,
|
|
6021
|
-
formattedDate: (0,
|
|
6022
|
-
(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))
|
|
6023
4759
|
)
|
|
6024
4760
|
})
|
|
6025
4761
|
);
|
|
@@ -6035,10 +4771,10 @@ var getSAutoRewards = async () => {
|
|
|
6035
4771
|
};
|
|
6036
4772
|
|
|
6037
4773
|
// functions/getUserSAutoRewards.ts
|
|
6038
|
-
var
|
|
6039
|
-
var
|
|
4774
|
+
var import_config12 = require("@tokemak/config");
|
|
4775
|
+
var import_utils40 = require("@tokemak/utils");
|
|
6040
4776
|
var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
6041
|
-
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = (0,
|
|
4777
|
+
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = (0, import_config12.getMainnetConfig)();
|
|
6042
4778
|
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
6043
4779
|
stoke: sAuto,
|
|
6044
4780
|
chainId: 1
|
|
@@ -6082,19 +4818,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
|
6082
4818
|
return null;
|
|
6083
4819
|
}
|
|
6084
4820
|
}
|
|
6085
|
-
const claimableNum = (0,
|
|
4821
|
+
const claimableNum = (0, import_utils40.formatEtherNum)(autoRewards?.claimable || 0n);
|
|
6086
4822
|
const claimableUsd = autoPrice * claimableNum;
|
|
6087
4823
|
const hasClaimable = claimableNum > 0;
|
|
6088
|
-
let pendingRewards = (0,
|
|
4824
|
+
let pendingRewards = (0, import_utils40.formatEtherNum)(
|
|
6089
4825
|
autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
6090
4826
|
);
|
|
6091
4827
|
if (currentCycle === 4242n) {
|
|
6092
|
-
pendingRewards = (0,
|
|
4828
|
+
pendingRewards = (0, import_utils40.formatEtherNum)(
|
|
6093
4829
|
autoRewards?.rewardsPayload.payload.amount || 0n
|
|
6094
4830
|
);
|
|
6095
4831
|
}
|
|
6096
4832
|
const pendingRewardsUsd = autoPrice * pendingRewards;
|
|
6097
|
-
const totalRewardsReceived = (0,
|
|
4833
|
+
const totalRewardsReceived = (0, import_utils40.formatEtherNum)(
|
|
6098
4834
|
autoRewards.rewardsPayload.payload.amount || 0n
|
|
6099
4835
|
);
|
|
6100
4836
|
const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
|
|
@@ -6128,20 +4864,20 @@ var getUserMerklRewards = async (address) => {
|
|
|
6128
4864
|
};
|
|
6129
4865
|
|
|
6130
4866
|
// functions/getUserEthAutoLPRewards.ts
|
|
6131
|
-
var
|
|
6132
|
-
var
|
|
6133
|
-
var
|
|
4867
|
+
var import_viem19 = require("viem");
|
|
4868
|
+
var import_utils41 = require("@tokemak/utils");
|
|
4869
|
+
var import_tokenlist14 = require("@tokemak/tokenlist");
|
|
6134
4870
|
var getUserEthAutoLPRewards = async (address) => {
|
|
6135
4871
|
const rewards = await getUserMerklRewards(address);
|
|
6136
4872
|
const autoTokenRewards = rewards?.rewards?.filter(
|
|
6137
|
-
(reward) => (0,
|
|
4873
|
+
(reward) => (0, import_viem19.getAddress)(reward.token.address) === (0, import_viem19.getAddress)(import_tokenlist14.TOKE_TOKEN.address)
|
|
6138
4874
|
);
|
|
6139
4875
|
const autoRewards = autoTokenRewards?.[0];
|
|
6140
4876
|
const amount = autoRewards?.amount;
|
|
6141
4877
|
const claimed = autoRewards?.claimed;
|
|
6142
4878
|
const claimable = Number(amount) - Number(claimed);
|
|
6143
|
-
const formattedClaimable = (0,
|
|
6144
|
-
(0,
|
|
4879
|
+
const formattedClaimable = (0, import_utils41.formatAmount)(
|
|
4880
|
+
(0, import_utils41.formatUnitsNum)(BigInt(claimable || 0), 18)
|
|
6145
4881
|
);
|
|
6146
4882
|
const users = [];
|
|
6147
4883
|
const tokens = [];
|
|
@@ -6193,12 +4929,12 @@ async function getMerklPoolApr({
|
|
|
6193
4929
|
}
|
|
6194
4930
|
|
|
6195
4931
|
// functions/getSAutoApr.ts
|
|
6196
|
-
var
|
|
6197
|
-
var
|
|
6198
|
-
var
|
|
4932
|
+
var import_graph_cli15 = require("@tokemak/graph-cli");
|
|
4933
|
+
var import_chains15 = require("viem/chains");
|
|
4934
|
+
var import_utils42 = require("@tokemak/utils");
|
|
6199
4935
|
var getSAutoApr = async () => {
|
|
6200
4936
|
try {
|
|
6201
|
-
const { GetSAutoApr } = (0,
|
|
4937
|
+
const { GetSAutoApr } = (0, import_graph_cli15.getSdkByChainId)(import_chains15.mainnet.id);
|
|
6202
4938
|
const { globalRewardsBalances } = await GetSAutoApr();
|
|
6203
4939
|
if (!globalRewardsBalances || globalRewardsBalances.length === 0) {
|
|
6204
4940
|
return {
|
|
@@ -6214,12 +4950,12 @@ var getSAutoApr = async () => {
|
|
|
6214
4950
|
aprFormatted: void 0
|
|
6215
4951
|
};
|
|
6216
4952
|
}
|
|
6217
|
-
const aprPerCredit = (0,
|
|
4953
|
+
const aprPerCredit = (0, import_utils42.formatEtherNum)(rawApr);
|
|
6218
4954
|
const lockDuration = 16;
|
|
6219
4955
|
const apr = aprPerCredit * lockDuration;
|
|
6220
4956
|
return {
|
|
6221
4957
|
apr,
|
|
6222
|
-
aprFormatted: (0,
|
|
4958
|
+
aprFormatted: (0, import_utils42.formatPercent)(apr)
|
|
6223
4959
|
};
|
|
6224
4960
|
} catch (error) {
|
|
6225
4961
|
console.error("Error fetching sAUTO APR:", error);
|
|
@@ -6230,58 +4966,45 @@ var getSAutoApr = async () => {
|
|
|
6230
4966
|
}
|
|
6231
4967
|
};
|
|
6232
4968
|
|
|
6233
|
-
// functions/
|
|
6234
|
-
var
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
}
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
}
|
|
6264
|
-
if (!dateByTs.has(ts)) dateByTs.set(ts, item.formattedDate);
|
|
6265
|
-
}
|
|
6266
|
-
const allTimestamps = Array.from(
|
|
6267
|
-
/* @__PURE__ */ new Set([...stokeByTs.keys(), ...sAutoByTs.keys()])
|
|
6268
|
-
).sort((a, b) => a - b);
|
|
6269
|
-
let lastStoke = { balance: 0, balanceUSD: 0 };
|
|
6270
|
-
let lastSAuto = { balance: 0, balanceUSD: 0 };
|
|
6271
|
-
const historicalRewards = allTimestamps.map((ts) => {
|
|
6272
|
-
if (stokeByTs.has(ts)) lastStoke = stokeByTs.get(ts);
|
|
6273
|
-
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
|
+
});
|
|
6274
4999
|
return {
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
5000
|
+
asyncSwapperRegistry,
|
|
5001
|
+
autopoolRouter,
|
|
5002
|
+
autopoolRegistry,
|
|
5003
|
+
swapRouter
|
|
6278
5004
|
};
|
|
6279
|
-
})
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
totalEarningsUsd,
|
|
6283
|
-
historicalRewards
|
|
6284
|
-
};
|
|
5005
|
+
} catch (e) {
|
|
5006
|
+
console.log(e);
|
|
5007
|
+
}
|
|
6285
5008
|
};
|
|
6286
5009
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6287
5010
|
0 && (module.exports = {
|
|
@@ -6289,8 +5012,11 @@ var getCombinedRewards = async () => {
|
|
|
6289
5012
|
BATCH_SIZE,
|
|
6290
5013
|
ETH_BASE_ASSETS,
|
|
6291
5014
|
EUR_BASE_ASSETS,
|
|
6292
|
-
|
|
5015
|
+
GET_USER_POSITIONS,
|
|
5016
|
+
GET_V4_POOL_TVL,
|
|
5017
|
+
GRAPH_V4_SUBGRAPH_PROXY_PATH,
|
|
6293
5018
|
USD_BASE_ASSETS,
|
|
5019
|
+
V4_SUBGRAPH_IDS,
|
|
6294
5020
|
aggregateSTokeRewardsDayData,
|
|
6295
5021
|
arraysToObject,
|
|
6296
5022
|
calculateRebalanceStats,
|
|
@@ -6307,7 +5033,6 @@ var getCombinedRewards = async () => {
|
|
|
6307
5033
|
findClosestTimestampEntry,
|
|
6308
5034
|
formatDateRange,
|
|
6309
5035
|
getAddressFromSystemRegistry,
|
|
6310
|
-
getAllowance,
|
|
6311
5036
|
getAmountDeposited,
|
|
6312
5037
|
getAmountWithdrawn,
|
|
6313
5038
|
getAutopilotRouter,
|
|
@@ -6321,61 +5046,44 @@ var getCombinedRewards = async () => {
|
|
|
6321
5046
|
getAutopoolUserHistory,
|
|
6322
5047
|
getAutopools,
|
|
6323
5048
|
getAutopoolsHistory,
|
|
6324
|
-
getAutopoolsRebalances,
|
|
6325
5049
|
getBlobData,
|
|
6326
5050
|
getBlobHistoricalTokenPrices,
|
|
6327
5051
|
getBridgeFee,
|
|
6328
5052
|
getChainAutopools,
|
|
6329
5053
|
getChainAutopoolsApr,
|
|
6330
|
-
getChainCycleRolloverBlockNumber,
|
|
6331
|
-
getChainSToke,
|
|
6332
|
-
getChainSTokeRewards,
|
|
6333
5054
|
getChainSubgraphStatus,
|
|
6334
5055
|
getChainUserActivity,
|
|
6335
5056
|
getChainUserAutopools,
|
|
6336
|
-
getChainUserSToke,
|
|
6337
|
-
getChainUserSTokeRewards,
|
|
6338
5057
|
getChainsForEnv,
|
|
6339
|
-
getCombinedRewards,
|
|
6340
5058
|
getCurrentCycleId,
|
|
6341
|
-
getCurveLP,
|
|
6342
|
-
getCycleV1,
|
|
6343
5059
|
getDefillamaPoolApr,
|
|
6344
5060
|
getDefillamaPrice,
|
|
5061
|
+
getDeprecatedAutopools,
|
|
6345
5062
|
getDynamicSwap,
|
|
6346
5063
|
getEthAutoLP,
|
|
6347
|
-
getEthPrice,
|
|
6348
5064
|
getEthPriceAtBlock,
|
|
6349
5065
|
getExchangeNames,
|
|
6350
5066
|
getGenStratAprs,
|
|
6351
5067
|
getHistoricalTokenPrices,
|
|
6352
|
-
getLayerzeroStatus,
|
|
6353
5068
|
getMerklCreatorApr,
|
|
6354
5069
|
getMerklPoolApr,
|
|
6355
|
-
getMutlipleAutopoolRebalances,
|
|
6356
5070
|
getPoolStats,
|
|
6357
5071
|
getPoolsAndDestinations,
|
|
6358
|
-
getProtocolStats,
|
|
6359
5072
|
getRebalanceStats,
|
|
6360
5073
|
getRebalanceValueUsd,
|
|
6361
5074
|
getRewardsPayloadV1,
|
|
6362
5075
|
getSAuto,
|
|
6363
5076
|
getSAutoApr,
|
|
6364
5077
|
getSAutoRewards,
|
|
6365
|
-
getSToke,
|
|
6366
5078
|
getSTokeChainsForEnv,
|
|
6367
|
-
getSTokeRewards,
|
|
6368
5079
|
getSubgraphStatus,
|
|
6369
|
-
getSushiLP,
|
|
6370
5080
|
getSwapQuote,
|
|
6371
5081
|
getSystemConfig,
|
|
6372
5082
|
getTimestampDaysFromStart,
|
|
6373
5083
|
getTokePrice,
|
|
6374
|
-
getTokenList,
|
|
6375
5084
|
getTokenPrice,
|
|
6376
5085
|
getTokenPrices,
|
|
6377
5086
|
getTopAutopoolHolders,
|
|
6378
|
-
getUniV4Pool,
|
|
6379
5087
|
getUniV4PoolById,
|
|
6380
5088
|
getUserActivity,
|
|
6381
5089
|
getUserAutoEthRewards,
|
|
@@ -6383,19 +5091,17 @@ var getCombinedRewards = async () => {
|
|
|
6383
5091
|
getUserAutopools,
|
|
6384
5092
|
getUserAutopoolsHistory,
|
|
6385
5093
|
getUserAutopoolsRewards,
|
|
6386
|
-
getUserCurveLP,
|
|
6387
5094
|
getUserEthAutoLP,
|
|
6388
5095
|
getUserEthAutoLPRewards,
|
|
6389
5096
|
getUserMerklRewards,
|
|
6390
5097
|
getUserRewardsV1,
|
|
6391
5098
|
getUserSAuto,
|
|
6392
5099
|
getUserSAutoRewards,
|
|
6393
|
-
getUserSToke,
|
|
6394
|
-
getUserSushiLP,
|
|
6395
5100
|
getUserTokenBalances,
|
|
6396
5101
|
getUserUniV4Positions,
|
|
6397
5102
|
getUserUniV4PositionsById,
|
|
6398
|
-
|
|
5103
|
+
getV4PoolTvlFromSubgraph,
|
|
5104
|
+
getV4SubgraphUrl,
|
|
6399
5105
|
mergeArrays,
|
|
6400
5106
|
mergeArraysWithKey,
|
|
6401
5107
|
mergeStringArrays,
|
|
@@ -6405,6 +5111,5 @@ var getCombinedRewards = async () => {
|
|
|
6405
5111
|
processRebalance,
|
|
6406
5112
|
processRebalancesInBatches,
|
|
6407
5113
|
systemRegistryFunctionNames,
|
|
6408
|
-
updateRebalanceStats
|
|
6409
|
-
waitForMessageReceived
|
|
5114
|
+
updateRebalanceStats
|
|
6410
5115
|
});
|