@tokemak/queries 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/getAutopoolDayData.d.ts.map +1 -1
- package/dist/functions/getAutopoolHistory.d.ts +24 -0
- package/dist/functions/getAutopoolHistory.d.ts.map +1 -0
- package/dist/functions/getAutopoolUser.d.ts +166 -0
- package/dist/functions/getAutopoolUser.d.ts.map +1 -0
- package/dist/functions/getAutopoolUserActivity.d.ts +18 -0
- package/dist/functions/getAutopoolUserActivity.d.ts.map +1 -0
- package/dist/functions/getAutopoolUserHistory.d.ts +23 -0
- package/dist/functions/getAutopoolUserHistory.d.ts.map +1 -0
- package/dist/functions/getAutopools.d.ts +15 -15
- package/dist/functions/getAutopools.d.ts.map +1 -1
- package/dist/functions/getAutopoolsRebalances.d.ts.map +1 -1
- package/dist/functions/getBaseChainUserActivity.d.ts +10 -0
- package/dist/functions/getBaseChainUserActivity.d.ts.map +1 -0
- package/dist/functions/getChainAutopools.d.ts +15 -15
- package/dist/functions/getChainAutopools.d.ts.map +1 -1
- package/dist/functions/getChainSTokeRewards.d.ts.map +1 -1
- package/dist/functions/getChainUserActivity.d.ts +3 -3
- package/dist/functions/getChainUserActivity.d.ts.map +1 -1
- package/dist/functions/getCombinedRewards.d.ts.map +1 -1
- package/dist/functions/getMultipleAutopoolRebalances.d.ts.map +1 -1
- package/dist/functions/getTokenPrices.d.ts +71 -71
- package/dist/functions/getUserAutopool.d.ts +3 -3
- package/dist/functions/getUserAutopoolBalanceChanges.d.ts.map +1 -1
- package/dist/functions/getUserAutopools.d.ts +9 -9
- package/dist/functions/getUserMerklRewards.d.ts +2 -1
- package/dist/functions/getUserMerklRewards.d.ts.map +1 -1
- package/dist/functions/getUserSushiLP.d.ts +1 -1
- package/dist/functions/index.d.ts +5 -0
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/index.js +872 -499
- package/dist/index.mjs +648 -276
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1127,13 +1127,74 @@ var getAutopoolsRebalances = async (chainId = 1) => {
|
|
|
1127
1127
|
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
1128
1128
|
};
|
|
1129
1129
|
|
|
1130
|
+
// functions/getAutopoolDayData.ts
|
|
1131
|
+
import { formatUnits as formatUnits3 } from "viem";
|
|
1132
|
+
import { formatEtherNum as formatEtherNum3 } from "@tokemak/utils";
|
|
1133
|
+
import { TOKEMAK_LAUNCH_TIMESTAMP } from "@tokemak/constants";
|
|
1134
|
+
import { getSdkByChainId as getSdkByChainId4 } from "@tokemak/graph-cli";
|
|
1135
|
+
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_LAUNCH_TIMESTAMP) => {
|
|
1136
|
+
try {
|
|
1137
|
+
const { GetAutopoolDayData } = getSdkByChainId4(chainId);
|
|
1138
|
+
const { autopoolDayDatas } = await GetAutopoolDayData({
|
|
1139
|
+
address,
|
|
1140
|
+
timestamp: startTimestamp
|
|
1141
|
+
});
|
|
1142
|
+
const formattedDayDatas = autopoolDayDatas.map((autoPoolDayData) => {
|
|
1143
|
+
const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
|
|
1144
|
+
let baseApy = autoPoolDayData.autopoolApy;
|
|
1145
|
+
let rewarderApy = 0;
|
|
1146
|
+
const formattedRewarder7DayMAApy = formatEtherNum3(
|
|
1147
|
+
BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
|
|
1148
|
+
);
|
|
1149
|
+
const formattedRewarder30DayMAApy = formatEtherNum3(
|
|
1150
|
+
BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
|
|
1151
|
+
);
|
|
1152
|
+
if (formattedRewarder7DayMAApy) {
|
|
1153
|
+
rewarderApy = formattedRewarder7DayMAApy;
|
|
1154
|
+
}
|
|
1155
|
+
if (formattedRewarder30DayMAApy) {
|
|
1156
|
+
rewarderApy = formattedRewarder30DayMAApy;
|
|
1157
|
+
}
|
|
1158
|
+
if (!baseApy) {
|
|
1159
|
+
baseApy = 0;
|
|
1160
|
+
} else {
|
|
1161
|
+
baseApy = Number(
|
|
1162
|
+
formatUnits3(BigInt(baseApy), autoPoolDayData.baseAsset.decimals)
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
if (baseApy < 0) {
|
|
1166
|
+
baseApy = 0;
|
|
1167
|
+
}
|
|
1168
|
+
const combinedApy = rewarderApy + baseApy;
|
|
1169
|
+
return {
|
|
1170
|
+
...autoPoolDayData,
|
|
1171
|
+
navPerShare,
|
|
1172
|
+
rewarderApy,
|
|
1173
|
+
baseApy,
|
|
1174
|
+
combinedApy,
|
|
1175
|
+
date: new Date(Number(autoPoolDayData.timestamp) * 1e3)
|
|
1176
|
+
};
|
|
1177
|
+
});
|
|
1178
|
+
const filledDayDatas = fillMissingDates(formattedDayDatas);
|
|
1179
|
+
return filledDayDatas;
|
|
1180
|
+
} catch (e) {
|
|
1181
|
+
console.log(e);
|
|
1182
|
+
return [];
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
// functions/getAutopoolHistory.ts
|
|
1187
|
+
var getAutopoolHistory = async (autopool) => {
|
|
1188
|
+
return getAutopoolDayData(autopool.poolAddress, autopool.chain?.chainId);
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1130
1191
|
// functions/getAutopoolsHistory.ts
|
|
1131
1192
|
import { getAddress as getAddress3 } from "viem";
|
|
1132
1193
|
|
|
1133
1194
|
// functions/getAutopoolsDayData.ts
|
|
1134
|
-
import { getSdkByChainId as
|
|
1195
|
+
import { getSdkByChainId as getSdkByChainId5 } from "@tokemak/graph-cli";
|
|
1135
1196
|
var getAutopoolsDayData = async (chainId, timestamp) => {
|
|
1136
|
-
const { GetAutopoolsDayData } =
|
|
1197
|
+
const { GetAutopoolsDayData } = getSdkByChainId5(chainId);
|
|
1137
1198
|
const PAGE_SIZE = 1e3;
|
|
1138
1199
|
let allResults = [];
|
|
1139
1200
|
let hasMore = true;
|
|
@@ -1209,6 +1270,329 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
|
|
|
1209
1270
|
}
|
|
1210
1271
|
};
|
|
1211
1272
|
|
|
1273
|
+
// functions/getAutopoolUser.ts
|
|
1274
|
+
import { erc20Abi } from "viem";
|
|
1275
|
+
import { readContract as readContract2, readContracts } from "@wagmi/core";
|
|
1276
|
+
import { autopoolEthAbi } from "@tokemak/abis";
|
|
1277
|
+
import {
|
|
1278
|
+
convertTimestampToDate as convertTimestampToDate2,
|
|
1279
|
+
formatEtherNum as formatEtherNum4,
|
|
1280
|
+
formatUnitsNum as formatUnitsNum2
|
|
1281
|
+
} from "@tokemak/utils";
|
|
1282
|
+
var getAutopoolUser = async (config, {
|
|
1283
|
+
autopool,
|
|
1284
|
+
address,
|
|
1285
|
+
userActivity,
|
|
1286
|
+
prices
|
|
1287
|
+
}) => {
|
|
1288
|
+
const autopoolContract = {
|
|
1289
|
+
address: autopool?.poolAddress,
|
|
1290
|
+
abi: autopoolEthAbi,
|
|
1291
|
+
chainId: autopool?.chain?.chainId
|
|
1292
|
+
};
|
|
1293
|
+
const [
|
|
1294
|
+
{ result: autopoolRewarderContract },
|
|
1295
|
+
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
1296
|
+
] = await readContracts(config, {
|
|
1297
|
+
contracts: [
|
|
1298
|
+
{
|
|
1299
|
+
...autopoolContract,
|
|
1300
|
+
functionName: "rewarder",
|
|
1301
|
+
args: []
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
...autopoolContract,
|
|
1305
|
+
functionName: "balanceOf",
|
|
1306
|
+
args: [address]
|
|
1307
|
+
}
|
|
1308
|
+
]
|
|
1309
|
+
});
|
|
1310
|
+
if (!autopoolRewarderContract) {
|
|
1311
|
+
throw new Error("No rewarder contract found");
|
|
1312
|
+
}
|
|
1313
|
+
if (unstakedPoolSharesError) {
|
|
1314
|
+
throw new Error("Error fetching unstaked pool shares");
|
|
1315
|
+
}
|
|
1316
|
+
const stakedPoolShares = await readContract2(config, {
|
|
1317
|
+
address: autopoolRewarderContract,
|
|
1318
|
+
abi: erc20Abi,
|
|
1319
|
+
functionName: "balanceOf",
|
|
1320
|
+
args: [address],
|
|
1321
|
+
chainId: autopool?.chain?.chainId
|
|
1322
|
+
});
|
|
1323
|
+
const stakedShares = formatEtherNum4(stakedPoolShares);
|
|
1324
|
+
const staked = convertBaseAssetToTokenPricesAndDenom(
|
|
1325
|
+
stakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
1326
|
+
autopool?.baseAsset.price,
|
|
1327
|
+
autopool?.denomination.price,
|
|
1328
|
+
prices
|
|
1329
|
+
);
|
|
1330
|
+
const unstakedShares = formatEtherNum4(unstakedPoolShares || 0n);
|
|
1331
|
+
const unstaked = convertBaseAssetToTokenPricesAndDenom(
|
|
1332
|
+
unstakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
1333
|
+
autopool?.baseAsset.price,
|
|
1334
|
+
autopool?.denomination.price,
|
|
1335
|
+
prices
|
|
1336
|
+
);
|
|
1337
|
+
const shares = unstakedShares + stakedShares;
|
|
1338
|
+
const nav = convertBaseAssetToTokenPricesAndDenom(
|
|
1339
|
+
shares * (autopool?.navPerShare.baseAsset || 0),
|
|
1340
|
+
autopool?.baseAsset.price,
|
|
1341
|
+
autopool?.denomination.price,
|
|
1342
|
+
prices
|
|
1343
|
+
);
|
|
1344
|
+
const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
|
|
1345
|
+
formatUnitsNum2(
|
|
1346
|
+
userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
|
|
1347
|
+
autopool?.baseAsset.decimals
|
|
1348
|
+
),
|
|
1349
|
+
autopool?.baseAsset.price,
|
|
1350
|
+
autopool?.denomination.price,
|
|
1351
|
+
prices
|
|
1352
|
+
);
|
|
1353
|
+
const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
|
|
1354
|
+
formatUnitsNum2(
|
|
1355
|
+
userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
|
|
1356
|
+
autopool?.baseAsset.decimals
|
|
1357
|
+
),
|
|
1358
|
+
autopool?.baseAsset.price,
|
|
1359
|
+
autopool?.denomination.price,
|
|
1360
|
+
prices
|
|
1361
|
+
);
|
|
1362
|
+
const returns = convertBaseAssetToTokenPricesAndDenom(
|
|
1363
|
+
nav.baseAsset + totalWithdrawals.baseAsset - totalDeposits.baseAsset,
|
|
1364
|
+
autopool?.baseAsset.price,
|
|
1365
|
+
autopool?.denomination.price,
|
|
1366
|
+
prices
|
|
1367
|
+
);
|
|
1368
|
+
const supplied = convertBaseAssetToTokenPricesAndDenom(
|
|
1369
|
+
totalDeposits.baseAsset - totalWithdrawals.baseAsset,
|
|
1370
|
+
autopool?.baseAsset.price,
|
|
1371
|
+
autopool?.denomination.price,
|
|
1372
|
+
prices
|
|
1373
|
+
);
|
|
1374
|
+
const poolEvents = userActivity?.events.filter(
|
|
1375
|
+
(event) => event.vaultAddress === autopool?.poolAddress
|
|
1376
|
+
);
|
|
1377
|
+
let lastDeposit;
|
|
1378
|
+
if (poolEvents && poolEvents?.length > 0) {
|
|
1379
|
+
lastDeposit = convertTimestampToDate2(
|
|
1380
|
+
poolEvents[poolEvents.length - 1].timestamp
|
|
1381
|
+
).toLocaleDateString("en-US", {
|
|
1382
|
+
day: "2-digit",
|
|
1383
|
+
month: "short",
|
|
1384
|
+
year: "numeric"
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
return {
|
|
1388
|
+
symbol: autopool?.symbol,
|
|
1389
|
+
poolAddress: autopool?.poolAddress,
|
|
1390
|
+
userAddress: address,
|
|
1391
|
+
shares: {
|
|
1392
|
+
unstaked: unstakedShares,
|
|
1393
|
+
staked: stakedShares,
|
|
1394
|
+
total: shares
|
|
1395
|
+
},
|
|
1396
|
+
balance: {
|
|
1397
|
+
unstaked,
|
|
1398
|
+
staked,
|
|
1399
|
+
total: nav
|
|
1400
|
+
},
|
|
1401
|
+
returns,
|
|
1402
|
+
activity: {
|
|
1403
|
+
totalDeposits,
|
|
1404
|
+
totalWithdrawals,
|
|
1405
|
+
lastDeposit,
|
|
1406
|
+
supplied
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
// functions/getAutopoolUserActivity.ts
|
|
1412
|
+
import { getSdkByChainId as getSdkByChainId6 } from "@tokemak/graph-cli";
|
|
1413
|
+
import { formatUnitsNum as formatUnitsNum3 } from "@tokemak/utils";
|
|
1414
|
+
var getAutopoolUserActivity = async ({
|
|
1415
|
+
autopool,
|
|
1416
|
+
userAddress
|
|
1417
|
+
}) => {
|
|
1418
|
+
if (!autopool || !autopool.chain?.chainId) {
|
|
1419
|
+
throw new Error("Autopool not found");
|
|
1420
|
+
}
|
|
1421
|
+
const { GetUserAutopoolBalanceChangeHistory } = getSdkByChainId6(
|
|
1422
|
+
autopool.chain?.chainId
|
|
1423
|
+
);
|
|
1424
|
+
try {
|
|
1425
|
+
const userAutopoolBalanceChanges = await paginateQuery(
|
|
1426
|
+
(vars) => GetUserAutopoolBalanceChangeHistory({
|
|
1427
|
+
userAddress,
|
|
1428
|
+
vaultAddress: autopool.poolAddress,
|
|
1429
|
+
first: vars?.first || 1e3,
|
|
1430
|
+
skip: vars?.skip || 0
|
|
1431
|
+
}),
|
|
1432
|
+
"userSpecificAutopoolBalanceChanges",
|
|
1433
|
+
{
|
|
1434
|
+
first: 1e3,
|
|
1435
|
+
maxPages: 100
|
|
1436
|
+
}
|
|
1437
|
+
);
|
|
1438
|
+
let userActivityTotals = {};
|
|
1439
|
+
let events = [];
|
|
1440
|
+
userAutopoolBalanceChanges.forEach((activity) => {
|
|
1441
|
+
if (!userActivityTotals[activity.vaultAddress]) {
|
|
1442
|
+
userActivityTotals[activity.vaultAddress] = {
|
|
1443
|
+
totalDeposits: 0n,
|
|
1444
|
+
totalWithdrawals: 0n,
|
|
1445
|
+
totalStakes: 0n,
|
|
1446
|
+
totalUnstakes: 0n,
|
|
1447
|
+
chainId: autopool.chain?.chainId
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
activity.items.forEach((item) => {
|
|
1451
|
+
let eventType;
|
|
1452
|
+
if (item.staked && item.assetChange > 0n) {
|
|
1453
|
+
userActivityTotals[activity.vaultAddress].totalStakes += BigInt(
|
|
1454
|
+
item.assetChange
|
|
1455
|
+
);
|
|
1456
|
+
eventType = "Stake";
|
|
1457
|
+
} else if (item.staked && item.assetChange < 0n) {
|
|
1458
|
+
userActivityTotals[activity.vaultAddress].totalUnstakes += BigInt(
|
|
1459
|
+
BigInt(item.assetChange) * -1n
|
|
1460
|
+
);
|
|
1461
|
+
eventType = "Unstake";
|
|
1462
|
+
} else if (!item.staked && item.assetChange > 0n) {
|
|
1463
|
+
userActivityTotals[activity.vaultAddress].totalDeposits += BigInt(
|
|
1464
|
+
item.assetChange
|
|
1465
|
+
);
|
|
1466
|
+
eventType = "Deposit";
|
|
1467
|
+
} else if (!item.staked && item.assetChange < 0n) {
|
|
1468
|
+
userActivityTotals[activity.vaultAddress].totalWithdrawals += BigInt(
|
|
1469
|
+
BigInt(item.assetChange) * -1n
|
|
1470
|
+
);
|
|
1471
|
+
eventType = "Withdrawal";
|
|
1472
|
+
} else {
|
|
1473
|
+
eventType = "Unknown";
|
|
1474
|
+
}
|
|
1475
|
+
const netDeposits = formatUnitsNum3(
|
|
1476
|
+
userActivityTotals[activity.vaultAddress].totalDeposits - userActivityTotals[activity.vaultAddress].totalWithdrawals,
|
|
1477
|
+
autopool.baseAsset.decimals
|
|
1478
|
+
);
|
|
1479
|
+
if (!item.staked) {
|
|
1480
|
+
events.push({
|
|
1481
|
+
timestamp: activity.timestamp,
|
|
1482
|
+
shareChange: item.shareChange,
|
|
1483
|
+
assetChange: item.assetChange,
|
|
1484
|
+
vaultAddress: activity.vaultAddress,
|
|
1485
|
+
netDeposits,
|
|
1486
|
+
eventType
|
|
1487
|
+
// staked: item.staked,
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
});
|
|
1492
|
+
return { events, totals: userActivityTotals };
|
|
1493
|
+
} catch (error) {
|
|
1494
|
+
console.error(error);
|
|
1495
|
+
return [];
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
|
|
1499
|
+
// functions/getAutopoolUserHistory.ts
|
|
1500
|
+
import { getSdkByChainId as getSdkByChainId7 } from "@tokemak/graph-cli";
|
|
1501
|
+
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP2 } from "@tokemak/constants";
|
|
1502
|
+
import { base } from "viem/chains";
|
|
1503
|
+
import { formatEtherNum as formatEtherNum5, formatUnitsNum as formatUnitsNum4 } from "@tokemak/utils";
|
|
1504
|
+
var getAutopoolUserHistory = async ({
|
|
1505
|
+
userAddress,
|
|
1506
|
+
autopool,
|
|
1507
|
+
userActivity
|
|
1508
|
+
}) => {
|
|
1509
|
+
const { GetUserVaultDayData } = getSdkByChainId7(
|
|
1510
|
+
autopool?.chain?.chainId || base.id
|
|
1511
|
+
);
|
|
1512
|
+
try {
|
|
1513
|
+
if (userAddress) {
|
|
1514
|
+
const { userVaultDayDatas } = await GetUserVaultDayData({
|
|
1515
|
+
address: userAddress,
|
|
1516
|
+
timestamp: TOKEMAK_LAUNCH_TIMESTAMP2,
|
|
1517
|
+
vaultAddress: autopool?.poolAddress
|
|
1518
|
+
});
|
|
1519
|
+
const autopoolDayData = await getAutopoolHistory(autopool);
|
|
1520
|
+
if (!autopoolDayData) {
|
|
1521
|
+
throw new Error("No autopool history found");
|
|
1522
|
+
}
|
|
1523
|
+
const formattedUserVaultDayDatas = userVaultDayDatas.map((dayData) => {
|
|
1524
|
+
if (!dayData.timestamp) {
|
|
1525
|
+
throw new Error("Missing timestamp in userVaultDayData");
|
|
1526
|
+
}
|
|
1527
|
+
return {
|
|
1528
|
+
...dayData,
|
|
1529
|
+
date: new Date(Number(dayData.timestamp) * 1e3),
|
|
1530
|
+
timestamp: dayData.timestamp.toString()
|
|
1531
|
+
};
|
|
1532
|
+
});
|
|
1533
|
+
const filledMissingDates = fillMissingDates(formattedUserVaultDayDatas);
|
|
1534
|
+
if (filledMissingDates.length > 0) {
|
|
1535
|
+
const firstEntry = filledMissingDates[0];
|
|
1536
|
+
const dayBefore = new Date(firstEntry.date);
|
|
1537
|
+
dayBefore.setDate(dayBefore.getDate() - 1);
|
|
1538
|
+
const dayBeforeTimestamp = Math.floor(
|
|
1539
|
+
dayBefore.getTime() / 1e3
|
|
1540
|
+
).toString();
|
|
1541
|
+
const dayBeforeEntry = {
|
|
1542
|
+
...firstEntry,
|
|
1543
|
+
date: dayBefore,
|
|
1544
|
+
timestamp: dayBeforeTimestamp,
|
|
1545
|
+
totalShares: 0
|
|
1546
|
+
};
|
|
1547
|
+
filledMissingDates.unshift(dayBeforeEntry);
|
|
1548
|
+
}
|
|
1549
|
+
let lastKnownNetDeposits = null;
|
|
1550
|
+
const matchedData = filledMissingDates.map((userVaultDayData) => {
|
|
1551
|
+
const matchingAutopoolDayData = autopoolDayData.find(
|
|
1552
|
+
(autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
|
|
1553
|
+
);
|
|
1554
|
+
const userPortionOfVault = formatEtherNum5(userVaultDayData.totalShares) / formatEtherNum5(matchingAutopoolDayData?.totalSupply);
|
|
1555
|
+
const userNav = userPortionOfVault * formatUnitsNum4(
|
|
1556
|
+
BigInt(matchingAutopoolDayData?.nav || 0),
|
|
1557
|
+
autopool?.baseAsset.decimals
|
|
1558
|
+
);
|
|
1559
|
+
const eventsForDay = userActivity.events?.filter((event) => {
|
|
1560
|
+
const eventDate = new Date(Number(event.timestamp) * 1e3);
|
|
1561
|
+
const windowStart = new Date(userVaultDayData.date.getTime());
|
|
1562
|
+
const windowEnd = new Date(
|
|
1563
|
+
userVaultDayData.date.getTime() + 24 * 60 * 60 * 1e3
|
|
1564
|
+
);
|
|
1565
|
+
const matches = eventDate.getTime() > windowStart.getTime() && eventDate.getTime() <= windowEnd.getTime();
|
|
1566
|
+
return matches;
|
|
1567
|
+
});
|
|
1568
|
+
const lastEventForDay = eventsForDay && eventsForDay.length > 0 ? eventsForDay.sort(
|
|
1569
|
+
(a, b) => Number(b.timestamp) - Number(a.timestamp)
|
|
1570
|
+
)[0] : 0;
|
|
1571
|
+
let netDeposits = 0;
|
|
1572
|
+
if (lastEventForDay && "netDeposits" in lastEventForDay && typeof lastEventForDay.netDeposits === "number") {
|
|
1573
|
+
netDeposits = lastEventForDay.netDeposits;
|
|
1574
|
+
lastKnownNetDeposits = netDeposits;
|
|
1575
|
+
} else {
|
|
1576
|
+
netDeposits = lastKnownNetDeposits;
|
|
1577
|
+
}
|
|
1578
|
+
return {
|
|
1579
|
+
date: userVaultDayData.date,
|
|
1580
|
+
timestamp: userVaultDayData.timestamp,
|
|
1581
|
+
baseAsset: autopool?.baseAsset.symbol,
|
|
1582
|
+
nav: userNav,
|
|
1583
|
+
events: eventsForDay,
|
|
1584
|
+
netDeposits
|
|
1585
|
+
};
|
|
1586
|
+
});
|
|
1587
|
+
return matchedData;
|
|
1588
|
+
}
|
|
1589
|
+
return [];
|
|
1590
|
+
} catch (e) {
|
|
1591
|
+
console.error(e);
|
|
1592
|
+
return [];
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
|
|
1212
1596
|
// functions/getCurveLP.ts
|
|
1213
1597
|
import { getMainnetConfig } from "@tokemak/config";
|
|
1214
1598
|
import { CURVE_API_URL, TOKE_CURVE_POOL_ID } from "@tokemak/constants";
|
|
@@ -1246,7 +1630,7 @@ var getCurveLP = async () => {
|
|
|
1246
1630
|
// functions/getSushiLP.ts
|
|
1247
1631
|
import { sushiPoolAbi } from "@tokemak/abis";
|
|
1248
1632
|
import { getMainnetConfig as getMainnetConfig2 } from "@tokemak/config";
|
|
1249
|
-
import { readContracts } from "@wagmi/core";
|
|
1633
|
+
import { readContracts as readContracts2 } from "@wagmi/core";
|
|
1250
1634
|
import { formatEther } from "viem";
|
|
1251
1635
|
import { mainnet } from "viem/chains";
|
|
1252
1636
|
var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
@@ -1256,7 +1640,7 @@ var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
|
1256
1640
|
abi: sushiPoolAbi
|
|
1257
1641
|
};
|
|
1258
1642
|
try {
|
|
1259
|
-
const [{ result: reserves }, { result: totalSupply }] = await
|
|
1643
|
+
const [{ result: reserves }, { result: totalSupply }] = await readContracts2(
|
|
1260
1644
|
wagmiConfig,
|
|
1261
1645
|
{
|
|
1262
1646
|
contracts: [
|
|
@@ -1298,8 +1682,8 @@ var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
|
1298
1682
|
};
|
|
1299
1683
|
|
|
1300
1684
|
// functions/getUniV4Pool.ts
|
|
1301
|
-
import { readContracts as
|
|
1302
|
-
import { formatUnits as
|
|
1685
|
+
import { readContracts as readContracts3 } from "@wagmi/core";
|
|
1686
|
+
import { formatUnits as formatUnits4, keccak256, encodeAbiParameters } from "viem";
|
|
1303
1687
|
import { mainnet as mainnet2 } from "viem/chains";
|
|
1304
1688
|
import {
|
|
1305
1689
|
UNISWAP_V4_POOL_MANAGER,
|
|
@@ -1326,7 +1710,7 @@ var stateViewAbi = [
|
|
|
1326
1710
|
type: "function"
|
|
1327
1711
|
}
|
|
1328
1712
|
];
|
|
1329
|
-
var
|
|
1713
|
+
var erc20Abi2 = [
|
|
1330
1714
|
{
|
|
1331
1715
|
inputs: [],
|
|
1332
1716
|
name: "decimals",
|
|
@@ -1409,7 +1793,7 @@ async function getUniV4Pool(wagmiConfig, {
|
|
|
1409
1793
|
const poolManager = UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1410
1794
|
const poolId = computePoolId(poolKey);
|
|
1411
1795
|
try {
|
|
1412
|
-
const [{ result: slot0 }, { result: liquidity }] = await
|
|
1796
|
+
const [{ result: slot0 }, { result: liquidity }] = await readContracts3(
|
|
1413
1797
|
wagmiConfig,
|
|
1414
1798
|
{
|
|
1415
1799
|
contracts: [
|
|
@@ -1440,19 +1824,19 @@ async function getUniV4Pool(wagmiConfig, {
|
|
|
1440
1824
|
tokenContracts.push(
|
|
1441
1825
|
{
|
|
1442
1826
|
address: poolKey.currency0,
|
|
1443
|
-
abi:
|
|
1827
|
+
abi: erc20Abi2,
|
|
1444
1828
|
functionName: "decimals",
|
|
1445
1829
|
chainId
|
|
1446
1830
|
},
|
|
1447
1831
|
{
|
|
1448
1832
|
address: poolKey.currency0,
|
|
1449
|
-
abi:
|
|
1833
|
+
abi: erc20Abi2,
|
|
1450
1834
|
functionName: "symbol",
|
|
1451
1835
|
chainId
|
|
1452
1836
|
},
|
|
1453
1837
|
{
|
|
1454
1838
|
address: poolKey.currency0,
|
|
1455
|
-
abi:
|
|
1839
|
+
abi: erc20Abi2,
|
|
1456
1840
|
functionName: "balanceOf",
|
|
1457
1841
|
args: [poolManager],
|
|
1458
1842
|
chainId
|
|
@@ -1463,26 +1847,26 @@ async function getUniV4Pool(wagmiConfig, {
|
|
|
1463
1847
|
tokenContracts.push(
|
|
1464
1848
|
{
|
|
1465
1849
|
address: poolKey.currency1,
|
|
1466
|
-
abi:
|
|
1850
|
+
abi: erc20Abi2,
|
|
1467
1851
|
functionName: "decimals",
|
|
1468
1852
|
chainId
|
|
1469
1853
|
},
|
|
1470
1854
|
{
|
|
1471
1855
|
address: poolKey.currency1,
|
|
1472
|
-
abi:
|
|
1856
|
+
abi: erc20Abi2,
|
|
1473
1857
|
functionName: "symbol",
|
|
1474
1858
|
chainId
|
|
1475
1859
|
},
|
|
1476
1860
|
{
|
|
1477
1861
|
address: poolKey.currency1,
|
|
1478
|
-
abi:
|
|
1862
|
+
abi: erc20Abi2,
|
|
1479
1863
|
functionName: "balanceOf",
|
|
1480
1864
|
args: [poolManager],
|
|
1481
1865
|
chainId
|
|
1482
1866
|
}
|
|
1483
1867
|
);
|
|
1484
1868
|
}
|
|
1485
|
-
const tokenResults = tokenContracts.length > 0 ? await
|
|
1869
|
+
const tokenResults = tokenContracts.length > 0 ? await readContracts3(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
1486
1870
|
let decimals0 = 18;
|
|
1487
1871
|
let symbol0 = "ETH";
|
|
1488
1872
|
let balance0 = 0n;
|
|
@@ -1502,8 +1886,8 @@ async function getUniV4Pool(wagmiConfig, {
|
|
|
1502
1886
|
}
|
|
1503
1887
|
const [sqrtPriceX96, tick] = slot0;
|
|
1504
1888
|
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1505
|
-
const balance0Formatted = Number(
|
|
1506
|
-
const balance1Formatted = Number(
|
|
1889
|
+
const balance0Formatted = Number(formatUnits4(balance0, decimals0));
|
|
1890
|
+
const balance1Formatted = Number(formatUnits4(balance1, decimals1));
|
|
1507
1891
|
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1508
1892
|
liquidity ?? 0n,
|
|
1509
1893
|
sqrtPriceX96,
|
|
@@ -1587,7 +1971,7 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1587
1971
|
}
|
|
1588
1972
|
const poolManager = UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1589
1973
|
try {
|
|
1590
|
-
const [{ result: slot0 }, { result: liquidity }] = await
|
|
1974
|
+
const [{ result: slot0 }, { result: liquidity }] = await readContracts3(
|
|
1591
1975
|
wagmiConfig,
|
|
1592
1976
|
{
|
|
1593
1977
|
contracts: [
|
|
@@ -1618,19 +2002,19 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1618
2002
|
tokenContracts.push(
|
|
1619
2003
|
{
|
|
1620
2004
|
address: currency0,
|
|
1621
|
-
abi:
|
|
2005
|
+
abi: erc20Abi2,
|
|
1622
2006
|
functionName: "decimals",
|
|
1623
2007
|
chainId
|
|
1624
2008
|
},
|
|
1625
2009
|
{
|
|
1626
2010
|
address: currency0,
|
|
1627
|
-
abi:
|
|
2011
|
+
abi: erc20Abi2,
|
|
1628
2012
|
functionName: "symbol",
|
|
1629
2013
|
chainId
|
|
1630
2014
|
},
|
|
1631
2015
|
{
|
|
1632
2016
|
address: currency0,
|
|
1633
|
-
abi:
|
|
2017
|
+
abi: erc20Abi2,
|
|
1634
2018
|
functionName: "balanceOf",
|
|
1635
2019
|
args: [poolManager],
|
|
1636
2020
|
chainId
|
|
@@ -1641,26 +2025,26 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1641
2025
|
tokenContracts.push(
|
|
1642
2026
|
{
|
|
1643
2027
|
address: currency1,
|
|
1644
|
-
abi:
|
|
2028
|
+
abi: erc20Abi2,
|
|
1645
2029
|
functionName: "decimals",
|
|
1646
2030
|
chainId
|
|
1647
2031
|
},
|
|
1648
2032
|
{
|
|
1649
2033
|
address: currency1,
|
|
1650
|
-
abi:
|
|
2034
|
+
abi: erc20Abi2,
|
|
1651
2035
|
functionName: "symbol",
|
|
1652
2036
|
chainId
|
|
1653
2037
|
},
|
|
1654
2038
|
{
|
|
1655
2039
|
address: currency1,
|
|
1656
|
-
abi:
|
|
2040
|
+
abi: erc20Abi2,
|
|
1657
2041
|
functionName: "balanceOf",
|
|
1658
2042
|
args: [poolManager],
|
|
1659
2043
|
chainId
|
|
1660
2044
|
}
|
|
1661
2045
|
);
|
|
1662
2046
|
}
|
|
1663
|
-
const tokenResults = tokenContracts.length > 0 ? await
|
|
2047
|
+
const tokenResults = tokenContracts.length > 0 ? await readContracts3(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
1664
2048
|
let decimals0 = 18;
|
|
1665
2049
|
let symbol0 = "ETH";
|
|
1666
2050
|
let balance0 = 0n;
|
|
@@ -1680,8 +2064,8 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1680
2064
|
}
|
|
1681
2065
|
const [sqrtPriceX96, tick] = slot0;
|
|
1682
2066
|
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1683
|
-
const balance0Formatted = Number(
|
|
1684
|
-
const balance1Formatted = Number(
|
|
2067
|
+
const balance0Formatted = Number(formatUnits4(balance0, decimals0));
|
|
2068
|
+
const balance1Formatted = Number(formatUnits4(balance1, decimals1));
|
|
1685
2069
|
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1686
2070
|
liquidity ?? 0n,
|
|
1687
2071
|
sqrtPriceX96,
|
|
@@ -1732,8 +2116,8 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1732
2116
|
}
|
|
1733
2117
|
|
|
1734
2118
|
// functions/getUserUniV4Positions.ts
|
|
1735
|
-
import { readContracts as
|
|
1736
|
-
import { formatUnits as
|
|
2119
|
+
import { readContracts as readContracts4 } from "@wagmi/core";
|
|
2120
|
+
import { formatUnits as formatUnits5 } from "viem";
|
|
1737
2121
|
import { mainnet as mainnet3 } from "viem/chains";
|
|
1738
2122
|
import { GraphQLClient, gql } from "graphql-request";
|
|
1739
2123
|
import {
|
|
@@ -1800,7 +2184,7 @@ var stateViewAbi2 = [
|
|
|
1800
2184
|
type: "function"
|
|
1801
2185
|
}
|
|
1802
2186
|
];
|
|
1803
|
-
var
|
|
2187
|
+
var erc20Abi3 = [
|
|
1804
2188
|
{
|
|
1805
2189
|
inputs: [],
|
|
1806
2190
|
name: "decimals",
|
|
@@ -1850,8 +2234,8 @@ function getTokenAmountsFromLiquidity(liquidity, sqrtPriceX96, tickLower, tickUp
|
|
|
1850
2234
|
amount1 = liquidity * (sqrtPriceX96 - sqrtPriceLower) / Q96;
|
|
1851
2235
|
}
|
|
1852
2236
|
return {
|
|
1853
|
-
amount0: Number(
|
|
1854
|
-
amount1: Number(
|
|
2237
|
+
amount0: Number(formatUnits5(amount0, token0Decimals)),
|
|
2238
|
+
amount1: Number(formatUnits5(amount1, token1Decimals))
|
|
1855
2239
|
};
|
|
1856
2240
|
}
|
|
1857
2241
|
function feeToTierString2(fee) {
|
|
@@ -1930,7 +2314,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
1930
2314
|
chainId
|
|
1931
2315
|
}
|
|
1932
2316
|
]);
|
|
1933
|
-
const positionResults = await
|
|
2317
|
+
const positionResults = await readContracts4(wagmiConfig, {
|
|
1934
2318
|
contracts: positionInfoCalls
|
|
1935
2319
|
});
|
|
1936
2320
|
const matchingPositions = [];
|
|
@@ -1980,13 +2364,13 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
1980
2364
|
...!isToken0Native ? [
|
|
1981
2365
|
{
|
|
1982
2366
|
address: currency0,
|
|
1983
|
-
abi:
|
|
2367
|
+
abi: erc20Abi3,
|
|
1984
2368
|
functionName: "decimals",
|
|
1985
2369
|
chainId
|
|
1986
2370
|
},
|
|
1987
2371
|
{
|
|
1988
2372
|
address: currency0,
|
|
1989
|
-
abi:
|
|
2373
|
+
abi: erc20Abi3,
|
|
1990
2374
|
functionName: "symbol",
|
|
1991
2375
|
chainId
|
|
1992
2376
|
}
|
|
@@ -1994,19 +2378,19 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
1994
2378
|
...!isToken1Native ? [
|
|
1995
2379
|
{
|
|
1996
2380
|
address: currency1,
|
|
1997
|
-
abi:
|
|
2381
|
+
abi: erc20Abi3,
|
|
1998
2382
|
functionName: "decimals",
|
|
1999
2383
|
chainId
|
|
2000
2384
|
},
|
|
2001
2385
|
{
|
|
2002
2386
|
address: currency1,
|
|
2003
|
-
abi:
|
|
2387
|
+
abi: erc20Abi3,
|
|
2004
2388
|
functionName: "symbol",
|
|
2005
2389
|
chainId
|
|
2006
2390
|
}
|
|
2007
2391
|
] : []
|
|
2008
2392
|
];
|
|
2009
|
-
const infoResults = await
|
|
2393
|
+
const infoResults = await readContracts4(wagmiConfig, {
|
|
2010
2394
|
contracts: infoCalls
|
|
2011
2395
|
});
|
|
2012
2396
|
const slot0 = infoResults[0]?.result;
|
|
@@ -2269,9 +2653,9 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2269
2653
|
}
|
|
2270
2654
|
|
|
2271
2655
|
// functions/getChainUserActivity.ts
|
|
2272
|
-
import { getSdkByChainId as
|
|
2656
|
+
import { getSdkByChainId as getSdkByChainId8 } from "@tokemak/graph-cli";
|
|
2273
2657
|
var getChainUserActivity = async (address, chainId = 1) => {
|
|
2274
|
-
const { GetUserBalanceChangeHistory } =
|
|
2658
|
+
const { GetUserBalanceChangeHistory } = getSdkByChainId8(chainId);
|
|
2275
2659
|
try {
|
|
2276
2660
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
2277
2661
|
(vars) => GetUserBalanceChangeHistory({
|
|
@@ -2359,7 +2743,7 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
|
|
|
2359
2743
|
|
|
2360
2744
|
// functions/getUserAutoEthRewards.ts
|
|
2361
2745
|
import { autoEthRewardsHashAbi } from "@tokemak/abis";
|
|
2362
|
-
import { readContract as
|
|
2746
|
+
import { readContract as readContract3 } from "@wagmi/core";
|
|
2363
2747
|
import { convertChainCycleToUnix, formatCurrency } from "@tokemak/utils";
|
|
2364
2748
|
var getAutoEthRewards = async (wagmiConfig, {
|
|
2365
2749
|
account,
|
|
@@ -2369,14 +2753,14 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2369
2753
|
chainId
|
|
2370
2754
|
}) => {
|
|
2371
2755
|
try {
|
|
2372
|
-
const [, drippingHash] = await
|
|
2756
|
+
const [, drippingHash] = await readContract3(wagmiConfig, {
|
|
2373
2757
|
address: rewardsHash,
|
|
2374
2758
|
abi: autoEthRewardsHashAbi,
|
|
2375
2759
|
functionName: "cycleHashes",
|
|
2376
2760
|
args: [currentCycleIndex - 306n],
|
|
2377
2761
|
chainId
|
|
2378
2762
|
});
|
|
2379
|
-
const [, lastWeekHash] = await
|
|
2763
|
+
const [, lastWeekHash] = await readContract3(wagmiConfig, {
|
|
2380
2764
|
address: rewardsHash,
|
|
2381
2765
|
abi: autoEthRewardsHashAbi,
|
|
2382
2766
|
functionName: "cycleHashes",
|
|
@@ -2427,7 +2811,7 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
|
|
|
2427
2811
|
|
|
2428
2812
|
// functions/getUserRewardsV1.ts
|
|
2429
2813
|
import { rewardsV1Abi, rewardsV1HashAbi } from "@tokemak/abis";
|
|
2430
|
-
import { readContract as
|
|
2814
|
+
import { readContract as readContract4 } from "@wagmi/core";
|
|
2431
2815
|
var getUserRewardsV1 = async (wagmiConfig, {
|
|
2432
2816
|
address,
|
|
2433
2817
|
rewardsCycleIndex,
|
|
@@ -2437,7 +2821,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2437
2821
|
chainId
|
|
2438
2822
|
}) => {
|
|
2439
2823
|
try {
|
|
2440
|
-
const [latestClaimableHash, cycleRewardsHash] = await
|
|
2824
|
+
const [latestClaimableHash, cycleRewardsHash] = await readContract4(
|
|
2441
2825
|
wagmiConfig,
|
|
2442
2826
|
{
|
|
2443
2827
|
address: rewardsV1Hash,
|
|
@@ -2461,7 +2845,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2461
2845
|
const {
|
|
2462
2846
|
payload: { chainId: payloadChainId, cycle, wallet, amount }
|
|
2463
2847
|
} = latestClaimablePayload;
|
|
2464
|
-
const claimable = await
|
|
2848
|
+
const claimable = await readContract4(wagmiConfig, {
|
|
2465
2849
|
address: rewardsV1,
|
|
2466
2850
|
abi: rewardsV1Abi,
|
|
2467
2851
|
functionName: "getClaimableAmount",
|
|
@@ -2478,7 +2862,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2478
2862
|
|
|
2479
2863
|
// functions/getUserV1.ts
|
|
2480
2864
|
import { rewardsV1Abi as rewardsV1Abi2, stakingV1Abi } from "@tokemak/abis";
|
|
2481
|
-
import { readContract as
|
|
2865
|
+
import { readContract as readContract5 } from "@wagmi/core";
|
|
2482
2866
|
import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
|
|
2483
2867
|
import { mainnet as mainnet6 } from "viem/chains";
|
|
2484
2868
|
var getUserV1 = async (wagmiConfig, {
|
|
@@ -2497,7 +2881,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2497
2881
|
missedTokeRewards
|
|
2498
2882
|
} = getMainnetConfig3(mainnet6.id);
|
|
2499
2883
|
try {
|
|
2500
|
-
const userStakedTokeV1 = await
|
|
2884
|
+
const userStakedTokeV1 = await readContract5(wagmiConfig, {
|
|
2501
2885
|
address: stakingV1,
|
|
2502
2886
|
abi: stakingV1Abi,
|
|
2503
2887
|
functionName: "availableForWithdrawal",
|
|
@@ -2529,7 +2913,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2529
2913
|
const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
|
|
2530
2914
|
const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
|
|
2531
2915
|
const amount = autoEthGuardedRewardsPayload?.payload?.amount;
|
|
2532
|
-
const claimableAutoEth = await
|
|
2916
|
+
const claimableAutoEth = await readContract5(wagmiConfig, {
|
|
2533
2917
|
address: autoEthGuardedRewards,
|
|
2534
2918
|
abi: rewardsV1Abi2,
|
|
2535
2919
|
functionName: "getClaimableAmount",
|
|
@@ -2553,7 +2937,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2553
2937
|
const {
|
|
2554
2938
|
payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
|
|
2555
2939
|
} = missedTokeRewardsPayload;
|
|
2556
|
-
claimableMissedToke = await
|
|
2940
|
+
claimableMissedToke = await readContract5(wagmiConfig, {
|
|
2557
2941
|
address: missedTokeRewards,
|
|
2558
2942
|
abi: rewardsV1Abi2,
|
|
2559
2943
|
functionName: "getClaimableAmount",
|
|
@@ -2584,18 +2968,18 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2584
2968
|
};
|
|
2585
2969
|
|
|
2586
2970
|
// functions/getChainUserAutopoolsHistory.tsx
|
|
2587
|
-
import { getSdkByChainId as
|
|
2588
|
-
import { TOKEMAK_LAUNCH_TIMESTAMP } from "@tokemak/constants";
|
|
2971
|
+
import { getSdkByChainId as getSdkByChainId9 } from "@tokemak/graph-cli";
|
|
2972
|
+
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP3 } from "@tokemak/constants";
|
|
2589
2973
|
var getChainUserAutopoolsHistory = async ({
|
|
2590
2974
|
address,
|
|
2591
2975
|
chainId = 1
|
|
2592
2976
|
}) => {
|
|
2593
|
-
const { GetUserVaultsDayData } =
|
|
2977
|
+
const { GetUserVaultsDayData } = getSdkByChainId9(chainId);
|
|
2594
2978
|
try {
|
|
2595
2979
|
if (address) {
|
|
2596
2980
|
const { userVaultDayDatas } = await GetUserVaultsDayData({
|
|
2597
2981
|
address,
|
|
2598
|
-
timestamp:
|
|
2982
|
+
timestamp: TOKEMAK_LAUNCH_TIMESTAMP3
|
|
2599
2983
|
});
|
|
2600
2984
|
return userVaultDayDatas;
|
|
2601
2985
|
}
|
|
@@ -2609,25 +2993,25 @@ var getChainUserAutopoolsHistory = async ({
|
|
|
2609
2993
|
// functions/getUserAutopoolsHistory.ts
|
|
2610
2994
|
import {
|
|
2611
2995
|
formatDateToReadable as formatDateToReadable2,
|
|
2612
|
-
formatUnitsNum as
|
|
2996
|
+
formatUnitsNum as formatUnitsNum5
|
|
2613
2997
|
} from "@tokemak/utils";
|
|
2614
2998
|
|
|
2615
2999
|
// functions/getTokenValueDayDatas.ts
|
|
2616
3000
|
import { mainnet as mainnet7 } from "viem/chains";
|
|
2617
|
-
import { convertTimestampToDate as
|
|
2618
|
-
import { formatUnits as
|
|
2619
|
-
import { getSdkByChainId as
|
|
3001
|
+
import { convertTimestampToDate as convertTimestampToDate3 } from "@tokemak/utils";
|
|
3002
|
+
import { formatUnits as formatUnits6 } from "viem";
|
|
3003
|
+
import { getSdkByChainId as getSdkByChainId10 } from "@tokemak/graph-cli";
|
|
2620
3004
|
var getTokenValueDayDatas = async (tokenAddress, chainId = mainnet7.id) => {
|
|
2621
|
-
const { GetTokenValueDayDatas } =
|
|
3005
|
+
const { GetTokenValueDayDatas } = getSdkByChainId10(chainId);
|
|
2622
3006
|
try {
|
|
2623
3007
|
const { tokenValueDayDatas } = await GetTokenValueDayDatas({
|
|
2624
3008
|
tokenAddress: tokenAddress.toLowerCase()
|
|
2625
3009
|
});
|
|
2626
3010
|
const historicalPrice = tokenValueDayDatas.map((tokenValueDayData) => {
|
|
2627
|
-
const date =
|
|
3011
|
+
const date = convertTimestampToDate3(
|
|
2628
3012
|
tokenValueDayData.lastSnapshotTimestamp
|
|
2629
3013
|
);
|
|
2630
|
-
const usdPrice =
|
|
3014
|
+
const usdPrice = formatUnits6(tokenValueDayData.priceInUsd, 8);
|
|
2631
3015
|
return {
|
|
2632
3016
|
timestamp: Number(tokenValueDayData.lastSnapshotTimestamp),
|
|
2633
3017
|
date,
|
|
@@ -2907,7 +3291,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
2907
3291
|
Math.floor(sharesRatio * Number(SCALE))
|
|
2908
3292
|
);
|
|
2909
3293
|
const navBigInt = sharesRatioBigInt * BigInt(dayData.nav) / SCALE;
|
|
2910
|
-
const navNum =
|
|
3294
|
+
const navNum = formatUnitsNum5(
|
|
2911
3295
|
navBigInt,
|
|
2912
3296
|
dayData.baseAsset.decimals
|
|
2913
3297
|
);
|
|
@@ -3026,7 +3410,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3026
3410
|
return sum;
|
|
3027
3411
|
}
|
|
3028
3412
|
const decimals = vault.baseAsset.decimals;
|
|
3029
|
-
const assetChangeNum =
|
|
3413
|
+
const assetChangeNum = formatUnitsNum5(
|
|
3030
3414
|
BigInt(event.assetChange || 0n),
|
|
3031
3415
|
decimals
|
|
3032
3416
|
);
|
|
@@ -3050,7 +3434,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3050
3434
|
};
|
|
3051
3435
|
|
|
3052
3436
|
// functions/getUserSushiLP.ts
|
|
3053
|
-
import { readContracts as
|
|
3437
|
+
import { readContracts as readContracts5 } from "@wagmi/core";
|
|
3054
3438
|
import { poolV1Abi, sushiPoolAbi as sushiPoolAbi2 } from "@tokemak/abis";
|
|
3055
3439
|
import { getMainnetConfig as getMainnetConfig4 } from "@tokemak/config";
|
|
3056
3440
|
var getUserSushiLP = async (wagmiConfig, {
|
|
@@ -3067,7 +3451,7 @@ var getUserSushiLP = async (wagmiConfig, {
|
|
|
3067
3451
|
{ result: sushiLPBalance },
|
|
3068
3452
|
{ result: tSushiLPBalance },
|
|
3069
3453
|
{ result: tSushiLPRequested }
|
|
3070
|
-
] = await
|
|
3454
|
+
] = await readContracts5(wagmiConfig, {
|
|
3071
3455
|
contracts: [
|
|
3072
3456
|
{
|
|
3073
3457
|
address: sushiPool,
|
|
@@ -3095,7 +3479,7 @@ var getUserSushiLP = async (wagmiConfig, {
|
|
|
3095
3479
|
const [
|
|
3096
3480
|
{ result: startTSushiLPBalance },
|
|
3097
3481
|
{ result: startTSushiLPRequested }
|
|
3098
|
-
] = await
|
|
3482
|
+
] = await readContracts5(wagmiConfig, {
|
|
3099
3483
|
contracts: [
|
|
3100
3484
|
{
|
|
3101
3485
|
address: tSushiLP,
|
|
@@ -3149,7 +3533,7 @@ var getUserSushiLP = async (wagmiConfig, {
|
|
|
3149
3533
|
};
|
|
3150
3534
|
|
|
3151
3535
|
// functions/getUserCurveLP.ts
|
|
3152
|
-
import { readContracts as
|
|
3536
|
+
import { readContracts as readContracts6 } from "@wagmi/core";
|
|
3153
3537
|
import { poolV1Abi as poolV1Abi2 } from "@tokemak/abis";
|
|
3154
3538
|
import { getMainnetConfig as getMainnetConfig5 } from "@tokemak/config";
|
|
3155
3539
|
var getUserCurveLP = async (wagmiConfig, {
|
|
@@ -3160,7 +3544,7 @@ var getUserCurveLP = async (wagmiConfig, {
|
|
|
3160
3544
|
try {
|
|
3161
3545
|
const { curvePool, convexRewarder } = getMainnetConfig5();
|
|
3162
3546
|
if (address && curveLP && curvePool && convexRewarder) {
|
|
3163
|
-
const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await
|
|
3547
|
+
const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await readContracts6(wagmiConfig, {
|
|
3164
3548
|
contracts: [
|
|
3165
3549
|
{
|
|
3166
3550
|
address: curvePool,
|
|
@@ -3197,9 +3581,9 @@ var getUserCurveLP = async (wagmiConfig, {
|
|
|
3197
3581
|
};
|
|
3198
3582
|
|
|
3199
3583
|
// functions/getMultipleAutopoolRebalances.ts
|
|
3200
|
-
import { getSdkByChainId as
|
|
3584
|
+
import { getSdkByChainId as getSdkByChainId11 } from "@tokemak/graph-cli";
|
|
3201
3585
|
var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
3202
|
-
const { GetMutlipleAutopoolRebalances } =
|
|
3586
|
+
const { GetMutlipleAutopoolRebalances } = getSdkByChainId11(chainId);
|
|
3203
3587
|
const { autopools } = await GetMutlipleAutopoolRebalances({
|
|
3204
3588
|
addresses: ids
|
|
3205
3589
|
});
|
|
@@ -3207,64 +3591,8 @@ var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
|
3207
3591
|
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
3208
3592
|
};
|
|
3209
3593
|
|
|
3210
|
-
// functions/getAutopoolDayData.ts
|
|
3211
|
-
import { formatUnits as formatUnits6 } from "viem";
|
|
3212
|
-
import { formatEtherNum as formatEtherNum4 } from "@tokemak/utils";
|
|
3213
|
-
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP2 } from "@tokemak/constants";
|
|
3214
|
-
import { getSdkByChainId as getSdkByChainId9 } from "@tokemak/graph-cli";
|
|
3215
|
-
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_LAUNCH_TIMESTAMP2) => {
|
|
3216
|
-
try {
|
|
3217
|
-
const { GetAutopoolDayData } = getSdkByChainId9(chainId);
|
|
3218
|
-
const { autopoolDayDatas } = await GetAutopoolDayData({
|
|
3219
|
-
address,
|
|
3220
|
-
timestamp: startTimestamp
|
|
3221
|
-
});
|
|
3222
|
-
const formattedDayDatas = autopoolDayDatas.map((autoPoolDayData) => {
|
|
3223
|
-
const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
|
|
3224
|
-
let baseApy = autoPoolDayData.autopoolApy;
|
|
3225
|
-
let rewarderApy = 0;
|
|
3226
|
-
const formattedRewarder7DayMAApy = formatEtherNum4(
|
|
3227
|
-
BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
|
|
3228
|
-
);
|
|
3229
|
-
const formattedRewarder30DayMAApy = formatEtherNum4(
|
|
3230
|
-
BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
|
|
3231
|
-
);
|
|
3232
|
-
if (formattedRewarder7DayMAApy) {
|
|
3233
|
-
rewarderApy = formattedRewarder7DayMAApy;
|
|
3234
|
-
}
|
|
3235
|
-
if (formattedRewarder30DayMAApy) {
|
|
3236
|
-
rewarderApy = formattedRewarder30DayMAApy;
|
|
3237
|
-
}
|
|
3238
|
-
if (!baseApy) {
|
|
3239
|
-
baseApy = 0;
|
|
3240
|
-
} else {
|
|
3241
|
-
baseApy = Number(
|
|
3242
|
-
formatUnits6(BigInt(baseApy), autoPoolDayData.baseAsset.decimals)
|
|
3243
|
-
);
|
|
3244
|
-
}
|
|
3245
|
-
if (baseApy < 0) {
|
|
3246
|
-
baseApy = 0;
|
|
3247
|
-
}
|
|
3248
|
-
const combinedApy = rewarderApy + baseApy;
|
|
3249
|
-
return {
|
|
3250
|
-
...autoPoolDayData,
|
|
3251
|
-
navPerShare,
|
|
3252
|
-
rewarderApy,
|
|
3253
|
-
baseApy,
|
|
3254
|
-
combinedApy,
|
|
3255
|
-
date: new Date(Number(autoPoolDayData.timestamp) * 1e3)
|
|
3256
|
-
};
|
|
3257
|
-
});
|
|
3258
|
-
const filledDayDatas = fillMissingDates(formattedDayDatas);
|
|
3259
|
-
return filledDayDatas;
|
|
3260
|
-
} catch (e) {
|
|
3261
|
-
console.log(e);
|
|
3262
|
-
return [];
|
|
3263
|
-
}
|
|
3264
|
-
};
|
|
3265
|
-
|
|
3266
3594
|
// functions/getSystemConfig.ts
|
|
3267
|
-
import { readContracts as
|
|
3595
|
+
import { readContracts as readContracts7 } from "@wagmi/core";
|
|
3268
3596
|
import { systemRegistryAbi } from "@tokemak/abis";
|
|
3269
3597
|
var systemRegistryFunctionNames = [
|
|
3270
3598
|
"asyncSwapperRegistry",
|
|
@@ -3290,7 +3618,7 @@ var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
|
3290
3618
|
{ result: autopoolRouter },
|
|
3291
3619
|
{ result: autopoolRegistry },
|
|
3292
3620
|
{ result: swapRouter }
|
|
3293
|
-
] = await
|
|
3621
|
+
] = await readContracts7(wagmiConfig, {
|
|
3294
3622
|
contracts: systemRegistryCalls
|
|
3295
3623
|
});
|
|
3296
3624
|
return {
|
|
@@ -3305,12 +3633,12 @@ var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
|
3305
3633
|
};
|
|
3306
3634
|
|
|
3307
3635
|
// functions/getChainUserAutopools.tsx
|
|
3308
|
-
import { getSdkByChainId as
|
|
3636
|
+
import { getSdkByChainId as getSdkByChainId12 } from "@tokemak/graph-cli";
|
|
3309
3637
|
var getChainUserAutopools = async ({
|
|
3310
3638
|
address,
|
|
3311
3639
|
chainId = 1
|
|
3312
3640
|
}) => {
|
|
3313
|
-
const { GetUserVaultInfo } =
|
|
3641
|
+
const { GetUserVaultInfo } = getSdkByChainId12(chainId);
|
|
3314
3642
|
try {
|
|
3315
3643
|
if (address) {
|
|
3316
3644
|
const { userInfo } = await GetUserVaultInfo({
|
|
@@ -3327,17 +3655,17 @@ var getChainUserAutopools = async ({
|
|
|
3327
3655
|
|
|
3328
3656
|
// functions/getUserAutopools.ts
|
|
3329
3657
|
import {
|
|
3330
|
-
convertTimestampToDate as
|
|
3331
|
-
formatEtherNum as
|
|
3332
|
-
formatUnitsNum as
|
|
3658
|
+
convertTimestampToDate as convertTimestampToDate4,
|
|
3659
|
+
formatEtherNum as formatEtherNum8,
|
|
3660
|
+
formatUnitsNum as formatUnitsNum6
|
|
3333
3661
|
} from "@tokemak/utils";
|
|
3334
3662
|
import { ETH_TOKEN as ETH_TOKEN6 } from "@tokemak/tokenlist";
|
|
3335
3663
|
|
|
3336
3664
|
// functions/getUserAutopool.tsx
|
|
3337
|
-
import { erc20Abi as
|
|
3338
|
-
import { readContract as
|
|
3339
|
-
import { formatEtherNum as
|
|
3340
|
-
import { autopoolEthAbi } from "@tokemak/abis";
|
|
3665
|
+
import { erc20Abi as erc20Abi4 } from "viem";
|
|
3666
|
+
import { readContract as readContract6, readContracts as readContracts8 } from "@wagmi/core";
|
|
3667
|
+
import { formatEtherNum as formatEtherNum7 } from "@tokemak/utils";
|
|
3668
|
+
import { autopoolEthAbi as autopoolEthAbi2 } from "@tokemak/abis";
|
|
3341
3669
|
var getUserAutopool = async (wagmiConfig, {
|
|
3342
3670
|
address,
|
|
3343
3671
|
autopool
|
|
@@ -3346,14 +3674,14 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3346
3674
|
if (autopool && address) {
|
|
3347
3675
|
const autopoolContract = {
|
|
3348
3676
|
address: autopool?.poolAddress,
|
|
3349
|
-
abi:
|
|
3677
|
+
abi: autopoolEthAbi2,
|
|
3350
3678
|
chainId: autopool?.chain?.chainId
|
|
3351
3679
|
};
|
|
3352
3680
|
const [
|
|
3353
3681
|
{ result: autopoolRewarderContract },
|
|
3354
3682
|
{ result: pastRewarders },
|
|
3355
3683
|
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
3356
|
-
] = await
|
|
3684
|
+
] = await readContracts8(wagmiConfig, {
|
|
3357
3685
|
contracts: [
|
|
3358
3686
|
{
|
|
3359
3687
|
...autopoolContract,
|
|
@@ -3378,17 +3706,17 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3378
3706
|
if (unstakedPoolSharesError) {
|
|
3379
3707
|
throw new Error("Error fetching unstaked pool shares");
|
|
3380
3708
|
}
|
|
3381
|
-
const stakedPoolShares = await
|
|
3709
|
+
const stakedPoolShares = await readContract6(wagmiConfig, {
|
|
3382
3710
|
address: autopoolRewarderContract,
|
|
3383
|
-
abi:
|
|
3711
|
+
abi: erc20Abi4,
|
|
3384
3712
|
functionName: "balanceOf",
|
|
3385
3713
|
args: [address],
|
|
3386
3714
|
chainId: autopool?.chain?.chainId
|
|
3387
3715
|
});
|
|
3388
|
-
const stakedShares =
|
|
3716
|
+
const stakedShares = formatEtherNum7(stakedPoolShares);
|
|
3389
3717
|
const stakedNav = stakedShares * (autopool?.navPerShare.baseAsset || 0);
|
|
3390
3718
|
const stakedNavUsd = stakedShares * (autopool?.navPerShare.USD || 0);
|
|
3391
|
-
const unstakedShares =
|
|
3719
|
+
const unstakedShares = formatEtherNum7(unstakedPoolShares || 0n);
|
|
3392
3720
|
const unstakedNav = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
3393
3721
|
const unstakedNavUsd = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
3394
3722
|
const totalShares = unstakedShares + stakedShares;
|
|
@@ -3399,17 +3727,17 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3399
3727
|
if (pastRewarders && pastRewarders?.length > 0) {
|
|
3400
3728
|
const pastRewardBalances = pastRewarders.map((rewarder) => ({
|
|
3401
3729
|
address: rewarder,
|
|
3402
|
-
abi:
|
|
3730
|
+
abi: erc20Abi4,
|
|
3403
3731
|
functionName: "balanceOf",
|
|
3404
3732
|
args: [address],
|
|
3405
3733
|
chainId: autopool?.chain?.chainId
|
|
3406
3734
|
}));
|
|
3407
|
-
const pastRewards = await
|
|
3735
|
+
const pastRewards = await readContracts8(wagmiConfig, {
|
|
3408
3736
|
contracts: pastRewardBalances
|
|
3409
3737
|
});
|
|
3410
3738
|
pastRewarderBalances = pastRewards.map(({ result }, index) => {
|
|
3411
3739
|
const balance = result;
|
|
3412
|
-
const shares =
|
|
3740
|
+
const shares = formatEtherNum7(result);
|
|
3413
3741
|
const nav = shares * (autopool?.navPerShare.baseAsset || 0);
|
|
3414
3742
|
const navUsd = shares * (autopool?.navPerShare.USD || 0);
|
|
3415
3743
|
return {
|
|
@@ -3527,14 +3855,14 @@ var getUserAutopools = async ({
|
|
|
3527
3855
|
);
|
|
3528
3856
|
if (autopoolData) {
|
|
3529
3857
|
const isDOLA = autopoolData.symbol === "autoDOLA" && userAutoDOLA;
|
|
3530
|
-
const userShares = isDOLA ? userAutoDOLA?.totalShares :
|
|
3531
|
-
const totalVaultShares =
|
|
3858
|
+
const userShares = isDOLA ? userAutoDOLA?.totalShares : formatEtherNum8(userAutopool?.totalShares);
|
|
3859
|
+
const totalVaultShares = formatEtherNum8(autopoolData?.totalSupply);
|
|
3532
3860
|
const userShareOfVault = userShares / totalVaultShares;
|
|
3533
|
-
const totalDeposits =
|
|
3861
|
+
const totalDeposits = formatUnitsNum6(
|
|
3534
3862
|
userActivity?.totals[userAutopool.vaultAddress]?.totalDeposits || 0n,
|
|
3535
3863
|
autopoolData?.baseAsset.decimals
|
|
3536
3864
|
);
|
|
3537
|
-
const totalWithdrawals =
|
|
3865
|
+
const totalWithdrawals = formatUnitsNum6(
|
|
3538
3866
|
userActivity?.totals[userAutopool.vaultAddress]?.totalWithdrawals || 0n,
|
|
3539
3867
|
autopoolData?.baseAsset.decimals
|
|
3540
3868
|
);
|
|
@@ -3543,7 +3871,7 @@ var getUserAutopools = async ({
|
|
|
3543
3871
|
);
|
|
3544
3872
|
let lastDeposit;
|
|
3545
3873
|
if (poolEvents && poolEvents?.length > 0) {
|
|
3546
|
-
lastDeposit =
|
|
3874
|
+
lastDeposit = convertTimestampToDate4(
|
|
3547
3875
|
poolEvents[poolEvents.length - 1].timestamp
|
|
3548
3876
|
).toLocaleDateString("en-US", {
|
|
3549
3877
|
day: "2-digit",
|
|
@@ -3643,7 +3971,7 @@ var getUserAutopools = async ({
|
|
|
3643
3971
|
totalWithdrawals: prev.totalWithdrawals + totalWithdrawals
|
|
3644
3972
|
};
|
|
3645
3973
|
const stakedBalance = isDOLA ? userAutoDOLA?.staked.balance : BigInt(userAutopool?.stakedShares);
|
|
3646
|
-
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares :
|
|
3974
|
+
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : formatEtherNum8(stakedBalance);
|
|
3647
3975
|
const stakedNav = stakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
3648
3976
|
const staked = convertBaseAssetToTokenPrices(
|
|
3649
3977
|
stakedNav,
|
|
@@ -3651,7 +3979,7 @@ var getUserAutopools = async ({
|
|
|
3651
3979
|
prices
|
|
3652
3980
|
);
|
|
3653
3981
|
const unstakedBalance = isDOLA ? userAutoDOLA?.unstaked.balance : BigInt(userAutopool?.walletShares);
|
|
3654
|
-
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares :
|
|
3982
|
+
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : formatEtherNum8(unstakedBalance);
|
|
3655
3983
|
const unstakedNav = unstakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
3656
3984
|
const unstaked = convertBaseAssetToTokenPrices(
|
|
3657
3985
|
unstakedNav,
|
|
@@ -3844,12 +4172,12 @@ var getUserAutopools = async ({
|
|
|
3844
4172
|
|
|
3845
4173
|
// functions/getUserTokenBalances.ts
|
|
3846
4174
|
import { hexToBigInt } from "viem";
|
|
3847
|
-
import { base, mainnet as mainnet8, sonic as sonic2 } from "viem/chains";
|
|
4175
|
+
import { base as base2, mainnet as mainnet8, sonic as sonic2 } from "viem/chains";
|
|
3848
4176
|
var networkToAlchemyUrl = (chainId, apiKey) => {
|
|
3849
4177
|
switch (chainId) {
|
|
3850
4178
|
case mainnet8.id:
|
|
3851
4179
|
return `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`;
|
|
3852
|
-
case
|
|
4180
|
+
case base2.id:
|
|
3853
4181
|
return `https://base-mainnet.g.alchemy.com/v2/${apiKey}`;
|
|
3854
4182
|
case sonic2.id:
|
|
3855
4183
|
return `https://sonic-mainnet.g.alchemy.com/v2/${apiKey}`;
|
|
@@ -3910,10 +4238,10 @@ var getTokenList = async () => {
|
|
|
3910
4238
|
};
|
|
3911
4239
|
|
|
3912
4240
|
// functions/getTopAutopoolHolders.ts
|
|
3913
|
-
import { getSdkByChainId as
|
|
4241
|
+
import { getSdkByChainId as getSdkByChainId13 } from "@tokemak/graph-cli";
|
|
3914
4242
|
var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
3915
4243
|
try {
|
|
3916
|
-
const { GetTopAutopoolHolders } =
|
|
4244
|
+
const { GetTopAutopoolHolders } = getSdkByChainId13(chainId);
|
|
3917
4245
|
const { holders } = await GetTopAutopoolHolders({
|
|
3918
4246
|
address: autopoolAddress
|
|
3919
4247
|
});
|
|
@@ -3925,17 +4253,17 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
|
3925
4253
|
};
|
|
3926
4254
|
|
|
3927
4255
|
// functions/getAllowance.ts
|
|
3928
|
-
import { readContract as
|
|
3929
|
-
import { erc20Abi as
|
|
4256
|
+
import { readContract as readContract7 } from "@wagmi/core";
|
|
4257
|
+
import { erc20Abi as erc20Abi5 } from "viem";
|
|
3930
4258
|
var getAllowance = async (wagmiConfig, {
|
|
3931
4259
|
token,
|
|
3932
4260
|
address,
|
|
3933
4261
|
spender
|
|
3934
4262
|
}) => {
|
|
3935
4263
|
try {
|
|
3936
|
-
const allowance = await
|
|
4264
|
+
const allowance = await readContract7(wagmiConfig, {
|
|
3937
4265
|
address: token,
|
|
3938
|
-
abi:
|
|
4266
|
+
abi: erc20Abi5,
|
|
3939
4267
|
functionName: "allowance",
|
|
3940
4268
|
args: [address || "0x0", spender]
|
|
3941
4269
|
});
|
|
@@ -3975,12 +4303,41 @@ var getUserActivity = async ({
|
|
|
3975
4303
|
return mergedActivity;
|
|
3976
4304
|
};
|
|
3977
4305
|
|
|
4306
|
+
// functions/getBaseChainUserActivity.ts
|
|
4307
|
+
import { getSdkByChainId as getSdkByChainId14 } from "@tokemak/graph-cli";
|
|
4308
|
+
var BASE_CHAIN_ID = 8453;
|
|
4309
|
+
var getBaseChainUserActivity = async (address) => {
|
|
4310
|
+
const { GetUserActivity } = getSdkByChainId14(BASE_CHAIN_ID);
|
|
4311
|
+
try {
|
|
4312
|
+
const result = await GetUserActivity({ address });
|
|
4313
|
+
return (result.userActivities ?? []).map((activity) => {
|
|
4314
|
+
const eventType = activity.type === "VaultDeposit" ? "Deposit" : activity.type === "VaultWithdraw" ? "Withdrawal" : activity.type === "Stake" ? "Stake" : activity.type === "Unstake" ? "Unstake" : "Unknown";
|
|
4315
|
+
return {
|
|
4316
|
+
id: activity.id,
|
|
4317
|
+
timestamp: Number(activity.timestamp),
|
|
4318
|
+
eventType,
|
|
4319
|
+
assets: (() => {
|
|
4320
|
+
try {
|
|
4321
|
+
return JSON.parse(activity.data)?.assets ?? null;
|
|
4322
|
+
} catch {
|
|
4323
|
+
return null;
|
|
4324
|
+
}
|
|
4325
|
+
})(),
|
|
4326
|
+
transactionHash: activity.transactionHash ?? void 0
|
|
4327
|
+
};
|
|
4328
|
+
});
|
|
4329
|
+
} catch (e) {
|
|
4330
|
+
console.log(e);
|
|
4331
|
+
return [];
|
|
4332
|
+
}
|
|
4333
|
+
};
|
|
4334
|
+
|
|
3978
4335
|
// functions/getUserAutopoolsRewards.ts
|
|
3979
4336
|
import { getAddress as getAddress4 } from "viem";
|
|
3980
4337
|
|
|
3981
4338
|
// functions/getChainUserAutopoolsRewards.ts
|
|
3982
4339
|
import { getCoreConfig as getCoreConfig2 } from "@tokemak/config";
|
|
3983
|
-
import { readContract as
|
|
4340
|
+
import { readContract as readContract8 } from "@wagmi/core";
|
|
3984
4341
|
import { lensAbi as lensAbi2 } from "@tokemak/abis";
|
|
3985
4342
|
var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
3986
4343
|
chainId,
|
|
@@ -3988,7 +4345,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
3988
4345
|
}) => {
|
|
3989
4346
|
try {
|
|
3990
4347
|
const coreConfig = getCoreConfig2(chainId);
|
|
3991
|
-
const userRewardsInfo = await
|
|
4348
|
+
const userRewardsInfo = await readContract8(wagmiConfig, {
|
|
3992
4349
|
address: coreConfig.lens,
|
|
3993
4350
|
abi: lensAbi2,
|
|
3994
4351
|
functionName: "getUserRewardInfo",
|
|
@@ -4020,7 +4377,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4020
4377
|
};
|
|
4021
4378
|
|
|
4022
4379
|
// functions/getUserAutopoolsRewards.ts
|
|
4023
|
-
import { formatUnitsNum as
|
|
4380
|
+
import { formatUnitsNum as formatUnitsNum7, getToken as getToken2 } from "@tokemak/utils";
|
|
4024
4381
|
import { SILO_TOKEN as SILO_TOKEN2, TOKE_TOKEN as TOKE_TOKEN3 } from "@tokemak/tokenlist";
|
|
4025
4382
|
import { plasma } from "viem/chains";
|
|
4026
4383
|
var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
@@ -4060,7 +4417,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4060
4417
|
if (rewarderToken.symbol === "XSILO") {
|
|
4061
4418
|
price = tokenPrices[SILO_TOKEN2.symbol] || 0;
|
|
4062
4419
|
}
|
|
4063
|
-
const formattedAmount =
|
|
4420
|
+
const formattedAmount = formatUnitsNum7(
|
|
4064
4421
|
claimableAmount,
|
|
4065
4422
|
rewarderToken.decimals || 18
|
|
4066
4423
|
);
|
|
@@ -4098,7 +4455,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4098
4455
|
if (tokenSymbol === "XSILO") {
|
|
4099
4456
|
price = tokenPrices[SILO_TOKEN2.symbol] || 0;
|
|
4100
4457
|
}
|
|
4101
|
-
const formattedAmount =
|
|
4458
|
+
const formattedAmount = formatUnitsNum7(amount, decimals || 18);
|
|
4102
4459
|
tokenRewards[tokenSymbol] = {
|
|
4103
4460
|
amount,
|
|
4104
4461
|
formattedAmount,
|
|
@@ -4178,7 +4535,7 @@ import {
|
|
|
4178
4535
|
import { TOKEMAK_SWAP_QUOTE_URL } from "@tokemak/constants";
|
|
4179
4536
|
|
|
4180
4537
|
// functions/getAddressFromSystemRegistry.ts
|
|
4181
|
-
import { readContract as
|
|
4538
|
+
import { readContract as readContract9 } from "@wagmi/core";
|
|
4182
4539
|
import { getCoreConfig as getCoreConfig3 } from "@tokemak/config";
|
|
4183
4540
|
import { systemRegistryAbi as systemRegistryAbi2 } from "@tokemak/abis";
|
|
4184
4541
|
var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
@@ -4186,7 +4543,7 @@ var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
|
4186
4543
|
functionName
|
|
4187
4544
|
}) => {
|
|
4188
4545
|
const { systemRegistry } = getCoreConfig3(chainId);
|
|
4189
|
-
return await
|
|
4546
|
+
return await readContract9(wagmiConfig, {
|
|
4190
4547
|
address: systemRegistry,
|
|
4191
4548
|
abi: systemRegistryAbi2,
|
|
4192
4549
|
functionName,
|
|
@@ -4246,8 +4603,8 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4246
4603
|
};
|
|
4247
4604
|
|
|
4248
4605
|
// functions/getDynamicSwap.ts
|
|
4249
|
-
import { getPublicClient, readContract as
|
|
4250
|
-
import { autopilotRouterAbi, autopoolEthAbi as
|
|
4606
|
+
import { getPublicClient, readContract as readContract10 } from "@wagmi/core";
|
|
4607
|
+
import { autopilotRouterAbi, autopoolEthAbi as autopoolEthAbi3 } from "@tokemak/abis";
|
|
4251
4608
|
import { getCoreConfig as getCoreConfig5 } from "@tokemak/config";
|
|
4252
4609
|
import { getLiquidations } from "@tokemak/autopilot-swap-route-calc";
|
|
4253
4610
|
import {
|
|
@@ -4342,9 +4699,9 @@ var getDynamicSwap = async ({
|
|
|
4342
4699
|
console.log(e);
|
|
4343
4700
|
}
|
|
4344
4701
|
}
|
|
4345
|
-
const previewRedeemOnChain = await
|
|
4702
|
+
const previewRedeemOnChain = await readContract10(config, {
|
|
4346
4703
|
address,
|
|
4347
|
-
abi:
|
|
4704
|
+
abi: autopoolEthAbi3,
|
|
4348
4705
|
functionName: "previewRedeem",
|
|
4349
4706
|
args: [amount],
|
|
4350
4707
|
chainId,
|
|
@@ -4364,8 +4721,8 @@ var getDynamicSwap = async ({
|
|
|
4364
4721
|
// functions/getAmountWithdrawn.ts
|
|
4365
4722
|
import { ETH_TOKEN as ETH_TOKEN8 } from "@tokemak/tokenlist";
|
|
4366
4723
|
import { getCoreConfig as getCoreConfig6 } from "@tokemak/config";
|
|
4367
|
-
import { readContract as
|
|
4368
|
-
import { autopoolEthAbi as
|
|
4724
|
+
import { readContract as readContract11 } from "@wagmi/core";
|
|
4725
|
+
import { autopoolEthAbi as autopoolEthAbi4 } from "@tokemak/abis";
|
|
4369
4726
|
var getAmountWithdrawn = async ({
|
|
4370
4727
|
address,
|
|
4371
4728
|
slippage,
|
|
@@ -4404,9 +4761,9 @@ var getAmountWithdrawn = async ({
|
|
|
4404
4761
|
const weth = getCoreConfig6(chainId).weth;
|
|
4405
4762
|
buyToken = weth;
|
|
4406
4763
|
}
|
|
4407
|
-
convertedAssets = await
|
|
4764
|
+
convertedAssets = await readContract11(config, {
|
|
4408
4765
|
address: autopool,
|
|
4409
|
-
abi:
|
|
4766
|
+
abi: autopoolEthAbi4,
|
|
4410
4767
|
functionName: "convertToAssets",
|
|
4411
4768
|
args: [amount],
|
|
4412
4769
|
chainId
|
|
@@ -4444,9 +4801,9 @@ var getAmountWithdrawn = async ({
|
|
|
4444
4801
|
};
|
|
4445
4802
|
|
|
4446
4803
|
// functions/getAmountDeposited.ts
|
|
4447
|
-
import { readContract as
|
|
4448
|
-
import { autopoolEthAbi as
|
|
4449
|
-
import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as
|
|
4804
|
+
import { readContract as readContract12 } from "@wagmi/core";
|
|
4805
|
+
import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
|
|
4806
|
+
import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as formatEtherNum9 } from "@tokemak/utils";
|
|
4450
4807
|
var getAmountDeposited = async ({
|
|
4451
4808
|
address,
|
|
4452
4809
|
chainId,
|
|
@@ -4459,9 +4816,9 @@ var getAmountDeposited = async ({
|
|
|
4459
4816
|
if (!address || !chainId || !amount || typeof slippage !== "number") {
|
|
4460
4817
|
throw new Error("Invalid parameters");
|
|
4461
4818
|
}
|
|
4462
|
-
const previewDeposit = await
|
|
4819
|
+
const previewDeposit = await readContract12(config, {
|
|
4463
4820
|
address,
|
|
4464
|
-
abi:
|
|
4821
|
+
abi: autopoolEthAbi5,
|
|
4465
4822
|
functionName: "previewDeposit",
|
|
4466
4823
|
args: [amount],
|
|
4467
4824
|
chainId
|
|
@@ -4471,9 +4828,9 @@ var getAmountDeposited = async ({
|
|
|
4471
4828
|
previewDeposit,
|
|
4472
4829
|
slippage
|
|
4473
4830
|
);
|
|
4474
|
-
return
|
|
4831
|
+
return formatEtherNum9(minAmountWithSlippage);
|
|
4475
4832
|
} else {
|
|
4476
|
-
return
|
|
4833
|
+
return formatEtherNum9(previewDeposit);
|
|
4477
4834
|
}
|
|
4478
4835
|
} catch (e) {
|
|
4479
4836
|
console.error(e);
|
|
@@ -4483,7 +4840,7 @@ var getAmountDeposited = async ({
|
|
|
4483
4840
|
};
|
|
4484
4841
|
|
|
4485
4842
|
// functions/getBridgeFee.ts
|
|
4486
|
-
import { readContract as
|
|
4843
|
+
import { readContract as readContract13 } from "@wagmi/core";
|
|
4487
4844
|
import { layerZeroEndpointAbi, oftAdapterAbi } from "@tokemak/abis";
|
|
4488
4845
|
import { toHex } from "viem";
|
|
4489
4846
|
import { addressToBytes32 } from "@layerzerolabs/lz-v2-utilities";
|
|
@@ -4496,13 +4853,13 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4496
4853
|
from
|
|
4497
4854
|
}) => {
|
|
4498
4855
|
try {
|
|
4499
|
-
const endpoint = await
|
|
4856
|
+
const endpoint = await readContract13(wagmiConfig, {
|
|
4500
4857
|
address: destAddress,
|
|
4501
4858
|
abi: oftAdapterAbi,
|
|
4502
4859
|
functionName: "endpoint",
|
|
4503
4860
|
chainId: destChainId
|
|
4504
4861
|
});
|
|
4505
|
-
const eid = await
|
|
4862
|
+
const eid = await readContract13(wagmiConfig, {
|
|
4506
4863
|
address: endpoint,
|
|
4507
4864
|
abi: layerZeroEndpointAbi,
|
|
4508
4865
|
functionName: "eid",
|
|
@@ -4520,7 +4877,7 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4520
4877
|
composeMsg: "0x",
|
|
4521
4878
|
oftCmd: "0x"
|
|
4522
4879
|
};
|
|
4523
|
-
const feeQuote = await
|
|
4880
|
+
const feeQuote = await readContract13(wagmiConfig, {
|
|
4524
4881
|
address: sourceAddress,
|
|
4525
4882
|
abi: oftAdapterAbi,
|
|
4526
4883
|
functionName: "quoteSend",
|
|
@@ -4595,20 +4952,20 @@ import {
|
|
|
4595
4952
|
convertChainCycleToUnix as convertChainCycleToUnix2,
|
|
4596
4953
|
convertSecondsToRemainingTime,
|
|
4597
4954
|
formatCurrency as formatCurrency2,
|
|
4598
|
-
formatEtherNum as
|
|
4955
|
+
formatEtherNum as formatEtherNum10
|
|
4599
4956
|
} from "@tokemak/utils";
|
|
4600
|
-
import { readContracts as
|
|
4957
|
+
import { readContracts as readContracts9 } from "@wagmi/core";
|
|
4601
4958
|
import { formatEther as formatEther2 } from "viem";
|
|
4602
4959
|
import { sepolia as sepolia2 } from "viem/chains";
|
|
4603
4960
|
|
|
4604
4961
|
// functions/getCurrentCycleId.ts
|
|
4605
4962
|
import { accTokeV1Abi } from "@tokemak/abis";
|
|
4606
|
-
import { readContract as
|
|
4963
|
+
import { readContract as readContract14 } from "@wagmi/core";
|
|
4607
4964
|
var getCurrentCycleId = async (wagmiConfig, {
|
|
4608
4965
|
stoke,
|
|
4609
4966
|
chainId
|
|
4610
4967
|
}) => {
|
|
4611
|
-
return
|
|
4968
|
+
return readContract14(wagmiConfig, {
|
|
4612
4969
|
address: stoke,
|
|
4613
4970
|
abi: accTokeV1Abi,
|
|
4614
4971
|
chainId,
|
|
@@ -4617,7 +4974,7 @@ var getCurrentCycleId = async (wagmiConfig, {
|
|
|
4617
4974
|
};
|
|
4618
4975
|
|
|
4619
4976
|
// functions/getChainUserSToke.ts
|
|
4620
|
-
import { getSdkByChainId as
|
|
4977
|
+
import { getSdkByChainId as getSdkByChainId15 } from "@tokemak/graph-cli";
|
|
4621
4978
|
var getChainUserSToke = async (wagmiConfig, {
|
|
4622
4979
|
address,
|
|
4623
4980
|
tokePrice,
|
|
@@ -4627,7 +4984,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4627
4984
|
const { stoke } = getCoreConfig7(chainId);
|
|
4628
4985
|
const cycleIndex = await getCurrentCycleId(wagmiConfig, { chainId, stoke });
|
|
4629
4986
|
if (address && cycleIndex && stoke && tokePrice) {
|
|
4630
|
-
const { GetUserSTokeBalance } =
|
|
4987
|
+
const { GetUserSTokeBalance } = getSdkByChainId15(
|
|
4631
4988
|
chainId
|
|
4632
4989
|
);
|
|
4633
4990
|
const { accountBalanceV1S } = await GetUserSTokeBalance({
|
|
@@ -4642,7 +4999,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4642
4999
|
{ result: balance },
|
|
4643
5000
|
{ result: depositInfoResult },
|
|
4644
5001
|
{ result: withdrawalInfoResult }
|
|
4645
|
-
] = await
|
|
5002
|
+
] = await readContracts9(wagmiConfig, {
|
|
4646
5003
|
contracts: [
|
|
4647
5004
|
{
|
|
4648
5005
|
...stokeContract,
|
|
@@ -4673,7 +5030,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4673
5030
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
4674
5031
|
}
|
|
4675
5032
|
const withdrawalAmountUsd = formatCurrency2(
|
|
4676
|
-
|
|
5033
|
+
formatEtherNum10(withdrawalAmount) * tokePrice
|
|
4677
5034
|
);
|
|
4678
5035
|
const lockDuration = Number(depositLockDuration);
|
|
4679
5036
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -4698,7 +5055,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4698
5055
|
Number(formatEther2(balanceExcludingWithdrawal)) * tokePrice
|
|
4699
5056
|
);
|
|
4700
5057
|
const balanceExcludingWithdrawalUsd = formatCurrency2(
|
|
4701
|
-
|
|
5058
|
+
formatEtherNum10(balanceExcludingWithdrawal) * tokePrice
|
|
4702
5059
|
);
|
|
4703
5060
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
4704
5061
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
@@ -4726,8 +5083,8 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4726
5083
|
unlockPeriodDateRangeArray,
|
|
4727
5084
|
chainId === sepolia2.id ? "time" : "date"
|
|
4728
5085
|
);
|
|
4729
|
-
const totalActiveUserCredits =
|
|
4730
|
-
const totalUserCredits =
|
|
5086
|
+
const totalActiveUserCredits = formatEtherNum10(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
5087
|
+
const totalUserCredits = formatEtherNum10(balance) * lockDurationInMonths;
|
|
4731
5088
|
return {
|
|
4732
5089
|
balance,
|
|
4733
5090
|
balanceUSD,
|
|
@@ -4754,7 +5111,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4754
5111
|
unlockRenewalDate,
|
|
4755
5112
|
lockDurationInMonths,
|
|
4756
5113
|
boost: lockDuration,
|
|
4757
|
-
points:
|
|
5114
|
+
points: formatEtherNum10(balanceExcludingWithdrawal) * lockDuration,
|
|
4758
5115
|
totalActiveCredits: totalActiveUserCredits,
|
|
4759
5116
|
totalCredits: totalUserCredits
|
|
4760
5117
|
};
|
|
@@ -4766,7 +5123,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4766
5123
|
};
|
|
4767
5124
|
|
|
4768
5125
|
// functions/getUserSToke.ts
|
|
4769
|
-
import { formatCurrency as formatCurrency3, formatEtherNum as
|
|
5126
|
+
import { formatCurrency as formatCurrency3, formatEtherNum as formatEtherNum11 } from "@tokemak/utils";
|
|
4770
5127
|
var getUserSToke = async (wagmiConfig, {
|
|
4771
5128
|
address,
|
|
4772
5129
|
tokePrice,
|
|
@@ -4793,7 +5150,7 @@ var getUserSToke = async (wagmiConfig, {
|
|
|
4793
5150
|
}
|
|
4794
5151
|
return acc;
|
|
4795
5152
|
}, 0n);
|
|
4796
|
-
const totalBalance =
|
|
5153
|
+
const totalBalance = formatEtherNum11(totalBalanceRaw || 0n);
|
|
4797
5154
|
const totalBalanceUsd = formatCurrency3(totalBalance * tokePrice);
|
|
4798
5155
|
const hasBalance = totalBalance > 0;
|
|
4799
5156
|
return {
|
|
@@ -4809,7 +5166,7 @@ var getUserSToke = async (wagmiConfig, {
|
|
|
4809
5166
|
|
|
4810
5167
|
// functions/getChainSToke.ts
|
|
4811
5168
|
import { formatEther as formatEther3 } from "viem";
|
|
4812
|
-
import { readContracts as
|
|
5169
|
+
import { readContracts as readContracts10 } from "@wagmi/core";
|
|
4813
5170
|
import { accTokeV1Abi as accTokeV1Abi3 } from "@tokemak/abis";
|
|
4814
5171
|
import {
|
|
4815
5172
|
convertChainCycleToUnix as convertChainCycleToUnix3,
|
|
@@ -4831,7 +5188,7 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
4831
5188
|
chainId
|
|
4832
5189
|
};
|
|
4833
5190
|
if (stoke && tokePrice) {
|
|
4834
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await
|
|
5191
|
+
const [{ result: totalSupply }, { result: currentCycle }] = await readContracts10(wagmiConfig, {
|
|
4835
5192
|
contracts: [
|
|
4836
5193
|
{
|
|
4837
5194
|
...baseConfig,
|
|
@@ -4903,7 +5260,7 @@ import { accTokeV1Abi as accTokeV1Abi4, managerV1Abi } from "@tokemak/abis";
|
|
|
4903
5260
|
import {
|
|
4904
5261
|
getBlockNumber,
|
|
4905
5262
|
getPublicClient as getPublicClient2,
|
|
4906
|
-
readContract as
|
|
5263
|
+
readContract as readContract15
|
|
4907
5264
|
} from "@wagmi/core";
|
|
4908
5265
|
var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
4909
5266
|
stoke,
|
|
@@ -4917,7 +5274,7 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
4917
5274
|
const blockNumber = await getBlockNumber(wagmiConfig, {
|
|
4918
5275
|
chainId
|
|
4919
5276
|
});
|
|
4920
|
-
const manager = await
|
|
5277
|
+
const manager = await readContract15(wagmiConfig, {
|
|
4921
5278
|
functionName: "manager",
|
|
4922
5279
|
address: stoke,
|
|
4923
5280
|
abi: accTokeV1Abi4,
|
|
@@ -4948,13 +5305,13 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
4948
5305
|
// functions/getChainSTokeRewards.ts
|
|
4949
5306
|
import { AUTOPOOLS_WHITELIST_PROD as AUTOPOOLS_WHITELIST_PROD2 } from "@tokemak/config";
|
|
4950
5307
|
import { formatUnits as formatUnits8 } from "viem";
|
|
4951
|
-
import { formatEtherNum as
|
|
4952
|
-
import { getSdkByChainId as
|
|
5308
|
+
import { formatEtherNum as formatEtherNum12 } from "@tokemak/utils";
|
|
5309
|
+
import { getSdkByChainId as getSdkByChainId16 } from "@tokemak/graph-cli";
|
|
4953
5310
|
var getChainSTokeRewards = async ({
|
|
4954
5311
|
chainId
|
|
4955
5312
|
}) => {
|
|
4956
5313
|
try {
|
|
4957
|
-
const { GetSTokeRewards } =
|
|
5314
|
+
const { GetSTokeRewards } = getSdkByChainId16(chainId);
|
|
4958
5315
|
const { poolRewardsBalances } = await GetSTokeRewards();
|
|
4959
5316
|
const allPoolRewardsBalanceDayDatas = await paginateQuery(
|
|
4960
5317
|
GetSTokeRewards,
|
|
@@ -4972,9 +5329,9 @@ var getChainSTokeRewards = async ({
|
|
|
4972
5329
|
if (!whitelistedPools.includes(pool.id.toLowerCase())) {
|
|
4973
5330
|
continue;
|
|
4974
5331
|
}
|
|
4975
|
-
const convertedBalance =
|
|
5332
|
+
const convertedBalance = formatEtherNum12(pool.balance);
|
|
4976
5333
|
const convertedBalanceUSD = Number(formatUnits8(pool.balanceUSD, 8));
|
|
4977
|
-
const convertedApr =
|
|
5334
|
+
const convertedApr = formatEtherNum12(pool.currentAprPerCredit);
|
|
4978
5335
|
if (minApr === null || convertedApr < minApr) {
|
|
4979
5336
|
minApr = convertedApr;
|
|
4980
5337
|
}
|
|
@@ -4989,9 +5346,10 @@ var getChainSTokeRewards = async ({
|
|
|
4989
5346
|
totalEarnings += convertedBalance;
|
|
4990
5347
|
totalEarningsUsd += convertedBalanceUSD;
|
|
4991
5348
|
}
|
|
4992
|
-
const
|
|
4993
|
-
|
|
5349
|
+
const activeDayDatas = allPoolRewardsBalanceDayDatas.filter(
|
|
5350
|
+
(item) => item.balance !== "0"
|
|
4994
5351
|
);
|
|
5352
|
+
const historicalRewards = aggregateSTokeRewardsDayData(activeDayDatas);
|
|
4995
5353
|
const aprRange = [(minApr ?? 0) * 4, (maxApr ?? 0) * 16];
|
|
4996
5354
|
return {
|
|
4997
5355
|
autopools,
|
|
@@ -5050,7 +5408,7 @@ import {
|
|
|
5050
5408
|
getCoreConfig as getCoreConfig9,
|
|
5051
5409
|
getMainnetConfig as getMainnetConfig6
|
|
5052
5410
|
} from "@tokemak/config";
|
|
5053
|
-
import { formatEtherNum as
|
|
5411
|
+
import { formatEtherNum as formatEtherNum13 } from "@tokemak/utils";
|
|
5054
5412
|
var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
5055
5413
|
address,
|
|
5056
5414
|
chainId,
|
|
@@ -5101,14 +5459,14 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5101
5459
|
throw fallbackError;
|
|
5102
5460
|
}
|
|
5103
5461
|
}
|
|
5104
|
-
const claimableNum =
|
|
5462
|
+
const claimableNum = formatEtherNum13(tokeRewards?.claimable || 0n);
|
|
5105
5463
|
const claimableUsd = tokePrice * claimableNum;
|
|
5106
5464
|
const hasClaimable = claimableNum > 0n;
|
|
5107
|
-
const pendingRewards =
|
|
5465
|
+
const pendingRewards = formatEtherNum13(
|
|
5108
5466
|
tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5109
5467
|
);
|
|
5110
5468
|
const pendingRewardsUsd = tokePrice * pendingRewards;
|
|
5111
|
-
const totalRewardsReceived =
|
|
5469
|
+
const totalRewardsReceived = formatEtherNum13(
|
|
5112
5470
|
tokeRewards.rewardsPayload.payload.amount || 0n
|
|
5113
5471
|
);
|
|
5114
5472
|
const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
|
|
@@ -5125,11 +5483,11 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5125
5483
|
};
|
|
5126
5484
|
|
|
5127
5485
|
// functions/getChainSubgraphStatus.ts
|
|
5128
|
-
import { getSdkByChainId as
|
|
5486
|
+
import { getSdkByChainId as getSdkByChainId17 } from "@tokemak/graph-cli";
|
|
5129
5487
|
var getChainSubgraphStatus = async (chain) => {
|
|
5130
5488
|
const currentTimestamp = Math.floor(Date.now() / 1e3);
|
|
5131
5489
|
try {
|
|
5132
|
-
const { GetLatestSubgraphTimestamp } =
|
|
5490
|
+
const { GetLatestSubgraphTimestamp } = getSdkByChainId17(
|
|
5133
5491
|
chain.chainId
|
|
5134
5492
|
);
|
|
5135
5493
|
const { _meta } = await GetLatestSubgraphTimestamp();
|
|
@@ -5181,7 +5539,7 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5181
5539
|
};
|
|
5182
5540
|
|
|
5183
5541
|
// functions/getCycleV1.ts
|
|
5184
|
-
import { readContract as
|
|
5542
|
+
import { readContract as readContract16 } from "@wagmi/core";
|
|
5185
5543
|
import { managerV1Abi as managerV1Abi2 } from "@tokemak/abis";
|
|
5186
5544
|
import { createPublicClient, http } from "viem";
|
|
5187
5545
|
import {
|
|
@@ -5203,7 +5561,7 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5203
5561
|
const { managerV1 } = getMainnetConfig7();
|
|
5204
5562
|
try {
|
|
5205
5563
|
if (currentBlockNumber && managerV1) {
|
|
5206
|
-
const currentCycleIndex = await
|
|
5564
|
+
const currentCycleIndex = await readContract16(wagmiConfig, {
|
|
5207
5565
|
address: managerV1,
|
|
5208
5566
|
abi: managerV1Abi2,
|
|
5209
5567
|
functionName: "getCurrentCycleIndex",
|
|
@@ -5236,7 +5594,7 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5236
5594
|
};
|
|
5237
5595
|
|
|
5238
5596
|
// functions/getProtocolStats.ts
|
|
5239
|
-
import { formatLargeNumber as formatLargeNumber3, formatTVL as formatTVL3, formatEtherNum as
|
|
5597
|
+
import { formatLargeNumber as formatLargeNumber3, formatTVL as formatTVL3, formatEtherNum as formatEtherNum14 } from "@tokemak/utils";
|
|
5240
5598
|
var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
5241
5599
|
try {
|
|
5242
5600
|
if (!autopools || !stoke || !sushiLP) {
|
|
@@ -5281,7 +5639,7 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
|
5281
5639
|
const totalDestinations = uniqueVaultAddresses.length;
|
|
5282
5640
|
const stakedTVL = {
|
|
5283
5641
|
totalSupply: formatLargeNumber3(
|
|
5284
|
-
|
|
5642
|
+
formatEtherNum14(
|
|
5285
5643
|
(sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
|
|
5286
5644
|
)
|
|
5287
5645
|
),
|
|
@@ -5321,11 +5679,11 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
|
5321
5679
|
};
|
|
5322
5680
|
|
|
5323
5681
|
// functions/getRebalanceStats.ts
|
|
5324
|
-
import { getSdkByChainId as
|
|
5682
|
+
import { getSdkByChainId as getSdkByChainId18 } from "@tokemak/graph-cli";
|
|
5325
5683
|
|
|
5326
5684
|
// functions/getEthPriceAtBlock.ts
|
|
5327
5685
|
import { getCoreConfig as getCoreConfig10 } from "@tokemak/config";
|
|
5328
|
-
import { readContract as
|
|
5686
|
+
import { readContract as readContract17 } from "@wagmi/core";
|
|
5329
5687
|
import { rootPriceOracleAbi } from "@tokemak/abis";
|
|
5330
5688
|
import { USDC_TOKEN as USDC_TOKEN2 } from "@tokemak/tokenlist";
|
|
5331
5689
|
var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
|
|
@@ -5333,7 +5691,7 @@ var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
|
|
|
5333
5691
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5334
5692
|
const weth = config.weth;
|
|
5335
5693
|
const usdc = USDC_TOKEN2.extensions?.bridgeInfo?.[chainId]?.tokenAddress || USDC_TOKEN2.address;
|
|
5336
|
-
const priceAtBlock = await
|
|
5694
|
+
const priceAtBlock = await readContract17(wagmiConfig, {
|
|
5337
5695
|
address: rootPriceOracle,
|
|
5338
5696
|
abi: rootPriceOracleAbi,
|
|
5339
5697
|
functionName: "getPriceInQuote",
|
|
@@ -5345,12 +5703,12 @@ var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
|
|
|
5345
5703
|
};
|
|
5346
5704
|
|
|
5347
5705
|
// functions/getRebalanceStats.ts
|
|
5348
|
-
import { formatEtherNum as
|
|
5706
|
+
import { formatEtherNum as formatEtherNum15, formatUnitsNum as formatUnitsNum8 } from "@tokemak/utils";
|
|
5349
5707
|
import { USDC_TOKEN as USDC_TOKEN3 } from "@tokemak/tokenlist";
|
|
5350
5708
|
import { sonic as sonic4 } from "viem/chains";
|
|
5351
5709
|
var BATCH_SIZE = 500;
|
|
5352
5710
|
var fetchChainRebalances = async (chainId) => {
|
|
5353
|
-
const { GetAllAutopoolRebalances } =
|
|
5711
|
+
const { GetAllAutopoolRebalances } = getSdkByChainId18(chainId);
|
|
5354
5712
|
const allRebalances = await paginateQuery(
|
|
5355
5713
|
GetAllAutopoolRebalances,
|
|
5356
5714
|
"autopoolRebalances"
|
|
@@ -5378,8 +5736,8 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5378
5736
|
BigInt(rebalance.blockNumber),
|
|
5379
5737
|
chainId
|
|
5380
5738
|
);
|
|
5381
|
-
const ethUsd = Number(
|
|
5382
|
-
const ethAmt = Number(
|
|
5739
|
+
const ethUsd = Number(formatUnitsNum8(price, USDC_TOKEN3.decimals));
|
|
5740
|
+
const ethAmt = Number(formatEtherNum15(ethWei));
|
|
5383
5741
|
const usd = ethAmt * ethUsd;
|
|
5384
5742
|
return usd;
|
|
5385
5743
|
} catch (e) {
|
|
@@ -5390,7 +5748,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5390
5748
|
var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
5391
5749
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5392
5750
|
const baseAssetAmount = Number(
|
|
5393
|
-
|
|
5751
|
+
formatUnitsNum8(
|
|
5394
5752
|
BigInt(rebalance.tokenOutValueBaseAsset || "0"),
|
|
5395
5753
|
baseDecimals
|
|
5396
5754
|
)
|
|
@@ -5504,9 +5862,9 @@ import {
|
|
|
5504
5862
|
convertSecondsToRemainingTime as convertSecondsToRemainingTime4,
|
|
5505
5863
|
formatAmount,
|
|
5506
5864
|
formatCurrency as formatCurrency4,
|
|
5507
|
-
formatEtherNum as
|
|
5865
|
+
formatEtherNum as formatEtherNum16
|
|
5508
5866
|
} from "@tokemak/utils";
|
|
5509
|
-
import { readContracts as
|
|
5867
|
+
import { readContracts as readContracts11 } from "@wagmi/core";
|
|
5510
5868
|
import { formatEther as formatEther5 } from "viem";
|
|
5511
5869
|
import { mainnet as mainnet10 } from "viem/chains";
|
|
5512
5870
|
var getUserSAuto = async (wagmiConfig, {
|
|
@@ -5531,7 +5889,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5531
5889
|
{ result: depositInfoResult },
|
|
5532
5890
|
{ result: withdrawalInfoResult },
|
|
5533
5891
|
{ result: cycleIndex }
|
|
5534
|
-
] = await
|
|
5892
|
+
] = await readContracts11(wagmiConfig, {
|
|
5535
5893
|
contracts: [
|
|
5536
5894
|
{
|
|
5537
5895
|
...sAutoContract,
|
|
@@ -5568,7 +5926,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5568
5926
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
5569
5927
|
}
|
|
5570
5928
|
const withdrawalAmountUsd = formatCurrency4(
|
|
5571
|
-
|
|
5929
|
+
formatEtherNum16(withdrawalAmount) * autoPrice
|
|
5572
5930
|
);
|
|
5573
5931
|
const lockDuration = Number(depositLockDuration);
|
|
5574
5932
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -5582,7 +5940,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5582
5940
|
Number(formatEther5(balanceExcludingWithdrawal)) * autoPrice
|
|
5583
5941
|
);
|
|
5584
5942
|
const balanceExcludingWithdrawalUsd = formatCurrency4(
|
|
5585
|
-
|
|
5943
|
+
formatEtherNum16(balanceExcludingWithdrawal) * autoPrice
|
|
5586
5944
|
);
|
|
5587
5945
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
5588
5946
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
@@ -5604,8 +5962,8 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5604
5962
|
unlockPeriodStartDate,
|
|
5605
5963
|
unlockRenewalDate
|
|
5606
5964
|
} = formatDateRange(unlockPeriodDateRangeArray, "date");
|
|
5607
|
-
const totalActiveUserCredits =
|
|
5608
|
-
const totalUserCredits =
|
|
5965
|
+
const totalActiveUserCredits = formatEtherNum16(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
5966
|
+
const totalUserCredits = formatEtherNum16(balance) * lockDurationInMonths;
|
|
5609
5967
|
const hasAddedLockedAuto = depositAmount > 0n;
|
|
5610
5968
|
const addedLockedAuto = depositAmount;
|
|
5611
5969
|
return {
|
|
@@ -5634,7 +5992,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5634
5992
|
unlockRenewalDate,
|
|
5635
5993
|
lockDurationInMonths,
|
|
5636
5994
|
boost: lockDuration,
|
|
5637
|
-
points:
|
|
5995
|
+
points: formatEtherNum16(balanceExcludingWithdrawal) * lockDuration,
|
|
5638
5996
|
totalActiveCredits: totalActiveUserCredits,
|
|
5639
5997
|
totalCredits: totalUserCredits,
|
|
5640
5998
|
hasBalance
|
|
@@ -5647,7 +6005,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5647
6005
|
|
|
5648
6006
|
// functions/getSAuto.ts
|
|
5649
6007
|
import { formatEther as formatEther6 } from "viem";
|
|
5650
|
-
import { readContracts as
|
|
6008
|
+
import { readContracts as readContracts12 } from "@wagmi/core";
|
|
5651
6009
|
import { sAutoAbi as sAutoAbi2 } from "@tokemak/abis";
|
|
5652
6010
|
import {
|
|
5653
6011
|
convertAutoCycleToUnix as convertAutoCycleToUnix2,
|
|
@@ -5669,7 +6027,7 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5669
6027
|
chainId
|
|
5670
6028
|
};
|
|
5671
6029
|
if (sAuto && autoPrice) {
|
|
5672
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await
|
|
6030
|
+
const [{ result: totalSupply }, { result: currentCycle }] = await readContracts12(wagmiConfig, {
|
|
5673
6031
|
contracts: [
|
|
5674
6032
|
{
|
|
5675
6033
|
...baseConfig,
|
|
@@ -5702,22 +6060,22 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5702
6060
|
// functions/getSAutoRewards.ts
|
|
5703
6061
|
import { formatUnits as formatUnits9 } from "viem";
|
|
5704
6062
|
import {
|
|
5705
|
-
convertTimestampToDate as
|
|
6063
|
+
convertTimestampToDate as convertTimestampToDate5,
|
|
5706
6064
|
formatDateToReadable as formatDateToReadable3,
|
|
5707
|
-
formatEtherNum as
|
|
6065
|
+
formatEtherNum as formatEtherNum17
|
|
5708
6066
|
} from "@tokemak/utils";
|
|
5709
|
-
import { getSdkByChainId as
|
|
6067
|
+
import { getSdkByChainId as getSdkByChainId19 } from "@tokemak/graph-cli";
|
|
5710
6068
|
import { mainnet as mainnet12 } from "viem/chains";
|
|
5711
6069
|
var getSAutoRewards = async () => {
|
|
5712
6070
|
try {
|
|
5713
|
-
const { GetSAutoRewards } =
|
|
6071
|
+
const { GetSAutoRewards } = getSdkByChainId19(mainnet12.id);
|
|
5714
6072
|
const { globalRewardsBalances } = await GetSAutoRewards();
|
|
5715
6073
|
const allGlobalRewardsBalanceDayDatas = await paginateQuery(
|
|
5716
6074
|
GetSAutoRewards,
|
|
5717
6075
|
"globalRewardsBalanceDayDatas"
|
|
5718
6076
|
);
|
|
5719
6077
|
const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
|
|
5720
|
-
return acc +
|
|
6078
|
+
return acc + formatEtherNum17(balance.balance);
|
|
5721
6079
|
}, 0);
|
|
5722
6080
|
const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
|
|
5723
6081
|
return acc + Number(formatUnits9(balance.balanceUSD, 8));
|
|
@@ -5725,13 +6083,13 @@ var getSAutoRewards = async () => {
|
|
|
5725
6083
|
const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
|
|
5726
6084
|
(dayData) => ({
|
|
5727
6085
|
timestamp: String(dayData.timestamp),
|
|
5728
|
-
balance:
|
|
6086
|
+
balance: formatEtherNum17(dayData.balance),
|
|
5729
6087
|
balanceUSD: Number(formatUnits9(dayData.balanceUSD, 8)),
|
|
5730
|
-
earned:
|
|
6088
|
+
earned: formatEtherNum17(dayData.earned),
|
|
5731
6089
|
earnedUSD: Number(formatUnits9(dayData.earnedUSD, 8)),
|
|
5732
|
-
dayAprPerCredit:
|
|
6090
|
+
dayAprPerCredit: formatEtherNum17(dayData.dayAprPerCredit),
|
|
5733
6091
|
formattedDate: formatDateToReadable3(
|
|
5734
|
-
|
|
6092
|
+
convertTimestampToDate5(Number(dayData.timestamp))
|
|
5735
6093
|
)
|
|
5736
6094
|
})
|
|
5737
6095
|
);
|
|
@@ -5748,7 +6106,7 @@ var getSAutoRewards = async () => {
|
|
|
5748
6106
|
|
|
5749
6107
|
// functions/getUserSAutoRewards.ts
|
|
5750
6108
|
import { getMainnetConfig as getMainnetConfig10 } from "@tokemak/config";
|
|
5751
|
-
import { formatEtherNum as
|
|
6109
|
+
import { formatEtherNum as formatEtherNum18 } from "@tokemak/utils";
|
|
5752
6110
|
var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
5753
6111
|
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = getMainnetConfig10();
|
|
5754
6112
|
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
@@ -5794,19 +6152,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
|
5794
6152
|
return null;
|
|
5795
6153
|
}
|
|
5796
6154
|
}
|
|
5797
|
-
const claimableNum =
|
|
6155
|
+
const claimableNum = formatEtherNum18(autoRewards?.claimable || 0n);
|
|
5798
6156
|
const claimableUsd = autoPrice * claimableNum;
|
|
5799
6157
|
const hasClaimable = claimableNum > 0;
|
|
5800
|
-
let pendingRewards =
|
|
6158
|
+
let pendingRewards = formatEtherNum18(
|
|
5801
6159
|
autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5802
6160
|
);
|
|
5803
6161
|
if (currentCycle === 4242n) {
|
|
5804
|
-
pendingRewards =
|
|
6162
|
+
pendingRewards = formatEtherNum18(
|
|
5805
6163
|
autoRewards?.rewardsPayload.payload.amount || 0n
|
|
5806
6164
|
);
|
|
5807
6165
|
}
|
|
5808
6166
|
const pendingRewardsUsd = autoPrice * pendingRewards;
|
|
5809
|
-
const totalRewardsReceived =
|
|
6167
|
+
const totalRewardsReceived = formatEtherNum18(
|
|
5810
6168
|
autoRewards.rewardsPayload.payload.amount || 0n
|
|
5811
6169
|
);
|
|
5812
6170
|
const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
|
|
@@ -5841,7 +6199,7 @@ var getUserMerklRewards = async (address) => {
|
|
|
5841
6199
|
|
|
5842
6200
|
// functions/getUserEthAutoLPRewards.ts
|
|
5843
6201
|
import { getAddress as getAddress5 } from "viem";
|
|
5844
|
-
import { formatAmount as formatAmount2, formatUnitsNum as
|
|
6202
|
+
import { formatAmount as formatAmount2, formatUnitsNum as formatUnitsNum9 } from "@tokemak/utils";
|
|
5845
6203
|
import {
|
|
5846
6204
|
TOKE_TOKEN as TOKE_TOKEN4
|
|
5847
6205
|
} from "@tokemak/tokenlist";
|
|
@@ -5855,7 +6213,7 @@ var getUserEthAutoLPRewards = async (address) => {
|
|
|
5855
6213
|
const claimed = autoRewards?.claimed;
|
|
5856
6214
|
const claimable = Number(amount) - Number(claimed);
|
|
5857
6215
|
const formattedClaimable = formatAmount2(
|
|
5858
|
-
|
|
6216
|
+
formatUnitsNum9(BigInt(claimable || 0), 18)
|
|
5859
6217
|
);
|
|
5860
6218
|
const users = [];
|
|
5861
6219
|
const tokens = [];
|
|
@@ -5907,12 +6265,12 @@ async function getMerklPoolApr({
|
|
|
5907
6265
|
}
|
|
5908
6266
|
|
|
5909
6267
|
// functions/getSAutoApr.ts
|
|
5910
|
-
import { getSdkByChainId as
|
|
6268
|
+
import { getSdkByChainId as getSdkByChainId20 } from "@tokemak/graph-cli";
|
|
5911
6269
|
import { mainnet as mainnet13 } from "viem/chains";
|
|
5912
|
-
import { formatEtherNum as
|
|
6270
|
+
import { formatEtherNum as formatEtherNum19, formatPercent } from "@tokemak/utils";
|
|
5913
6271
|
var getSAutoApr = async () => {
|
|
5914
6272
|
try {
|
|
5915
|
-
const { GetSAutoApr } =
|
|
6273
|
+
const { GetSAutoApr } = getSdkByChainId20(mainnet13.id);
|
|
5916
6274
|
const { globalRewardsBalances } = await GetSAutoApr();
|
|
5917
6275
|
if (!globalRewardsBalances || globalRewardsBalances.length === 0) {
|
|
5918
6276
|
return {
|
|
@@ -5928,7 +6286,7 @@ var getSAutoApr = async () => {
|
|
|
5928
6286
|
aprFormatted: void 0
|
|
5929
6287
|
};
|
|
5930
6288
|
}
|
|
5931
|
-
const aprPerCredit =
|
|
6289
|
+
const aprPerCredit = formatEtherNum19(rawApr);
|
|
5932
6290
|
const lockDuration = 16;
|
|
5933
6291
|
const apr = aprPerCredit * lockDuration;
|
|
5934
6292
|
return {
|
|
@@ -5952,36 +6310,45 @@ var getCombinedRewards = async () => {
|
|
|
5952
6310
|
]);
|
|
5953
6311
|
const totalEarnings = (stokeRewards?.totalEarnings || 0) + (sAutoRewards?.totalEarnings || 0);
|
|
5954
6312
|
const totalEarningsUsd = (stokeRewards?.totalEarningsUsd || 0) + (sAutoRewards?.totalEarningsUsd || 0);
|
|
5955
|
-
const
|
|
6313
|
+
const stokeByTs = /* @__PURE__ */ new Map();
|
|
6314
|
+
const sAutoByTs = /* @__PURE__ */ new Map();
|
|
6315
|
+
const dateByTs = /* @__PURE__ */ new Map();
|
|
5956
6316
|
for (const item of stokeRewards?.historicalRewards || []) {
|
|
5957
|
-
const
|
|
5958
|
-
const existing =
|
|
6317
|
+
const ts = Number(item.timestamp);
|
|
6318
|
+
const existing = stokeByTs.get(ts);
|
|
5959
6319
|
if (existing) {
|
|
5960
6320
|
existing.balance += item.balance;
|
|
5961
6321
|
existing.balanceUSD += item.balanceUSD;
|
|
5962
6322
|
} else {
|
|
5963
|
-
|
|
5964
|
-
balance: item.balance,
|
|
5965
|
-
balanceUSD: item.balanceUSD,
|
|
5966
|
-
formattedDate: item.formattedDate
|
|
5967
|
-
});
|
|
6323
|
+
stokeByTs.set(ts, { balance: item.balance, balanceUSD: item.balanceUSD });
|
|
5968
6324
|
}
|
|
6325
|
+
if (!dateByTs.has(ts)) dateByTs.set(ts, item.formattedDate);
|
|
5969
6326
|
}
|
|
5970
6327
|
for (const item of sAutoRewards?.historicalRewards || []) {
|
|
5971
|
-
const
|
|
5972
|
-
const existing =
|
|
6328
|
+
const ts = Number(item.timestamp);
|
|
6329
|
+
const existing = sAutoByTs.get(ts);
|
|
5973
6330
|
if (existing) {
|
|
5974
6331
|
existing.balance += item.balance;
|
|
5975
6332
|
existing.balanceUSD += item.balanceUSD;
|
|
5976
6333
|
} else {
|
|
5977
|
-
|
|
5978
|
-
balance: item.balance,
|
|
5979
|
-
balanceUSD: item.balanceUSD,
|
|
5980
|
-
formattedDate: item.formattedDate
|
|
5981
|
-
});
|
|
6334
|
+
sAutoByTs.set(ts, { balance: item.balance, balanceUSD: item.balanceUSD });
|
|
5982
6335
|
}
|
|
6336
|
+
if (!dateByTs.has(ts)) dateByTs.set(ts, item.formattedDate);
|
|
5983
6337
|
}
|
|
5984
|
-
const
|
|
6338
|
+
const allTimestamps = Array.from(
|
|
6339
|
+
/* @__PURE__ */ new Set([...stokeByTs.keys(), ...sAutoByTs.keys()])
|
|
6340
|
+
).sort((a, b) => a - b);
|
|
6341
|
+
let lastStoke = { balance: 0, balanceUSD: 0 };
|
|
6342
|
+
let lastSAuto = { balance: 0, balanceUSD: 0 };
|
|
6343
|
+
const historicalRewards = allTimestamps.map((ts) => {
|
|
6344
|
+
if (stokeByTs.has(ts)) lastStoke = stokeByTs.get(ts);
|
|
6345
|
+
if (sAutoByTs.has(ts)) lastSAuto = sAutoByTs.get(ts);
|
|
6346
|
+
return {
|
|
6347
|
+
balance: lastStoke.balance + lastSAuto.balance,
|
|
6348
|
+
balanceUSD: lastStoke.balanceUSD + lastSAuto.balanceUSD,
|
|
6349
|
+
formattedDate: dateByTs.get(ts)
|
|
6350
|
+
};
|
|
6351
|
+
});
|
|
5985
6352
|
return {
|
|
5986
6353
|
totalEarnings,
|
|
5987
6354
|
totalEarningsUsd,
|
|
@@ -6019,11 +6386,16 @@ export {
|
|
|
6019
6386
|
getAutopilotRouter,
|
|
6020
6387
|
getAutopoolCategory,
|
|
6021
6388
|
getAutopoolDayData,
|
|
6389
|
+
getAutopoolHistory,
|
|
6022
6390
|
getAutopoolInfo,
|
|
6023
6391
|
getAutopoolRebalances,
|
|
6392
|
+
getAutopoolUser,
|
|
6393
|
+
getAutopoolUserActivity,
|
|
6394
|
+
getAutopoolUserHistory,
|
|
6024
6395
|
getAutopools,
|
|
6025
6396
|
getAutopoolsHistory,
|
|
6026
6397
|
getAutopoolsRebalances,
|
|
6398
|
+
getBaseChainUserActivity,
|
|
6027
6399
|
getBlobData,
|
|
6028
6400
|
getBlobHistoricalTokenPrices,
|
|
6029
6401
|
getBridgeFee,
|