@tokemak/queries 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/getAutopoolDayData.d.ts.map +1 -1
- package/dist/functions/getAutopoolHistory.d.ts.map +1 -1
- package/dist/functions/getAutopools.d.ts +3 -3
- package/dist/functions/getAutopools.d.ts.map +1 -1
- package/dist/functions/getAutopoolsRebalances.d.ts.map +1 -1
- package/dist/functions/getChainAutopools.d.ts +3 -3
- package/dist/functions/getChainAutopools.d.ts.map +1 -1
- package/dist/functions/getEthPriceAtBlock.d.ts +2 -2
- package/dist/functions/getEthPriceAtBlock.d.ts.map +1 -1
- package/dist/functions/getMultipleAutopoolRebalances.d.ts.map +1 -1
- package/dist/functions/getPoolsAndDestinations.d.ts +2 -2
- package/dist/functions/getPoolsAndDestinations.d.ts.map +1 -1
- package/dist/functions/getRebalanceStats.d.ts +7 -6
- package/dist/functions/getRebalanceStats.d.ts.map +1 -1
- package/dist/functions/getTokenPrices.d.ts +1 -1
- package/dist/functions/getTokenPrices.d.ts.map +1 -1
- package/dist/functions/getUserAutopoolBalanceChanges.d.ts.map +1 -1
- package/dist/functions/getUserAutopools.d.ts +1 -1
- package/dist/functions/getUserAutopools.d.ts.map +1 -1
- package/dist/functions/getUserSAuto.d.ts +1 -1
- package/dist/functions/getUserSAuto.d.ts.map +1 -1
- package/dist/functions/updateRebalanceStats.d.ts +2 -2
- package/dist/functions/updateRebalanceStats.d.ts.map +1 -1
- package/dist/index.js +290 -358
- package/dist/index.mjs +180 -251
- package/dist/safe.d.ts +9 -0
- package/dist/safe.d.ts.map +1 -0
- package/dist/safe.js +860 -0
- package/dist/safe.mjs +848 -0
- package/package.json +27 -16
- package/dist/functions/getBackupApr.d.ts +0 -2
- package/dist/functions/getBackupApr.d.ts.map +0 -1
- package/dist/functions/getBackupTokenPrices.d.ts +0 -6
- package/dist/functions/getBackupTokenPrices.d.ts.map +0 -1
- package/dist/functions/getPoolsAndDestinationsBackup.d.ts +0 -67
- package/dist/functions/getPoolsAndDestinationsBackup.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -127,6 +127,9 @@ var getTokePrice = async () => {
|
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
+
// functions/getAutopools.ts
|
|
131
|
+
import { getPublicClient } from "@wagmi/core";
|
|
132
|
+
|
|
130
133
|
// utils/getExchangeNames.ts
|
|
131
134
|
function getExchangeNames(destinationVaults) {
|
|
132
135
|
const uniqueNamesSet = /* @__PURE__ */ new Set();
|
|
@@ -487,26 +490,12 @@ async function paginateQuery(queryFn, arrayKey, options = {}) {
|
|
|
487
490
|
return results;
|
|
488
491
|
}
|
|
489
492
|
|
|
490
|
-
// functions/getPoolsAndDestinationsBackup.ts
|
|
491
|
-
import { getNetwork } from "@tokemak/utils";
|
|
492
|
-
var getPoolsAndDestinationsBackup = async (chainId) => {
|
|
493
|
-
try {
|
|
494
|
-
const networkName = getNetwork(chainId)?.name.toLowerCase();
|
|
495
|
-
const backupData = await getBlobData(
|
|
496
|
-
`${networkName}-getPoolsAndDestinations-latest-success.json`
|
|
497
|
-
);
|
|
498
|
-
return backupData?.data;
|
|
499
|
-
} catch (e) {
|
|
500
|
-
console.error(e);
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
|
|
504
493
|
// functions/getChainAutopools.ts
|
|
505
494
|
import {
|
|
506
495
|
formatEtherNum as formatEtherNum2,
|
|
507
496
|
formatPoolName,
|
|
508
497
|
formatUnitsNum,
|
|
509
|
-
getNetwork
|
|
498
|
+
getNetwork,
|
|
510
499
|
getProtocol,
|
|
511
500
|
getToken
|
|
512
501
|
} from "@tokemak/utils";
|
|
@@ -620,16 +609,14 @@ import { sonic } from "viem/chains";
|
|
|
620
609
|
|
|
621
610
|
// functions/getPoolsAndDestinations.ts
|
|
622
611
|
import { getCoreConfig } from "@tokemak/config";
|
|
623
|
-
import { readContract } from "@wagmi/core";
|
|
624
612
|
import { lensAbi } from "@tokemak/abis";
|
|
625
|
-
var getPoolsAndDestinations = async (
|
|
613
|
+
var getPoolsAndDestinations = async (client, { chainId }) => {
|
|
626
614
|
try {
|
|
627
615
|
const { lens } = getCoreConfig(chainId);
|
|
628
|
-
const { autoPools, destinations } = await readContract(
|
|
616
|
+
const { autoPools, destinations } = await client.readContract({
|
|
629
617
|
address: lens,
|
|
630
618
|
abi: lensAbi,
|
|
631
|
-
functionName: "getPoolsAndDestinations"
|
|
632
|
-
chainId
|
|
619
|
+
functionName: "getPoolsAndDestinations"
|
|
633
620
|
});
|
|
634
621
|
const autopoolsAndDestinations = mergeArraysWithKey(
|
|
635
622
|
autoPools,
|
|
@@ -642,27 +629,6 @@ var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
|
|
|
642
629
|
}
|
|
643
630
|
};
|
|
644
631
|
|
|
645
|
-
// functions/getBackupApr.ts
|
|
646
|
-
import { getNetwork as getNetwork2 } from "@tokemak/utils";
|
|
647
|
-
var getBackupApr = async (chainId, poolAddress) => {
|
|
648
|
-
try {
|
|
649
|
-
const networkName = getNetwork2(chainId)?.name.toLowerCase();
|
|
650
|
-
const backupData = await getBlobData(
|
|
651
|
-
`${networkName}-getChainAutopools-latest-success.json`
|
|
652
|
-
);
|
|
653
|
-
if (backupData) {
|
|
654
|
-
const backupApr = backupData.data.find(
|
|
655
|
-
(item) => item.poolAddress.toLowerCase() === poolAddress.toLowerCase()
|
|
656
|
-
)?.apr.base;
|
|
657
|
-
return backupApr || 0;
|
|
658
|
-
}
|
|
659
|
-
} catch (e) {
|
|
660
|
-
console.error(e);
|
|
661
|
-
return 0;
|
|
662
|
-
}
|
|
663
|
-
return null;
|
|
664
|
-
};
|
|
665
|
-
|
|
666
632
|
// functions/getChainAutopools.ts
|
|
667
633
|
import {
|
|
668
634
|
NEW_AUTOPOOL_THRESHOLD_DAYS,
|
|
@@ -670,7 +636,7 @@ import {
|
|
|
670
636
|
DEAD_ADDRESS,
|
|
671
637
|
ZERO_ADDRESS
|
|
672
638
|
} from "@tokemak/constants";
|
|
673
|
-
var getChainAutopools = async (
|
|
639
|
+
var getChainAutopools = async (client, {
|
|
674
640
|
chainId,
|
|
675
641
|
prices
|
|
676
642
|
}) => {
|
|
@@ -684,21 +650,19 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
684
650
|
const genStratAprs = await getGenStratAprs({
|
|
685
651
|
chainId
|
|
686
652
|
});
|
|
687
|
-
|
|
653
|
+
const autopoolsAndDestinations = await getPoolsAndDestinations(client, {
|
|
688
654
|
chainId
|
|
689
655
|
});
|
|
690
656
|
if (!autopoolsAndDestinations) {
|
|
691
|
-
|
|
692
|
-
if (backupData) {
|
|
693
|
-
autopoolsAndDestinations = backupData;
|
|
694
|
-
} else {
|
|
695
|
-
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
696
|
-
}
|
|
657
|
+
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
697
658
|
}
|
|
698
|
-
const vaultAddedMapping = vaultAddeds.reduce(
|
|
699
|
-
acc
|
|
700
|
-
|
|
701
|
-
|
|
659
|
+
const vaultAddedMapping = vaultAddeds.reduce(
|
|
660
|
+
(acc, vaultAdded) => {
|
|
661
|
+
acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
|
|
662
|
+
return acc;
|
|
663
|
+
},
|
|
664
|
+
{}
|
|
665
|
+
);
|
|
702
666
|
const autopools = await Promise.all(
|
|
703
667
|
autopoolsAndDestinations.map(async (autopool) => {
|
|
704
668
|
let baseAsset = getToken(autopool.baseAsset);
|
|
@@ -820,15 +784,18 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
820
784
|
},
|
|
821
785
|
[]
|
|
822
786
|
);
|
|
823
|
-
const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
|
|
824
|
-
|
|
825
|
-
acc[token.address]
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
787
|
+
const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
|
|
788
|
+
(acc, token) => {
|
|
789
|
+
if (acc[token.address]) {
|
|
790
|
+
acc[token.address].valueUsd += token.valueUsd;
|
|
791
|
+
acc[token.address].value += token.value;
|
|
792
|
+
} else {
|
|
793
|
+
acc[token.address] = { ...token };
|
|
794
|
+
}
|
|
795
|
+
return acc;
|
|
796
|
+
},
|
|
797
|
+
{}
|
|
798
|
+
);
|
|
832
799
|
const HIDDEN_TOKEN_SYMBOLS = ["USR", "WSTUSR"];
|
|
833
800
|
const uniqueTokens = Object.values(uniqueTokensWithValueHeldMap).filter(
|
|
834
801
|
(token) => !HIDDEN_TOKEN_SYMBOLS.includes(token.symbol?.toUpperCase())
|
|
@@ -857,20 +824,8 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
857
824
|
const aprs = autopoolsApr.find(
|
|
858
825
|
(autopoolApr) => getAddress(autopoolApr.id) === getAddress(autopool.poolAddress)
|
|
859
826
|
);
|
|
860
|
-
|
|
827
|
+
const baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
|
|
861
828
|
let extraApr = 0;
|
|
862
|
-
if (baseApr === void 0) {
|
|
863
|
-
try {
|
|
864
|
-
const backupApr = await getBackupApr(chainId, autopool.poolAddress);
|
|
865
|
-
if (backupApr) {
|
|
866
|
-
baseApr = backupApr;
|
|
867
|
-
console.log("using backup apr", backupApr);
|
|
868
|
-
}
|
|
869
|
-
} catch (e) {
|
|
870
|
-
console.error(e);
|
|
871
|
-
console.log("unable to retrieve backup apr");
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
829
|
let extraRewards = [];
|
|
875
830
|
if (aprs?.rewards && aprs.rewards.length > 0) {
|
|
876
831
|
extraRewards = aprs.rewards.map((reward) => {
|
|
@@ -882,8 +837,8 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
882
837
|
});
|
|
883
838
|
}
|
|
884
839
|
extraApr = extraRewards.reduce((acc, reward) => acc + reward.apr, 0);
|
|
885
|
-
|
|
886
|
-
const combinedApr =
|
|
840
|
+
const baseForMath = baseApr ?? 0;
|
|
841
|
+
const combinedApr = baseForMath + extraApr;
|
|
887
842
|
let denominatedToken = ETH_TOKEN;
|
|
888
843
|
let useDenominatedValues = false;
|
|
889
844
|
const denominationData = autopoolsDenomination.find(
|
|
@@ -938,7 +893,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
938
893
|
prices
|
|
939
894
|
);
|
|
940
895
|
const baseDailyEarnings = convertBaseAssetToTokenPricesAndDenom(
|
|
941
|
-
totalAssets *
|
|
896
|
+
totalAssets * baseForMath / DAYS_PER_YEAR,
|
|
942
897
|
baseAssetPrice,
|
|
943
898
|
denominatedTokenPrice,
|
|
944
899
|
prices
|
|
@@ -946,36 +901,39 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
946
901
|
const tokenOrder = [UIBaseAsset.symbol, ...UITokenOrder].filter(
|
|
947
902
|
(value, index, array) => array.indexOf(value) === index
|
|
948
903
|
);
|
|
949
|
-
const UITokens = uniqueTokens.reduce(
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
904
|
+
const UITokens = uniqueTokens.reduce(
|
|
905
|
+
(acc, token) => {
|
|
906
|
+
try {
|
|
907
|
+
const parentAsset = token.extensions?.parentAsset;
|
|
908
|
+
if (parentAsset) {
|
|
909
|
+
const parentToken = ALL_TOKENS.find(
|
|
910
|
+
(t) => t.symbol.toLowerCase() === parentAsset.toLowerCase()
|
|
911
|
+
);
|
|
912
|
+
if (parentToken && !acc.some(
|
|
913
|
+
(t) => t?.address?.toLowerCase() === parentToken?.address?.toLowerCase()
|
|
914
|
+
)) {
|
|
915
|
+
acc.push({
|
|
916
|
+
...parentToken,
|
|
917
|
+
valueUsd: 0,
|
|
918
|
+
value: 0,
|
|
919
|
+
allocation: 0
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
} else if (!acc.some(
|
|
923
|
+
(t) => t?.address?.toLowerCase() === token?.address?.toLowerCase()
|
|
958
924
|
)) {
|
|
959
|
-
acc.push(
|
|
960
|
-
...parentToken,
|
|
961
|
-
valueUsd: 0,
|
|
962
|
-
value: 0,
|
|
963
|
-
allocation: 0
|
|
964
|
-
});
|
|
925
|
+
acc.push(token);
|
|
965
926
|
}
|
|
966
|
-
}
|
|
967
|
-
(
|
|
968
|
-
|
|
969
|
-
|
|
927
|
+
} catch (error) {
|
|
928
|
+
console.warn(
|
|
929
|
+
`Error processing token: ${token?.symbol || "unknown"}`,
|
|
930
|
+
error
|
|
931
|
+
);
|
|
970
932
|
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
);
|
|
976
|
-
}
|
|
977
|
-
return acc;
|
|
978
|
-
}, []).sort((a, b) => {
|
|
933
|
+
return acc;
|
|
934
|
+
},
|
|
935
|
+
[]
|
|
936
|
+
).sort((a, b) => {
|
|
979
937
|
try {
|
|
980
938
|
const aIndex = tokenOrder.indexOf(a.symbol.toUpperCase());
|
|
981
939
|
const bIndex = tokenOrder.indexOf(b.symbol.toUpperCase());
|
|
@@ -1018,7 +976,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1018
976
|
});
|
|
1019
977
|
const autopoolInfo = getAutopoolInfo(autopool.symbol);
|
|
1020
978
|
if (autopoolInfo && !autopoolInfo.description) {
|
|
1021
|
-
autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${
|
|
979
|
+
autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${getNetwork(chainId)?.name}.`;
|
|
1022
980
|
}
|
|
1023
981
|
return {
|
|
1024
982
|
...autopool,
|
|
@@ -1044,9 +1002,9 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1044
1002
|
UITokens,
|
|
1045
1003
|
UIExchanges: finalUIExchanges,
|
|
1046
1004
|
tokens: uniqueTokens,
|
|
1047
|
-
chain:
|
|
1005
|
+
chain: getNetwork(chainId),
|
|
1048
1006
|
apr: {
|
|
1049
|
-
base: baseApr,
|
|
1007
|
+
base: baseApr ?? null,
|
|
1050
1008
|
extraAprs: extraRewards,
|
|
1051
1009
|
combined: combinedApr,
|
|
1052
1010
|
hasExtraAprs: extraRewards.length > 0
|
|
@@ -1084,12 +1042,13 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1084
1042
|
try {
|
|
1085
1043
|
const chains = getChainsForEnv({ includeTestnet });
|
|
1086
1044
|
const autopools = (await Promise.all(
|
|
1087
|
-
chains.map(
|
|
1088
|
-
|
|
1045
|
+
chains.map((chain) => {
|
|
1046
|
+
const chainId = chain?.chainId;
|
|
1047
|
+
return getChainAutopools(getPublicClient(wagmiConfig, { chainId }), {
|
|
1089
1048
|
prices,
|
|
1090
|
-
chainId
|
|
1091
|
-
})
|
|
1092
|
-
)
|
|
1049
|
+
chainId
|
|
1050
|
+
});
|
|
1051
|
+
})
|
|
1093
1052
|
)).flat();
|
|
1094
1053
|
const sortedAutopoolsByTimestamp = autopools.sort(
|
|
1095
1054
|
(a, b) => b.timestamp - a.timestamp
|
|
@@ -1280,7 +1239,7 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
|
|
|
1280
1239
|
|
|
1281
1240
|
// functions/getAutopoolUser.ts
|
|
1282
1241
|
import { erc20Abi } from "viem";
|
|
1283
|
-
import { readContract
|
|
1242
|
+
import { readContract, readContracts } from "@wagmi/core";
|
|
1284
1243
|
import { autopoolEthAbi } from "@tokemak/abis";
|
|
1285
1244
|
import {
|
|
1286
1245
|
convertTimestampToDate as convertTimestampToDate2,
|
|
@@ -1321,7 +1280,7 @@ var getAutopoolUser = async (config, {
|
|
|
1321
1280
|
if (unstakedPoolSharesError) {
|
|
1322
1281
|
throw new Error("Error fetching unstaked pool shares");
|
|
1323
1282
|
}
|
|
1324
|
-
const stakedPoolShares = await
|
|
1283
|
+
const stakedPoolShares = await readContract(config, {
|
|
1325
1284
|
address: autopoolRewarderContract,
|
|
1326
1285
|
abi: erc20Abi,
|
|
1327
1286
|
functionName: "balanceOf",
|
|
@@ -2751,7 +2710,7 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
|
|
|
2751
2710
|
|
|
2752
2711
|
// functions/getUserAutoEthRewards.ts
|
|
2753
2712
|
import { autoEthRewardsHashAbi } from "@tokemak/abis";
|
|
2754
|
-
import { readContract as
|
|
2713
|
+
import { readContract as readContract2 } from "@wagmi/core";
|
|
2755
2714
|
import { convertChainCycleToUnix, formatCurrency } from "@tokemak/utils";
|
|
2756
2715
|
var getAutoEthRewards = async (wagmiConfig, {
|
|
2757
2716
|
account,
|
|
@@ -2761,14 +2720,14 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2761
2720
|
chainId
|
|
2762
2721
|
}) => {
|
|
2763
2722
|
try {
|
|
2764
|
-
const [, drippingHash] = await
|
|
2723
|
+
const [, drippingHash] = await readContract2(wagmiConfig, {
|
|
2765
2724
|
address: rewardsHash,
|
|
2766
2725
|
abi: autoEthRewardsHashAbi,
|
|
2767
2726
|
functionName: "cycleHashes",
|
|
2768
2727
|
args: [currentCycleIndex - 306n],
|
|
2769
2728
|
chainId
|
|
2770
2729
|
});
|
|
2771
|
-
const [, lastWeekHash] = await
|
|
2730
|
+
const [, lastWeekHash] = await readContract2(wagmiConfig, {
|
|
2772
2731
|
address: rewardsHash,
|
|
2773
2732
|
abi: autoEthRewardsHashAbi,
|
|
2774
2733
|
functionName: "cycleHashes",
|
|
@@ -2819,7 +2778,7 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
|
|
|
2819
2778
|
|
|
2820
2779
|
// functions/getUserRewardsV1.ts
|
|
2821
2780
|
import { rewardsV1Abi, rewardsV1HashAbi } from "@tokemak/abis";
|
|
2822
|
-
import { readContract as
|
|
2781
|
+
import { readContract as readContract3 } from "@wagmi/core";
|
|
2823
2782
|
var getUserRewardsV1 = async (wagmiConfig, {
|
|
2824
2783
|
address,
|
|
2825
2784
|
rewardsCycleIndex,
|
|
@@ -2829,7 +2788,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2829
2788
|
chainId
|
|
2830
2789
|
}) => {
|
|
2831
2790
|
try {
|
|
2832
|
-
const [latestClaimableHash, cycleRewardsHash] = await
|
|
2791
|
+
const [latestClaimableHash, cycleRewardsHash] = await readContract3(
|
|
2833
2792
|
wagmiConfig,
|
|
2834
2793
|
{
|
|
2835
2794
|
address: rewardsV1Hash,
|
|
@@ -2853,7 +2812,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2853
2812
|
const {
|
|
2854
2813
|
payload: { chainId: payloadChainId, cycle, wallet, amount }
|
|
2855
2814
|
} = latestClaimablePayload;
|
|
2856
|
-
const claimable = await
|
|
2815
|
+
const claimable = await readContract3(wagmiConfig, {
|
|
2857
2816
|
address: rewardsV1,
|
|
2858
2817
|
abi: rewardsV1Abi,
|
|
2859
2818
|
functionName: "getClaimableAmount",
|
|
@@ -2870,7 +2829,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2870
2829
|
|
|
2871
2830
|
// functions/getUserV1.ts
|
|
2872
2831
|
import { rewardsV1Abi as rewardsV1Abi2, stakingV1Abi } from "@tokemak/abis";
|
|
2873
|
-
import { readContract as
|
|
2832
|
+
import { readContract as readContract4 } from "@wagmi/core";
|
|
2874
2833
|
import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
|
|
2875
2834
|
import { mainnet as mainnet6 } from "viem/chains";
|
|
2876
2835
|
var getUserV1 = async (wagmiConfig, {
|
|
@@ -2889,7 +2848,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2889
2848
|
missedTokeRewards
|
|
2890
2849
|
} = getMainnetConfig3(mainnet6.id);
|
|
2891
2850
|
try {
|
|
2892
|
-
const userStakedTokeV1 = await
|
|
2851
|
+
const userStakedTokeV1 = await readContract4(wagmiConfig, {
|
|
2893
2852
|
address: stakingV1,
|
|
2894
2853
|
abi: stakingV1Abi,
|
|
2895
2854
|
functionName: "availableForWithdrawal",
|
|
@@ -2921,7 +2880,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2921
2880
|
const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
|
|
2922
2881
|
const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
|
|
2923
2882
|
const amount = autoEthGuardedRewardsPayload?.payload?.amount;
|
|
2924
|
-
const claimableAutoEth = await
|
|
2883
|
+
const claimableAutoEth = await readContract4(wagmiConfig, {
|
|
2925
2884
|
address: autoEthGuardedRewards,
|
|
2926
2885
|
abi: rewardsV1Abi2,
|
|
2927
2886
|
functionName: "getClaimableAmount",
|
|
@@ -2945,7 +2904,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2945
2904
|
const {
|
|
2946
2905
|
payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
|
|
2947
2906
|
} = missedTokeRewardsPayload;
|
|
2948
|
-
claimableMissedToke = await
|
|
2907
|
+
claimableMissedToke = await readContract4(wagmiConfig, {
|
|
2949
2908
|
address: missedTokeRewards,
|
|
2950
2909
|
abi: rewardsV1Abi2,
|
|
2951
2910
|
functionName: "getClaimableAmount",
|
|
@@ -3548,7 +3507,7 @@ import { ETH_TOKEN as ETH_TOKEN5, PRICED_TOKENS } from "@tokemak/tokenlist";
|
|
|
3548
3507
|
|
|
3549
3508
|
// functions/getUserAutopool.tsx
|
|
3550
3509
|
import { erc20Abi as erc20Abi4 } from "viem";
|
|
3551
|
-
import { readContract as
|
|
3510
|
+
import { readContract as readContract5, readContracts as readContracts8 } from "@wagmi/core";
|
|
3552
3511
|
import { formatEtherNum as formatEtherNum7 } from "@tokemak/utils";
|
|
3553
3512
|
import { autopoolEthAbi as autopoolEthAbi2 } from "@tokemak/abis";
|
|
3554
3513
|
var getUserAutopool = async (wagmiConfig, {
|
|
@@ -3591,7 +3550,7 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3591
3550
|
if (unstakedPoolSharesError) {
|
|
3592
3551
|
throw new Error("Error fetching unstaked pool shares");
|
|
3593
3552
|
}
|
|
3594
|
-
const stakedPoolShares = await
|
|
3553
|
+
const stakedPoolShares = await readContract5(wagmiConfig, {
|
|
3595
3554
|
address: autopoolRewarderContract,
|
|
3596
3555
|
abi: erc20Abi4,
|
|
3597
3556
|
functionName: "balanceOf",
|
|
@@ -3873,7 +3832,7 @@ var getUserAutopools = async ({
|
|
|
3873
3832
|
);
|
|
3874
3833
|
const stakedRatio = stakedShares / userShares;
|
|
3875
3834
|
const unstakedRatio = 1 - stakedRatio;
|
|
3876
|
-
const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * autopoolData?.apr?.base;
|
|
3835
|
+
const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * (autopoolData?.apr?.base ?? 0);
|
|
3877
3836
|
return {
|
|
3878
3837
|
name: autopoolData?.name,
|
|
3879
3838
|
symbol: autopoolData?.symbol,
|
|
@@ -3915,13 +3874,16 @@ var getUserAutopools = async ({
|
|
|
3915
3874
|
denominatedToken = autopoolWithDenomination?.denomination;
|
|
3916
3875
|
}
|
|
3917
3876
|
}
|
|
3918
|
-
const nav = Object.values(categories).reduce(
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3877
|
+
const nav = Object.values(categories).reduce(
|
|
3878
|
+
(acc, { nav: nav2 }) => {
|
|
3879
|
+
return Object.keys(nav2).reduce((sumAcc, key) => {
|
|
3880
|
+
const typedKey = key;
|
|
3881
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + nav2[typedKey];
|
|
3882
|
+
return sumAcc;
|
|
3883
|
+
}, acc);
|
|
3884
|
+
},
|
|
3885
|
+
{}
|
|
3886
|
+
);
|
|
3925
3887
|
const idleWithTokenPrices = userAutopoolsWithData.reduce(
|
|
3926
3888
|
(acc, userAutopool) => {
|
|
3927
3889
|
if (!userAutopool) return acc;
|
|
@@ -3949,20 +3911,26 @@ var getUserAutopools = async ({
|
|
|
3949
3911
|
...idle2,
|
|
3950
3912
|
allocation: idle2.USD / nav.USD
|
|
3951
3913
|
}));
|
|
3952
|
-
const returns = Object.values(categories).reduce(
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3914
|
+
const returns = Object.values(categories).reduce(
|
|
3915
|
+
(acc, { returns: returns2 }) => {
|
|
3916
|
+
return Object.keys(returns2).reduce((sumAcc, key) => {
|
|
3917
|
+
const typedKey = key;
|
|
3918
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + returns2[typedKey];
|
|
3919
|
+
return sumAcc;
|
|
3920
|
+
}, acc);
|
|
3921
|
+
},
|
|
3922
|
+
{}
|
|
3923
|
+
);
|
|
3924
|
+
const supplied = Object.values(categories).reduce(
|
|
3925
|
+
(acc, { supplied: supplied2 }) => {
|
|
3926
|
+
return Object.keys(supplied2).reduce((sumAcc, key) => {
|
|
3927
|
+
const typedKey = key;
|
|
3928
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + supplied2[typedKey];
|
|
3929
|
+
return sumAcc;
|
|
3930
|
+
}, acc);
|
|
3931
|
+
},
|
|
3932
|
+
{}
|
|
3933
|
+
);
|
|
3966
3934
|
const userExchangesWithAllocations = Object.values(userExchanges).map(
|
|
3967
3935
|
(userExchange) => {
|
|
3968
3936
|
return {
|
|
@@ -4024,11 +3992,14 @@ var getUserAutopools = async ({
|
|
|
4024
3992
|
categories[categoryKey] = {
|
|
4025
3993
|
...categoryData,
|
|
4026
3994
|
apr,
|
|
4027
|
-
avgDailyReturns: Object.keys(categoryData.nav).reduce(
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
3995
|
+
avgDailyReturns: Object.keys(categoryData.nav).reduce(
|
|
3996
|
+
(acc, key) => {
|
|
3997
|
+
const typedKey = key;
|
|
3998
|
+
acc[typedKey] = dailyRate * categoryData.nav[typedKey];
|
|
3999
|
+
return acc;
|
|
4000
|
+
},
|
|
4001
|
+
{}
|
|
4002
|
+
)
|
|
4032
4003
|
};
|
|
4033
4004
|
});
|
|
4034
4005
|
return {
|
|
@@ -4126,7 +4097,7 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
|
4126
4097
|
};
|
|
4127
4098
|
|
|
4128
4099
|
// functions/getAllowance.ts
|
|
4129
|
-
import { readContract as
|
|
4100
|
+
import { readContract as readContract6 } from "@wagmi/core";
|
|
4130
4101
|
import { erc20Abi as erc20Abi5 } from "viem";
|
|
4131
4102
|
var getAllowance = async (wagmiConfig, {
|
|
4132
4103
|
token,
|
|
@@ -4134,7 +4105,7 @@ var getAllowance = async (wagmiConfig, {
|
|
|
4134
4105
|
spender
|
|
4135
4106
|
}) => {
|
|
4136
4107
|
try {
|
|
4137
|
-
const allowance = await
|
|
4108
|
+
const allowance = await readContract6(wagmiConfig, {
|
|
4138
4109
|
address: token,
|
|
4139
4110
|
abi: erc20Abi5,
|
|
4140
4111
|
functionName: "allowance",
|
|
@@ -4181,7 +4152,7 @@ import { getAddress as getAddress4 } from "viem";
|
|
|
4181
4152
|
|
|
4182
4153
|
// functions/getChainUserAutopoolsRewards.ts
|
|
4183
4154
|
import { getCoreConfig as getCoreConfig2 } from "@tokemak/config";
|
|
4184
|
-
import { readContract as
|
|
4155
|
+
import { readContract as readContract7 } from "@wagmi/core";
|
|
4185
4156
|
import { lensAbi as lensAbi2 } from "@tokemak/abis";
|
|
4186
4157
|
var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
4187
4158
|
chainId,
|
|
@@ -4189,7 +4160,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4189
4160
|
}) => {
|
|
4190
4161
|
try {
|
|
4191
4162
|
const coreConfig = getCoreConfig2(chainId);
|
|
4192
|
-
const userRewardsInfo = await
|
|
4163
|
+
const userRewardsInfo = await readContract7(wagmiConfig, {
|
|
4193
4164
|
address: coreConfig.lens,
|
|
4194
4165
|
abi: lensAbi2,
|
|
4195
4166
|
functionName: "getUserRewardInfo",
|
|
@@ -4379,7 +4350,7 @@ import {
|
|
|
4379
4350
|
import { TOKEMAK_SWAP_QUOTE_URL } from "@tokemak/constants";
|
|
4380
4351
|
|
|
4381
4352
|
// functions/getAddressFromSystemRegistry.ts
|
|
4382
|
-
import { readContract as
|
|
4353
|
+
import { readContract as readContract8 } from "@wagmi/core";
|
|
4383
4354
|
import { getCoreConfig as getCoreConfig3 } from "@tokemak/config";
|
|
4384
4355
|
import { systemRegistryAbi as systemRegistryAbi2 } from "@tokemak/abis";
|
|
4385
4356
|
var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
@@ -4387,7 +4358,7 @@ var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
|
4387
4358
|
functionName
|
|
4388
4359
|
}) => {
|
|
4389
4360
|
const { systemRegistry } = getCoreConfig3(chainId);
|
|
4390
|
-
return await
|
|
4361
|
+
return await readContract8(wagmiConfig, {
|
|
4391
4362
|
address: systemRegistry,
|
|
4392
4363
|
abi: systemRegistryAbi2,
|
|
4393
4364
|
functionName,
|
|
@@ -4447,7 +4418,7 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4447
4418
|
};
|
|
4448
4419
|
|
|
4449
4420
|
// functions/getDynamicSwap.ts
|
|
4450
|
-
import { getPublicClient, readContract as
|
|
4421
|
+
import { getPublicClient as getPublicClient2, readContract as readContract9 } from "@wagmi/core";
|
|
4451
4422
|
import { autopilotRouterAbi, autopoolEthAbi as autopoolEthAbi3 } from "@tokemak/abis";
|
|
4452
4423
|
import { getCoreConfig as getCoreConfig5 } from "@tokemak/config";
|
|
4453
4424
|
import { getLiquidations } from "@tokemak/autopilot-swap-route-calc";
|
|
@@ -4473,7 +4444,7 @@ var getDynamicSwap = async ({
|
|
|
4473
4444
|
let previewRedeem = 0n;
|
|
4474
4445
|
let dynamicSwaps;
|
|
4475
4446
|
let standardPreviewRedeem = false;
|
|
4476
|
-
const client = await
|
|
4447
|
+
const client = await getPublicClient2(config, { chainId });
|
|
4477
4448
|
try {
|
|
4478
4449
|
const { systemRegistry } = getCoreConfig5(chainId);
|
|
4479
4450
|
client.transport.retryCount = 0;
|
|
@@ -4543,7 +4514,7 @@ var getDynamicSwap = async ({
|
|
|
4543
4514
|
console.log(e);
|
|
4544
4515
|
}
|
|
4545
4516
|
}
|
|
4546
|
-
const previewRedeemOnChain = await
|
|
4517
|
+
const previewRedeemOnChain = await readContract9(config, {
|
|
4547
4518
|
address,
|
|
4548
4519
|
abi: autopoolEthAbi3,
|
|
4549
4520
|
functionName: "previewRedeem",
|
|
@@ -4565,7 +4536,7 @@ var getDynamicSwap = async ({
|
|
|
4565
4536
|
// functions/getAmountWithdrawn.ts
|
|
4566
4537
|
import { ETH_TOKEN as ETH_TOKEN7 } from "@tokemak/tokenlist";
|
|
4567
4538
|
import { getCoreConfig as getCoreConfig6 } from "@tokemak/config";
|
|
4568
|
-
import { readContract as
|
|
4539
|
+
import { readContract as readContract10 } from "@wagmi/core";
|
|
4569
4540
|
import { autopoolEthAbi as autopoolEthAbi4 } from "@tokemak/abis";
|
|
4570
4541
|
var getAmountWithdrawn = async ({
|
|
4571
4542
|
address,
|
|
@@ -4605,7 +4576,7 @@ var getAmountWithdrawn = async ({
|
|
|
4605
4576
|
const weth = getCoreConfig6(chainId).weth;
|
|
4606
4577
|
buyToken = weth;
|
|
4607
4578
|
}
|
|
4608
|
-
convertedAssets = await
|
|
4579
|
+
convertedAssets = await readContract10(config, {
|
|
4609
4580
|
address: autopool,
|
|
4610
4581
|
abi: autopoolEthAbi4,
|
|
4611
4582
|
functionName: "convertToAssets",
|
|
@@ -4645,7 +4616,7 @@ var getAmountWithdrawn = async ({
|
|
|
4645
4616
|
};
|
|
4646
4617
|
|
|
4647
4618
|
// functions/getAmountDeposited.ts
|
|
4648
|
-
import { readContract as
|
|
4619
|
+
import { readContract as readContract11 } from "@wagmi/core";
|
|
4649
4620
|
import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
|
|
4650
4621
|
import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as formatEtherNum9 } from "@tokemak/utils";
|
|
4651
4622
|
var getAmountDeposited = async ({
|
|
@@ -4660,7 +4631,7 @@ var getAmountDeposited = async ({
|
|
|
4660
4631
|
if (!address || !chainId || !amount || typeof slippage !== "number") {
|
|
4661
4632
|
throw new Error("Invalid parameters");
|
|
4662
4633
|
}
|
|
4663
|
-
const previewDeposit = await
|
|
4634
|
+
const previewDeposit = await readContract11(config, {
|
|
4664
4635
|
address,
|
|
4665
4636
|
abi: autopoolEthAbi5,
|
|
4666
4637
|
functionName: "previewDeposit",
|
|
@@ -4684,7 +4655,7 @@ var getAmountDeposited = async ({
|
|
|
4684
4655
|
};
|
|
4685
4656
|
|
|
4686
4657
|
// functions/getBridgeFee.ts
|
|
4687
|
-
import { readContract as
|
|
4658
|
+
import { readContract as readContract12 } from "@wagmi/core";
|
|
4688
4659
|
import { layerZeroEndpointAbi, oftAdapterAbi } from "@tokemak/abis";
|
|
4689
4660
|
import { toHex } from "viem";
|
|
4690
4661
|
import { addressToBytes32 } from "@layerzerolabs/lz-v2-utilities";
|
|
@@ -4697,13 +4668,13 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4697
4668
|
from
|
|
4698
4669
|
}) => {
|
|
4699
4670
|
try {
|
|
4700
|
-
const endpoint = await
|
|
4671
|
+
const endpoint = await readContract12(wagmiConfig, {
|
|
4701
4672
|
address: destAddress,
|
|
4702
4673
|
abi: oftAdapterAbi,
|
|
4703
4674
|
functionName: "endpoint",
|
|
4704
4675
|
chainId: destChainId
|
|
4705
4676
|
});
|
|
4706
|
-
const eid = await
|
|
4677
|
+
const eid = await readContract12(wagmiConfig, {
|
|
4707
4678
|
address: endpoint,
|
|
4708
4679
|
abi: layerZeroEndpointAbi,
|
|
4709
4680
|
functionName: "eid",
|
|
@@ -4721,7 +4692,7 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4721
4692
|
composeMsg: "0x",
|
|
4722
4693
|
oftCmd: "0x"
|
|
4723
4694
|
};
|
|
4724
|
-
const feeQuote = await
|
|
4695
|
+
const feeQuote = await readContract12(wagmiConfig, {
|
|
4725
4696
|
address: sourceAddress,
|
|
4726
4697
|
abi: oftAdapterAbi,
|
|
4727
4698
|
functionName: "quoteSend",
|
|
@@ -4804,12 +4775,12 @@ import { sepolia as sepolia2 } from "viem/chains";
|
|
|
4804
4775
|
|
|
4805
4776
|
// functions/getCurrentCycleId.ts
|
|
4806
4777
|
import { accTokeV1Abi } from "@tokemak/abis";
|
|
4807
|
-
import { readContract as
|
|
4778
|
+
import { readContract as readContract13 } from "@wagmi/core";
|
|
4808
4779
|
var getCurrentCycleId = async (wagmiConfig, {
|
|
4809
4780
|
stoke,
|
|
4810
4781
|
chainId
|
|
4811
4782
|
}) => {
|
|
4812
|
-
return
|
|
4783
|
+
return readContract13(wagmiConfig, {
|
|
4813
4784
|
address: stoke,
|
|
4814
4785
|
abi: accTokeV1Abi,
|
|
4815
4786
|
chainId,
|
|
@@ -5019,7 +4990,7 @@ import {
|
|
|
5019
4990
|
formatTVL
|
|
5020
4991
|
} from "@tokemak/utils";
|
|
5021
4992
|
import { getCoreConfig as getCoreConfig8 } from "@tokemak/config";
|
|
5022
|
-
import { getNetwork as
|
|
4993
|
+
import { getNetwork as getNetwork2 } from "@tokemak/utils";
|
|
5023
4994
|
var getChainSToke = async (wagmiConfig, {
|
|
5024
4995
|
tokePrice,
|
|
5025
4996
|
chainId
|
|
@@ -5052,7 +5023,7 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
5052
5023
|
tvl: formatTVL(tvl),
|
|
5053
5024
|
rawTVL: tvl,
|
|
5054
5025
|
currentCycle,
|
|
5055
|
-
chain:
|
|
5026
|
+
chain: getNetwork2(chainId),
|
|
5056
5027
|
timeBeforeNextCycle: convertSecondsToRemainingTime2(
|
|
5057
5028
|
secondsLeftBeforeNextCycle
|
|
5058
5029
|
)
|
|
@@ -5103,8 +5074,8 @@ var getSToke = async (wagmiConfig, {
|
|
|
5103
5074
|
import { accTokeV1Abi as accTokeV1Abi4, managerV1Abi } from "@tokemak/abis";
|
|
5104
5075
|
import {
|
|
5105
5076
|
getBlockNumber,
|
|
5106
|
-
getPublicClient as
|
|
5107
|
-
readContract as
|
|
5077
|
+
getPublicClient as getPublicClient3,
|
|
5078
|
+
readContract as readContract14
|
|
5108
5079
|
} from "@wagmi/core";
|
|
5109
5080
|
var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
5110
5081
|
stoke,
|
|
@@ -5113,12 +5084,12 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
5113
5084
|
const scanPeriodInDays = 8;
|
|
5114
5085
|
const blockTime = 12;
|
|
5115
5086
|
try {
|
|
5116
|
-
const client =
|
|
5087
|
+
const client = getPublicClient3(wagmiConfig, { chainId });
|
|
5117
5088
|
if (!!client) {
|
|
5118
5089
|
const blockNumber = await getBlockNumber(wagmiConfig, {
|
|
5119
5090
|
chainId
|
|
5120
5091
|
});
|
|
5121
|
-
const manager = await
|
|
5092
|
+
const manager = await readContract14(wagmiConfig, {
|
|
5122
5093
|
functionName: "manager",
|
|
5123
5094
|
address: stoke,
|
|
5124
5095
|
abi: accTokeV1Abi4,
|
|
@@ -5327,30 +5298,9 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5327
5298
|
};
|
|
5328
5299
|
|
|
5329
5300
|
// functions/getTokenPrices.ts
|
|
5330
|
-
import {
|
|
5331
|
-
PRICED_TOKENS as PRICED_TOKENS2
|
|
5332
|
-
} from "@tokemak/tokenlist";
|
|
5301
|
+
import { PRICED_TOKENS as PRICED_TOKENS2 } from "@tokemak/tokenlist";
|
|
5333
5302
|
import { TOKEMAK_PRICES_STAGING_URL } from "@tokemak/constants";
|
|
5334
|
-
|
|
5335
|
-
// functions/getBackupTokenPrices.ts
|
|
5336
|
-
var getBackupTokenPrices = async () => {
|
|
5337
|
-
try {
|
|
5338
|
-
const backupData = await getBlobData(`getTokenPrices-latest-success.json`);
|
|
5339
|
-
if (backupData) {
|
|
5340
|
-
return backupData;
|
|
5341
|
-
}
|
|
5342
|
-
} catch (e) {
|
|
5343
|
-
console.error(e);
|
|
5344
|
-
return void 0;
|
|
5345
|
-
}
|
|
5346
|
-
return void 0;
|
|
5347
|
-
};
|
|
5348
|
-
|
|
5349
|
-
// functions/getTokenPrices.ts
|
|
5350
|
-
var isStale = (timestamp) => {
|
|
5351
|
-
return timestamp - Math.floor(Date.now() / 1e3) > 5 * 60;
|
|
5352
|
-
};
|
|
5353
|
-
var getTokenPrices = async (isCronJob = false) => {
|
|
5303
|
+
var getTokenPrices = async () => {
|
|
5354
5304
|
try {
|
|
5355
5305
|
const body = {
|
|
5356
5306
|
tokens: PRICED_TOKENS2.map((asset) => ({
|
|
@@ -5388,27 +5338,12 @@ var getTokenPrices = async (isCronJob = false) => {
|
|
|
5388
5338
|
}
|
|
5389
5339
|
};
|
|
5390
5340
|
} catch (e) {
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
} else {
|
|
5398
|
-
const backupPrices = await getBackupTokenPrices();
|
|
5399
|
-
if (backupPrices) {
|
|
5400
|
-
return {
|
|
5401
|
-
prices: backupPrices.prices,
|
|
5402
|
-
timestamp: backupPrices.timestamp,
|
|
5403
|
-
isStale: isStale(backupPrices.timestamp)
|
|
5404
|
-
};
|
|
5405
|
-
}
|
|
5406
|
-
return {
|
|
5407
|
-
prices: void 0,
|
|
5408
|
-
timestamp: void 0,
|
|
5409
|
-
isStale: false
|
|
5410
|
-
};
|
|
5411
|
-
}
|
|
5341
|
+
console.error("getTokenPrices failed:", e);
|
|
5342
|
+
return {
|
|
5343
|
+
prices: void 0,
|
|
5344
|
+
timestamp: void 0,
|
|
5345
|
+
isStale: false
|
|
5346
|
+
};
|
|
5412
5347
|
}
|
|
5413
5348
|
};
|
|
5414
5349
|
|
|
@@ -5469,7 +5404,7 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5469
5404
|
};
|
|
5470
5405
|
|
|
5471
5406
|
// functions/getCycleV1.ts
|
|
5472
|
-
import { readContract as
|
|
5407
|
+
import { readContract as readContract15 } from "@wagmi/core";
|
|
5473
5408
|
import { managerV1Abi as managerV1Abi2 } from "@tokemak/abis";
|
|
5474
5409
|
import { createPublicClient, http } from "viem";
|
|
5475
5410
|
import {
|
|
@@ -5491,7 +5426,7 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5491
5426
|
const { managerV1 } = getMainnetConfig7();
|
|
5492
5427
|
try {
|
|
5493
5428
|
if (currentBlockNumber && managerV1) {
|
|
5494
|
-
const currentCycleIndex = await
|
|
5429
|
+
const currentCycleIndex = await readContract15(wagmiConfig, {
|
|
5495
5430
|
address: managerV1,
|
|
5496
5431
|
abi: managerV1Abi2,
|
|
5497
5432
|
functionName: "getCurrentCycleIndex",
|
|
@@ -5613,21 +5548,19 @@ import { getSdkByChainId as getSdkByChainId17 } from "@tokemak/graph-cli";
|
|
|
5613
5548
|
|
|
5614
5549
|
// functions/getEthPriceAtBlock.ts
|
|
5615
5550
|
import { getCoreConfig as getCoreConfig10 } from "@tokemak/config";
|
|
5616
|
-
import { readContract as readContract17 } from "@wagmi/core";
|
|
5617
5551
|
import { rootPriceOracleAbi } from "@tokemak/abis";
|
|
5618
5552
|
import { USDC_TOKEN } from "@tokemak/tokenlist";
|
|
5619
|
-
var getEthPriceAtBlock = async (
|
|
5553
|
+
var getEthPriceAtBlock = async (client, blockNumber, chainId) => {
|
|
5620
5554
|
const config = getCoreConfig10(chainId);
|
|
5621
5555
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5622
5556
|
const weth = config.weth;
|
|
5623
5557
|
const usdc = USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || USDC_TOKEN.address;
|
|
5624
|
-
const priceAtBlock = await
|
|
5558
|
+
const priceAtBlock = await client.readContract({
|
|
5625
5559
|
address: rootPriceOracle,
|
|
5626
5560
|
abi: rootPriceOracleAbi,
|
|
5627
5561
|
functionName: "getPriceInQuote",
|
|
5628
5562
|
args: [weth, usdc],
|
|
5629
|
-
blockNumber
|
|
5630
|
-
chainId
|
|
5563
|
+
blockNumber
|
|
5631
5564
|
});
|
|
5632
5565
|
return priceAtBlock;
|
|
5633
5566
|
};
|
|
@@ -5657,12 +5590,12 @@ function inferBaseAssetDecimals(rebalance, chainId) {
|
|
|
5657
5590
|
}
|
|
5658
5591
|
return USDC_TOKEN2.decimals;
|
|
5659
5592
|
}
|
|
5660
|
-
var getRebalanceValueUsd = async (rebalance, chainId,
|
|
5593
|
+
var getRebalanceValueUsd = async (rebalance, chainId, client) => {
|
|
5661
5594
|
const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
|
|
5662
5595
|
if (ethWei === 0n) return null;
|
|
5663
5596
|
try {
|
|
5664
5597
|
const price = await getEthPriceAtBlock(
|
|
5665
|
-
|
|
5598
|
+
client,
|
|
5666
5599
|
BigInt(rebalance.blockNumber),
|
|
5667
5600
|
chainId
|
|
5668
5601
|
);
|
|
@@ -5675,7 +5608,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5675
5608
|
return null;
|
|
5676
5609
|
}
|
|
5677
5610
|
};
|
|
5678
|
-
var processRebalance = async (rebalance, chainId,
|
|
5611
|
+
var processRebalance = async (rebalance, chainId, client) => {
|
|
5679
5612
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5680
5613
|
const baseAssetAmount = Number(
|
|
5681
5614
|
formatUnitsNum8(
|
|
@@ -5683,11 +5616,7 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5683
5616
|
baseDecimals
|
|
5684
5617
|
)
|
|
5685
5618
|
);
|
|
5686
|
-
const ethPathUsd = await getRebalanceValueUsd(
|
|
5687
|
-
rebalance,
|
|
5688
|
-
chainId,
|
|
5689
|
-
wagmiConfig
|
|
5690
|
-
);
|
|
5619
|
+
const ethPathUsd = await getRebalanceValueUsd(rebalance, chainId, client);
|
|
5691
5620
|
if (ethPathUsd != null) {
|
|
5692
5621
|
return {
|
|
5693
5622
|
autopool: rebalance.autopool,
|
|
@@ -5707,12 +5636,12 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5707
5636
|
valueInAsset: baseAssetAmount
|
|
5708
5637
|
};
|
|
5709
5638
|
};
|
|
5710
|
-
var processRebalancesInBatches = async (rebalances, chainId,
|
|
5639
|
+
var processRebalancesInBatches = async (rebalances, chainId, client) => {
|
|
5711
5640
|
const processedRebalances = [];
|
|
5712
5641
|
for (let i = 0; i < rebalances.length; i += BATCH_SIZE) {
|
|
5713
5642
|
const batch = rebalances.slice(i, i + BATCH_SIZE);
|
|
5714
5643
|
const batchPromises = batch.map(
|
|
5715
|
-
async (rebalance) => processRebalance(rebalance, chainId,
|
|
5644
|
+
async (rebalance) => processRebalance(rebalance, chainId, client)
|
|
5716
5645
|
);
|
|
5717
5646
|
const batchResults = await Promise.all(batchPromises);
|
|
5718
5647
|
processedRebalances.push(...batchResults);
|
|
@@ -5737,18 +5666,15 @@ var calculateRebalanceStats = (rebalances) => {
|
|
|
5737
5666
|
rebalances
|
|
5738
5667
|
};
|
|
5739
5668
|
};
|
|
5740
|
-
var getRebalanceStats = async (
|
|
5669
|
+
var getRebalanceStats = async (getClient, {
|
|
5741
5670
|
includeTestnet = false
|
|
5742
5671
|
}) => {
|
|
5743
5672
|
const chains = getChainsForEnv({ includeTestnet });
|
|
5744
5673
|
const rebalances = await Promise.all(
|
|
5745
5674
|
chains.map(async (chain) => {
|
|
5746
5675
|
const rawRebalances = await fetchChainRebalances(chain.chainId);
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
chain.chainId,
|
|
5750
|
-
wagmiConfig
|
|
5751
|
-
);
|
|
5676
|
+
const client = getClient(chain.chainId);
|
|
5677
|
+
return processRebalancesInBatches(rawRebalances, chain.chainId, client);
|
|
5752
5678
|
})
|
|
5753
5679
|
);
|
|
5754
5680
|
const allRebalances = rebalances.flat();
|
|
@@ -5756,6 +5682,7 @@ var getRebalanceStats = async (wagmiConfig, {
|
|
|
5756
5682
|
};
|
|
5757
5683
|
|
|
5758
5684
|
// functions/updateRebalanceStats.ts
|
|
5685
|
+
import { getPublicClient as getPublicClient4 } from "@wagmi/core";
|
|
5759
5686
|
var updateRebalanceStats = async (wagmiConfig, {
|
|
5760
5687
|
currentRebalances,
|
|
5761
5688
|
includeTestnet = false
|
|
@@ -5770,10 +5697,13 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5770
5697
|
)
|
|
5771
5698
|
);
|
|
5772
5699
|
if (newRawRebalances.length > 0) {
|
|
5700
|
+
const client = getPublicClient4(wagmiConfig, {
|
|
5701
|
+
chainId: chain.chainId
|
|
5702
|
+
});
|
|
5773
5703
|
return processRebalancesInBatches(
|
|
5774
5704
|
newRawRebalances,
|
|
5775
5705
|
chain.chainId,
|
|
5776
|
-
|
|
5706
|
+
client
|
|
5777
5707
|
);
|
|
5778
5708
|
}
|
|
5779
5709
|
return [];
|
|
@@ -5790,7 +5720,6 @@ import { getMainnetConfig as getMainnetConfig8 } from "@tokemak/config";
|
|
|
5790
5720
|
import {
|
|
5791
5721
|
convertAutoCycleToUnix,
|
|
5792
5722
|
convertSecondsToRemainingTime as convertSecondsToRemainingTime4,
|
|
5793
|
-
formatAmount,
|
|
5794
5723
|
formatCurrency as formatCurrency4,
|
|
5795
5724
|
formatEtherNum as formatEtherNum16
|
|
5796
5725
|
} from "@tokemak/utils";
|
|
@@ -5899,7 +5828,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5899
5828
|
return {
|
|
5900
5829
|
balance,
|
|
5901
5830
|
balanceUSD,
|
|
5902
|
-
balanceExcludingWithdrawal: hasBalance ?
|
|
5831
|
+
balanceExcludingWithdrawal: hasBalance ? formatEther5(balanceExcludingWithdrawal) : "0.00",
|
|
5903
5832
|
balanceExcludingWithdrawalUsd,
|
|
5904
5833
|
hasBalanceExcludingWithdrawal,
|
|
5905
5834
|
timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime4(
|
|
@@ -6129,7 +6058,7 @@ var getUserMerklRewards = async (address) => {
|
|
|
6129
6058
|
|
|
6130
6059
|
// functions/getUserEthAutoLPRewards.ts
|
|
6131
6060
|
import { getAddress as getAddress5 } from "viem";
|
|
6132
|
-
import { formatAmount
|
|
6061
|
+
import { formatAmount, formatUnitsNum as formatUnitsNum9 } from "@tokemak/utils";
|
|
6133
6062
|
import {
|
|
6134
6063
|
TOKE_TOKEN as TOKE_TOKEN3
|
|
6135
6064
|
} from "@tokemak/tokenlist";
|
|
@@ -6142,7 +6071,7 @@ var getUserEthAutoLPRewards = async (address) => {
|
|
|
6142
6071
|
const amount = autoRewards?.amount;
|
|
6143
6072
|
const claimed = autoRewards?.claimed;
|
|
6144
6073
|
const claimable = Number(amount) - Number(claimed);
|
|
6145
|
-
const formattedClaimable =
|
|
6074
|
+
const formattedClaimable = formatAmount(
|
|
6146
6075
|
formatUnitsNum9(BigInt(claimable || 0), 18)
|
|
6147
6076
|
);
|
|
6148
6077
|
const users = [];
|