@tokemak/queries 0.1.4 → 0.1.7
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/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 +22 -0
- package/dist/functions/getAutopoolUserHistory.d.ts.map +1 -0
- package/dist/functions/getAutopools.d.ts +15 -15
- package/dist/functions/getChainAutopools.d.ts +15 -15
- package/dist/functions/getChainUserActivity.d.ts +2 -3
- package/dist/functions/getChainUserActivity.d.ts.map +1 -1
- package/dist/functions/getTokenPrices.d.ts +71 -71
- package/dist/functions/getUserAutopoolBalanceChanges.d.ts.map +1 -1
- package/dist/functions/getUserSushiLP.d.ts +1 -1
- package/dist/functions/index.d.ts +4 -0
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/index.js +813 -481
- package/dist/index.mjs +590 -258
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -50,8 +50,12 @@ __export(index_exports, {
|
|
|
50
50
|
getAutopilotRouter: () => getAutopilotRouter,
|
|
51
51
|
getAutopoolCategory: () => getAutopoolCategory,
|
|
52
52
|
getAutopoolDayData: () => getAutopoolDayData,
|
|
53
|
+
getAutopoolHistory: () => getAutopoolHistory,
|
|
53
54
|
getAutopoolInfo: () => getAutopoolInfo,
|
|
54
55
|
getAutopoolRebalances: () => getAutopoolRebalances,
|
|
56
|
+
getAutopoolUser: () => getAutopoolUser,
|
|
57
|
+
getAutopoolUserActivity: () => getAutopoolUserActivity,
|
|
58
|
+
getAutopoolUserHistory: () => getAutopoolUserHistory,
|
|
55
59
|
getAutopools: () => getAutopools,
|
|
56
60
|
getAutopoolsHistory: () => getAutopoolsHistory,
|
|
57
61
|
getAutopoolsRebalances: () => getAutopoolsRebalances,
|
|
@@ -1241,13 +1245,74 @@ var getAutopoolsRebalances = async (chainId = 1) => {
|
|
|
1241
1245
|
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
1242
1246
|
};
|
|
1243
1247
|
|
|
1244
|
-
// functions/
|
|
1248
|
+
// functions/getAutopoolDayData.ts
|
|
1245
1249
|
var import_viem4 = require("viem");
|
|
1250
|
+
var import_utils10 = require("@tokemak/utils");
|
|
1251
|
+
var import_constants7 = require("@tokemak/constants");
|
|
1252
|
+
var import_graph_cli4 = require("@tokemak/graph-cli");
|
|
1253
|
+
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_constants7.TOKEMAK_LAUNCH_TIMESTAMP) => {
|
|
1254
|
+
try {
|
|
1255
|
+
const { GetAutopoolDayData } = (0, import_graph_cli4.getSdkByChainId)(chainId);
|
|
1256
|
+
const { autopoolDayDatas } = await GetAutopoolDayData({
|
|
1257
|
+
address,
|
|
1258
|
+
timestamp: startTimestamp
|
|
1259
|
+
});
|
|
1260
|
+
const formattedDayDatas = autopoolDayDatas.map((autoPoolDayData) => {
|
|
1261
|
+
const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
|
|
1262
|
+
let baseApy = autoPoolDayData.autopoolApy;
|
|
1263
|
+
let rewarderApy = 0;
|
|
1264
|
+
const formattedRewarder7DayMAApy = (0, import_utils10.formatEtherNum)(
|
|
1265
|
+
BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
|
|
1266
|
+
);
|
|
1267
|
+
const formattedRewarder30DayMAApy = (0, import_utils10.formatEtherNum)(
|
|
1268
|
+
BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
|
|
1269
|
+
);
|
|
1270
|
+
if (formattedRewarder7DayMAApy) {
|
|
1271
|
+
rewarderApy = formattedRewarder7DayMAApy;
|
|
1272
|
+
}
|
|
1273
|
+
if (formattedRewarder30DayMAApy) {
|
|
1274
|
+
rewarderApy = formattedRewarder30DayMAApy;
|
|
1275
|
+
}
|
|
1276
|
+
if (!baseApy) {
|
|
1277
|
+
baseApy = 0;
|
|
1278
|
+
} else {
|
|
1279
|
+
baseApy = Number(
|
|
1280
|
+
(0, import_viem4.formatUnits)(BigInt(baseApy), autoPoolDayData.baseAsset.decimals)
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
if (baseApy < 0) {
|
|
1284
|
+
baseApy = 0;
|
|
1285
|
+
}
|
|
1286
|
+
const combinedApy = rewarderApy + baseApy;
|
|
1287
|
+
return {
|
|
1288
|
+
...autoPoolDayData,
|
|
1289
|
+
navPerShare,
|
|
1290
|
+
rewarderApy,
|
|
1291
|
+
baseApy,
|
|
1292
|
+
combinedApy,
|
|
1293
|
+
date: new Date(Number(autoPoolDayData.timestamp) * 1e3)
|
|
1294
|
+
};
|
|
1295
|
+
});
|
|
1296
|
+
const filledDayDatas = fillMissingDates(formattedDayDatas);
|
|
1297
|
+
return filledDayDatas;
|
|
1298
|
+
} catch (e) {
|
|
1299
|
+
console.log(e);
|
|
1300
|
+
return [];
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
|
|
1304
|
+
// functions/getAutopoolHistory.ts
|
|
1305
|
+
var getAutopoolHistory = async (autopool) => {
|
|
1306
|
+
return getAutopoolDayData(autopool.poolAddress, autopool.chain?.chainId);
|
|
1307
|
+
};
|
|
1308
|
+
|
|
1309
|
+
// functions/getAutopoolsHistory.ts
|
|
1310
|
+
var import_viem5 = require("viem");
|
|
1246
1311
|
|
|
1247
1312
|
// functions/getAutopoolsDayData.ts
|
|
1248
|
-
var
|
|
1313
|
+
var import_graph_cli5 = require("@tokemak/graph-cli");
|
|
1249
1314
|
var getAutopoolsDayData = async (chainId, timestamp) => {
|
|
1250
|
-
const { GetAutopoolsDayData } = (0,
|
|
1315
|
+
const { GetAutopoolsDayData } = (0, import_graph_cli5.getSdkByChainId)(chainId);
|
|
1251
1316
|
const PAGE_SIZE = 1e3;
|
|
1252
1317
|
let allResults = [];
|
|
1253
1318
|
let hasMore = true;
|
|
@@ -1304,7 +1369,7 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
|
|
|
1304
1369
|
...data,
|
|
1305
1370
|
date: new Date(data.timestamp * 1e3),
|
|
1306
1371
|
baseAsset: autopools.find(
|
|
1307
|
-
(pool) => (0,
|
|
1372
|
+
(pool) => (0, import_viem5.getAddress)(pool.poolAddress) === (0, import_viem5.getAddress)(vaultId)
|
|
1308
1373
|
)?.baseAsset
|
|
1309
1374
|
});
|
|
1310
1375
|
}
|
|
@@ -1323,9 +1388,328 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
|
|
|
1323
1388
|
}
|
|
1324
1389
|
};
|
|
1325
1390
|
|
|
1391
|
+
// functions/getAutopoolUser.ts
|
|
1392
|
+
var import_viem6 = require("viem");
|
|
1393
|
+
var import_core2 = require("@wagmi/core");
|
|
1394
|
+
var import_abis2 = require("@tokemak/abis");
|
|
1395
|
+
var import_utils12 = require("@tokemak/utils");
|
|
1396
|
+
var getAutopoolUser = async (config, {
|
|
1397
|
+
autopool,
|
|
1398
|
+
address,
|
|
1399
|
+
userActivity,
|
|
1400
|
+
prices
|
|
1401
|
+
}) => {
|
|
1402
|
+
const autopoolContract = {
|
|
1403
|
+
address: autopool?.poolAddress,
|
|
1404
|
+
abi: import_abis2.autopoolEthAbi,
|
|
1405
|
+
chainId: autopool?.chain?.chainId
|
|
1406
|
+
};
|
|
1407
|
+
const [
|
|
1408
|
+
{ result: autopoolRewarderContract },
|
|
1409
|
+
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
1410
|
+
] = await (0, import_core2.readContracts)(config, {
|
|
1411
|
+
contracts: [
|
|
1412
|
+
{
|
|
1413
|
+
...autopoolContract,
|
|
1414
|
+
functionName: "rewarder",
|
|
1415
|
+
args: []
|
|
1416
|
+
},
|
|
1417
|
+
{
|
|
1418
|
+
...autopoolContract,
|
|
1419
|
+
functionName: "balanceOf",
|
|
1420
|
+
args: [address]
|
|
1421
|
+
}
|
|
1422
|
+
]
|
|
1423
|
+
});
|
|
1424
|
+
if (!autopoolRewarderContract) {
|
|
1425
|
+
throw new Error("No rewarder contract found");
|
|
1426
|
+
}
|
|
1427
|
+
if (unstakedPoolSharesError) {
|
|
1428
|
+
throw new Error("Error fetching unstaked pool shares");
|
|
1429
|
+
}
|
|
1430
|
+
const stakedPoolShares = await (0, import_core2.readContract)(config, {
|
|
1431
|
+
address: autopoolRewarderContract,
|
|
1432
|
+
abi: import_viem6.erc20Abi,
|
|
1433
|
+
functionName: "balanceOf",
|
|
1434
|
+
args: [address],
|
|
1435
|
+
chainId: autopool?.chain?.chainId
|
|
1436
|
+
});
|
|
1437
|
+
const stakedShares = (0, import_utils12.formatEtherNum)(stakedPoolShares);
|
|
1438
|
+
const staked = convertBaseAssetToTokenPricesAndDenom(
|
|
1439
|
+
stakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
1440
|
+
autopool?.baseAsset.price,
|
|
1441
|
+
autopool?.denomination.price,
|
|
1442
|
+
prices
|
|
1443
|
+
);
|
|
1444
|
+
const unstakedShares = (0, import_utils12.formatEtherNum)(unstakedPoolShares || 0n);
|
|
1445
|
+
const unstaked = convertBaseAssetToTokenPricesAndDenom(
|
|
1446
|
+
unstakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
1447
|
+
autopool?.baseAsset.price,
|
|
1448
|
+
autopool?.denomination.price,
|
|
1449
|
+
prices
|
|
1450
|
+
);
|
|
1451
|
+
const shares = unstakedShares + stakedShares;
|
|
1452
|
+
const nav = convertBaseAssetToTokenPricesAndDenom(
|
|
1453
|
+
shares * (autopool?.navPerShare.baseAsset || 0),
|
|
1454
|
+
autopool?.baseAsset.price,
|
|
1455
|
+
autopool?.denomination.price,
|
|
1456
|
+
prices
|
|
1457
|
+
);
|
|
1458
|
+
const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
|
|
1459
|
+
(0, import_utils12.formatUnitsNum)(
|
|
1460
|
+
userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
|
|
1461
|
+
autopool?.baseAsset.decimals
|
|
1462
|
+
),
|
|
1463
|
+
autopool?.baseAsset.price,
|
|
1464
|
+
autopool?.denomination.price,
|
|
1465
|
+
prices
|
|
1466
|
+
);
|
|
1467
|
+
const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
|
|
1468
|
+
(0, import_utils12.formatUnitsNum)(
|
|
1469
|
+
userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
|
|
1470
|
+
autopool?.baseAsset.decimals
|
|
1471
|
+
),
|
|
1472
|
+
autopool?.baseAsset.price,
|
|
1473
|
+
autopool?.denomination.price,
|
|
1474
|
+
prices
|
|
1475
|
+
);
|
|
1476
|
+
const returns = convertBaseAssetToTokenPricesAndDenom(
|
|
1477
|
+
nav.baseAsset + totalWithdrawals.baseAsset - totalDeposits.baseAsset,
|
|
1478
|
+
autopool?.baseAsset.price,
|
|
1479
|
+
autopool?.denomination.price,
|
|
1480
|
+
prices
|
|
1481
|
+
);
|
|
1482
|
+
const supplied = convertBaseAssetToTokenPricesAndDenom(
|
|
1483
|
+
totalDeposits.baseAsset - totalWithdrawals.baseAsset,
|
|
1484
|
+
autopool?.baseAsset.price,
|
|
1485
|
+
autopool?.denomination.price,
|
|
1486
|
+
prices
|
|
1487
|
+
);
|
|
1488
|
+
const poolEvents = userActivity?.events.filter(
|
|
1489
|
+
(event) => event.vaultAddress === autopool?.poolAddress
|
|
1490
|
+
);
|
|
1491
|
+
let lastDeposit;
|
|
1492
|
+
if (poolEvents && poolEvents?.length > 0) {
|
|
1493
|
+
lastDeposit = (0, import_utils12.convertTimestampToDate)(
|
|
1494
|
+
poolEvents[poolEvents.length - 1].timestamp
|
|
1495
|
+
).toLocaleDateString("en-US", {
|
|
1496
|
+
day: "2-digit",
|
|
1497
|
+
month: "short",
|
|
1498
|
+
year: "numeric"
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
return {
|
|
1502
|
+
symbol: autopool?.symbol,
|
|
1503
|
+
poolAddress: autopool?.poolAddress,
|
|
1504
|
+
userAddress: address,
|
|
1505
|
+
shares: {
|
|
1506
|
+
unstaked: unstakedShares,
|
|
1507
|
+
staked: stakedShares,
|
|
1508
|
+
total: shares
|
|
1509
|
+
},
|
|
1510
|
+
balance: {
|
|
1511
|
+
unstaked,
|
|
1512
|
+
staked,
|
|
1513
|
+
total: nav
|
|
1514
|
+
},
|
|
1515
|
+
returns,
|
|
1516
|
+
activity: {
|
|
1517
|
+
totalDeposits,
|
|
1518
|
+
totalWithdrawals,
|
|
1519
|
+
lastDeposit,
|
|
1520
|
+
supplied
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
};
|
|
1524
|
+
|
|
1525
|
+
// functions/getAutopoolUserActivity.ts
|
|
1526
|
+
var import_graph_cli6 = require("@tokemak/graph-cli");
|
|
1527
|
+
var import_utils15 = require("@tokemak/utils");
|
|
1528
|
+
var getAutopoolUserActivity = async ({
|
|
1529
|
+
autopool,
|
|
1530
|
+
userAddress
|
|
1531
|
+
}) => {
|
|
1532
|
+
if (!autopool || !autopool.chain?.chainId) {
|
|
1533
|
+
throw new Error("Autopool not found");
|
|
1534
|
+
}
|
|
1535
|
+
const { GetUserAutopoolBalanceChangeHistory } = (0, import_graph_cli6.getSdkByChainId)(
|
|
1536
|
+
autopool.chain?.chainId
|
|
1537
|
+
);
|
|
1538
|
+
try {
|
|
1539
|
+
const userAutopoolBalanceChanges = await paginateQuery(
|
|
1540
|
+
(vars) => GetUserAutopoolBalanceChangeHistory({
|
|
1541
|
+
userAddress,
|
|
1542
|
+
vaultAddress: autopool.poolAddress,
|
|
1543
|
+
first: vars?.first || 1e3,
|
|
1544
|
+
skip: vars?.skip || 0
|
|
1545
|
+
}),
|
|
1546
|
+
"userSpecificAutopoolBalanceChanges",
|
|
1547
|
+
{
|
|
1548
|
+
first: 1e3,
|
|
1549
|
+
maxPages: 100
|
|
1550
|
+
}
|
|
1551
|
+
);
|
|
1552
|
+
let userActivityTotals = {};
|
|
1553
|
+
let events = [];
|
|
1554
|
+
userAutopoolBalanceChanges.forEach((activity) => {
|
|
1555
|
+
if (!userActivityTotals[activity.vaultAddress]) {
|
|
1556
|
+
userActivityTotals[activity.vaultAddress] = {
|
|
1557
|
+
totalDeposits: 0n,
|
|
1558
|
+
totalWithdrawals: 0n,
|
|
1559
|
+
totalStakes: 0n,
|
|
1560
|
+
totalUnstakes: 0n,
|
|
1561
|
+
chainId: autopool.chain?.chainId
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
activity.items.forEach((item) => {
|
|
1565
|
+
let eventType;
|
|
1566
|
+
if (item.staked && item.assetChange > 0n) {
|
|
1567
|
+
userActivityTotals[activity.vaultAddress].totalStakes += BigInt(
|
|
1568
|
+
item.assetChange
|
|
1569
|
+
);
|
|
1570
|
+
eventType = "Stake";
|
|
1571
|
+
} else if (item.staked && item.assetChange < 0n) {
|
|
1572
|
+
userActivityTotals[activity.vaultAddress].totalUnstakes += BigInt(
|
|
1573
|
+
BigInt(item.assetChange) * -1n
|
|
1574
|
+
);
|
|
1575
|
+
eventType = "Unstake";
|
|
1576
|
+
} else if (!item.staked && item.assetChange > 0n) {
|
|
1577
|
+
userActivityTotals[activity.vaultAddress].totalDeposits += BigInt(
|
|
1578
|
+
item.assetChange
|
|
1579
|
+
);
|
|
1580
|
+
eventType = "Deposit";
|
|
1581
|
+
} else if (!item.staked && item.assetChange < 0n) {
|
|
1582
|
+
userActivityTotals[activity.vaultAddress].totalWithdrawals += BigInt(
|
|
1583
|
+
BigInt(item.assetChange) * -1n
|
|
1584
|
+
);
|
|
1585
|
+
eventType = "Withdrawal";
|
|
1586
|
+
} else {
|
|
1587
|
+
eventType = "Unknown";
|
|
1588
|
+
}
|
|
1589
|
+
const netDeposits = (0, import_utils15.formatUnitsNum)(
|
|
1590
|
+
userActivityTotals[activity.vaultAddress].totalDeposits - userActivityTotals[activity.vaultAddress].totalWithdrawals,
|
|
1591
|
+
autopool.baseAsset.decimals
|
|
1592
|
+
);
|
|
1593
|
+
if (!item.staked) {
|
|
1594
|
+
events.push({
|
|
1595
|
+
timestamp: activity.timestamp,
|
|
1596
|
+
shareChange: item.shareChange,
|
|
1597
|
+
assetChange: item.assetChange,
|
|
1598
|
+
vaultAddress: activity.vaultAddress,
|
|
1599
|
+
netDeposits,
|
|
1600
|
+
eventType
|
|
1601
|
+
// staked: item.staked,
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
});
|
|
1605
|
+
});
|
|
1606
|
+
return { events, totals: userActivityTotals };
|
|
1607
|
+
} catch (error) {
|
|
1608
|
+
console.error(error);
|
|
1609
|
+
return [];
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
|
|
1613
|
+
// functions/getAutopoolUserHistory.ts
|
|
1614
|
+
var import_graph_cli7 = require("@tokemak/graph-cli");
|
|
1615
|
+
var import_constants8 = require("@tokemak/constants");
|
|
1616
|
+
var import_chains3 = require("viem/chains");
|
|
1617
|
+
var import_utils17 = require("@tokemak/utils");
|
|
1618
|
+
var getAutopoolUserHistory = async ({
|
|
1619
|
+
userAddress,
|
|
1620
|
+
autopool,
|
|
1621
|
+
userActivity
|
|
1622
|
+
}) => {
|
|
1623
|
+
const { GetUserVaultDayData } = (0, import_graph_cli7.getSdkByChainId)(
|
|
1624
|
+
autopool?.chain?.chainId || import_chains3.base.id
|
|
1625
|
+
);
|
|
1626
|
+
try {
|
|
1627
|
+
if (userAddress) {
|
|
1628
|
+
const { userVaultDayDatas } = await GetUserVaultDayData({
|
|
1629
|
+
address: userAddress,
|
|
1630
|
+
timestamp: import_constants8.TOKEMAK_LAUNCH_TIMESTAMP,
|
|
1631
|
+
vaultAddress: autopool?.poolAddress
|
|
1632
|
+
});
|
|
1633
|
+
const autopoolDayData = await getAutopoolHistory(autopool);
|
|
1634
|
+
if (!autopoolDayData) {
|
|
1635
|
+
throw new Error("No autopool history found");
|
|
1636
|
+
}
|
|
1637
|
+
const formattedUserVaultDayDatas = userVaultDayDatas.map((dayData) => {
|
|
1638
|
+
if (!dayData.timestamp) {
|
|
1639
|
+
throw new Error("Missing timestamp in userVaultDayData");
|
|
1640
|
+
}
|
|
1641
|
+
return {
|
|
1642
|
+
...dayData,
|
|
1643
|
+
date: new Date(Number(dayData.timestamp) * 1e3),
|
|
1644
|
+
timestamp: dayData.timestamp.toString()
|
|
1645
|
+
};
|
|
1646
|
+
});
|
|
1647
|
+
const filledMissingDates = fillMissingDates(formattedUserVaultDayDatas);
|
|
1648
|
+
if (filledMissingDates.length > 0) {
|
|
1649
|
+
const firstEntry = filledMissingDates[0];
|
|
1650
|
+
const dayBefore = new Date(firstEntry.date);
|
|
1651
|
+
dayBefore.setDate(dayBefore.getDate() - 1);
|
|
1652
|
+
const dayBeforeTimestamp = Math.floor(
|
|
1653
|
+
dayBefore.getTime() / 1e3
|
|
1654
|
+
).toString();
|
|
1655
|
+
const dayBeforeEntry = {
|
|
1656
|
+
...firstEntry,
|
|
1657
|
+
date: dayBefore,
|
|
1658
|
+
timestamp: dayBeforeTimestamp,
|
|
1659
|
+
totalShares: 0
|
|
1660
|
+
};
|
|
1661
|
+
filledMissingDates.unshift(dayBeforeEntry);
|
|
1662
|
+
}
|
|
1663
|
+
let lastKnownNetDeposits = null;
|
|
1664
|
+
const matchedData = filledMissingDates.map((userVaultDayData) => {
|
|
1665
|
+
const matchingAutopoolDayData = autopoolDayData.find(
|
|
1666
|
+
(autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
|
|
1667
|
+
);
|
|
1668
|
+
const userPortionOfVault = (0, import_utils17.formatEtherNum)(userVaultDayData.totalShares) / (0, import_utils17.formatEtherNum)(matchingAutopoolDayData?.totalSupply);
|
|
1669
|
+
const userNav = userPortionOfVault * (0, import_utils17.formatUnitsNum)(
|
|
1670
|
+
BigInt(matchingAutopoolDayData?.nav || 0),
|
|
1671
|
+
autopool?.baseAsset.decimals
|
|
1672
|
+
);
|
|
1673
|
+
const eventsForDay = userActivity.events?.filter((event) => {
|
|
1674
|
+
const eventDate = new Date(Number(event.timestamp) * 1e3);
|
|
1675
|
+
const windowStart = new Date(userVaultDayData.date.getTime());
|
|
1676
|
+
const windowEnd = new Date(
|
|
1677
|
+
userVaultDayData.date.getTime() + 24 * 60 * 60 * 1e3
|
|
1678
|
+
);
|
|
1679
|
+
const matches = eventDate.getTime() > windowStart.getTime() && eventDate.getTime() <= windowEnd.getTime();
|
|
1680
|
+
return matches;
|
|
1681
|
+
});
|
|
1682
|
+
const lastEventForDay = eventsForDay && eventsForDay.length > 0 ? eventsForDay.sort(
|
|
1683
|
+
(a, b) => Number(b.timestamp) - Number(a.timestamp)
|
|
1684
|
+
)[0] : 0;
|
|
1685
|
+
let netDeposits = 0;
|
|
1686
|
+
if (lastEventForDay && "netDeposits" in lastEventForDay && typeof lastEventForDay.netDeposits === "number") {
|
|
1687
|
+
netDeposits = lastEventForDay.netDeposits;
|
|
1688
|
+
lastKnownNetDeposits = netDeposits;
|
|
1689
|
+
} else {
|
|
1690
|
+
netDeposits = lastKnownNetDeposits;
|
|
1691
|
+
}
|
|
1692
|
+
return {
|
|
1693
|
+
date: userVaultDayData.date,
|
|
1694
|
+
timestamp: userVaultDayData.timestamp,
|
|
1695
|
+
baseAsset: autopool?.baseAsset.symbol,
|
|
1696
|
+
nav: userNav,
|
|
1697
|
+
events: eventsForDay,
|
|
1698
|
+
netDeposits
|
|
1699
|
+
};
|
|
1700
|
+
});
|
|
1701
|
+
return matchedData;
|
|
1702
|
+
}
|
|
1703
|
+
return [];
|
|
1704
|
+
} catch (e) {
|
|
1705
|
+
console.error(e);
|
|
1706
|
+
return [];
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1326
1710
|
// functions/getCurveLP.ts
|
|
1327
1711
|
var import_config3 = require("@tokemak/config");
|
|
1328
|
-
var
|
|
1712
|
+
var import_constants9 = require("@tokemak/constants");
|
|
1329
1713
|
var getCurveLP = async () => {
|
|
1330
1714
|
let curveData;
|
|
1331
1715
|
const { curveRewardsUrl } = (0, import_config3.getMainnetConfig)();
|
|
@@ -1342,10 +1726,10 @@ var getCurveLP = async () => {
|
|
|
1342
1726
|
console.error(e);
|
|
1343
1727
|
}
|
|
1344
1728
|
try {
|
|
1345
|
-
const curvePoolsResponse = await fetch(
|
|
1729
|
+
const curvePoolsResponse = await fetch(import_constants9.CURVE_API_URL);
|
|
1346
1730
|
const curvePoolsData = await curvePoolsResponse.json();
|
|
1347
1731
|
const curveTOKEPool = curvePoolsData?.data?.poolData.find(
|
|
1348
|
-
(pool) => pool.id ===
|
|
1732
|
+
(pool) => pool.id === import_constants9.TOKE_CURVE_POOL_ID
|
|
1349
1733
|
);
|
|
1350
1734
|
if (curveData) {
|
|
1351
1735
|
curveData.curveTvl = curveTOKEPool?.usdTotal;
|
|
@@ -1358,31 +1742,31 @@ var getCurveLP = async () => {
|
|
|
1358
1742
|
};
|
|
1359
1743
|
|
|
1360
1744
|
// functions/getSushiLP.ts
|
|
1361
|
-
var
|
|
1745
|
+
var import_abis3 = require("@tokemak/abis");
|
|
1362
1746
|
var import_config4 = require("@tokemak/config");
|
|
1363
|
-
var
|
|
1364
|
-
var
|
|
1365
|
-
var
|
|
1747
|
+
var import_core3 = require("@wagmi/core");
|
|
1748
|
+
var import_viem7 = require("viem");
|
|
1749
|
+
var import_chains4 = require("viem/chains");
|
|
1366
1750
|
var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
1367
1751
|
const { sushiPool, lpRewardsV1Url } = (0, import_config4.getMainnetConfig)();
|
|
1368
1752
|
const sushiPoolContract = {
|
|
1369
1753
|
address: sushiPool,
|
|
1370
|
-
abi:
|
|
1754
|
+
abi: import_abis3.sushiPoolAbi
|
|
1371
1755
|
};
|
|
1372
1756
|
try {
|
|
1373
|
-
const [{ result: reserves }, { result: totalSupply }] = await (0,
|
|
1757
|
+
const [{ result: reserves }, { result: totalSupply }] = await (0, import_core3.readContracts)(
|
|
1374
1758
|
wagmiConfig,
|
|
1375
1759
|
{
|
|
1376
1760
|
contracts: [
|
|
1377
1761
|
{
|
|
1378
1762
|
...sushiPoolContract,
|
|
1379
1763
|
functionName: "getReserves",
|
|
1380
|
-
chainId:
|
|
1764
|
+
chainId: import_chains4.mainnet.id
|
|
1381
1765
|
},
|
|
1382
1766
|
{
|
|
1383
1767
|
...sushiPoolContract,
|
|
1384
1768
|
functionName: "totalSupply",
|
|
1385
|
-
chainId:
|
|
1769
|
+
chainId: import_chains4.mainnet.id
|
|
1386
1770
|
}
|
|
1387
1771
|
]
|
|
1388
1772
|
}
|
|
@@ -1394,8 +1778,8 @@ var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
|
1394
1778
|
);
|
|
1395
1779
|
if (reserves && totalSupply && ethPrice) {
|
|
1396
1780
|
const lpReserve = reserves[1] * 2n;
|
|
1397
|
-
const tvl = Number((0,
|
|
1398
|
-
const valueOf1LP = tvl / Number((0,
|
|
1781
|
+
const tvl = Number((0, import_viem7.formatEther)(lpReserve)) * ethPrice;
|
|
1782
|
+
const valueOf1LP = tvl / Number((0, import_viem7.formatEther)(totalSupply));
|
|
1399
1783
|
return {
|
|
1400
1784
|
tvl,
|
|
1401
1785
|
lpReserve,
|
|
@@ -1412,10 +1796,10 @@ var getSushiLP = async (wagmiConfig, { ethPrice }) => {
|
|
|
1412
1796
|
};
|
|
1413
1797
|
|
|
1414
1798
|
// functions/getUniV4Pool.ts
|
|
1415
|
-
var
|
|
1416
|
-
var
|
|
1417
|
-
var
|
|
1418
|
-
var
|
|
1799
|
+
var import_core4 = require("@wagmi/core");
|
|
1800
|
+
var import_viem8 = require("viem");
|
|
1801
|
+
var import_chains5 = require("viem/chains");
|
|
1802
|
+
var import_constants10 = require("@tokemak/constants");
|
|
1419
1803
|
var stateViewAbi = [
|
|
1420
1804
|
{
|
|
1421
1805
|
inputs: [{ internalType: "PoolId", name: "poolId", type: "bytes32" }],
|
|
@@ -1437,7 +1821,7 @@ var stateViewAbi = [
|
|
|
1437
1821
|
type: "function"
|
|
1438
1822
|
}
|
|
1439
1823
|
];
|
|
1440
|
-
var
|
|
1824
|
+
var erc20Abi2 = [
|
|
1441
1825
|
{
|
|
1442
1826
|
inputs: [],
|
|
1443
1827
|
name: "decimals",
|
|
@@ -1461,8 +1845,8 @@ var erc20Abi = [
|
|
|
1461
1845
|
}
|
|
1462
1846
|
];
|
|
1463
1847
|
function computePoolId(poolKey) {
|
|
1464
|
-
return (0,
|
|
1465
|
-
(0,
|
|
1848
|
+
return (0, import_viem8.keccak256)(
|
|
1849
|
+
(0, import_viem8.encodeAbiParameters)(
|
|
1466
1850
|
[
|
|
1467
1851
|
{ type: "address", name: "currency0" },
|
|
1468
1852
|
{ type: "address", name: "currency1" },
|
|
@@ -1509,18 +1893,18 @@ function feeToTierString(fee) {
|
|
|
1509
1893
|
}
|
|
1510
1894
|
async function getUniV4Pool(wagmiConfig, {
|
|
1511
1895
|
poolKey,
|
|
1512
|
-
chainId =
|
|
1896
|
+
chainId = import_chains5.mainnet.id,
|
|
1513
1897
|
prices
|
|
1514
1898
|
}) {
|
|
1515
|
-
const stateView =
|
|
1899
|
+
const stateView = import_constants10.UNISWAP_V4_STATE_VIEW[chainId];
|
|
1516
1900
|
if (!stateView) {
|
|
1517
1901
|
console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
|
|
1518
1902
|
return null;
|
|
1519
1903
|
}
|
|
1520
|
-
const poolManager =
|
|
1904
|
+
const poolManager = import_constants10.UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1521
1905
|
const poolId = computePoolId(poolKey);
|
|
1522
1906
|
try {
|
|
1523
|
-
const [{ result: slot0 }, { result: liquidity }] = await (0,
|
|
1907
|
+
const [{ result: slot0 }, { result: liquidity }] = await (0, import_core4.readContracts)(
|
|
1524
1908
|
wagmiConfig,
|
|
1525
1909
|
{
|
|
1526
1910
|
contracts: [
|
|
@@ -1551,19 +1935,19 @@ async function getUniV4Pool(wagmiConfig, {
|
|
|
1551
1935
|
tokenContracts.push(
|
|
1552
1936
|
{
|
|
1553
1937
|
address: poolKey.currency0,
|
|
1554
|
-
abi:
|
|
1938
|
+
abi: erc20Abi2,
|
|
1555
1939
|
functionName: "decimals",
|
|
1556
1940
|
chainId
|
|
1557
1941
|
},
|
|
1558
1942
|
{
|
|
1559
1943
|
address: poolKey.currency0,
|
|
1560
|
-
abi:
|
|
1944
|
+
abi: erc20Abi2,
|
|
1561
1945
|
functionName: "symbol",
|
|
1562
1946
|
chainId
|
|
1563
1947
|
},
|
|
1564
1948
|
{
|
|
1565
1949
|
address: poolKey.currency0,
|
|
1566
|
-
abi:
|
|
1950
|
+
abi: erc20Abi2,
|
|
1567
1951
|
functionName: "balanceOf",
|
|
1568
1952
|
args: [poolManager],
|
|
1569
1953
|
chainId
|
|
@@ -1574,26 +1958,26 @@ async function getUniV4Pool(wagmiConfig, {
|
|
|
1574
1958
|
tokenContracts.push(
|
|
1575
1959
|
{
|
|
1576
1960
|
address: poolKey.currency1,
|
|
1577
|
-
abi:
|
|
1961
|
+
abi: erc20Abi2,
|
|
1578
1962
|
functionName: "decimals",
|
|
1579
1963
|
chainId
|
|
1580
1964
|
},
|
|
1581
1965
|
{
|
|
1582
1966
|
address: poolKey.currency1,
|
|
1583
|
-
abi:
|
|
1967
|
+
abi: erc20Abi2,
|
|
1584
1968
|
functionName: "symbol",
|
|
1585
1969
|
chainId
|
|
1586
1970
|
},
|
|
1587
1971
|
{
|
|
1588
1972
|
address: poolKey.currency1,
|
|
1589
|
-
abi:
|
|
1973
|
+
abi: erc20Abi2,
|
|
1590
1974
|
functionName: "balanceOf",
|
|
1591
1975
|
args: [poolManager],
|
|
1592
1976
|
chainId
|
|
1593
1977
|
}
|
|
1594
1978
|
);
|
|
1595
1979
|
}
|
|
1596
|
-
const tokenResults = tokenContracts.length > 0 ? await (0,
|
|
1980
|
+
const tokenResults = tokenContracts.length > 0 ? await (0, import_core4.readContracts)(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
1597
1981
|
let decimals0 = 18;
|
|
1598
1982
|
let symbol0 = "ETH";
|
|
1599
1983
|
let balance0 = 0n;
|
|
@@ -1613,8 +1997,8 @@ async function getUniV4Pool(wagmiConfig, {
|
|
|
1613
1997
|
}
|
|
1614
1998
|
const [sqrtPriceX96, tick] = slot0;
|
|
1615
1999
|
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1616
|
-
const balance0Formatted = Number((0,
|
|
1617
|
-
const balance1Formatted = Number((0,
|
|
2000
|
+
const balance0Formatted = Number((0, import_viem8.formatUnits)(balance0, decimals0));
|
|
2001
|
+
const balance1Formatted = Number((0, import_viem8.formatUnits)(balance1, decimals1));
|
|
1618
2002
|
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1619
2003
|
liquidity ?? 0n,
|
|
1620
2004
|
sqrtPriceX96,
|
|
@@ -1688,17 +2072,17 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1688
2072
|
currency0,
|
|
1689
2073
|
currency1,
|
|
1690
2074
|
fee,
|
|
1691
|
-
chainId =
|
|
2075
|
+
chainId = import_chains5.mainnet.id,
|
|
1692
2076
|
prices
|
|
1693
2077
|
}) {
|
|
1694
|
-
const stateView =
|
|
2078
|
+
const stateView = import_constants10.UNISWAP_V4_STATE_VIEW[chainId];
|
|
1695
2079
|
if (!stateView) {
|
|
1696
2080
|
console.error(`Uniswap V4 State View not found for chainId ${chainId}`);
|
|
1697
2081
|
return null;
|
|
1698
2082
|
}
|
|
1699
|
-
const poolManager =
|
|
2083
|
+
const poolManager = import_constants10.UNISWAP_V4_POOL_MANAGER[chainId];
|
|
1700
2084
|
try {
|
|
1701
|
-
const [{ result: slot0 }, { result: liquidity }] = await (0,
|
|
2085
|
+
const [{ result: slot0 }, { result: liquidity }] = await (0, import_core4.readContracts)(
|
|
1702
2086
|
wagmiConfig,
|
|
1703
2087
|
{
|
|
1704
2088
|
contracts: [
|
|
@@ -1729,19 +2113,19 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1729
2113
|
tokenContracts.push(
|
|
1730
2114
|
{
|
|
1731
2115
|
address: currency0,
|
|
1732
|
-
abi:
|
|
2116
|
+
abi: erc20Abi2,
|
|
1733
2117
|
functionName: "decimals",
|
|
1734
2118
|
chainId
|
|
1735
2119
|
},
|
|
1736
2120
|
{
|
|
1737
2121
|
address: currency0,
|
|
1738
|
-
abi:
|
|
2122
|
+
abi: erc20Abi2,
|
|
1739
2123
|
functionName: "symbol",
|
|
1740
2124
|
chainId
|
|
1741
2125
|
},
|
|
1742
2126
|
{
|
|
1743
2127
|
address: currency0,
|
|
1744
|
-
abi:
|
|
2128
|
+
abi: erc20Abi2,
|
|
1745
2129
|
functionName: "balanceOf",
|
|
1746
2130
|
args: [poolManager],
|
|
1747
2131
|
chainId
|
|
@@ -1752,26 +2136,26 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1752
2136
|
tokenContracts.push(
|
|
1753
2137
|
{
|
|
1754
2138
|
address: currency1,
|
|
1755
|
-
abi:
|
|
2139
|
+
abi: erc20Abi2,
|
|
1756
2140
|
functionName: "decimals",
|
|
1757
2141
|
chainId
|
|
1758
2142
|
},
|
|
1759
2143
|
{
|
|
1760
2144
|
address: currency1,
|
|
1761
|
-
abi:
|
|
2145
|
+
abi: erc20Abi2,
|
|
1762
2146
|
functionName: "symbol",
|
|
1763
2147
|
chainId
|
|
1764
2148
|
},
|
|
1765
2149
|
{
|
|
1766
2150
|
address: currency1,
|
|
1767
|
-
abi:
|
|
2151
|
+
abi: erc20Abi2,
|
|
1768
2152
|
functionName: "balanceOf",
|
|
1769
2153
|
args: [poolManager],
|
|
1770
2154
|
chainId
|
|
1771
2155
|
}
|
|
1772
2156
|
);
|
|
1773
2157
|
}
|
|
1774
|
-
const tokenResults = tokenContracts.length > 0 ? await (0,
|
|
2158
|
+
const tokenResults = tokenContracts.length > 0 ? await (0, import_core4.readContracts)(wagmiConfig, { contracts: tokenContracts }) : [];
|
|
1775
2159
|
let decimals0 = 18;
|
|
1776
2160
|
let symbol0 = "ETH";
|
|
1777
2161
|
let balance0 = 0n;
|
|
@@ -1791,8 +2175,8 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1791
2175
|
}
|
|
1792
2176
|
const [sqrtPriceX96, tick] = slot0;
|
|
1793
2177
|
const price = sqrtPriceX96ToPrice(sqrtPriceX96, decimals0, decimals1);
|
|
1794
|
-
const balance0Formatted = Number((0,
|
|
1795
|
-
const balance1Formatted = Number((0,
|
|
2178
|
+
const balance0Formatted = Number((0, import_viem8.formatUnits)(balance0, decimals0));
|
|
2179
|
+
const balance1Formatted = Number((0, import_viem8.formatUnits)(balance1, decimals1));
|
|
1796
2180
|
const liquidityAmounts = calculateAmountsFromLiquidity(
|
|
1797
2181
|
liquidity ?? 0n,
|
|
1798
2182
|
sqrtPriceX96,
|
|
@@ -1843,13 +2227,13 @@ async function getUniV4PoolById(wagmiConfig, {
|
|
|
1843
2227
|
}
|
|
1844
2228
|
|
|
1845
2229
|
// functions/getUserUniV4Positions.ts
|
|
1846
|
-
var
|
|
1847
|
-
var
|
|
1848
|
-
var
|
|
2230
|
+
var import_core5 = require("@wagmi/core");
|
|
2231
|
+
var import_viem9 = require("viem");
|
|
2232
|
+
var import_chains6 = require("viem/chains");
|
|
1849
2233
|
var import_graphql_request = require("graphql-request");
|
|
1850
|
-
var
|
|
2234
|
+
var import_constants11 = require("@tokemak/constants");
|
|
1851
2235
|
var V4_SUBGRAPH_IDS = {
|
|
1852
|
-
[
|
|
2236
|
+
[import_chains6.mainnet.id]: "DiYPVdygkfjDWhbxGSqAQxwBKmfKnkWQojqeM2rkLb3G"
|
|
1853
2237
|
};
|
|
1854
2238
|
function getV4SubgraphUrl(chainId, apiKey) {
|
|
1855
2239
|
const subgraphId = V4_SUBGRAPH_IDS[chainId];
|
|
@@ -1907,7 +2291,7 @@ var stateViewAbi2 = [
|
|
|
1907
2291
|
type: "function"
|
|
1908
2292
|
}
|
|
1909
2293
|
];
|
|
1910
|
-
var
|
|
2294
|
+
var erc20Abi3 = [
|
|
1911
2295
|
{
|
|
1912
2296
|
inputs: [],
|
|
1913
2297
|
name: "decimals",
|
|
@@ -1957,8 +2341,8 @@ function getTokenAmountsFromLiquidity(liquidity, sqrtPriceX96, tickLower, tickUp
|
|
|
1957
2341
|
amount1 = liquidity * (sqrtPriceX96 - sqrtPriceLower) / Q96;
|
|
1958
2342
|
}
|
|
1959
2343
|
return {
|
|
1960
|
-
amount0: Number((0,
|
|
1961
|
-
amount1: Number((0,
|
|
2344
|
+
amount0: Number((0, import_viem9.formatUnits)(amount0, token0Decimals)),
|
|
2345
|
+
amount1: Number((0, import_viem9.formatUnits)(amount1, token1Decimals))
|
|
1962
2346
|
};
|
|
1963
2347
|
}
|
|
1964
2348
|
function feeToTierString2(fee) {
|
|
@@ -1995,13 +2379,13 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
1995
2379
|
poolId,
|
|
1996
2380
|
currency0,
|
|
1997
2381
|
currency1,
|
|
1998
|
-
chainId =
|
|
2382
|
+
chainId = import_chains6.mainnet.id,
|
|
1999
2383
|
prices,
|
|
2000
2384
|
graphApiKey,
|
|
2001
2385
|
knownTokenIds
|
|
2002
2386
|
}) {
|
|
2003
|
-
const positionManager =
|
|
2004
|
-
const stateView =
|
|
2387
|
+
const positionManager = import_constants11.UNISWAP_V4_POSITION_MANAGER[chainId];
|
|
2388
|
+
const stateView = import_constants11.UNISWAP_V4_STATE_VIEW[chainId];
|
|
2005
2389
|
if (!positionManager || !stateView) {
|
|
2006
2390
|
console.error(`V4 contracts not found for chainId ${chainId}`);
|
|
2007
2391
|
return { positions: [], totalValueUsd: 0, totalPositions: 0 };
|
|
@@ -2011,7 +2395,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2011
2395
|
if (knownTokenIds && knownTokenIds.length > 0) {
|
|
2012
2396
|
tokenIds = knownTokenIds;
|
|
2013
2397
|
} else {
|
|
2014
|
-
const apiKey = graphApiKey ||
|
|
2398
|
+
const apiKey = graphApiKey || import_constants11.GRAPH_API_KEY;
|
|
2015
2399
|
tokenIds = await getPositionTokenIdsFromSubgraph(
|
|
2016
2400
|
userAddress,
|
|
2017
2401
|
chainId,
|
|
@@ -2037,7 +2421,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2037
2421
|
chainId
|
|
2038
2422
|
}
|
|
2039
2423
|
]);
|
|
2040
|
-
const positionResults = await (0,
|
|
2424
|
+
const positionResults = await (0, import_core5.readContracts)(wagmiConfig, {
|
|
2041
2425
|
contracts: positionInfoCalls
|
|
2042
2426
|
});
|
|
2043
2427
|
const matchingPositions = [];
|
|
@@ -2087,13 +2471,13 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2087
2471
|
...!isToken0Native ? [
|
|
2088
2472
|
{
|
|
2089
2473
|
address: currency0,
|
|
2090
|
-
abi:
|
|
2474
|
+
abi: erc20Abi3,
|
|
2091
2475
|
functionName: "decimals",
|
|
2092
2476
|
chainId
|
|
2093
2477
|
},
|
|
2094
2478
|
{
|
|
2095
2479
|
address: currency0,
|
|
2096
|
-
abi:
|
|
2480
|
+
abi: erc20Abi3,
|
|
2097
2481
|
functionName: "symbol",
|
|
2098
2482
|
chainId
|
|
2099
2483
|
}
|
|
@@ -2101,19 +2485,19 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2101
2485
|
...!isToken1Native ? [
|
|
2102
2486
|
{
|
|
2103
2487
|
address: currency1,
|
|
2104
|
-
abi:
|
|
2488
|
+
abi: erc20Abi3,
|
|
2105
2489
|
functionName: "decimals",
|
|
2106
2490
|
chainId
|
|
2107
2491
|
},
|
|
2108
2492
|
{
|
|
2109
2493
|
address: currency1,
|
|
2110
|
-
abi:
|
|
2494
|
+
abi: erc20Abi3,
|
|
2111
2495
|
functionName: "symbol",
|
|
2112
2496
|
chainId
|
|
2113
2497
|
}
|
|
2114
2498
|
] : []
|
|
2115
2499
|
];
|
|
2116
|
-
const infoResults = await (0,
|
|
2500
|
+
const infoResults = await (0, import_core5.readContracts)(wagmiConfig, {
|
|
2117
2501
|
contracts: infoCalls
|
|
2118
2502
|
});
|
|
2119
2503
|
const slot0 = infoResults[0]?.result;
|
|
@@ -2189,7 +2573,7 @@ async function getUserUniV4PositionsById(wagmiConfig, {
|
|
|
2189
2573
|
async function getUserUniV4Positions(wagmiConfig, {
|
|
2190
2574
|
userAddress,
|
|
2191
2575
|
poolKey,
|
|
2192
|
-
chainId =
|
|
2576
|
+
chainId = import_chains6.mainnet.id,
|
|
2193
2577
|
prices,
|
|
2194
2578
|
graphApiKey,
|
|
2195
2579
|
knownTokenIds
|
|
@@ -2208,14 +2592,14 @@ async function getUserUniV4Positions(wagmiConfig, {
|
|
|
2208
2592
|
}
|
|
2209
2593
|
|
|
2210
2594
|
// functions/getDefillamaPoolApr.ts
|
|
2211
|
-
var
|
|
2595
|
+
var import_constants12 = require("@tokemak/constants");
|
|
2212
2596
|
var poolsCache = null;
|
|
2213
2597
|
var CACHE_TTL = 5 * 60 * 1e3;
|
|
2214
2598
|
async function fetchDefiLlamaPools() {
|
|
2215
2599
|
if (poolsCache && Date.now() - poolsCache.timestamp < CACHE_TTL) {
|
|
2216
2600
|
return poolsCache.data;
|
|
2217
2601
|
}
|
|
2218
|
-
const response = await fetch(
|
|
2602
|
+
const response = await fetch(import_constants12.DEFILLAMA_YIELDS_API);
|
|
2219
2603
|
if (!response.ok) {
|
|
2220
2604
|
throw new Error(`DefiLlama API request failed: ${response.statusText}`);
|
|
2221
2605
|
}
|
|
@@ -2268,9 +2652,9 @@ function clearDefillamaCache() {
|
|
|
2268
2652
|
}
|
|
2269
2653
|
|
|
2270
2654
|
// functions/getEthAutoLP.ts
|
|
2271
|
-
var
|
|
2655
|
+
var import_chains7 = require("viem/chains");
|
|
2272
2656
|
var import_tokenlist4 = require("@tokemak/tokenlist");
|
|
2273
|
-
var
|
|
2657
|
+
var import_constants13 = require("@tokemak/constants");
|
|
2274
2658
|
|
|
2275
2659
|
// functions/getMerklCreatorApr.ts
|
|
2276
2660
|
var import_api = require("@merkl/api");
|
|
@@ -2319,11 +2703,11 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2319
2703
|
const currency0 = import_tokenlist4.ETH_TOKEN.address;
|
|
2320
2704
|
const currency1 = import_tokenlist4.AUTO_TOKEN.address;
|
|
2321
2705
|
const poolData = await getUniV4PoolById(wagmiConfig, {
|
|
2322
|
-
poolId:
|
|
2706
|
+
poolId: import_constants13.ETH_AUTO_V4_POOL_ID,
|
|
2323
2707
|
currency0,
|
|
2324
2708
|
currency1,
|
|
2325
|
-
fee:
|
|
2326
|
-
chainId:
|
|
2709
|
+
fee: import_constants13.ETH_AUTO_FEE_TIER,
|
|
2710
|
+
chainId: import_chains7.mainnet.id,
|
|
2327
2711
|
prices
|
|
2328
2712
|
});
|
|
2329
2713
|
if (!poolData) {
|
|
@@ -2332,8 +2716,8 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2332
2716
|
let apr = void 0;
|
|
2333
2717
|
try {
|
|
2334
2718
|
const aprResult = await getMerklCreatorApr({
|
|
2335
|
-
creatorAddress:
|
|
2336
|
-
identifier:
|
|
2719
|
+
creatorAddress: import_constants13.MERKL_CREATOR_ADDRESS,
|
|
2720
|
+
identifier: import_constants13.UNI_V4_POOL_ID
|
|
2337
2721
|
});
|
|
2338
2722
|
apr = aprResult?.totalApr;
|
|
2339
2723
|
} catch (error) {
|
|
@@ -2346,12 +2730,12 @@ async function getEthAutoLP(wagmiConfig, {
|
|
|
2346
2730
|
}
|
|
2347
2731
|
|
|
2348
2732
|
// functions/getUserEthAutoLP.ts
|
|
2349
|
-
var
|
|
2733
|
+
var import_chains8 = require("viem/chains");
|
|
2350
2734
|
var import_tokenlist5 = require("@tokemak/tokenlist");
|
|
2351
|
-
var
|
|
2735
|
+
var import_constants14 = require("@tokemak/constants");
|
|
2352
2736
|
async function getUserEthAutoLP(wagmiConfig, {
|
|
2353
2737
|
userAddress,
|
|
2354
|
-
chainId =
|
|
2738
|
+
chainId = import_chains8.mainnet.id,
|
|
2355
2739
|
prices,
|
|
2356
2740
|
graphApiKey,
|
|
2357
2741
|
knownTokenIds
|
|
@@ -2360,7 +2744,7 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2360
2744
|
const currency1 = import_tokenlist5.AUTO_TOKEN.address;
|
|
2361
2745
|
return getUserUniV4PositionsById(wagmiConfig, {
|
|
2362
2746
|
userAddress,
|
|
2363
|
-
poolId:
|
|
2747
|
+
poolId: import_constants14.ETH_AUTO_V4_POOL_ID,
|
|
2364
2748
|
currency0,
|
|
2365
2749
|
currency1,
|
|
2366
2750
|
chainId,
|
|
@@ -2371,9 +2755,9 @@ async function getUserEthAutoLP(wagmiConfig, {
|
|
|
2371
2755
|
}
|
|
2372
2756
|
|
|
2373
2757
|
// functions/getChainUserActivity.ts
|
|
2374
|
-
var
|
|
2758
|
+
var import_graph_cli8 = require("@tokemak/graph-cli");
|
|
2375
2759
|
var getChainUserActivity = async (address, chainId = 1) => {
|
|
2376
|
-
const { GetUserBalanceChangeHistory } = (0,
|
|
2760
|
+
const { GetUserBalanceChangeHistory } = (0, import_graph_cli8.getSdkByChainId)(chainId);
|
|
2377
2761
|
try {
|
|
2378
2762
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
2379
2763
|
(vars) => GetUserBalanceChangeHistory({
|
|
@@ -2459,10 +2843,10 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
|
|
|
2459
2843
|
}
|
|
2460
2844
|
};
|
|
2461
2845
|
|
|
2462
|
-
// functions/getUserAutoEthRewards.ts
|
|
2463
|
-
var
|
|
2464
|
-
var
|
|
2465
|
-
var
|
|
2846
|
+
// functions/getUserAutoEthRewards.ts
|
|
2847
|
+
var import_abis4 = require("@tokemak/abis");
|
|
2848
|
+
var import_core6 = require("@wagmi/core");
|
|
2849
|
+
var import_utils19 = require("@tokemak/utils");
|
|
2466
2850
|
var getAutoEthRewards = async (wagmiConfig, {
|
|
2467
2851
|
account,
|
|
2468
2852
|
currentCycleIndex,
|
|
@@ -2471,16 +2855,16 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2471
2855
|
chainId
|
|
2472
2856
|
}) => {
|
|
2473
2857
|
try {
|
|
2474
|
-
const [, drippingHash] = await (0,
|
|
2858
|
+
const [, drippingHash] = await (0, import_core6.readContract)(wagmiConfig, {
|
|
2475
2859
|
address: rewardsHash,
|
|
2476
|
-
abi:
|
|
2860
|
+
abi: import_abis4.autoEthRewardsHashAbi,
|
|
2477
2861
|
functionName: "cycleHashes",
|
|
2478
2862
|
args: [currentCycleIndex - 306n],
|
|
2479
2863
|
chainId
|
|
2480
2864
|
});
|
|
2481
|
-
const [, lastWeekHash] = await (0,
|
|
2865
|
+
const [, lastWeekHash] = await (0, import_core6.readContract)(wagmiConfig, {
|
|
2482
2866
|
address: rewardsHash,
|
|
2483
|
-
abi:
|
|
2867
|
+
abi: import_abis4.autoEthRewardsHashAbi,
|
|
2484
2868
|
functionName: "cycleHashes",
|
|
2485
2869
|
// -1 to get the previous cycle
|
|
2486
2870
|
args: [currentCycleIndex - 306n - 1n],
|
|
@@ -2500,7 +2884,7 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2500
2884
|
const currentAmount = Number(drippingHashPayload?.summary?.currentAmount);
|
|
2501
2885
|
const previousAmount = Number(drippingHashPayload?.summary?.previousAmount);
|
|
2502
2886
|
const cycleDuration = 604800;
|
|
2503
|
-
const lastCycleStart = (0,
|
|
2887
|
+
const lastCycleStart = (0, import_utils19.convertChainCycleToUnix)(Number(currentCycleIndex));
|
|
2504
2888
|
const timeSinceCycleStart = Date.now() / 1e3 - lastCycleStart;
|
|
2505
2889
|
const currentUserRewards = currentAmount * Math.min(timeSinceCycleStart, cycleDuration) / cycleDuration + previousAmount;
|
|
2506
2890
|
const lastWeekRewards = Number(lastWeekHashPayload?.summary?.currentAmount);
|
|
@@ -2521,15 +2905,15 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
|
|
|
2521
2905
|
rewardsHash,
|
|
2522
2906
|
chainId
|
|
2523
2907
|
});
|
|
2524
|
-
const currentUserRewardsUsd = (0,
|
|
2908
|
+
const currentUserRewardsUsd = (0, import_utils19.formatCurrency)(
|
|
2525
2909
|
ethPrice * (autoETHRewards?.currentUserRewards || 0)
|
|
2526
2910
|
);
|
|
2527
2911
|
return { ...autoETHRewards, currentUserRewardsUsd };
|
|
2528
2912
|
};
|
|
2529
2913
|
|
|
2530
2914
|
// functions/getUserRewardsV1.ts
|
|
2531
|
-
var
|
|
2532
|
-
var
|
|
2915
|
+
var import_abis5 = require("@tokemak/abis");
|
|
2916
|
+
var import_core7 = require("@wagmi/core");
|
|
2533
2917
|
var getUserRewardsV1 = async (wagmiConfig, {
|
|
2534
2918
|
address,
|
|
2535
2919
|
rewardsCycleIndex,
|
|
@@ -2539,11 +2923,11 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2539
2923
|
chainId
|
|
2540
2924
|
}) => {
|
|
2541
2925
|
try {
|
|
2542
|
-
const [latestClaimableHash, cycleRewardsHash] = await (0,
|
|
2926
|
+
const [latestClaimableHash, cycleRewardsHash] = await (0, import_core7.readContract)(
|
|
2543
2927
|
wagmiConfig,
|
|
2544
2928
|
{
|
|
2545
2929
|
address: rewardsV1Hash,
|
|
2546
|
-
abi:
|
|
2930
|
+
abi: import_abis5.rewardsV1HashAbi,
|
|
2547
2931
|
functionName: "cycleHashes",
|
|
2548
2932
|
args: [rewardsCycleIndex],
|
|
2549
2933
|
chainId
|
|
@@ -2563,9 +2947,9 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2563
2947
|
const {
|
|
2564
2948
|
payload: { chainId: payloadChainId, cycle, wallet, amount }
|
|
2565
2949
|
} = latestClaimablePayload;
|
|
2566
|
-
const claimable = await (0,
|
|
2950
|
+
const claimable = await (0, import_core7.readContract)(wagmiConfig, {
|
|
2567
2951
|
address: rewardsV1,
|
|
2568
|
-
abi:
|
|
2952
|
+
abi: import_abis5.rewardsV1Abi,
|
|
2569
2953
|
functionName: "getClaimableAmount",
|
|
2570
2954
|
args: [{ chainId: payloadChainId, cycle, wallet, amount }],
|
|
2571
2955
|
chainId
|
|
@@ -2579,10 +2963,10 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2579
2963
|
};
|
|
2580
2964
|
|
|
2581
2965
|
// functions/getUserV1.ts
|
|
2582
|
-
var
|
|
2583
|
-
var
|
|
2966
|
+
var import_abis6 = require("@tokemak/abis");
|
|
2967
|
+
var import_core8 = require("@wagmi/core");
|
|
2584
2968
|
var import_config5 = require("@tokemak/config");
|
|
2585
|
-
var
|
|
2969
|
+
var import_chains9 = require("viem/chains");
|
|
2586
2970
|
var getUserV1 = async (wagmiConfig, {
|
|
2587
2971
|
currentCycleIndex,
|
|
2588
2972
|
address,
|
|
@@ -2597,14 +2981,14 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2597
2981
|
autoEthGuardedRewards,
|
|
2598
2982
|
rewardsV1,
|
|
2599
2983
|
missedTokeRewards
|
|
2600
|
-
} = (0, import_config5.getMainnetConfig)(
|
|
2984
|
+
} = (0, import_config5.getMainnetConfig)(import_chains9.mainnet.id);
|
|
2601
2985
|
try {
|
|
2602
|
-
const userStakedTokeV1 = await (0,
|
|
2986
|
+
const userStakedTokeV1 = await (0, import_core8.readContract)(wagmiConfig, {
|
|
2603
2987
|
address: stakingV1,
|
|
2604
|
-
abi:
|
|
2988
|
+
abi: import_abis6.stakingV1Abi,
|
|
2605
2989
|
functionName: "availableForWithdrawal",
|
|
2606
2990
|
args: [address, 0n],
|
|
2607
|
-
chainId:
|
|
2991
|
+
chainId: import_chains9.mainnet.id
|
|
2608
2992
|
});
|
|
2609
2993
|
const tokeRewards = await getUserRewardsV1(wagmiConfig, {
|
|
2610
2994
|
address,
|
|
@@ -2631,9 +3015,9 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2631
3015
|
const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
|
|
2632
3016
|
const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
|
|
2633
3017
|
const amount = autoEthGuardedRewardsPayload?.payload?.amount;
|
|
2634
|
-
const claimableAutoEth = await (0,
|
|
3018
|
+
const claimableAutoEth = await (0, import_core8.readContract)(wagmiConfig, {
|
|
2635
3019
|
address: autoEthGuardedRewards,
|
|
2636
|
-
abi:
|
|
3020
|
+
abi: import_abis6.rewardsV1Abi,
|
|
2637
3021
|
functionName: "getClaimableAmount",
|
|
2638
3022
|
args: [
|
|
2639
3023
|
{
|
|
@@ -2655,9 +3039,9 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2655
3039
|
const {
|
|
2656
3040
|
payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
|
|
2657
3041
|
} = missedTokeRewardsPayload;
|
|
2658
|
-
claimableMissedToke = await (0,
|
|
3042
|
+
claimableMissedToke = await (0, import_core8.readContract)(wagmiConfig, {
|
|
2659
3043
|
address: missedTokeRewards,
|
|
2660
|
-
abi:
|
|
3044
|
+
abi: import_abis6.rewardsV1Abi,
|
|
2661
3045
|
functionName: "getClaimableAmount",
|
|
2662
3046
|
args: [
|
|
2663
3047
|
{
|
|
@@ -2686,18 +3070,18 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2686
3070
|
};
|
|
2687
3071
|
|
|
2688
3072
|
// functions/getChainUserAutopoolsHistory.tsx
|
|
2689
|
-
var
|
|
2690
|
-
var
|
|
3073
|
+
var import_graph_cli9 = require("@tokemak/graph-cli");
|
|
3074
|
+
var import_constants15 = require("@tokemak/constants");
|
|
2691
3075
|
var getChainUserAutopoolsHistory = async ({
|
|
2692
3076
|
address,
|
|
2693
3077
|
chainId = 1
|
|
2694
3078
|
}) => {
|
|
2695
|
-
const { GetUserVaultsDayData } = (0,
|
|
3079
|
+
const { GetUserVaultsDayData } = (0, import_graph_cli9.getSdkByChainId)(chainId);
|
|
2696
3080
|
try {
|
|
2697
3081
|
if (address) {
|
|
2698
3082
|
const { userVaultDayDatas } = await GetUserVaultsDayData({
|
|
2699
3083
|
address,
|
|
2700
|
-
timestamp:
|
|
3084
|
+
timestamp: import_constants15.TOKEMAK_LAUNCH_TIMESTAMP
|
|
2701
3085
|
});
|
|
2702
3086
|
return userVaultDayDatas;
|
|
2703
3087
|
}
|
|
@@ -2709,24 +3093,24 @@ var getChainUserAutopoolsHistory = async ({
|
|
|
2709
3093
|
};
|
|
2710
3094
|
|
|
2711
3095
|
// functions/getUserAutopoolsHistory.ts
|
|
2712
|
-
var
|
|
3096
|
+
var import_utils23 = require("@tokemak/utils");
|
|
2713
3097
|
|
|
2714
3098
|
// functions/getTokenValueDayDatas.ts
|
|
2715
|
-
var
|
|
2716
|
-
var
|
|
2717
|
-
var
|
|
2718
|
-
var
|
|
2719
|
-
var getTokenValueDayDatas = async (tokenAddress, chainId =
|
|
2720
|
-
const { GetTokenValueDayDatas } = (0,
|
|
3099
|
+
var import_chains10 = require("viem/chains");
|
|
3100
|
+
var import_utils20 = require("@tokemak/utils");
|
|
3101
|
+
var import_viem10 = require("viem");
|
|
3102
|
+
var import_graph_cli10 = require("@tokemak/graph-cli");
|
|
3103
|
+
var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainnet.id) => {
|
|
3104
|
+
const { GetTokenValueDayDatas } = (0, import_graph_cli10.getSdkByChainId)(chainId);
|
|
2721
3105
|
try {
|
|
2722
3106
|
const { tokenValueDayDatas } = await GetTokenValueDayDatas({
|
|
2723
3107
|
tokenAddress: tokenAddress.toLowerCase()
|
|
2724
3108
|
});
|
|
2725
3109
|
const historicalPrice = tokenValueDayDatas.map((tokenValueDayData) => {
|
|
2726
|
-
const date = (0,
|
|
3110
|
+
const date = (0, import_utils20.convertTimestampToDate)(
|
|
2727
3111
|
tokenValueDayData.lastSnapshotTimestamp
|
|
2728
3112
|
);
|
|
2729
|
-
const usdPrice = (0,
|
|
3113
|
+
const usdPrice = (0, import_viem10.formatUnits)(tokenValueDayData.priceInUsd, 8);
|
|
2730
3114
|
return {
|
|
2731
3115
|
timestamp: Number(tokenValueDayData.lastSnapshotTimestamp),
|
|
2732
3116
|
date,
|
|
@@ -2741,7 +3125,7 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains9.mainne
|
|
|
2741
3125
|
|
|
2742
3126
|
// functions/getTokenPrices.ts
|
|
2743
3127
|
var import_tokenlist6 = require("@tokemak/tokenlist");
|
|
2744
|
-
var
|
|
3128
|
+
var import_constants16 = require("@tokemak/constants");
|
|
2745
3129
|
|
|
2746
3130
|
// functions/getBackupTokenPrices.ts
|
|
2747
3131
|
var getBackupTokenPrices = async () => {
|
|
@@ -2794,7 +3178,7 @@ var getTokenPrices = async (isCronJob = false) => {
|
|
|
2794
3178
|
timeoutMS: 5 * 1e3
|
|
2795
3179
|
}))
|
|
2796
3180
|
};
|
|
2797
|
-
const response = await fetch(`${
|
|
3181
|
+
const response = await fetch(`${import_constants16.TOKEMAK_PRICES_STAGING_URL}`, {
|
|
2798
3182
|
method: "POST",
|
|
2799
3183
|
headers: {
|
|
2800
3184
|
"Content-Type": "application/json"
|
|
@@ -2990,7 +3374,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
2990
3374
|
Math.floor(sharesRatio * Number(SCALE))
|
|
2991
3375
|
);
|
|
2992
3376
|
const navBigInt = sharesRatioBigInt * BigInt(dayData.nav) / SCALE;
|
|
2993
|
-
const navNum = (0,
|
|
3377
|
+
const navNum = (0, import_utils23.formatUnitsNum)(
|
|
2994
3378
|
navBigInt,
|
|
2995
3379
|
dayData.baseAsset.decimals
|
|
2996
3380
|
);
|
|
@@ -3061,7 +3445,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3061
3445
|
let finalAggregatedHistoryArray = Object.keys(aggregatedHistoryArray).map(
|
|
3062
3446
|
(dateKey) => ({
|
|
3063
3447
|
date: aggregatedHistoryArray[dateKey].date,
|
|
3064
|
-
formattedDate: (0,
|
|
3448
|
+
formattedDate: (0, import_utils23.formatDateToReadable)(aggregatedHistoryArray[dateKey].date),
|
|
3065
3449
|
nav: {
|
|
3066
3450
|
ETH: aggregatedHistoryArray[dateKey].nav.ETH,
|
|
3067
3451
|
USD: aggregatedHistoryArray[dateKey].nav.USD,
|
|
@@ -3109,7 +3493,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3109
3493
|
return sum;
|
|
3110
3494
|
}
|
|
3111
3495
|
const decimals = vault.baseAsset.decimals;
|
|
3112
|
-
const assetChangeNum = (0,
|
|
3496
|
+
const assetChangeNum = (0, import_utils23.formatUnitsNum)(
|
|
3113
3497
|
BigInt(event.assetChange || 0n),
|
|
3114
3498
|
decimals
|
|
3115
3499
|
);
|
|
@@ -3133,8 +3517,8 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3133
3517
|
};
|
|
3134
3518
|
|
|
3135
3519
|
// functions/getUserSushiLP.ts
|
|
3136
|
-
var
|
|
3137
|
-
var
|
|
3520
|
+
var import_core9 = require("@wagmi/core");
|
|
3521
|
+
var import_abis7 = require("@tokemak/abis");
|
|
3138
3522
|
var import_config6 = require("@tokemak/config");
|
|
3139
3523
|
var getUserSushiLP = async (wagmiConfig, {
|
|
3140
3524
|
sushiLP,
|
|
@@ -3150,25 +3534,25 @@ var getUserSushiLP = async (wagmiConfig, {
|
|
|
3150
3534
|
{ result: sushiLPBalance },
|
|
3151
3535
|
{ result: tSushiLPBalance },
|
|
3152
3536
|
{ result: tSushiLPRequested }
|
|
3153
|
-
] = await (0,
|
|
3537
|
+
] = await (0, import_core9.readContracts)(wagmiConfig, {
|
|
3154
3538
|
contracts: [
|
|
3155
3539
|
{
|
|
3156
3540
|
address: sushiPool,
|
|
3157
|
-
abi:
|
|
3541
|
+
abi: import_abis7.sushiPoolAbi,
|
|
3158
3542
|
functionName: "balanceOf",
|
|
3159
3543
|
args: [address],
|
|
3160
3544
|
chainId
|
|
3161
3545
|
},
|
|
3162
3546
|
{
|
|
3163
3547
|
address: tSushiLP,
|
|
3164
|
-
abi:
|
|
3548
|
+
abi: import_abis7.poolV1Abi,
|
|
3165
3549
|
functionName: "balanceOf",
|
|
3166
3550
|
args: [address],
|
|
3167
3551
|
chainId
|
|
3168
3552
|
},
|
|
3169
3553
|
{
|
|
3170
3554
|
address: tSushiLP,
|
|
3171
|
-
abi:
|
|
3555
|
+
abi: import_abis7.poolV1Abi,
|
|
3172
3556
|
functionName: "requestedWithdrawals",
|
|
3173
3557
|
args: [address],
|
|
3174
3558
|
chainId
|
|
@@ -3178,18 +3562,18 @@ var getUserSushiLP = async (wagmiConfig, {
|
|
|
3178
3562
|
const [
|
|
3179
3563
|
{ result: startTSushiLPBalance },
|
|
3180
3564
|
{ result: startTSushiLPRequested }
|
|
3181
|
-
] = await (0,
|
|
3565
|
+
] = await (0, import_core9.readContracts)(wagmiConfig, {
|
|
3182
3566
|
contracts: [
|
|
3183
3567
|
{
|
|
3184
3568
|
address: tSushiLP,
|
|
3185
|
-
abi:
|
|
3569
|
+
abi: import_abis7.poolV1Abi,
|
|
3186
3570
|
functionName: "balanceOf",
|
|
3187
3571
|
args: [address],
|
|
3188
3572
|
chainId
|
|
3189
3573
|
},
|
|
3190
3574
|
{
|
|
3191
3575
|
address: tSushiLP,
|
|
3192
|
-
abi:
|
|
3576
|
+
abi: import_abis7.poolV1Abi,
|
|
3193
3577
|
functionName: "requestedWithdrawals",
|
|
3194
3578
|
args: [address],
|
|
3195
3579
|
chainId
|
|
@@ -3232,8 +3616,8 @@ var getUserSushiLP = async (wagmiConfig, {
|
|
|
3232
3616
|
};
|
|
3233
3617
|
|
|
3234
3618
|
// functions/getUserCurveLP.ts
|
|
3235
|
-
var
|
|
3236
|
-
var
|
|
3619
|
+
var import_core10 = require("@wagmi/core");
|
|
3620
|
+
var import_abis8 = require("@tokemak/abis");
|
|
3237
3621
|
var import_config7 = require("@tokemak/config");
|
|
3238
3622
|
var getUserCurveLP = async (wagmiConfig, {
|
|
3239
3623
|
curveLP,
|
|
@@ -3243,18 +3627,18 @@ var getUserCurveLP = async (wagmiConfig, {
|
|
|
3243
3627
|
try {
|
|
3244
3628
|
const { curvePool, convexRewarder } = (0, import_config7.getMainnetConfig)();
|
|
3245
3629
|
if (address && curveLP && curvePool && convexRewarder) {
|
|
3246
|
-
const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await (0,
|
|
3630
|
+
const [{ result: userCurveLPBalance }, { result: userConvexLPBalance }] = await (0, import_core10.readContracts)(wagmiConfig, {
|
|
3247
3631
|
contracts: [
|
|
3248
3632
|
{
|
|
3249
3633
|
address: curvePool,
|
|
3250
|
-
abi:
|
|
3634
|
+
abi: import_abis8.poolV1Abi,
|
|
3251
3635
|
functionName: "balanceOf",
|
|
3252
3636
|
args: [address],
|
|
3253
3637
|
chainId
|
|
3254
3638
|
},
|
|
3255
3639
|
{
|
|
3256
3640
|
address: convexRewarder,
|
|
3257
|
-
abi:
|
|
3641
|
+
abi: import_abis8.poolV1Abi,
|
|
3258
3642
|
functionName: "balanceOf",
|
|
3259
3643
|
args: [address],
|
|
3260
3644
|
chainId
|
|
@@ -3280,9 +3664,9 @@ var getUserCurveLP = async (wagmiConfig, {
|
|
|
3280
3664
|
};
|
|
3281
3665
|
|
|
3282
3666
|
// functions/getMultipleAutopoolRebalances.ts
|
|
3283
|
-
var
|
|
3667
|
+
var import_graph_cli11 = require("@tokemak/graph-cli");
|
|
3284
3668
|
var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
3285
|
-
const { GetMutlipleAutopoolRebalances } = (0,
|
|
3669
|
+
const { GetMutlipleAutopoolRebalances } = (0, import_graph_cli11.getSdkByChainId)(chainId);
|
|
3286
3670
|
const { autopools } = await GetMutlipleAutopoolRebalances({
|
|
3287
3671
|
addresses: ids
|
|
3288
3672
|
});
|
|
@@ -3290,65 +3674,9 @@ var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
|
3290
3674
|
return rebalances.flat().sort((a, b) => b.timestamp - a.timestamp);
|
|
3291
3675
|
};
|
|
3292
3676
|
|
|
3293
|
-
// functions/getAutopoolDayData.ts
|
|
3294
|
-
var import_viem9 = require("viem");
|
|
3295
|
-
var import_utils17 = require("@tokemak/utils");
|
|
3296
|
-
var import_constants15 = require("@tokemak/constants");
|
|
3297
|
-
var import_graph_cli9 = require("@tokemak/graph-cli");
|
|
3298
|
-
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_constants15.TOKEMAK_LAUNCH_TIMESTAMP) => {
|
|
3299
|
-
try {
|
|
3300
|
-
const { GetAutopoolDayData } = (0, import_graph_cli9.getSdkByChainId)(chainId);
|
|
3301
|
-
const { autopoolDayDatas } = await GetAutopoolDayData({
|
|
3302
|
-
address,
|
|
3303
|
-
timestamp: startTimestamp
|
|
3304
|
-
});
|
|
3305
|
-
const formattedDayDatas = autopoolDayDatas.map((autoPoolDayData) => {
|
|
3306
|
-
const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
|
|
3307
|
-
let baseApy = autoPoolDayData.autopoolApy;
|
|
3308
|
-
let rewarderApy = 0;
|
|
3309
|
-
const formattedRewarder7DayMAApy = (0, import_utils17.formatEtherNum)(
|
|
3310
|
-
BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
|
|
3311
|
-
);
|
|
3312
|
-
const formattedRewarder30DayMAApy = (0, import_utils17.formatEtherNum)(
|
|
3313
|
-
BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
|
|
3314
|
-
);
|
|
3315
|
-
if (formattedRewarder7DayMAApy) {
|
|
3316
|
-
rewarderApy = formattedRewarder7DayMAApy;
|
|
3317
|
-
}
|
|
3318
|
-
if (formattedRewarder30DayMAApy) {
|
|
3319
|
-
rewarderApy = formattedRewarder30DayMAApy;
|
|
3320
|
-
}
|
|
3321
|
-
if (!baseApy) {
|
|
3322
|
-
baseApy = 0;
|
|
3323
|
-
} else {
|
|
3324
|
-
baseApy = Number(
|
|
3325
|
-
(0, import_viem9.formatUnits)(BigInt(baseApy), autoPoolDayData.baseAsset.decimals)
|
|
3326
|
-
);
|
|
3327
|
-
}
|
|
3328
|
-
if (baseApy < 0) {
|
|
3329
|
-
baseApy = 0;
|
|
3330
|
-
}
|
|
3331
|
-
const combinedApy = rewarderApy + baseApy;
|
|
3332
|
-
return {
|
|
3333
|
-
...autoPoolDayData,
|
|
3334
|
-
navPerShare,
|
|
3335
|
-
rewarderApy,
|
|
3336
|
-
baseApy,
|
|
3337
|
-
combinedApy,
|
|
3338
|
-
date: new Date(Number(autoPoolDayData.timestamp) * 1e3)
|
|
3339
|
-
};
|
|
3340
|
-
});
|
|
3341
|
-
const filledDayDatas = fillMissingDates(formattedDayDatas);
|
|
3342
|
-
return filledDayDatas;
|
|
3343
|
-
} catch (e) {
|
|
3344
|
-
console.log(e);
|
|
3345
|
-
return [];
|
|
3346
|
-
}
|
|
3347
|
-
};
|
|
3348
|
-
|
|
3349
3677
|
// functions/getSystemConfig.ts
|
|
3350
|
-
var
|
|
3351
|
-
var
|
|
3678
|
+
var import_core11 = require("@wagmi/core");
|
|
3679
|
+
var import_abis9 = require("@tokemak/abis");
|
|
3352
3680
|
var systemRegistryFunctionNames = [
|
|
3353
3681
|
"asyncSwapperRegistry",
|
|
3354
3682
|
"autoPoolRouter",
|
|
@@ -3359,7 +3687,7 @@ var systemRegistryFunctionNames = [
|
|
|
3359
3687
|
var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
3360
3688
|
const systemRegistryContract = {
|
|
3361
3689
|
address: systemRegistry,
|
|
3362
|
-
abi:
|
|
3690
|
+
abi: import_abis9.systemRegistryAbi
|
|
3363
3691
|
};
|
|
3364
3692
|
const systemRegistryCalls = systemRegistryFunctionNames.map(
|
|
3365
3693
|
(functionName) => ({
|
|
@@ -3373,7 +3701,7 @@ var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
|
3373
3701
|
{ result: autopoolRouter },
|
|
3374
3702
|
{ result: autopoolRegistry },
|
|
3375
3703
|
{ result: swapRouter }
|
|
3376
|
-
] = await (0,
|
|
3704
|
+
] = await (0, import_core11.readContracts)(wagmiConfig, {
|
|
3377
3705
|
contracts: systemRegistryCalls
|
|
3378
3706
|
});
|
|
3379
3707
|
return {
|
|
@@ -3388,12 +3716,12 @@ var getSystemConfig = async (wagmiConfig, { systemRegistry }) => {
|
|
|
3388
3716
|
};
|
|
3389
3717
|
|
|
3390
3718
|
// functions/getChainUserAutopools.tsx
|
|
3391
|
-
var
|
|
3719
|
+
var import_graph_cli12 = require("@tokemak/graph-cli");
|
|
3392
3720
|
var getChainUserAutopools = async ({
|
|
3393
3721
|
address,
|
|
3394
3722
|
chainId = 1
|
|
3395
3723
|
}) => {
|
|
3396
|
-
const { GetUserVaultInfo } = (0,
|
|
3724
|
+
const { GetUserVaultInfo } = (0, import_graph_cli12.getSdkByChainId)(chainId);
|
|
3397
3725
|
try {
|
|
3398
3726
|
if (address) {
|
|
3399
3727
|
const { userInfo } = await GetUserVaultInfo({
|
|
@@ -3409,14 +3737,14 @@ var getChainUserAutopools = async ({
|
|
|
3409
3737
|
};
|
|
3410
3738
|
|
|
3411
3739
|
// functions/getUserAutopools.ts
|
|
3412
|
-
var
|
|
3740
|
+
var import_utils25 = require("@tokemak/utils");
|
|
3413
3741
|
var import_tokenlist8 = require("@tokemak/tokenlist");
|
|
3414
3742
|
|
|
3415
3743
|
// functions/getUserAutopool.tsx
|
|
3416
|
-
var
|
|
3417
|
-
var
|
|
3418
|
-
var
|
|
3419
|
-
var
|
|
3744
|
+
var import_viem11 = require("viem");
|
|
3745
|
+
var import_core12 = require("@wagmi/core");
|
|
3746
|
+
var import_utils24 = require("@tokemak/utils");
|
|
3747
|
+
var import_abis10 = require("@tokemak/abis");
|
|
3420
3748
|
var getUserAutopool = async (wagmiConfig, {
|
|
3421
3749
|
address,
|
|
3422
3750
|
autopool
|
|
@@ -3425,14 +3753,14 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3425
3753
|
if (autopool && address) {
|
|
3426
3754
|
const autopoolContract = {
|
|
3427
3755
|
address: autopool?.poolAddress,
|
|
3428
|
-
abi:
|
|
3756
|
+
abi: import_abis10.autopoolEthAbi,
|
|
3429
3757
|
chainId: autopool?.chain?.chainId
|
|
3430
3758
|
};
|
|
3431
3759
|
const [
|
|
3432
3760
|
{ result: autopoolRewarderContract },
|
|
3433
3761
|
{ result: pastRewarders },
|
|
3434
3762
|
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
3435
|
-
] = await (0,
|
|
3763
|
+
] = await (0, import_core12.readContracts)(wagmiConfig, {
|
|
3436
3764
|
contracts: [
|
|
3437
3765
|
{
|
|
3438
3766
|
...autopoolContract,
|
|
@@ -3457,17 +3785,17 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3457
3785
|
if (unstakedPoolSharesError) {
|
|
3458
3786
|
throw new Error("Error fetching unstaked pool shares");
|
|
3459
3787
|
}
|
|
3460
|
-
const stakedPoolShares = await (0,
|
|
3788
|
+
const stakedPoolShares = await (0, import_core12.readContract)(wagmiConfig, {
|
|
3461
3789
|
address: autopoolRewarderContract,
|
|
3462
|
-
abi:
|
|
3790
|
+
abi: import_viem11.erc20Abi,
|
|
3463
3791
|
functionName: "balanceOf",
|
|
3464
3792
|
args: [address],
|
|
3465
3793
|
chainId: autopool?.chain?.chainId
|
|
3466
3794
|
});
|
|
3467
|
-
const stakedShares = (0,
|
|
3795
|
+
const stakedShares = (0, import_utils24.formatEtherNum)(stakedPoolShares);
|
|
3468
3796
|
const stakedNav = stakedShares * (autopool?.navPerShare.baseAsset || 0);
|
|
3469
3797
|
const stakedNavUsd = stakedShares * (autopool?.navPerShare.USD || 0);
|
|
3470
|
-
const unstakedShares = (0,
|
|
3798
|
+
const unstakedShares = (0, import_utils24.formatEtherNum)(unstakedPoolShares || 0n);
|
|
3471
3799
|
const unstakedNav = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
3472
3800
|
const unstakedNavUsd = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
3473
3801
|
const totalShares = unstakedShares + stakedShares;
|
|
@@ -3478,17 +3806,17 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3478
3806
|
if (pastRewarders && pastRewarders?.length > 0) {
|
|
3479
3807
|
const pastRewardBalances = pastRewarders.map((rewarder) => ({
|
|
3480
3808
|
address: rewarder,
|
|
3481
|
-
abi:
|
|
3809
|
+
abi: import_viem11.erc20Abi,
|
|
3482
3810
|
functionName: "balanceOf",
|
|
3483
3811
|
args: [address],
|
|
3484
3812
|
chainId: autopool?.chain?.chainId
|
|
3485
3813
|
}));
|
|
3486
|
-
const pastRewards = await (0,
|
|
3814
|
+
const pastRewards = await (0, import_core12.readContracts)(wagmiConfig, {
|
|
3487
3815
|
contracts: pastRewardBalances
|
|
3488
3816
|
});
|
|
3489
3817
|
pastRewarderBalances = pastRewards.map(({ result }, index) => {
|
|
3490
3818
|
const balance = result;
|
|
3491
|
-
const shares = (0,
|
|
3819
|
+
const shares = (0, import_utils24.formatEtherNum)(result);
|
|
3492
3820
|
const nav = shares * (autopool?.navPerShare.baseAsset || 0);
|
|
3493
3821
|
const navUsd = shares * (autopool?.navPerShare.USD || 0);
|
|
3494
3822
|
return {
|
|
@@ -3606,14 +3934,14 @@ var getUserAutopools = async ({
|
|
|
3606
3934
|
);
|
|
3607
3935
|
if (autopoolData) {
|
|
3608
3936
|
const isDOLA = autopoolData.symbol === "autoDOLA" && userAutoDOLA;
|
|
3609
|
-
const userShares = isDOLA ? userAutoDOLA?.totalShares : (0,
|
|
3610
|
-
const totalVaultShares = (0,
|
|
3937
|
+
const userShares = isDOLA ? userAutoDOLA?.totalShares : (0, import_utils25.formatEtherNum)(userAutopool?.totalShares);
|
|
3938
|
+
const totalVaultShares = (0, import_utils25.formatEtherNum)(autopoolData?.totalSupply);
|
|
3611
3939
|
const userShareOfVault = userShares / totalVaultShares;
|
|
3612
|
-
const totalDeposits = (0,
|
|
3940
|
+
const totalDeposits = (0, import_utils25.formatUnitsNum)(
|
|
3613
3941
|
userActivity?.totals[userAutopool.vaultAddress]?.totalDeposits || 0n,
|
|
3614
3942
|
autopoolData?.baseAsset.decimals
|
|
3615
3943
|
);
|
|
3616
|
-
const totalWithdrawals = (0,
|
|
3944
|
+
const totalWithdrawals = (0, import_utils25.formatUnitsNum)(
|
|
3617
3945
|
userActivity?.totals[userAutopool.vaultAddress]?.totalWithdrawals || 0n,
|
|
3618
3946
|
autopoolData?.baseAsset.decimals
|
|
3619
3947
|
);
|
|
@@ -3622,7 +3950,7 @@ var getUserAutopools = async ({
|
|
|
3622
3950
|
);
|
|
3623
3951
|
let lastDeposit;
|
|
3624
3952
|
if (poolEvents && poolEvents?.length > 0) {
|
|
3625
|
-
lastDeposit = (0,
|
|
3953
|
+
lastDeposit = (0, import_utils25.convertTimestampToDate)(
|
|
3626
3954
|
poolEvents[poolEvents.length - 1].timestamp
|
|
3627
3955
|
).toLocaleDateString("en-US", {
|
|
3628
3956
|
day: "2-digit",
|
|
@@ -3722,7 +4050,7 @@ var getUserAutopools = async ({
|
|
|
3722
4050
|
totalWithdrawals: prev.totalWithdrawals + totalWithdrawals
|
|
3723
4051
|
};
|
|
3724
4052
|
const stakedBalance = isDOLA ? userAutoDOLA?.staked.balance : BigInt(userAutopool?.stakedShares);
|
|
3725
|
-
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0,
|
|
4053
|
+
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0, import_utils25.formatEtherNum)(stakedBalance);
|
|
3726
4054
|
const stakedNav = stakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
3727
4055
|
const staked = convertBaseAssetToTokenPrices(
|
|
3728
4056
|
stakedNav,
|
|
@@ -3730,7 +4058,7 @@ var getUserAutopools = async ({
|
|
|
3730
4058
|
prices
|
|
3731
4059
|
);
|
|
3732
4060
|
const unstakedBalance = isDOLA ? userAutoDOLA?.unstaked.balance : BigInt(userAutopool?.walletShares);
|
|
3733
|
-
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0,
|
|
4061
|
+
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0, import_utils25.formatEtherNum)(unstakedBalance);
|
|
3734
4062
|
const unstakedNav = unstakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
3735
4063
|
const unstaked = convertBaseAssetToTokenPrices(
|
|
3736
4064
|
unstakedNav,
|
|
@@ -3922,15 +4250,15 @@ var getUserAutopools = async ({
|
|
|
3922
4250
|
};
|
|
3923
4251
|
|
|
3924
4252
|
// functions/getUserTokenBalances.ts
|
|
3925
|
-
var
|
|
3926
|
-
var
|
|
4253
|
+
var import_viem12 = require("viem");
|
|
4254
|
+
var import_chains11 = require("viem/chains");
|
|
3927
4255
|
var networkToAlchemyUrl = (chainId, apiKey) => {
|
|
3928
4256
|
switch (chainId) {
|
|
3929
|
-
case
|
|
4257
|
+
case import_chains11.mainnet.id:
|
|
3930
4258
|
return `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`;
|
|
3931
|
-
case
|
|
4259
|
+
case import_chains11.base.id:
|
|
3932
4260
|
return `https://base-mainnet.g.alchemy.com/v2/${apiKey}`;
|
|
3933
|
-
case
|
|
4261
|
+
case import_chains11.sonic.id:
|
|
3934
4262
|
return `https://sonic-mainnet.g.alchemy.com/v2/${apiKey}`;
|
|
3935
4263
|
default:
|
|
3936
4264
|
throw new Error("Unsupported network");
|
|
@@ -3963,7 +4291,7 @@ var getUserTokenBalances = async ({
|
|
|
3963
4291
|
const tokenBalances = data.result.tokenBalances.reduce(
|
|
3964
4292
|
(acc, balance) => {
|
|
3965
4293
|
if (balance.tokenBalance && BigInt(balance.tokenBalance) !== BigInt(0)) {
|
|
3966
|
-
acc[balance.contractAddress] = (0,
|
|
4294
|
+
acc[balance.contractAddress] = (0, import_viem12.hexToBigInt)(
|
|
3967
4295
|
balance.tokenBalance
|
|
3968
4296
|
);
|
|
3969
4297
|
}
|
|
@@ -3989,10 +4317,10 @@ var getTokenList = async () => {
|
|
|
3989
4317
|
};
|
|
3990
4318
|
|
|
3991
4319
|
// functions/getTopAutopoolHolders.ts
|
|
3992
|
-
var
|
|
4320
|
+
var import_graph_cli13 = require("@tokemak/graph-cli");
|
|
3993
4321
|
var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
3994
4322
|
try {
|
|
3995
|
-
const { GetTopAutopoolHolders } = (0,
|
|
4323
|
+
const { GetTopAutopoolHolders } = (0, import_graph_cli13.getSdkByChainId)(chainId);
|
|
3996
4324
|
const { holders } = await GetTopAutopoolHolders({
|
|
3997
4325
|
address: autopoolAddress
|
|
3998
4326
|
});
|
|
@@ -4004,17 +4332,17 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
|
4004
4332
|
};
|
|
4005
4333
|
|
|
4006
4334
|
// functions/getAllowance.ts
|
|
4007
|
-
var
|
|
4008
|
-
var
|
|
4335
|
+
var import_core13 = require("@wagmi/core");
|
|
4336
|
+
var import_viem13 = require("viem");
|
|
4009
4337
|
var getAllowance = async (wagmiConfig, {
|
|
4010
4338
|
token,
|
|
4011
4339
|
address,
|
|
4012
4340
|
spender
|
|
4013
4341
|
}) => {
|
|
4014
4342
|
try {
|
|
4015
|
-
const allowance = await (0,
|
|
4343
|
+
const allowance = await (0, import_core13.readContract)(wagmiConfig, {
|
|
4016
4344
|
address: token,
|
|
4017
|
-
abi:
|
|
4345
|
+
abi: import_viem13.erc20Abi,
|
|
4018
4346
|
functionName: "allowance",
|
|
4019
4347
|
args: [address || "0x0", spender]
|
|
4020
4348
|
});
|
|
@@ -4055,21 +4383,21 @@ var getUserActivity = async ({
|
|
|
4055
4383
|
};
|
|
4056
4384
|
|
|
4057
4385
|
// functions/getUserAutopoolsRewards.ts
|
|
4058
|
-
var
|
|
4386
|
+
var import_viem14 = require("viem");
|
|
4059
4387
|
|
|
4060
4388
|
// functions/getChainUserAutopoolsRewards.ts
|
|
4061
4389
|
var import_config8 = require("@tokemak/config");
|
|
4062
|
-
var
|
|
4063
|
-
var
|
|
4390
|
+
var import_core14 = require("@wagmi/core");
|
|
4391
|
+
var import_abis11 = require("@tokemak/abis");
|
|
4064
4392
|
var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
4065
4393
|
chainId,
|
|
4066
4394
|
address
|
|
4067
4395
|
}) => {
|
|
4068
4396
|
try {
|
|
4069
4397
|
const coreConfig = (0, import_config8.getCoreConfig)(chainId);
|
|
4070
|
-
const userRewardsInfo = await (0,
|
|
4398
|
+
const userRewardsInfo = await (0, import_core14.readContract)(wagmiConfig, {
|
|
4071
4399
|
address: coreConfig.lens,
|
|
4072
|
-
abi:
|
|
4400
|
+
abi: import_abis11.lensAbi,
|
|
4073
4401
|
functionName: "getUserRewardInfo",
|
|
4074
4402
|
args: [address],
|
|
4075
4403
|
chainId: coreConfig.id
|
|
@@ -4099,9 +4427,9 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4099
4427
|
};
|
|
4100
4428
|
|
|
4101
4429
|
// functions/getUserAutopoolsRewards.ts
|
|
4102
|
-
var
|
|
4430
|
+
var import_utils29 = require("@tokemak/utils");
|
|
4103
4431
|
var import_tokenlist10 = require("@tokemak/tokenlist");
|
|
4104
|
-
var
|
|
4432
|
+
var import_chains12 = require("viem/chains");
|
|
4105
4433
|
var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
4106
4434
|
address,
|
|
4107
4435
|
tokenPrices,
|
|
@@ -4124,27 +4452,27 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4124
4452
|
const extraRewardsArray = Object.entries(chainUserRewards).flatMap(
|
|
4125
4453
|
([autopoolAddress, rewards]) => {
|
|
4126
4454
|
const autopool = autopools.find(
|
|
4127
|
-
(autopool2) => (0,
|
|
4455
|
+
(autopool2) => (0, import_viem14.getAddress)(autopool2.poolAddress) === (0, import_viem14.getAddress)(autopoolAddress)
|
|
4128
4456
|
);
|
|
4129
4457
|
if (!autopool || !autopool.extraRewarders) {
|
|
4130
4458
|
return [];
|
|
4131
4459
|
}
|
|
4132
4460
|
return autopool.extraRewarders.map((extraRewards2) => {
|
|
4133
|
-
const rewarderToken = (0,
|
|
4461
|
+
const rewarderToken = (0, import_utils29.getToken)(
|
|
4134
4462
|
extraRewards2.rewardToken?.id,
|
|
4135
4463
|
autopool.chain?.chainId
|
|
4136
4464
|
);
|
|
4137
|
-
const claimableAmount = rewards ? rewards[(0,
|
|
4465
|
+
const claimableAmount = rewards ? rewards[(0, import_viem14.getAddress)(extraRewards2.rewardToken?.id)] : 0n;
|
|
4138
4466
|
let price = tokenPrices[rewarderToken.symbol] || 0;
|
|
4139
4467
|
if (rewarderToken.symbol === "XSILO") {
|
|
4140
4468
|
price = tokenPrices[import_tokenlist10.SILO_TOKEN.symbol] || 0;
|
|
4141
4469
|
}
|
|
4142
|
-
const formattedAmount = (0,
|
|
4470
|
+
const formattedAmount = (0, import_utils29.formatUnitsNum)(
|
|
4143
4471
|
claimableAmount,
|
|
4144
4472
|
rewarderToken.decimals || 18
|
|
4145
4473
|
);
|
|
4146
4474
|
return {
|
|
4147
|
-
address: (0,
|
|
4475
|
+
address: (0, import_viem14.getAddress)(extraRewards2?.id),
|
|
4148
4476
|
chainId,
|
|
4149
4477
|
token: rewarderToken,
|
|
4150
4478
|
amount: claimableAmount,
|
|
@@ -4157,7 +4485,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4157
4485
|
const tokenRewards = {};
|
|
4158
4486
|
Object.values(chainUserRewards).forEach((autopoolRewards) => {
|
|
4159
4487
|
Object.entries(autopoolRewards).forEach(([tokenAddress, amount]) => {
|
|
4160
|
-
const token = (0,
|
|
4488
|
+
const token = (0, import_utils29.getToken)(tokenAddress, chainId);
|
|
4161
4489
|
const tokenSymbol = token.symbol;
|
|
4162
4490
|
if (!tokenRewards[tokenSymbol]) {
|
|
4163
4491
|
tokenRewards[tokenSymbol] = {
|
|
@@ -4177,7 +4505,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4177
4505
|
if (tokenSymbol === "XSILO") {
|
|
4178
4506
|
price = tokenPrices[import_tokenlist10.SILO_TOKEN.symbol] || 0;
|
|
4179
4507
|
}
|
|
4180
|
-
const formattedAmount = (0,
|
|
4508
|
+
const formattedAmount = (0, import_utils29.formatUnitsNum)(amount, decimals || 18);
|
|
4181
4509
|
tokenRewards[tokenSymbol] = {
|
|
4182
4510
|
amount,
|
|
4183
4511
|
formattedAmount,
|
|
@@ -4186,7 +4514,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4186
4514
|
};
|
|
4187
4515
|
}
|
|
4188
4516
|
);
|
|
4189
|
-
if (Object.keys(tokenRewards).includes("undefined") && chainId ===
|
|
4517
|
+
if (Object.keys(tokenRewards).includes("undefined") && chainId === import_chains12.plasma.id) {
|
|
4190
4518
|
const undefinedToken = tokenRewards["undefined"];
|
|
4191
4519
|
let price = tokenPrices.TOKE || 0;
|
|
4192
4520
|
tokenRewards["TOKE"] = {
|
|
@@ -4247,24 +4575,24 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4247
4575
|
};
|
|
4248
4576
|
|
|
4249
4577
|
// functions/getAmountWithdrawn.ts
|
|
4250
|
-
var
|
|
4251
|
-
var
|
|
4578
|
+
var import_viem16 = require("viem");
|
|
4579
|
+
var import_utils31 = require("@tokemak/utils");
|
|
4252
4580
|
|
|
4253
4581
|
// functions/getSwapQuote.ts
|
|
4254
|
-
var
|
|
4582
|
+
var import_constants17 = require("@tokemak/constants");
|
|
4255
4583
|
|
|
4256
4584
|
// functions/getAddressFromSystemRegistry.ts
|
|
4257
|
-
var
|
|
4585
|
+
var import_core15 = require("@wagmi/core");
|
|
4258
4586
|
var import_config9 = require("@tokemak/config");
|
|
4259
|
-
var
|
|
4587
|
+
var import_abis12 = require("@tokemak/abis");
|
|
4260
4588
|
var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
4261
4589
|
chainId,
|
|
4262
4590
|
functionName
|
|
4263
4591
|
}) => {
|
|
4264
4592
|
const { systemRegistry } = (0, import_config9.getCoreConfig)(chainId);
|
|
4265
|
-
return await (0,
|
|
4593
|
+
return await (0, import_core15.readContract)(wagmiConfig, {
|
|
4266
4594
|
address: systemRegistry,
|
|
4267
|
-
abi:
|
|
4595
|
+
abi: import_abis12.systemRegistryAbi,
|
|
4268
4596
|
functionName,
|
|
4269
4597
|
chainId
|
|
4270
4598
|
});
|
|
@@ -4279,7 +4607,7 @@ var getAutopilotRouter = async (wagmiConfig, { chainId }) => await getAddressFro
|
|
|
4279
4607
|
// functions/getSwapQuote.ts
|
|
4280
4608
|
var import_config10 = require("@tokemak/config");
|
|
4281
4609
|
var import_tokenlist11 = require("@tokemak/tokenlist");
|
|
4282
|
-
var
|
|
4610
|
+
var import_chains13 = require("viem/chains");
|
|
4283
4611
|
var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
4284
4612
|
try {
|
|
4285
4613
|
if (!params.sellToken || !params.buyToken) {
|
|
@@ -4287,16 +4615,16 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4287
4615
|
}
|
|
4288
4616
|
if (params.sellToken === import_tokenlist11.ETH_TOKEN.address) {
|
|
4289
4617
|
params.sellToken = (0, import_config10.getCoreConfig)(chainId).weth;
|
|
4290
|
-
if (chainId ===
|
|
4618
|
+
if (chainId === import_chains13.sonic.id) {
|
|
4291
4619
|
params.sellToken = import_tokenlist11.WS_TOKEN.address;
|
|
4292
4620
|
}
|
|
4293
|
-
if (chainId ===
|
|
4621
|
+
if (chainId === import_chains13.plasma.id) {
|
|
4294
4622
|
params.sellToken = import_tokenlist11.WXPL_TOKEN.address;
|
|
4295
4623
|
}
|
|
4296
4624
|
}
|
|
4297
4625
|
const sellAmount = params.sellAmount.toString();
|
|
4298
4626
|
const taker = await getAutopilotRouter(config, { chainId });
|
|
4299
|
-
const response = await fetch(
|
|
4627
|
+
const response = await fetch(import_constants17.TOKEMAK_SWAP_QUOTE_URL, {
|
|
4300
4628
|
method: "POST",
|
|
4301
4629
|
headers: {
|
|
4302
4630
|
"Content-Type": "application/json"
|
|
@@ -4322,12 +4650,12 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4322
4650
|
};
|
|
4323
4651
|
|
|
4324
4652
|
// functions/getDynamicSwap.ts
|
|
4325
|
-
var
|
|
4326
|
-
var
|
|
4653
|
+
var import_core16 = require("@wagmi/core");
|
|
4654
|
+
var import_abis13 = require("@tokemak/abis");
|
|
4327
4655
|
var import_config11 = require("@tokemak/config");
|
|
4328
4656
|
var import_autopilot_swap_route_calc = require("@tokemak/autopilot-swap-route-calc");
|
|
4329
|
-
var
|
|
4330
|
-
var
|
|
4657
|
+
var import_viem15 = require("viem");
|
|
4658
|
+
var import_constants18 = require("@tokemak/constants");
|
|
4331
4659
|
var getDynamicSwap = async ({
|
|
4332
4660
|
address,
|
|
4333
4661
|
amount,
|
|
@@ -4340,7 +4668,7 @@ var getDynamicSwap = async ({
|
|
|
4340
4668
|
let previewRedeem = 0n;
|
|
4341
4669
|
let dynamicSwaps;
|
|
4342
4670
|
let standardPreviewRedeem = false;
|
|
4343
|
-
const client = await (0,
|
|
4671
|
+
const client = await (0, import_core16.getPublicClient)(config, { chainId });
|
|
4344
4672
|
try {
|
|
4345
4673
|
const { systemRegistry } = (0, import_config11.getCoreConfig)(chainId);
|
|
4346
4674
|
client.transport.retryCount = 0;
|
|
@@ -4351,7 +4679,7 @@ var getDynamicSwap = async ({
|
|
|
4351
4679
|
client.transport.transports[0].value.url,
|
|
4352
4680
|
address,
|
|
4353
4681
|
amount,
|
|
4354
|
-
|
|
4682
|
+
import_constants18.LIQUIDATION_PROBE_AMOUNT
|
|
4355
4683
|
);
|
|
4356
4684
|
if (liquidations?.liquidations?.length > 0) {
|
|
4357
4685
|
tokensToLiquidate = liquidations.liquidations;
|
|
@@ -4372,12 +4700,12 @@ var getDynamicSwap = async ({
|
|
|
4372
4700
|
chainId,
|
|
4373
4701
|
systemName: "gen3",
|
|
4374
4702
|
// slippageBps: Math.floor(slippage * 10000),
|
|
4375
|
-
slippageBps:
|
|
4703
|
+
slippageBps: import_constants18.DYNAMIC_SWAP_DEFAULT_SLIPPAGE_BPS,
|
|
4376
4704
|
tokensToLiquidate,
|
|
4377
4705
|
sellAllOnlyCompatible: true
|
|
4378
4706
|
})
|
|
4379
4707
|
};
|
|
4380
|
-
dynamicSwaps = await (await fetch(
|
|
4708
|
+
dynamicSwaps = await (await fetch(import_constants18.TOKEMAK_DYNAMIC_SWAP_ROUTES_URL, requestInit)).json();
|
|
4381
4709
|
if (dynamicSwaps?.success) {
|
|
4382
4710
|
const autopoolRouter = await getAutopilotRouter(config, { chainId });
|
|
4383
4711
|
if (!autopoolRouter) {
|
|
@@ -4386,7 +4714,7 @@ var getDynamicSwap = async ({
|
|
|
4386
4714
|
try {
|
|
4387
4715
|
await client?.simulateContract({
|
|
4388
4716
|
address: autopoolRouter,
|
|
4389
|
-
abi:
|
|
4717
|
+
abi: import_abis13.autopilotRouterAbi,
|
|
4390
4718
|
functionName: "previewRedeemWithRoutes",
|
|
4391
4719
|
args: [
|
|
4392
4720
|
address,
|
|
@@ -4398,10 +4726,10 @@ var getDynamicSwap = async ({
|
|
|
4398
4726
|
data: x.data
|
|
4399
4727
|
}))
|
|
4400
4728
|
],
|
|
4401
|
-
account: user ||
|
|
4729
|
+
account: user || import_constants18.SIMULATION_PLACEHOLDER_ADDRESS
|
|
4402
4730
|
});
|
|
4403
4731
|
} catch (e) {
|
|
4404
|
-
if (e instanceof
|
|
4732
|
+
if (e instanceof import_viem15.ContractFunctionExecutionError && e.cause instanceof import_viem15.ContractFunctionRevertedError && e.cause.data?.errorName === "PreviewRedeemWithRoutesResult") {
|
|
4405
4733
|
previewRedeem = e.cause.data?.args?.[0];
|
|
4406
4734
|
}
|
|
4407
4735
|
}
|
|
@@ -4410,13 +4738,13 @@ var getDynamicSwap = async ({
|
|
|
4410
4738
|
console.log(e);
|
|
4411
4739
|
}
|
|
4412
4740
|
}
|
|
4413
|
-
const previewRedeemOnChain = await (0,
|
|
4741
|
+
const previewRedeemOnChain = await (0, import_core16.readContract)(config, {
|
|
4414
4742
|
address,
|
|
4415
|
-
abi:
|
|
4743
|
+
abi: import_abis13.autopoolEthAbi,
|
|
4416
4744
|
functionName: "previewRedeem",
|
|
4417
4745
|
args: [amount],
|
|
4418
4746
|
chainId,
|
|
4419
|
-
account: user ||
|
|
4747
|
+
account: user || import_constants18.SIMULATION_PLACEHOLDER_ADDRESS
|
|
4420
4748
|
});
|
|
4421
4749
|
if (previewRedeemOnChain >= previewRedeem) {
|
|
4422
4750
|
standardPreviewRedeem = true;
|
|
@@ -4432,8 +4760,8 @@ var getDynamicSwap = async ({
|
|
|
4432
4760
|
// functions/getAmountWithdrawn.ts
|
|
4433
4761
|
var import_tokenlist12 = require("@tokemak/tokenlist");
|
|
4434
4762
|
var import_config12 = require("@tokemak/config");
|
|
4435
|
-
var
|
|
4436
|
-
var
|
|
4763
|
+
var import_core17 = require("@wagmi/core");
|
|
4764
|
+
var import_abis14 = require("@tokemak/abis");
|
|
4437
4765
|
var getAmountWithdrawn = async ({
|
|
4438
4766
|
address,
|
|
4439
4767
|
slippage,
|
|
@@ -4462,19 +4790,19 @@ var getAmountWithdrawn = async ({
|
|
|
4462
4790
|
let quote;
|
|
4463
4791
|
let convertedAssets;
|
|
4464
4792
|
if (!!dynamicSwap?.previewRedeem) {
|
|
4465
|
-
const minAmountWithSlippage = (0,
|
|
4793
|
+
const minAmountWithSlippage = (0, import_utils31.calculateMinAmountWithSlippage)(
|
|
4466
4794
|
dynamicSwap?.previewRedeem,
|
|
4467
4795
|
slippage
|
|
4468
4796
|
);
|
|
4469
|
-
let minAmount = (0,
|
|
4797
|
+
let minAmount = (0, import_viem16.formatUnits)(minAmountWithSlippage, decimals);
|
|
4470
4798
|
if (isSwap) {
|
|
4471
4799
|
if (buyToken === import_tokenlist12.ETH_TOKEN.address) {
|
|
4472
4800
|
const weth = (0, import_config12.getCoreConfig)(chainId).weth;
|
|
4473
4801
|
buyToken = weth;
|
|
4474
4802
|
}
|
|
4475
|
-
convertedAssets = await (0,
|
|
4803
|
+
convertedAssets = await (0, import_core17.readContract)(config, {
|
|
4476
4804
|
address: autopool,
|
|
4477
|
-
abi:
|
|
4805
|
+
abi: import_abis14.autopoolEthAbi,
|
|
4478
4806
|
functionName: "convertToAssets",
|
|
4479
4807
|
args: [amount],
|
|
4480
4808
|
chainId
|
|
@@ -4486,13 +4814,13 @@ var getAmountWithdrawn = async ({
|
|
|
4486
4814
|
buyToken,
|
|
4487
4815
|
sellToken,
|
|
4488
4816
|
sellAmount: dynamicSwap?.previewRedeem,
|
|
4489
|
-
slippageBps: (0,
|
|
4817
|
+
slippageBps: (0, import_utils31.convertNumToBps)(slippage),
|
|
4490
4818
|
chainId,
|
|
4491
4819
|
includeSources: "0xV2",
|
|
4492
4820
|
sellAll: true
|
|
4493
4821
|
});
|
|
4494
4822
|
if (quote) {
|
|
4495
|
-
minAmount = (0,
|
|
4823
|
+
minAmount = (0, import_viem16.formatUnits)(BigInt(quote?.minBuyAmount), decimals);
|
|
4496
4824
|
} else {
|
|
4497
4825
|
throw new Error("No quote found");
|
|
4498
4826
|
}
|
|
@@ -4512,9 +4840,9 @@ var getAmountWithdrawn = async ({
|
|
|
4512
4840
|
};
|
|
4513
4841
|
|
|
4514
4842
|
// functions/getAmountDeposited.ts
|
|
4515
|
-
var
|
|
4516
|
-
var
|
|
4517
|
-
var
|
|
4843
|
+
var import_core18 = require("@wagmi/core");
|
|
4844
|
+
var import_abis15 = require("@tokemak/abis");
|
|
4845
|
+
var import_utils32 = require("@tokemak/utils");
|
|
4518
4846
|
var getAmountDeposited = async ({
|
|
4519
4847
|
address,
|
|
4520
4848
|
chainId,
|
|
@@ -4527,21 +4855,21 @@ var getAmountDeposited = async ({
|
|
|
4527
4855
|
if (!address || !chainId || !amount || typeof slippage !== "number") {
|
|
4528
4856
|
throw new Error("Invalid parameters");
|
|
4529
4857
|
}
|
|
4530
|
-
const previewDeposit = await (0,
|
|
4858
|
+
const previewDeposit = await (0, import_core18.readContract)(config, {
|
|
4531
4859
|
address,
|
|
4532
|
-
abi:
|
|
4860
|
+
abi: import_abis15.autopoolEthAbi,
|
|
4533
4861
|
functionName: "previewDeposit",
|
|
4534
4862
|
args: [amount],
|
|
4535
4863
|
chainId
|
|
4536
4864
|
});
|
|
4537
4865
|
if (!isSwap) {
|
|
4538
|
-
let minAmountWithSlippage = (0,
|
|
4866
|
+
let minAmountWithSlippage = (0, import_utils32.calculateMinAmountWithSlippage)(
|
|
4539
4867
|
previewDeposit,
|
|
4540
4868
|
slippage
|
|
4541
4869
|
);
|
|
4542
|
-
return (0,
|
|
4870
|
+
return (0, import_utils32.formatEtherNum)(minAmountWithSlippage);
|
|
4543
4871
|
} else {
|
|
4544
|
-
return (0,
|
|
4872
|
+
return (0, import_utils32.formatEtherNum)(previewDeposit);
|
|
4545
4873
|
}
|
|
4546
4874
|
} catch (e) {
|
|
4547
4875
|
console.error(e);
|
|
@@ -4551,9 +4879,9 @@ var getAmountDeposited = async ({
|
|
|
4551
4879
|
};
|
|
4552
4880
|
|
|
4553
4881
|
// functions/getBridgeFee.ts
|
|
4554
|
-
var
|
|
4555
|
-
var
|
|
4556
|
-
var
|
|
4882
|
+
var import_core19 = require("@wagmi/core");
|
|
4883
|
+
var import_abis16 = require("@tokemak/abis");
|
|
4884
|
+
var import_viem17 = require("viem");
|
|
4557
4885
|
var import_lz_v2_utilities = require("@layerzerolabs/lz-v2-utilities");
|
|
4558
4886
|
var getBridgeFee = async (wagmiConfig, {
|
|
4559
4887
|
sourceAddress,
|
|
@@ -4564,15 +4892,15 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4564
4892
|
from
|
|
4565
4893
|
}) => {
|
|
4566
4894
|
try {
|
|
4567
|
-
const endpoint = await (0,
|
|
4895
|
+
const endpoint = await (0, import_core19.readContract)(wagmiConfig, {
|
|
4568
4896
|
address: destAddress,
|
|
4569
|
-
abi:
|
|
4897
|
+
abi: import_abis16.oftAdapterAbi,
|
|
4570
4898
|
functionName: "endpoint",
|
|
4571
4899
|
chainId: destChainId
|
|
4572
4900
|
});
|
|
4573
|
-
const eid = await (0,
|
|
4901
|
+
const eid = await (0, import_core19.readContract)(wagmiConfig, {
|
|
4574
4902
|
address: endpoint,
|
|
4575
|
-
abi:
|
|
4903
|
+
abi: import_abis16.layerZeroEndpointAbi,
|
|
4576
4904
|
functionName: "eid",
|
|
4577
4905
|
chainId: destChainId
|
|
4578
4906
|
});
|
|
@@ -4581,16 +4909,16 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4581
4909
|
const minAmountLD = amount / factor * factor;
|
|
4582
4910
|
const sendParams = {
|
|
4583
4911
|
dstEid: eid,
|
|
4584
|
-
to: (0,
|
|
4912
|
+
to: (0, import_viem17.toHex)((0, import_lz_v2_utilities.addressToBytes32)(from)),
|
|
4585
4913
|
amountLD: amount,
|
|
4586
4914
|
minAmountLD,
|
|
4587
4915
|
extraOptions: "0x",
|
|
4588
4916
|
composeMsg: "0x",
|
|
4589
4917
|
oftCmd: "0x"
|
|
4590
4918
|
};
|
|
4591
|
-
const feeQuote = await (0,
|
|
4919
|
+
const feeQuote = await (0, import_core19.readContract)(wagmiConfig, {
|
|
4592
4920
|
address: sourceAddress,
|
|
4593
|
-
abi:
|
|
4921
|
+
abi: import_abis16.oftAdapterAbi,
|
|
4594
4922
|
functionName: "quoteSend",
|
|
4595
4923
|
args: [sendParams, false],
|
|
4596
4924
|
chainId: sourceChainId
|
|
@@ -4657,30 +4985,30 @@ var waitForMessageReceived = async ({
|
|
|
4657
4985
|
};
|
|
4658
4986
|
|
|
4659
4987
|
// functions/getChainUserSToke.ts
|
|
4660
|
-
var
|
|
4988
|
+
var import_abis18 = require("@tokemak/abis");
|
|
4661
4989
|
var import_config13 = require("@tokemak/config");
|
|
4662
|
-
var
|
|
4663
|
-
var
|
|
4664
|
-
var
|
|
4665
|
-
var
|
|
4990
|
+
var import_utils33 = require("@tokemak/utils");
|
|
4991
|
+
var import_core21 = require("@wagmi/core");
|
|
4992
|
+
var import_viem18 = require("viem");
|
|
4993
|
+
var import_chains14 = require("viem/chains");
|
|
4666
4994
|
|
|
4667
4995
|
// functions/getCurrentCycleId.ts
|
|
4668
|
-
var
|
|
4669
|
-
var
|
|
4996
|
+
var import_abis17 = require("@tokemak/abis");
|
|
4997
|
+
var import_core20 = require("@wagmi/core");
|
|
4670
4998
|
var getCurrentCycleId = async (wagmiConfig, {
|
|
4671
4999
|
stoke,
|
|
4672
5000
|
chainId
|
|
4673
5001
|
}) => {
|
|
4674
|
-
return (0,
|
|
5002
|
+
return (0, import_core20.readContract)(wagmiConfig, {
|
|
4675
5003
|
address: stoke,
|
|
4676
|
-
abi:
|
|
5004
|
+
abi: import_abis17.accTokeV1Abi,
|
|
4677
5005
|
chainId,
|
|
4678
5006
|
functionName: "getCurrentCycleID"
|
|
4679
5007
|
});
|
|
4680
5008
|
};
|
|
4681
5009
|
|
|
4682
5010
|
// functions/getChainUserSToke.ts
|
|
4683
|
-
var
|
|
5011
|
+
var import_graph_cli14 = require("@tokemak/graph-cli");
|
|
4684
5012
|
var getChainUserSToke = async (wagmiConfig, {
|
|
4685
5013
|
address,
|
|
4686
5014
|
tokePrice,
|
|
@@ -4690,7 +5018,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4690
5018
|
const { stoke } = (0, import_config13.getCoreConfig)(chainId);
|
|
4691
5019
|
const cycleIndex = await getCurrentCycleId(wagmiConfig, { chainId, stoke });
|
|
4692
5020
|
if (address && cycleIndex && stoke && tokePrice) {
|
|
4693
|
-
const { GetUserSTokeBalance } = (0,
|
|
5021
|
+
const { GetUserSTokeBalance } = (0, import_graph_cli14.getSdkByChainId)(
|
|
4694
5022
|
chainId
|
|
4695
5023
|
);
|
|
4696
5024
|
const { accountBalanceV1S } = await GetUserSTokeBalance({
|
|
@@ -4699,13 +5027,13 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4699
5027
|
const cycleStartBalance = accountBalanceV1S[0]?.cycleStartBalance || 0n;
|
|
4700
5028
|
const stokeContract = {
|
|
4701
5029
|
address: stoke,
|
|
4702
|
-
abi:
|
|
5030
|
+
abi: import_abis18.accTokeV1Abi
|
|
4703
5031
|
};
|
|
4704
5032
|
const [
|
|
4705
5033
|
{ result: balance },
|
|
4706
5034
|
{ result: depositInfoResult },
|
|
4707
5035
|
{ result: withdrawalInfoResult }
|
|
4708
|
-
] = await (0,
|
|
5036
|
+
] = await (0, import_core21.readContracts)(wagmiConfig, {
|
|
4709
5037
|
contracts: [
|
|
4710
5038
|
{
|
|
4711
5039
|
...stokeContract,
|
|
@@ -4735,8 +5063,8 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4735
5063
|
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
4736
5064
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
4737
5065
|
}
|
|
4738
|
-
const withdrawalAmountUsd = (0,
|
|
4739
|
-
(0,
|
|
5066
|
+
const withdrawalAmountUsd = (0, import_utils33.formatCurrency)(
|
|
5067
|
+
(0, import_utils33.formatEtherNum)(withdrawalAmount) * tokePrice
|
|
4740
5068
|
);
|
|
4741
5069
|
const lockDuration = Number(depositLockDuration);
|
|
4742
5070
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -4757,27 +5085,27 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4757
5085
|
const withdrawAvailable = lockRenew - 1;
|
|
4758
5086
|
const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
|
|
4759
5087
|
const addedLockedToke = depositAmount - rolloverDepositAmount;
|
|
4760
|
-
const balanceUSD = (0,
|
|
4761
|
-
Number((0,
|
|
5088
|
+
const balanceUSD = (0, import_utils33.formatCurrency)(
|
|
5089
|
+
Number((0, import_viem18.formatEther)(balanceExcludingWithdrawal)) * tokePrice
|
|
4762
5090
|
);
|
|
4763
|
-
const balanceExcludingWithdrawalUsd = (0,
|
|
4764
|
-
(0,
|
|
5091
|
+
const balanceExcludingWithdrawalUsd = (0, import_utils33.formatCurrency)(
|
|
5092
|
+
(0, import_utils33.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
|
|
4765
5093
|
);
|
|
4766
5094
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
4767
5095
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
4768
|
-
const unlockRequestPeriodStartUnix = (0,
|
|
4769
|
-
const unlockRequestPeriodEndUnix = (0,
|
|
5096
|
+
const unlockRequestPeriodStartUnix = (0, import_utils33.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
|
|
5097
|
+
const unlockRequestPeriodEndUnix = (0, import_utils33.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
|
|
4770
5098
|
const hasBalance = balance > 0n;
|
|
4771
5099
|
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
4772
5100
|
const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
|
|
4773
5101
|
let cyclesInAMonth = 4;
|
|
4774
5102
|
let lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
4775
|
-
if (chainId ===
|
|
5103
|
+
if (chainId === import_chains14.sepolia.id) {
|
|
4776
5104
|
lockDurationInMonths = lockDuration - 1;
|
|
4777
5105
|
}
|
|
4778
5106
|
const unlockPeriodDateRangeArray = [
|
|
4779
|
-
new Date((0,
|
|
4780
|
-
new Date((0,
|
|
5107
|
+
new Date((0, import_utils33.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
|
|
5108
|
+
new Date((0, import_utils33.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
|
|
4781
5109
|
];
|
|
4782
5110
|
const {
|
|
4783
5111
|
unlockPeriodDateRange,
|
|
@@ -4787,20 +5115,20 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4787
5115
|
unlockRenewalDate
|
|
4788
5116
|
} = formatDateRange(
|
|
4789
5117
|
unlockPeriodDateRangeArray,
|
|
4790
|
-
chainId ===
|
|
5118
|
+
chainId === import_chains14.sepolia.id ? "time" : "date"
|
|
4791
5119
|
);
|
|
4792
|
-
const totalActiveUserCredits = (0,
|
|
4793
|
-
const totalUserCredits = (0,
|
|
5120
|
+
const totalActiveUserCredits = (0, import_utils33.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
5121
|
+
const totalUserCredits = (0, import_utils33.formatEtherNum)(balance) * lockDurationInMonths;
|
|
4794
5122
|
return {
|
|
4795
5123
|
balance,
|
|
4796
5124
|
balanceUSD,
|
|
4797
|
-
balanceExcludingWithdrawal: hasBalance ? (0,
|
|
5125
|
+
balanceExcludingWithdrawal: hasBalance ? (0, import_viem18.formatEther)(balanceExcludingWithdrawal) : "0.00",
|
|
4798
5126
|
balanceExcludingWithdrawalUsd,
|
|
4799
5127
|
hasBalanceExcludingWithdrawal,
|
|
4800
|
-
timeLeftBeforeUnlockRequestAvailable: (0,
|
|
5128
|
+
timeLeftBeforeUnlockRequestAvailable: (0, import_utils33.convertSecondsToRemainingTime)(
|
|
4801
5129
|
unlockRequestPeriodStartUnix
|
|
4802
5130
|
),
|
|
4803
|
-
timeLeftBeforeUnlockRequestUnavailable: (0,
|
|
5131
|
+
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils33.convertSecondsToRemainingTime)(
|
|
4804
5132
|
unlockRequestPeriodEndUnix
|
|
4805
5133
|
),
|
|
4806
5134
|
withdrawalAmount,
|
|
@@ -4817,7 +5145,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4817
5145
|
unlockRenewalDate,
|
|
4818
5146
|
lockDurationInMonths,
|
|
4819
5147
|
boost: lockDuration,
|
|
4820
|
-
points: (0,
|
|
5148
|
+
points: (0, import_utils33.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
4821
5149
|
totalActiveCredits: totalActiveUserCredits,
|
|
4822
5150
|
totalCredits: totalUserCredits
|
|
4823
5151
|
};
|
|
@@ -4829,7 +5157,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4829
5157
|
};
|
|
4830
5158
|
|
|
4831
5159
|
// functions/getUserSToke.ts
|
|
4832
|
-
var
|
|
5160
|
+
var import_utils35 = require("@tokemak/utils");
|
|
4833
5161
|
var getUserSToke = async (wagmiConfig, {
|
|
4834
5162
|
address,
|
|
4835
5163
|
tokePrice,
|
|
@@ -4856,8 +5184,8 @@ var getUserSToke = async (wagmiConfig, {
|
|
|
4856
5184
|
}
|
|
4857
5185
|
return acc;
|
|
4858
5186
|
}, 0n);
|
|
4859
|
-
const totalBalance = (0,
|
|
4860
|
-
const totalBalanceUsd = (0,
|
|
5187
|
+
const totalBalance = (0, import_utils35.formatEtherNum)(totalBalanceRaw || 0n);
|
|
5188
|
+
const totalBalanceUsd = (0, import_utils35.formatCurrency)(totalBalance * tokePrice);
|
|
4861
5189
|
const hasBalance = totalBalance > 0;
|
|
4862
5190
|
return {
|
|
4863
5191
|
chains: { ...userSToke },
|
|
@@ -4871,12 +5199,12 @@ var getUserSToke = async (wagmiConfig, {
|
|
|
4871
5199
|
};
|
|
4872
5200
|
|
|
4873
5201
|
// functions/getChainSToke.ts
|
|
4874
|
-
var
|
|
4875
|
-
var
|
|
4876
|
-
var
|
|
4877
|
-
var
|
|
5202
|
+
var import_viem19 = require("viem");
|
|
5203
|
+
var import_core22 = require("@wagmi/core");
|
|
5204
|
+
var import_abis19 = require("@tokemak/abis");
|
|
5205
|
+
var import_utils37 = require("@tokemak/utils");
|
|
4878
5206
|
var import_config14 = require("@tokemak/config");
|
|
4879
|
-
var
|
|
5207
|
+
var import_utils38 = require("@tokemak/utils");
|
|
4880
5208
|
var getChainSToke = async (wagmiConfig, {
|
|
4881
5209
|
tokePrice,
|
|
4882
5210
|
chainId
|
|
@@ -4885,11 +5213,11 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
4885
5213
|
const { stoke } = (0, import_config14.getCoreConfig)(chainId);
|
|
4886
5214
|
const baseConfig = {
|
|
4887
5215
|
address: stoke,
|
|
4888
|
-
abi:
|
|
5216
|
+
abi: import_abis19.accTokeV1Abi,
|
|
4889
5217
|
chainId
|
|
4890
5218
|
};
|
|
4891
5219
|
if (stoke && tokePrice) {
|
|
4892
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await (0,
|
|
5220
|
+
const [{ result: totalSupply }, { result: currentCycle }] = await (0, import_core22.readContracts)(wagmiConfig, {
|
|
4893
5221
|
contracts: [
|
|
4894
5222
|
{
|
|
4895
5223
|
...baseConfig,
|
|
@@ -4901,16 +5229,16 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
4901
5229
|
}
|
|
4902
5230
|
]
|
|
4903
5231
|
});
|
|
4904
|
-
const tvl = Number((0,
|
|
4905
|
-
const secondsLeftBeforeNextCycle = (0,
|
|
5232
|
+
const tvl = Number((0, import_viem19.formatEther)(totalSupply || 0n)) * tokePrice;
|
|
5233
|
+
const secondsLeftBeforeNextCycle = (0, import_utils37.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
|
|
4906
5234
|
return {
|
|
4907
5235
|
rawTotalSupply: totalSupply,
|
|
4908
|
-
totalSupply: (0,
|
|
4909
|
-
tvl: (0,
|
|
5236
|
+
totalSupply: (0, import_utils37.formatLargeNumber)((0, import_viem19.formatEther)(totalSupply || 0n)),
|
|
5237
|
+
tvl: (0, import_utils37.formatTVL)(tvl),
|
|
4910
5238
|
rawTVL: tvl,
|
|
4911
5239
|
currentCycle,
|
|
4912
|
-
chain: (0,
|
|
4913
|
-
timeBeforeNextCycle: (0,
|
|
5240
|
+
chain: (0, import_utils38.getNetwork)(chainId),
|
|
5241
|
+
timeBeforeNextCycle: (0, import_utils37.convertSecondsToRemainingTime)(
|
|
4914
5242
|
secondsLeftBeforeNextCycle
|
|
4915
5243
|
)
|
|
4916
5244
|
};
|
|
@@ -4921,8 +5249,8 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
4921
5249
|
};
|
|
4922
5250
|
|
|
4923
5251
|
// functions/getSToke.ts
|
|
4924
|
-
var
|
|
4925
|
-
var
|
|
5252
|
+
var import_utils39 = require("@tokemak/utils");
|
|
5253
|
+
var import_viem20 = require("viem");
|
|
4926
5254
|
var getSToke = async (wagmiConfig, {
|
|
4927
5255
|
tokePrice,
|
|
4928
5256
|
includeTestnet = false
|
|
@@ -4941,14 +5269,14 @@ var getSToke = async (wagmiConfig, {
|
|
|
4941
5269
|
}
|
|
4942
5270
|
return acc;
|
|
4943
5271
|
}, 0n);
|
|
4944
|
-
const totalSupply = (0,
|
|
5272
|
+
const totalSupply = (0, import_utils39.formatLargeNumber)((0, import_viem20.formatEther)(totalSupplyBigInt || 0n));
|
|
4945
5273
|
let tvlNum = Object.values(sToke).reduce((acc, item) => {
|
|
4946
5274
|
if (item && item.rawTVL) {
|
|
4947
5275
|
return acc + item.rawTVL;
|
|
4948
5276
|
}
|
|
4949
5277
|
return acc;
|
|
4950
5278
|
}, 0);
|
|
4951
|
-
const tvl = (0,
|
|
5279
|
+
const tvl = (0, import_utils39.formatTVL)(tvlNum);
|
|
4952
5280
|
return { totalSupply, rawTotalSupply: totalSupplyBigInt, tvl, rawTVL: tvlNum, chains: { ...sToke } };
|
|
4953
5281
|
} catch (e) {
|
|
4954
5282
|
console.error(e);
|
|
@@ -4957,8 +5285,8 @@ var getSToke = async (wagmiConfig, {
|
|
|
4957
5285
|
};
|
|
4958
5286
|
|
|
4959
5287
|
// functions/getChainCycleRolloverBlockNumber.ts
|
|
4960
|
-
var
|
|
4961
|
-
var
|
|
5288
|
+
var import_abis20 = require("@tokemak/abis");
|
|
5289
|
+
var import_core23 = require("@wagmi/core");
|
|
4962
5290
|
var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
4963
5291
|
stoke,
|
|
4964
5292
|
chainId
|
|
@@ -4966,15 +5294,15 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
4966
5294
|
const scanPeriodInDays = 8;
|
|
4967
5295
|
const blockTime = 12;
|
|
4968
5296
|
try {
|
|
4969
|
-
const client = (0,
|
|
5297
|
+
const client = (0, import_core23.getPublicClient)(wagmiConfig, { chainId });
|
|
4970
5298
|
if (!!client) {
|
|
4971
|
-
const blockNumber = await (0,
|
|
5299
|
+
const blockNumber = await (0, import_core23.getBlockNumber)(wagmiConfig, {
|
|
4972
5300
|
chainId
|
|
4973
5301
|
});
|
|
4974
|
-
const manager = await (0,
|
|
5302
|
+
const manager = await (0, import_core23.readContract)(wagmiConfig, {
|
|
4975
5303
|
functionName: "manager",
|
|
4976
5304
|
address: stoke,
|
|
4977
|
-
abi:
|
|
5305
|
+
abi: import_abis20.accTokeV1Abi,
|
|
4978
5306
|
chainId
|
|
4979
5307
|
});
|
|
4980
5308
|
if (!manager) {
|
|
@@ -4987,7 +5315,7 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
4987
5315
|
Number(blockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
4988
5316
|
)
|
|
4989
5317
|
),
|
|
4990
|
-
abi:
|
|
5318
|
+
abi: import_abis20.managerV1Abi,
|
|
4991
5319
|
eventName: "CycleRolloverComplete"
|
|
4992
5320
|
});
|
|
4993
5321
|
const rolloverEvents = await client.getFilterLogs({ filter });
|
|
@@ -5001,14 +5329,14 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
5001
5329
|
|
|
5002
5330
|
// functions/getChainSTokeRewards.ts
|
|
5003
5331
|
var import_config15 = require("@tokemak/config");
|
|
5004
|
-
var
|
|
5005
|
-
var
|
|
5006
|
-
var
|
|
5332
|
+
var import_viem21 = require("viem");
|
|
5333
|
+
var import_utils41 = require("@tokemak/utils");
|
|
5334
|
+
var import_graph_cli15 = require("@tokemak/graph-cli");
|
|
5007
5335
|
var getChainSTokeRewards = async ({
|
|
5008
5336
|
chainId
|
|
5009
5337
|
}) => {
|
|
5010
5338
|
try {
|
|
5011
|
-
const { GetSTokeRewards } = (0,
|
|
5339
|
+
const { GetSTokeRewards } = (0, import_graph_cli15.getSdkByChainId)(chainId);
|
|
5012
5340
|
const { poolRewardsBalances } = await GetSTokeRewards();
|
|
5013
5341
|
const allPoolRewardsBalanceDayDatas = await paginateQuery(
|
|
5014
5342
|
GetSTokeRewards,
|
|
@@ -5026,9 +5354,9 @@ var getChainSTokeRewards = async ({
|
|
|
5026
5354
|
if (!whitelistedPools.includes(pool.id.toLowerCase())) {
|
|
5027
5355
|
continue;
|
|
5028
5356
|
}
|
|
5029
|
-
const convertedBalance = (0,
|
|
5030
|
-
const convertedBalanceUSD = Number((0,
|
|
5031
|
-
const convertedApr = (0,
|
|
5357
|
+
const convertedBalance = (0, import_utils41.formatEtherNum)(pool.balance);
|
|
5358
|
+
const convertedBalanceUSD = Number((0, import_viem21.formatUnits)(pool.balanceUSD, 8));
|
|
5359
|
+
const convertedApr = (0, import_utils41.formatEtherNum)(pool.currentAprPerCredit);
|
|
5032
5360
|
if (minApr === null || convertedApr < minApr) {
|
|
5033
5361
|
minApr = convertedApr;
|
|
5034
5362
|
}
|
|
@@ -5101,7 +5429,7 @@ var getSTokeRewards = async ({
|
|
|
5101
5429
|
|
|
5102
5430
|
// functions/getChainUserSTokeRewards.ts
|
|
5103
5431
|
var import_config16 = require("@tokemak/config");
|
|
5104
|
-
var
|
|
5432
|
+
var import_utils44 = require("@tokemak/utils");
|
|
5105
5433
|
var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
5106
5434
|
address,
|
|
5107
5435
|
chainId,
|
|
@@ -5152,14 +5480,14 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5152
5480
|
throw fallbackError;
|
|
5153
5481
|
}
|
|
5154
5482
|
}
|
|
5155
|
-
const claimableNum = (0,
|
|
5483
|
+
const claimableNum = (0, import_utils44.formatEtherNum)(tokeRewards?.claimable || 0n);
|
|
5156
5484
|
const claimableUsd = tokePrice * claimableNum;
|
|
5157
5485
|
const hasClaimable = claimableNum > 0n;
|
|
5158
|
-
const pendingRewards = (0,
|
|
5486
|
+
const pendingRewards = (0, import_utils44.formatEtherNum)(
|
|
5159
5487
|
tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5160
5488
|
);
|
|
5161
5489
|
const pendingRewardsUsd = tokePrice * pendingRewards;
|
|
5162
|
-
const totalRewardsReceived = (0,
|
|
5490
|
+
const totalRewardsReceived = (0, import_utils44.formatEtherNum)(
|
|
5163
5491
|
tokeRewards.rewardsPayload.payload.amount || 0n
|
|
5164
5492
|
);
|
|
5165
5493
|
const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
|
|
@@ -5176,11 +5504,11 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5176
5504
|
};
|
|
5177
5505
|
|
|
5178
5506
|
// functions/getChainSubgraphStatus.ts
|
|
5179
|
-
var
|
|
5507
|
+
var import_graph_cli16 = require("@tokemak/graph-cli");
|
|
5180
5508
|
var getChainSubgraphStatus = async (chain) => {
|
|
5181
5509
|
const currentTimestamp = Math.floor(Date.now() / 1e3);
|
|
5182
5510
|
try {
|
|
5183
|
-
const { GetLatestSubgraphTimestamp } = (0,
|
|
5511
|
+
const { GetLatestSubgraphTimestamp } = (0, import_graph_cli16.getSdkByChainId)(
|
|
5184
5512
|
chain.chainId
|
|
5185
5513
|
);
|
|
5186
5514
|
const { _meta } = await GetLatestSubgraphTimestamp();
|
|
@@ -5232,15 +5560,15 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5232
5560
|
};
|
|
5233
5561
|
|
|
5234
5562
|
// functions/getCycleV1.ts
|
|
5235
|
-
var
|
|
5236
|
-
var
|
|
5237
|
-
var
|
|
5238
|
-
var
|
|
5563
|
+
var import_core24 = require("@wagmi/core");
|
|
5564
|
+
var import_abis21 = require("@tokemak/abis");
|
|
5565
|
+
var import_viem22 = require("viem");
|
|
5566
|
+
var import_utils46 = require("@tokemak/utils");
|
|
5239
5567
|
var import_config17 = require("@tokemak/config");
|
|
5240
|
-
var
|
|
5241
|
-
var publicClient = (0,
|
|
5242
|
-
chain:
|
|
5243
|
-
transport: (0,
|
|
5568
|
+
var import_chains15 = require("viem/chains");
|
|
5569
|
+
var publicClient = (0, import_viem22.createPublicClient)({
|
|
5570
|
+
chain: import_chains15.mainnet,
|
|
5571
|
+
transport: (0, import_viem22.http)("https://mainnet.infura.io/v3/2BtQ5D1QEPHvwgZwKwnZC7WQVhr")
|
|
5244
5572
|
});
|
|
5245
5573
|
var getCycleV1 = async (wagmiConfig, {
|
|
5246
5574
|
currentBlockNumber,
|
|
@@ -5251,9 +5579,9 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5251
5579
|
const { managerV1 } = (0, import_config17.getMainnetConfig)();
|
|
5252
5580
|
try {
|
|
5253
5581
|
if (currentBlockNumber && managerV1) {
|
|
5254
|
-
const currentCycleIndex = await (0,
|
|
5582
|
+
const currentCycleIndex = await (0, import_core24.readContract)(wagmiConfig, {
|
|
5255
5583
|
address: managerV1,
|
|
5256
|
-
abi:
|
|
5584
|
+
abi: import_abis21.managerV1Abi,
|
|
5257
5585
|
functionName: "getCurrentCycleIndex",
|
|
5258
5586
|
chainId
|
|
5259
5587
|
});
|
|
@@ -5264,16 +5592,16 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5264
5592
|
Number(currentBlockNumber) - 86400 / blockTime * scanPeriodInDays
|
|
5265
5593
|
)
|
|
5266
5594
|
),
|
|
5267
|
-
abi:
|
|
5595
|
+
abi: import_abis21.managerV1Abi,
|
|
5268
5596
|
eventName: "CycleRolloverComplete"
|
|
5269
5597
|
});
|
|
5270
5598
|
const rolloverEvents = await publicClient.getFilterLogs({ filter });
|
|
5271
5599
|
const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
|
|
5272
|
-
const secondsLeftBeforeNextCycle = (0,
|
|
5600
|
+
const secondsLeftBeforeNextCycle = (0, import_utils46.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
|
|
5273
5601
|
return {
|
|
5274
5602
|
currentCycleIndex,
|
|
5275
5603
|
cycleRolloverBlockNumber,
|
|
5276
|
-
timeBeforeNextCycle: (0,
|
|
5604
|
+
timeBeforeNextCycle: (0, import_utils46.convertSecondsToRemainingTime)(
|
|
5277
5605
|
secondsLeftBeforeNextCycle
|
|
5278
5606
|
)
|
|
5279
5607
|
};
|
|
@@ -5284,7 +5612,7 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5284
5612
|
};
|
|
5285
5613
|
|
|
5286
5614
|
// functions/getProtocolStats.ts
|
|
5287
|
-
var
|
|
5615
|
+
var import_utils47 = require("@tokemak/utils");
|
|
5288
5616
|
var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
5289
5617
|
try {
|
|
5290
5618
|
if (!autopools || !stoke || !sushiLP) {
|
|
@@ -5314,12 +5642,12 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
|
5314
5642
|
Object.entries(categories).map(([key, value]) => [
|
|
5315
5643
|
key,
|
|
5316
5644
|
{
|
|
5317
|
-
tvl: (0,
|
|
5318
|
-
supply: (0,
|
|
5645
|
+
tvl: (0, import_utils47.formatTVL)(value.tvl),
|
|
5646
|
+
supply: (0, import_utils47.formatLargeNumber)(value.supply || 0)
|
|
5319
5647
|
}
|
|
5320
5648
|
])
|
|
5321
5649
|
);
|
|
5322
|
-
const tvl = (0,
|
|
5650
|
+
const tvl = (0, import_utils47.formatTVL)(
|
|
5323
5651
|
autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0) + (EthAutoLP?.tvlUsd || 0) + (sauto?.rawTVL || 0)
|
|
5324
5652
|
);
|
|
5325
5653
|
const vaultAddresses = autopools?.flatMap(
|
|
@@ -5328,33 +5656,33 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
|
5328
5656
|
const uniqueVaultAddresses = [...new Set(vaultAddresses)];
|
|
5329
5657
|
const totalDestinations = uniqueVaultAddresses.length;
|
|
5330
5658
|
const stakedTVL = {
|
|
5331
|
-
totalSupply: (0,
|
|
5332
|
-
(0,
|
|
5659
|
+
totalSupply: (0, import_utils47.formatLargeNumber)(
|
|
5660
|
+
(0, import_utils47.formatEtherNum)(
|
|
5333
5661
|
(sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
|
|
5334
5662
|
)
|
|
5335
5663
|
),
|
|
5336
|
-
tvl: (0,
|
|
5664
|
+
tvl: (0, import_utils47.formatTVL)((sauto?.rawTVL || 0) + stoke.rawTVL)
|
|
5337
5665
|
};
|
|
5338
5666
|
return {
|
|
5339
5667
|
autopools: {
|
|
5340
|
-
tvl: (0,
|
|
5668
|
+
tvl: (0, import_utils47.formatTVL)(autopoolTVL),
|
|
5341
5669
|
tvlNum: autopoolTVL,
|
|
5342
5670
|
categories: formattedCategories
|
|
5343
5671
|
},
|
|
5344
5672
|
stoke: {
|
|
5345
|
-
tvl: (0,
|
|
5673
|
+
tvl: (0, import_utils47.formatTVL)(stoke.rawTVL),
|
|
5346
5674
|
tvlNum: stoke.rawTVL,
|
|
5347
5675
|
totalSupply: `${stoke.totalSupply} TOKE`
|
|
5348
5676
|
},
|
|
5349
5677
|
sushiLP: {
|
|
5350
|
-
tvl: (0,
|
|
5678
|
+
tvl: (0, import_utils47.formatTVL)(sushiLP?.tvl || 0),
|
|
5351
5679
|
totalSupply: sushiLP?.totalSupply || 0
|
|
5352
5680
|
},
|
|
5353
5681
|
EthAutoLP: {
|
|
5354
|
-
tvl: (0,
|
|
5682
|
+
tvl: (0, import_utils47.formatTVL)(EthAutoLP?.tvlUsd || 0)
|
|
5355
5683
|
},
|
|
5356
5684
|
sauto: {
|
|
5357
|
-
tvl: (0,
|
|
5685
|
+
tvl: (0, import_utils47.formatTVL)(sauto?.rawTVL || 0),
|
|
5358
5686
|
tvlNum: sauto?.rawTVL || 0,
|
|
5359
5687
|
totalSupply: `${sauto?.totalSupply} AUTO`
|
|
5360
5688
|
},
|
|
@@ -5369,21 +5697,21 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
|
5369
5697
|
};
|
|
5370
5698
|
|
|
5371
5699
|
// functions/getRebalanceStats.ts
|
|
5372
|
-
var
|
|
5700
|
+
var import_graph_cli17 = require("@tokemak/graph-cli");
|
|
5373
5701
|
|
|
5374
5702
|
// functions/getEthPriceAtBlock.ts
|
|
5375
5703
|
var import_config18 = require("@tokemak/config");
|
|
5376
|
-
var
|
|
5377
|
-
var
|
|
5704
|
+
var import_core25 = require("@wagmi/core");
|
|
5705
|
+
var import_abis22 = require("@tokemak/abis");
|
|
5378
5706
|
var import_tokenlist13 = require("@tokemak/tokenlist");
|
|
5379
5707
|
var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
|
|
5380
5708
|
const config = (0, import_config18.getCoreConfig)(chainId);
|
|
5381
5709
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5382
5710
|
const weth = config.weth;
|
|
5383
5711
|
const usdc = import_tokenlist13.USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || import_tokenlist13.USDC_TOKEN.address;
|
|
5384
|
-
const priceAtBlock = await (0,
|
|
5712
|
+
const priceAtBlock = await (0, import_core25.readContract)(wagmiConfig, {
|
|
5385
5713
|
address: rootPriceOracle,
|
|
5386
|
-
abi:
|
|
5714
|
+
abi: import_abis22.rootPriceOracleAbi,
|
|
5387
5715
|
functionName: "getPriceInQuote",
|
|
5388
5716
|
args: [weth, usdc],
|
|
5389
5717
|
blockNumber,
|
|
@@ -5393,12 +5721,12 @@ var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
|
|
|
5393
5721
|
};
|
|
5394
5722
|
|
|
5395
5723
|
// functions/getRebalanceStats.ts
|
|
5396
|
-
var
|
|
5724
|
+
var import_utils49 = require("@tokemak/utils");
|
|
5397
5725
|
var import_tokenlist14 = require("@tokemak/tokenlist");
|
|
5398
|
-
var
|
|
5726
|
+
var import_chains16 = require("viem/chains");
|
|
5399
5727
|
var BATCH_SIZE = 500;
|
|
5400
5728
|
var fetchChainRebalances = async (chainId) => {
|
|
5401
|
-
const { GetAllAutopoolRebalances } = (0,
|
|
5729
|
+
const { GetAllAutopoolRebalances } = (0, import_graph_cli17.getSdkByChainId)(chainId);
|
|
5402
5730
|
const allRebalances = await paginateQuery(
|
|
5403
5731
|
GetAllAutopoolRebalances,
|
|
5404
5732
|
"autopoolRebalances"
|
|
@@ -5412,7 +5740,7 @@ function inferBaseAssetDecimals(rebalance, chainId) {
|
|
|
5412
5740
|
if (BigInt(rebalance.tokenOutValueBaseAsset) === BigInt(rebalance.tokenOutValueInEth)) {
|
|
5413
5741
|
return 18;
|
|
5414
5742
|
}
|
|
5415
|
-
if (chainId ===
|
|
5743
|
+
if (chainId === import_chains16.sonic.id) {
|
|
5416
5744
|
return rebalance.tokenOut.decimals;
|
|
5417
5745
|
}
|
|
5418
5746
|
return import_tokenlist14.USDC_TOKEN.decimals;
|
|
@@ -5426,8 +5754,8 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5426
5754
|
BigInt(rebalance.blockNumber),
|
|
5427
5755
|
chainId
|
|
5428
5756
|
);
|
|
5429
|
-
const ethUsd = Number((0,
|
|
5430
|
-
const ethAmt = Number((0,
|
|
5757
|
+
const ethUsd = Number((0, import_utils49.formatUnitsNum)(price, import_tokenlist14.USDC_TOKEN.decimals));
|
|
5758
|
+
const ethAmt = Number((0, import_utils49.formatEtherNum)(ethWei));
|
|
5431
5759
|
const usd = ethAmt * ethUsd;
|
|
5432
5760
|
return usd;
|
|
5433
5761
|
} catch (e) {
|
|
@@ -5438,7 +5766,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5438
5766
|
var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
5439
5767
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5440
5768
|
const baseAssetAmount = Number(
|
|
5441
|
-
(0,
|
|
5769
|
+
(0, import_utils49.formatUnitsNum)(
|
|
5442
5770
|
BigInt(rebalance.tokenOutValueBaseAsset || "0"),
|
|
5443
5771
|
baseDecimals
|
|
5444
5772
|
)
|
|
@@ -5545,12 +5873,12 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5545
5873
|
};
|
|
5546
5874
|
|
|
5547
5875
|
// functions/getUserSAuto.ts
|
|
5548
|
-
var
|
|
5876
|
+
var import_abis23 = require("@tokemak/abis");
|
|
5549
5877
|
var import_config19 = require("@tokemak/config");
|
|
5550
|
-
var
|
|
5551
|
-
var
|
|
5552
|
-
var
|
|
5553
|
-
var
|
|
5878
|
+
var import_utils51 = require("@tokemak/utils");
|
|
5879
|
+
var import_core26 = require("@wagmi/core");
|
|
5880
|
+
var import_viem23 = require("viem");
|
|
5881
|
+
var import_chains17 = require("viem/chains");
|
|
5554
5882
|
var getUserSAuto = async (wagmiConfig, {
|
|
5555
5883
|
address,
|
|
5556
5884
|
autoPrice
|
|
@@ -5563,17 +5891,17 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5563
5891
|
throw new Error("Auto price not found");
|
|
5564
5892
|
}
|
|
5565
5893
|
const { sAuto } = (0, import_config19.getMainnetConfig)();
|
|
5566
|
-
const chainId =
|
|
5894
|
+
const chainId = import_chains17.mainnet.id;
|
|
5567
5895
|
const sAutoContract = {
|
|
5568
5896
|
address: sAuto,
|
|
5569
|
-
abi:
|
|
5897
|
+
abi: import_abis23.sAutoAbi
|
|
5570
5898
|
};
|
|
5571
5899
|
const [
|
|
5572
5900
|
{ result: balance },
|
|
5573
5901
|
{ result: depositInfoResult },
|
|
5574
5902
|
{ result: withdrawalInfoResult },
|
|
5575
5903
|
{ result: cycleIndex }
|
|
5576
|
-
] = await (0,
|
|
5904
|
+
] = await (0, import_core26.readContracts)(wagmiConfig, {
|
|
5577
5905
|
contracts: [
|
|
5578
5906
|
{
|
|
5579
5907
|
...sAutoContract,
|
|
@@ -5609,8 +5937,8 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5609
5937
|
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
5610
5938
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
5611
5939
|
}
|
|
5612
|
-
const withdrawalAmountUsd = (0,
|
|
5613
|
-
(0,
|
|
5940
|
+
const withdrawalAmountUsd = (0, import_utils51.formatCurrency)(
|
|
5941
|
+
(0, import_utils51.formatEtherNum)(withdrawalAmount) * autoPrice
|
|
5614
5942
|
);
|
|
5615
5943
|
const lockDuration = Number(depositLockDuration);
|
|
5616
5944
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -5620,24 +5948,24 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5620
5948
|
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
5621
5949
|
const lockRenew = currentCycle - lockStart > lockDuration ? currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement : currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd;
|
|
5622
5950
|
const withdrawAvailable = lockRenew - 1;
|
|
5623
|
-
const balanceUSD = (0,
|
|
5624
|
-
Number((0,
|
|
5951
|
+
const balanceUSD = (0, import_utils51.formatCurrency)(
|
|
5952
|
+
Number((0, import_viem23.formatEther)(balanceExcludingWithdrawal)) * autoPrice
|
|
5625
5953
|
);
|
|
5626
|
-
const balanceExcludingWithdrawalUsd = (0,
|
|
5627
|
-
(0,
|
|
5954
|
+
const balanceExcludingWithdrawalUsd = (0, import_utils51.formatCurrency)(
|
|
5955
|
+
(0, import_utils51.formatEtherNum)(balanceExcludingWithdrawal) * autoPrice
|
|
5628
5956
|
);
|
|
5629
5957
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
5630
5958
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
5631
|
-
const unlockRequestPeriodStartUnix = (0,
|
|
5632
|
-
const unlockRequestPeriodEndUnix = (0,
|
|
5959
|
+
const unlockRequestPeriodStartUnix = (0, import_utils51.convertAutoCycleToUnix)(withdrawAvailable) - Date.now() / 1e3;
|
|
5960
|
+
const unlockRequestPeriodEndUnix = (0, import_utils51.convertAutoCycleToUnix)(lockRenew) - Date.now() / 1e3;
|
|
5633
5961
|
const hasBalance = balance > 0n;
|
|
5634
5962
|
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
5635
5963
|
const hasUnlockableBalance = withdrawalMinCycle <= BigInt(currentCycle) && withdrawalAmount > 0n;
|
|
5636
5964
|
const cyclesInAMonth = 4;
|
|
5637
5965
|
const lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
5638
5966
|
const unlockPeriodDateRangeArray = [
|
|
5639
|
-
new Date((0,
|
|
5640
|
-
new Date((0,
|
|
5967
|
+
new Date((0, import_utils51.convertAutoCycleToUnix)(withdrawAvailable) * 1e3),
|
|
5968
|
+
new Date((0, import_utils51.convertAutoCycleToUnix)(lockRenew) * 1e3)
|
|
5641
5969
|
];
|
|
5642
5970
|
const {
|
|
5643
5971
|
unlockPeriodDateRange,
|
|
@@ -5646,20 +5974,20 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5646
5974
|
unlockPeriodStartDate,
|
|
5647
5975
|
unlockRenewalDate
|
|
5648
5976
|
} = formatDateRange(unlockPeriodDateRangeArray, "date");
|
|
5649
|
-
const totalActiveUserCredits = (0,
|
|
5650
|
-
const totalUserCredits = (0,
|
|
5977
|
+
const totalActiveUserCredits = (0, import_utils51.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
5978
|
+
const totalUserCredits = (0, import_utils51.formatEtherNum)(balance) * lockDurationInMonths;
|
|
5651
5979
|
const hasAddedLockedAuto = depositAmount > 0n;
|
|
5652
5980
|
const addedLockedAuto = depositAmount;
|
|
5653
5981
|
return {
|
|
5654
5982
|
balance,
|
|
5655
5983
|
balanceUSD,
|
|
5656
|
-
balanceExcludingWithdrawal: hasBalance ? (0,
|
|
5984
|
+
balanceExcludingWithdrawal: hasBalance ? (0, import_utils51.formatAmount)((0, import_viem23.formatEther)(balanceExcludingWithdrawal)) : "0.00",
|
|
5657
5985
|
balanceExcludingWithdrawalUsd,
|
|
5658
5986
|
hasBalanceExcludingWithdrawal,
|
|
5659
|
-
timeLeftBeforeUnlockRequestAvailable: (0,
|
|
5987
|
+
timeLeftBeforeUnlockRequestAvailable: (0, import_utils51.convertSecondsToRemainingTime)(
|
|
5660
5988
|
unlockRequestPeriodStartUnix
|
|
5661
5989
|
),
|
|
5662
|
-
timeLeftBeforeUnlockRequestUnavailable: (0,
|
|
5990
|
+
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils51.convertSecondsToRemainingTime)(
|
|
5663
5991
|
unlockRequestPeriodEndUnix
|
|
5664
5992
|
),
|
|
5665
5993
|
withdrawalAmount,
|
|
@@ -5676,7 +6004,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5676
6004
|
unlockRenewalDate,
|
|
5677
6005
|
lockDurationInMonths,
|
|
5678
6006
|
boost: lockDuration,
|
|
5679
|
-
points: (0,
|
|
6007
|
+
points: (0, import_utils51.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
5680
6008
|
totalActiveCredits: totalActiveUserCredits,
|
|
5681
6009
|
totalCredits: totalUserCredits,
|
|
5682
6010
|
hasBalance
|
|
@@ -5688,25 +6016,25 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5688
6016
|
};
|
|
5689
6017
|
|
|
5690
6018
|
// functions/getSAuto.ts
|
|
5691
|
-
var
|
|
5692
|
-
var
|
|
5693
|
-
var
|
|
5694
|
-
var
|
|
6019
|
+
var import_viem24 = require("viem");
|
|
6020
|
+
var import_core27 = require("@wagmi/core");
|
|
6021
|
+
var import_abis24 = require("@tokemak/abis");
|
|
6022
|
+
var import_utils53 = require("@tokemak/utils");
|
|
5695
6023
|
var import_config20 = require("@tokemak/config");
|
|
5696
|
-
var
|
|
6024
|
+
var import_chains18 = require("viem/chains");
|
|
5697
6025
|
var getSAuto = async (wagmiConfig, {
|
|
5698
6026
|
autoPrice
|
|
5699
6027
|
}) => {
|
|
5700
6028
|
try {
|
|
5701
6029
|
const { sAuto } = (0, import_config20.getMainnetConfig)();
|
|
5702
|
-
const chainId =
|
|
6030
|
+
const chainId = import_chains18.mainnet.id;
|
|
5703
6031
|
const baseConfig = {
|
|
5704
6032
|
address: sAuto,
|
|
5705
|
-
abi:
|
|
6033
|
+
abi: import_abis24.sAutoAbi,
|
|
5706
6034
|
chainId
|
|
5707
6035
|
};
|
|
5708
6036
|
if (sAuto && autoPrice) {
|
|
5709
|
-
const [{ result: totalSupply }, { result: currentCycle }] = await (0,
|
|
6037
|
+
const [{ result: totalSupply }, { result: currentCycle }] = await (0, import_core27.readContracts)(wagmiConfig, {
|
|
5710
6038
|
contracts: [
|
|
5711
6039
|
{
|
|
5712
6040
|
...baseConfig,
|
|
@@ -5718,15 +6046,15 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5718
6046
|
}
|
|
5719
6047
|
]
|
|
5720
6048
|
});
|
|
5721
|
-
const tvl = Number((0,
|
|
5722
|
-
const secondsLeftBeforeNextCycle = (0,
|
|
6049
|
+
const tvl = Number((0, import_viem24.formatEther)(totalSupply || 0n)) * autoPrice;
|
|
6050
|
+
const secondsLeftBeforeNextCycle = (0, import_utils53.convertAutoCycleToUnix)(Number(currentCycle) + 1) - Date.now() / 1e3;
|
|
5723
6051
|
return {
|
|
5724
6052
|
rawTotalSupply: totalSupply,
|
|
5725
|
-
totalSupply: (0,
|
|
5726
|
-
tvl: (0,
|
|
6053
|
+
totalSupply: (0, import_utils53.formatLargeNumber)((0, import_viem24.formatEther)(totalSupply || 0n)),
|
|
6054
|
+
tvl: (0, import_utils53.formatTVL)(tvl),
|
|
5727
6055
|
rawTVL: tvl,
|
|
5728
6056
|
currentCycle,
|
|
5729
|
-
timeBeforeNextCycle: (0,
|
|
6057
|
+
timeBeforeNextCycle: (0, import_utils53.convertSecondsToRemainingTime)(
|
|
5730
6058
|
secondsLeftBeforeNextCycle
|
|
5731
6059
|
)
|
|
5732
6060
|
};
|
|
@@ -5737,34 +6065,34 @@ var getSAuto = async (wagmiConfig, {
|
|
|
5737
6065
|
};
|
|
5738
6066
|
|
|
5739
6067
|
// functions/getSAutoRewards.ts
|
|
5740
|
-
var
|
|
5741
|
-
var
|
|
5742
|
-
var
|
|
5743
|
-
var
|
|
6068
|
+
var import_viem25 = require("viem");
|
|
6069
|
+
var import_utils54 = require("@tokemak/utils");
|
|
6070
|
+
var import_graph_cli18 = require("@tokemak/graph-cli");
|
|
6071
|
+
var import_chains19 = require("viem/chains");
|
|
5744
6072
|
var getSAutoRewards = async () => {
|
|
5745
6073
|
try {
|
|
5746
|
-
const { GetSAutoRewards } = (0,
|
|
6074
|
+
const { GetSAutoRewards } = (0, import_graph_cli18.getSdkByChainId)(import_chains19.mainnet.id);
|
|
5747
6075
|
const { globalRewardsBalances } = await GetSAutoRewards();
|
|
5748
6076
|
const allGlobalRewardsBalanceDayDatas = await paginateQuery(
|
|
5749
6077
|
GetSAutoRewards,
|
|
5750
6078
|
"globalRewardsBalanceDayDatas"
|
|
5751
6079
|
);
|
|
5752
6080
|
const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
|
|
5753
|
-
return acc + (0,
|
|
6081
|
+
return acc + (0, import_utils54.formatEtherNum)(balance.balance);
|
|
5754
6082
|
}, 0);
|
|
5755
6083
|
const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
|
|
5756
|
-
return acc + Number((0,
|
|
6084
|
+
return acc + Number((0, import_viem25.formatUnits)(balance.balanceUSD, 8));
|
|
5757
6085
|
}, 0);
|
|
5758
6086
|
const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
|
|
5759
6087
|
(dayData) => ({
|
|
5760
6088
|
timestamp: String(dayData.timestamp),
|
|
5761
|
-
balance: (0,
|
|
5762
|
-
balanceUSD: Number((0,
|
|
5763
|
-
earned: (0,
|
|
5764
|
-
earnedUSD: Number((0,
|
|
5765
|
-
dayAprPerCredit: (0,
|
|
5766
|
-
formattedDate: (0,
|
|
5767
|
-
(0,
|
|
6089
|
+
balance: (0, import_utils54.formatEtherNum)(dayData.balance),
|
|
6090
|
+
balanceUSD: Number((0, import_viem25.formatUnits)(dayData.balanceUSD, 8)),
|
|
6091
|
+
earned: (0, import_utils54.formatEtherNum)(dayData.earned),
|
|
6092
|
+
earnedUSD: Number((0, import_viem25.formatUnits)(dayData.earnedUSD, 8)),
|
|
6093
|
+
dayAprPerCredit: (0, import_utils54.formatEtherNum)(dayData.dayAprPerCredit),
|
|
6094
|
+
formattedDate: (0, import_utils54.formatDateToReadable)(
|
|
6095
|
+
(0, import_utils54.convertTimestampToDate)(Number(dayData.timestamp))
|
|
5768
6096
|
)
|
|
5769
6097
|
})
|
|
5770
6098
|
);
|
|
@@ -5781,7 +6109,7 @@ var getSAutoRewards = async () => {
|
|
|
5781
6109
|
|
|
5782
6110
|
// functions/getUserSAutoRewards.ts
|
|
5783
6111
|
var import_config21 = require("@tokemak/config");
|
|
5784
|
-
var
|
|
6112
|
+
var import_utils56 = require("@tokemak/utils");
|
|
5785
6113
|
var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
5786
6114
|
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = (0, import_config21.getMainnetConfig)();
|
|
5787
6115
|
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
@@ -5827,19 +6155,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
|
5827
6155
|
return null;
|
|
5828
6156
|
}
|
|
5829
6157
|
}
|
|
5830
|
-
const claimableNum = (0,
|
|
6158
|
+
const claimableNum = (0, import_utils56.formatEtherNum)(autoRewards?.claimable || 0n);
|
|
5831
6159
|
const claimableUsd = autoPrice * claimableNum;
|
|
5832
6160
|
const hasClaimable = claimableNum > 0;
|
|
5833
|
-
let pendingRewards = (0,
|
|
6161
|
+
let pendingRewards = (0, import_utils56.formatEtherNum)(
|
|
5834
6162
|
autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5835
6163
|
);
|
|
5836
6164
|
if (currentCycle === 4242n) {
|
|
5837
|
-
pendingRewards = (0,
|
|
6165
|
+
pendingRewards = (0, import_utils56.formatEtherNum)(
|
|
5838
6166
|
autoRewards?.rewardsPayload.payload.amount || 0n
|
|
5839
6167
|
);
|
|
5840
6168
|
}
|
|
5841
6169
|
const pendingRewardsUsd = autoPrice * pendingRewards;
|
|
5842
|
-
const totalRewardsReceived = (0,
|
|
6170
|
+
const totalRewardsReceived = (0, import_utils56.formatEtherNum)(
|
|
5843
6171
|
autoRewards.rewardsPayload.payload.amount || 0n
|
|
5844
6172
|
);
|
|
5845
6173
|
const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
|
|
@@ -5873,20 +6201,20 @@ var getUserMerklRewards = async (address) => {
|
|
|
5873
6201
|
};
|
|
5874
6202
|
|
|
5875
6203
|
// functions/getUserEthAutoLPRewards.ts
|
|
5876
|
-
var
|
|
5877
|
-
var
|
|
6204
|
+
var import_viem26 = require("viem");
|
|
6205
|
+
var import_utils57 = require("@tokemak/utils");
|
|
5878
6206
|
var import_tokenlist15 = require("@tokemak/tokenlist");
|
|
5879
6207
|
var getUserEthAutoLPRewards = async (address) => {
|
|
5880
6208
|
const rewards = await getUserMerklRewards(address);
|
|
5881
6209
|
const autoTokenRewards = rewards?.rewards?.filter(
|
|
5882
|
-
(reward) => (0,
|
|
6210
|
+
(reward) => (0, import_viem26.getAddress)(reward.token.address) === (0, import_viem26.getAddress)(import_tokenlist15.TOKE_TOKEN.address)
|
|
5883
6211
|
);
|
|
5884
6212
|
const autoRewards = autoTokenRewards?.[0];
|
|
5885
6213
|
const amount = autoRewards?.amount;
|
|
5886
6214
|
const claimed = autoRewards?.claimed;
|
|
5887
6215
|
const claimable = Number(amount) - Number(claimed);
|
|
5888
|
-
const formattedClaimable = (0,
|
|
5889
|
-
(0,
|
|
6216
|
+
const formattedClaimable = (0, import_utils57.formatAmount)(
|
|
6217
|
+
(0, import_utils57.formatUnitsNum)(BigInt(claimable || 0), 18)
|
|
5890
6218
|
);
|
|
5891
6219
|
const users = [];
|
|
5892
6220
|
const tokens = [];
|
|
@@ -5938,12 +6266,12 @@ async function getMerklPoolApr({
|
|
|
5938
6266
|
}
|
|
5939
6267
|
|
|
5940
6268
|
// functions/getSAutoApr.ts
|
|
5941
|
-
var
|
|
5942
|
-
var
|
|
5943
|
-
var
|
|
6269
|
+
var import_graph_cli19 = require("@tokemak/graph-cli");
|
|
6270
|
+
var import_chains20 = require("viem/chains");
|
|
6271
|
+
var import_utils58 = require("@tokemak/utils");
|
|
5944
6272
|
var getSAutoApr = async () => {
|
|
5945
6273
|
try {
|
|
5946
|
-
const { GetSAutoApr } = (0,
|
|
6274
|
+
const { GetSAutoApr } = (0, import_graph_cli19.getSdkByChainId)(import_chains20.mainnet.id);
|
|
5947
6275
|
const { globalRewardsBalances } = await GetSAutoApr();
|
|
5948
6276
|
if (!globalRewardsBalances || globalRewardsBalances.length === 0) {
|
|
5949
6277
|
return {
|
|
@@ -5959,12 +6287,12 @@ var getSAutoApr = async () => {
|
|
|
5959
6287
|
aprFormatted: void 0
|
|
5960
6288
|
};
|
|
5961
6289
|
}
|
|
5962
|
-
const aprPerCredit = (0,
|
|
6290
|
+
const aprPerCredit = (0, import_utils58.formatEtherNum)(rawApr);
|
|
5963
6291
|
const lockDuration = 16;
|
|
5964
6292
|
const apr = aprPerCredit * lockDuration;
|
|
5965
6293
|
return {
|
|
5966
6294
|
apr,
|
|
5967
|
-
aprFormatted: (0,
|
|
6295
|
+
aprFormatted: (0, import_utils58.formatPercent)(apr)
|
|
5968
6296
|
};
|
|
5969
6297
|
} catch (error) {
|
|
5970
6298
|
console.error("Error fetching sAUTO APR:", error);
|
|
@@ -6051,8 +6379,12 @@ var getCombinedRewards = async () => {
|
|
|
6051
6379
|
getAutopilotRouter,
|
|
6052
6380
|
getAutopoolCategory,
|
|
6053
6381
|
getAutopoolDayData,
|
|
6382
|
+
getAutopoolHistory,
|
|
6054
6383
|
getAutopoolInfo,
|
|
6055
6384
|
getAutopoolRebalances,
|
|
6385
|
+
getAutopoolUser,
|
|
6386
|
+
getAutopoolUserActivity,
|
|
6387
|
+
getAutopoolUserHistory,
|
|
6056
6388
|
getAutopools,
|
|
6057
6389
|
getAutopoolsHistory,
|
|
6058
6390
|
getAutopoolsRebalances,
|