@tokemak/queries 0.5.0 → 0.7.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 +20 -18
- 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 +4 -2
- package/dist/functions/getPoolsAndDestinations.d.ts.map +1 -1
- package/dist/functions/getRebalanceStats.d.ts +8 -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 +307 -352
- package/dist/index.mjs +197 -245
- package/dist/safe.d.ts +9 -0
- package/dist/safe.d.ts.map +1 -0
- package/dist/safe.js +883 -0
- package/dist/safe.mjs +871 -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,20 @@ 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, {
|
|
614
|
+
chainId,
|
|
615
|
+
account,
|
|
616
|
+
blockNumber
|
|
617
|
+
}) => {
|
|
626
618
|
try {
|
|
627
619
|
const { lens } = getCoreConfig(chainId);
|
|
628
|
-
const { autoPools, destinations } = await readContract(
|
|
620
|
+
const { autoPools, destinations } = await client.readContract({
|
|
629
621
|
address: lens,
|
|
630
622
|
abi: lensAbi,
|
|
631
623
|
functionName: "getPoolsAndDestinations",
|
|
632
|
-
|
|
624
|
+
account,
|
|
625
|
+
blockNumber
|
|
633
626
|
});
|
|
634
627
|
const autopoolsAndDestinations = mergeArraysWithKey(
|
|
635
628
|
autoPools,
|
|
@@ -642,27 +635,6 @@ var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
|
|
|
642
635
|
}
|
|
643
636
|
};
|
|
644
637
|
|
|
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
638
|
// functions/getChainAutopools.ts
|
|
667
639
|
import {
|
|
668
640
|
NEW_AUTOPOOL_THRESHOLD_DAYS,
|
|
@@ -670,9 +642,11 @@ import {
|
|
|
670
642
|
DEAD_ADDRESS,
|
|
671
643
|
ZERO_ADDRESS
|
|
672
644
|
} from "@tokemak/constants";
|
|
673
|
-
var getChainAutopools = async (
|
|
645
|
+
var getChainAutopools = async (client, {
|
|
674
646
|
chainId,
|
|
675
|
-
prices
|
|
647
|
+
prices,
|
|
648
|
+
account,
|
|
649
|
+
blockNumber
|
|
676
650
|
}) => {
|
|
677
651
|
const { GetVaultAddeds, GetAutopoolsInactiveDestinations } = getSdkByChainId(chainId);
|
|
678
652
|
try {
|
|
@@ -684,21 +658,21 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
684
658
|
const genStratAprs = await getGenStratAprs({
|
|
685
659
|
chainId
|
|
686
660
|
});
|
|
687
|
-
|
|
688
|
-
chainId
|
|
661
|
+
const autopoolsAndDestinations = await getPoolsAndDestinations(client, {
|
|
662
|
+
chainId,
|
|
663
|
+
account,
|
|
664
|
+
blockNumber
|
|
689
665
|
});
|
|
690
666
|
if (!autopoolsAndDestinations) {
|
|
691
|
-
|
|
692
|
-
if (backupData) {
|
|
693
|
-
autopoolsAndDestinations = backupData;
|
|
694
|
-
} else {
|
|
695
|
-
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
696
|
-
}
|
|
667
|
+
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
697
668
|
}
|
|
698
|
-
const vaultAddedMapping = vaultAddeds.reduce(
|
|
699
|
-
acc
|
|
700
|
-
|
|
701
|
-
|
|
669
|
+
const vaultAddedMapping = vaultAddeds.reduce(
|
|
670
|
+
(acc, vaultAdded) => {
|
|
671
|
+
acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
|
|
672
|
+
return acc;
|
|
673
|
+
},
|
|
674
|
+
{}
|
|
675
|
+
);
|
|
702
676
|
const autopools = await Promise.all(
|
|
703
677
|
autopoolsAndDestinations.map(async (autopool) => {
|
|
704
678
|
let baseAsset = getToken(autopool.baseAsset);
|
|
@@ -820,15 +794,18 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
820
794
|
},
|
|
821
795
|
[]
|
|
822
796
|
);
|
|
823
|
-
const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
|
|
824
|
-
|
|
825
|
-
acc[token.address]
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
797
|
+
const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
|
|
798
|
+
(acc, token) => {
|
|
799
|
+
if (acc[token.address]) {
|
|
800
|
+
acc[token.address].valueUsd += token.valueUsd;
|
|
801
|
+
acc[token.address].value += token.value;
|
|
802
|
+
} else {
|
|
803
|
+
acc[token.address] = { ...token };
|
|
804
|
+
}
|
|
805
|
+
return acc;
|
|
806
|
+
},
|
|
807
|
+
{}
|
|
808
|
+
);
|
|
832
809
|
const HIDDEN_TOKEN_SYMBOLS = ["USR", "WSTUSR"];
|
|
833
810
|
const uniqueTokens = Object.values(uniqueTokensWithValueHeldMap).filter(
|
|
834
811
|
(token) => !HIDDEN_TOKEN_SYMBOLS.includes(token.symbol?.toUpperCase())
|
|
@@ -857,20 +834,8 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
857
834
|
const aprs = autopoolsApr.find(
|
|
858
835
|
(autopoolApr) => getAddress(autopoolApr.id) === getAddress(autopool.poolAddress)
|
|
859
836
|
);
|
|
860
|
-
|
|
837
|
+
const baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
|
|
861
838
|
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
839
|
let extraRewards = [];
|
|
875
840
|
if (aprs?.rewards && aprs.rewards.length > 0) {
|
|
876
841
|
extraRewards = aprs.rewards.map((reward) => {
|
|
@@ -882,8 +847,8 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
882
847
|
});
|
|
883
848
|
}
|
|
884
849
|
extraApr = extraRewards.reduce((acc, reward) => acc + reward.apr, 0);
|
|
885
|
-
|
|
886
|
-
const combinedApr =
|
|
850
|
+
const baseForMath = baseApr ?? 0;
|
|
851
|
+
const combinedApr = baseForMath + extraApr;
|
|
887
852
|
let denominatedToken = ETH_TOKEN;
|
|
888
853
|
let useDenominatedValues = false;
|
|
889
854
|
const denominationData = autopoolsDenomination.find(
|
|
@@ -938,7 +903,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
938
903
|
prices
|
|
939
904
|
);
|
|
940
905
|
const baseDailyEarnings = convertBaseAssetToTokenPricesAndDenom(
|
|
941
|
-
totalAssets *
|
|
906
|
+
totalAssets * baseForMath / DAYS_PER_YEAR,
|
|
942
907
|
baseAssetPrice,
|
|
943
908
|
denominatedTokenPrice,
|
|
944
909
|
prices
|
|
@@ -946,36 +911,39 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
946
911
|
const tokenOrder = [UIBaseAsset.symbol, ...UITokenOrder].filter(
|
|
947
912
|
(value, index, array) => array.indexOf(value) === index
|
|
948
913
|
);
|
|
949
|
-
const UITokens = uniqueTokens.reduce(
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
914
|
+
const UITokens = uniqueTokens.reduce(
|
|
915
|
+
(acc, token) => {
|
|
916
|
+
try {
|
|
917
|
+
const parentAsset = token.extensions?.parentAsset;
|
|
918
|
+
if (parentAsset) {
|
|
919
|
+
const parentToken = ALL_TOKENS.find(
|
|
920
|
+
(t) => t.symbol.toLowerCase() === parentAsset.toLowerCase()
|
|
921
|
+
);
|
|
922
|
+
if (parentToken && !acc.some(
|
|
923
|
+
(t) => t?.address?.toLowerCase() === parentToken?.address?.toLowerCase()
|
|
924
|
+
)) {
|
|
925
|
+
acc.push({
|
|
926
|
+
...parentToken,
|
|
927
|
+
valueUsd: 0,
|
|
928
|
+
value: 0,
|
|
929
|
+
allocation: 0
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
} else if (!acc.some(
|
|
933
|
+
(t) => t?.address?.toLowerCase() === token?.address?.toLowerCase()
|
|
958
934
|
)) {
|
|
959
|
-
acc.push(
|
|
960
|
-
...parentToken,
|
|
961
|
-
valueUsd: 0,
|
|
962
|
-
value: 0,
|
|
963
|
-
allocation: 0
|
|
964
|
-
});
|
|
935
|
+
acc.push(token);
|
|
965
936
|
}
|
|
966
|
-
}
|
|
967
|
-
(
|
|
968
|
-
|
|
969
|
-
|
|
937
|
+
} catch (error) {
|
|
938
|
+
console.warn(
|
|
939
|
+
`Error processing token: ${token?.symbol || "unknown"}`,
|
|
940
|
+
error
|
|
941
|
+
);
|
|
970
942
|
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
);
|
|
976
|
-
}
|
|
977
|
-
return acc;
|
|
978
|
-
}, []).sort((a, b) => {
|
|
943
|
+
return acc;
|
|
944
|
+
},
|
|
945
|
+
[]
|
|
946
|
+
).sort((a, b) => {
|
|
979
947
|
try {
|
|
980
948
|
const aIndex = tokenOrder.indexOf(a.symbol.toUpperCase());
|
|
981
949
|
const bIndex = tokenOrder.indexOf(b.symbol.toUpperCase());
|
|
@@ -1018,7 +986,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1018
986
|
});
|
|
1019
987
|
const autopoolInfo = getAutopoolInfo(autopool.symbol);
|
|
1020
988
|
if (autopoolInfo && !autopoolInfo.description) {
|
|
1021
|
-
autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${
|
|
989
|
+
autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${getNetwork(chainId)?.name}.`;
|
|
1022
990
|
}
|
|
1023
991
|
return {
|
|
1024
992
|
...autopool,
|
|
@@ -1044,9 +1012,9 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1044
1012
|
UITokens,
|
|
1045
1013
|
UIExchanges: finalUIExchanges,
|
|
1046
1014
|
tokens: uniqueTokens,
|
|
1047
|
-
chain:
|
|
1015
|
+
chain: getNetwork(chainId),
|
|
1048
1016
|
apr: {
|
|
1049
|
-
base: baseApr,
|
|
1017
|
+
base: baseApr ?? null,
|
|
1050
1018
|
extraAprs: extraRewards,
|
|
1051
1019
|
combined: combinedApr,
|
|
1052
1020
|
hasExtraAprs: extraRewards.length > 0
|
|
@@ -1084,12 +1052,13 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1084
1052
|
try {
|
|
1085
1053
|
const chains = getChainsForEnv({ includeTestnet });
|
|
1086
1054
|
const autopools = (await Promise.all(
|
|
1087
|
-
chains.map(
|
|
1088
|
-
|
|
1055
|
+
chains.map((chain) => {
|
|
1056
|
+
const chainId = chain?.chainId;
|
|
1057
|
+
return getChainAutopools(getPublicClient(wagmiConfig, { chainId }), {
|
|
1089
1058
|
prices,
|
|
1090
|
-
chainId
|
|
1091
|
-
})
|
|
1092
|
-
)
|
|
1059
|
+
chainId
|
|
1060
|
+
});
|
|
1061
|
+
})
|
|
1093
1062
|
)).flat();
|
|
1094
1063
|
const sortedAutopoolsByTimestamp = autopools.sort(
|
|
1095
1064
|
(a, b) => b.timestamp - a.timestamp
|
|
@@ -1280,7 +1249,7 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
|
|
|
1280
1249
|
|
|
1281
1250
|
// functions/getAutopoolUser.ts
|
|
1282
1251
|
import { erc20Abi } from "viem";
|
|
1283
|
-
import { readContract
|
|
1252
|
+
import { readContract, readContracts } from "@wagmi/core";
|
|
1284
1253
|
import { autopoolEthAbi } from "@tokemak/abis";
|
|
1285
1254
|
import {
|
|
1286
1255
|
convertTimestampToDate as convertTimestampToDate2,
|
|
@@ -1321,7 +1290,7 @@ var getAutopoolUser = async (config, {
|
|
|
1321
1290
|
if (unstakedPoolSharesError) {
|
|
1322
1291
|
throw new Error("Error fetching unstaked pool shares");
|
|
1323
1292
|
}
|
|
1324
|
-
const stakedPoolShares = await
|
|
1293
|
+
const stakedPoolShares = await readContract(config, {
|
|
1325
1294
|
address: autopoolRewarderContract,
|
|
1326
1295
|
abi: erc20Abi,
|
|
1327
1296
|
functionName: "balanceOf",
|
|
@@ -2751,7 +2720,7 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
|
|
|
2751
2720
|
|
|
2752
2721
|
// functions/getUserAutoEthRewards.ts
|
|
2753
2722
|
import { autoEthRewardsHashAbi } from "@tokemak/abis";
|
|
2754
|
-
import { readContract as
|
|
2723
|
+
import { readContract as readContract2 } from "@wagmi/core";
|
|
2755
2724
|
import { convertChainCycleToUnix, formatCurrency } from "@tokemak/utils";
|
|
2756
2725
|
var getAutoEthRewards = async (wagmiConfig, {
|
|
2757
2726
|
account,
|
|
@@ -2761,14 +2730,14 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2761
2730
|
chainId
|
|
2762
2731
|
}) => {
|
|
2763
2732
|
try {
|
|
2764
|
-
const [, drippingHash] = await
|
|
2733
|
+
const [, drippingHash] = await readContract2(wagmiConfig, {
|
|
2765
2734
|
address: rewardsHash,
|
|
2766
2735
|
abi: autoEthRewardsHashAbi,
|
|
2767
2736
|
functionName: "cycleHashes",
|
|
2768
2737
|
args: [currentCycleIndex - 306n],
|
|
2769
2738
|
chainId
|
|
2770
2739
|
});
|
|
2771
|
-
const [, lastWeekHash] = await
|
|
2740
|
+
const [, lastWeekHash] = await readContract2(wagmiConfig, {
|
|
2772
2741
|
address: rewardsHash,
|
|
2773
2742
|
abi: autoEthRewardsHashAbi,
|
|
2774
2743
|
functionName: "cycleHashes",
|
|
@@ -2819,7 +2788,7 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
|
|
|
2819
2788
|
|
|
2820
2789
|
// functions/getUserRewardsV1.ts
|
|
2821
2790
|
import { rewardsV1Abi, rewardsV1HashAbi } from "@tokemak/abis";
|
|
2822
|
-
import { readContract as
|
|
2791
|
+
import { readContract as readContract3 } from "@wagmi/core";
|
|
2823
2792
|
var getUserRewardsV1 = async (wagmiConfig, {
|
|
2824
2793
|
address,
|
|
2825
2794
|
rewardsCycleIndex,
|
|
@@ -2829,7 +2798,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2829
2798
|
chainId
|
|
2830
2799
|
}) => {
|
|
2831
2800
|
try {
|
|
2832
|
-
const [latestClaimableHash, cycleRewardsHash] = await
|
|
2801
|
+
const [latestClaimableHash, cycleRewardsHash] = await readContract3(
|
|
2833
2802
|
wagmiConfig,
|
|
2834
2803
|
{
|
|
2835
2804
|
address: rewardsV1Hash,
|
|
@@ -2853,7 +2822,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2853
2822
|
const {
|
|
2854
2823
|
payload: { chainId: payloadChainId, cycle, wallet, amount }
|
|
2855
2824
|
} = latestClaimablePayload;
|
|
2856
|
-
const claimable = await
|
|
2825
|
+
const claimable = await readContract3(wagmiConfig, {
|
|
2857
2826
|
address: rewardsV1,
|
|
2858
2827
|
abi: rewardsV1Abi,
|
|
2859
2828
|
functionName: "getClaimableAmount",
|
|
@@ -2870,7 +2839,7 @@ var getUserRewardsV1 = async (wagmiConfig, {
|
|
|
2870
2839
|
|
|
2871
2840
|
// functions/getUserV1.ts
|
|
2872
2841
|
import { rewardsV1Abi as rewardsV1Abi2, stakingV1Abi } from "@tokemak/abis";
|
|
2873
|
-
import { readContract as
|
|
2842
|
+
import { readContract as readContract4 } from "@wagmi/core";
|
|
2874
2843
|
import { getMainnetConfig as getMainnetConfig3 } from "@tokemak/config";
|
|
2875
2844
|
import { mainnet as mainnet6 } from "viem/chains";
|
|
2876
2845
|
var getUserV1 = async (wagmiConfig, {
|
|
@@ -2889,7 +2858,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2889
2858
|
missedTokeRewards
|
|
2890
2859
|
} = getMainnetConfig3(mainnet6.id);
|
|
2891
2860
|
try {
|
|
2892
|
-
const userStakedTokeV1 = await
|
|
2861
|
+
const userStakedTokeV1 = await readContract4(wagmiConfig, {
|
|
2893
2862
|
address: stakingV1,
|
|
2894
2863
|
abi: stakingV1Abi,
|
|
2895
2864
|
functionName: "availableForWithdrawal",
|
|
@@ -2921,7 +2890,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2921
2890
|
const cycle = autoEthGuardedRewardsPayload?.payload?.cycle;
|
|
2922
2891
|
const wallet = autoEthGuardedRewardsPayload?.payload?.wallet;
|
|
2923
2892
|
const amount = autoEthGuardedRewardsPayload?.payload?.amount;
|
|
2924
|
-
const claimableAutoEth = await
|
|
2893
|
+
const claimableAutoEth = await readContract4(wagmiConfig, {
|
|
2925
2894
|
address: autoEthGuardedRewards,
|
|
2926
2895
|
abi: rewardsV1Abi2,
|
|
2927
2896
|
functionName: "getClaimableAmount",
|
|
@@ -2945,7 +2914,7 @@ var getUserV1 = async (wagmiConfig, {
|
|
|
2945
2914
|
const {
|
|
2946
2915
|
payload: { chainId: payloadChainId2, cycle: cycle2, wallet: wallet2, amount: amount2 }
|
|
2947
2916
|
} = missedTokeRewardsPayload;
|
|
2948
|
-
claimableMissedToke = await
|
|
2917
|
+
claimableMissedToke = await readContract4(wagmiConfig, {
|
|
2949
2918
|
address: missedTokeRewards,
|
|
2950
2919
|
abi: rewardsV1Abi2,
|
|
2951
2920
|
functionName: "getClaimableAmount",
|
|
@@ -3548,7 +3517,7 @@ import { ETH_TOKEN as ETH_TOKEN5, PRICED_TOKENS } from "@tokemak/tokenlist";
|
|
|
3548
3517
|
|
|
3549
3518
|
// functions/getUserAutopool.tsx
|
|
3550
3519
|
import { erc20Abi as erc20Abi4 } from "viem";
|
|
3551
|
-
import { readContract as
|
|
3520
|
+
import { readContract as readContract5, readContracts as readContracts8 } from "@wagmi/core";
|
|
3552
3521
|
import { formatEtherNum as formatEtherNum7 } from "@tokemak/utils";
|
|
3553
3522
|
import { autopoolEthAbi as autopoolEthAbi2 } from "@tokemak/abis";
|
|
3554
3523
|
var getUserAutopool = async (wagmiConfig, {
|
|
@@ -3591,7 +3560,7 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3591
3560
|
if (unstakedPoolSharesError) {
|
|
3592
3561
|
throw new Error("Error fetching unstaked pool shares");
|
|
3593
3562
|
}
|
|
3594
|
-
const stakedPoolShares = await
|
|
3563
|
+
const stakedPoolShares = await readContract5(wagmiConfig, {
|
|
3595
3564
|
address: autopoolRewarderContract,
|
|
3596
3565
|
abi: erc20Abi4,
|
|
3597
3566
|
functionName: "balanceOf",
|
|
@@ -3873,7 +3842,7 @@ var getUserAutopools = async ({
|
|
|
3873
3842
|
);
|
|
3874
3843
|
const stakedRatio = stakedShares / userShares;
|
|
3875
3844
|
const unstakedRatio = 1 - stakedRatio;
|
|
3876
|
-
const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * autopoolData?.apr?.base;
|
|
3845
|
+
const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * (autopoolData?.apr?.base ?? 0);
|
|
3877
3846
|
return {
|
|
3878
3847
|
name: autopoolData?.name,
|
|
3879
3848
|
symbol: autopoolData?.symbol,
|
|
@@ -3915,13 +3884,16 @@ var getUserAutopools = async ({
|
|
|
3915
3884
|
denominatedToken = autopoolWithDenomination?.denomination;
|
|
3916
3885
|
}
|
|
3917
3886
|
}
|
|
3918
|
-
const nav = Object.values(categories).reduce(
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3887
|
+
const nav = Object.values(categories).reduce(
|
|
3888
|
+
(acc, { nav: nav2 }) => {
|
|
3889
|
+
return Object.keys(nav2).reduce((sumAcc, key) => {
|
|
3890
|
+
const typedKey = key;
|
|
3891
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + nav2[typedKey];
|
|
3892
|
+
return sumAcc;
|
|
3893
|
+
}, acc);
|
|
3894
|
+
},
|
|
3895
|
+
{}
|
|
3896
|
+
);
|
|
3925
3897
|
const idleWithTokenPrices = userAutopoolsWithData.reduce(
|
|
3926
3898
|
(acc, userAutopool) => {
|
|
3927
3899
|
if (!userAutopool) return acc;
|
|
@@ -3949,20 +3921,26 @@ var getUserAutopools = async ({
|
|
|
3949
3921
|
...idle2,
|
|
3950
3922
|
allocation: idle2.USD / nav.USD
|
|
3951
3923
|
}));
|
|
3952
|
-
const returns = Object.values(categories).reduce(
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3924
|
+
const returns = Object.values(categories).reduce(
|
|
3925
|
+
(acc, { returns: returns2 }) => {
|
|
3926
|
+
return Object.keys(returns2).reduce((sumAcc, key) => {
|
|
3927
|
+
const typedKey = key;
|
|
3928
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + returns2[typedKey];
|
|
3929
|
+
return sumAcc;
|
|
3930
|
+
}, acc);
|
|
3931
|
+
},
|
|
3932
|
+
{}
|
|
3933
|
+
);
|
|
3934
|
+
const supplied = Object.values(categories).reduce(
|
|
3935
|
+
(acc, { supplied: supplied2 }) => {
|
|
3936
|
+
return Object.keys(supplied2).reduce((sumAcc, key) => {
|
|
3937
|
+
const typedKey = key;
|
|
3938
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + supplied2[typedKey];
|
|
3939
|
+
return sumAcc;
|
|
3940
|
+
}, acc);
|
|
3941
|
+
},
|
|
3942
|
+
{}
|
|
3943
|
+
);
|
|
3966
3944
|
const userExchangesWithAllocations = Object.values(userExchanges).map(
|
|
3967
3945
|
(userExchange) => {
|
|
3968
3946
|
return {
|
|
@@ -4024,11 +4002,14 @@ var getUserAutopools = async ({
|
|
|
4024
4002
|
categories[categoryKey] = {
|
|
4025
4003
|
...categoryData,
|
|
4026
4004
|
apr,
|
|
4027
|
-
avgDailyReturns: Object.keys(categoryData.nav).reduce(
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4005
|
+
avgDailyReturns: Object.keys(categoryData.nav).reduce(
|
|
4006
|
+
(acc, key) => {
|
|
4007
|
+
const typedKey = key;
|
|
4008
|
+
acc[typedKey] = dailyRate * categoryData.nav[typedKey];
|
|
4009
|
+
return acc;
|
|
4010
|
+
},
|
|
4011
|
+
{}
|
|
4012
|
+
)
|
|
4032
4013
|
};
|
|
4033
4014
|
});
|
|
4034
4015
|
return {
|
|
@@ -4126,7 +4107,7 @@ var getTopAutopoolHolders = async (autopoolAddress, chainId = 1) => {
|
|
|
4126
4107
|
};
|
|
4127
4108
|
|
|
4128
4109
|
// functions/getAllowance.ts
|
|
4129
|
-
import { readContract as
|
|
4110
|
+
import { readContract as readContract6 } from "@wagmi/core";
|
|
4130
4111
|
import { erc20Abi as erc20Abi5 } from "viem";
|
|
4131
4112
|
var getAllowance = async (wagmiConfig, {
|
|
4132
4113
|
token,
|
|
@@ -4134,7 +4115,7 @@ var getAllowance = async (wagmiConfig, {
|
|
|
4134
4115
|
spender
|
|
4135
4116
|
}) => {
|
|
4136
4117
|
try {
|
|
4137
|
-
const allowance = await
|
|
4118
|
+
const allowance = await readContract6(wagmiConfig, {
|
|
4138
4119
|
address: token,
|
|
4139
4120
|
abi: erc20Abi5,
|
|
4140
4121
|
functionName: "allowance",
|
|
@@ -4181,7 +4162,7 @@ import { getAddress as getAddress4 } from "viem";
|
|
|
4181
4162
|
|
|
4182
4163
|
// functions/getChainUserAutopoolsRewards.ts
|
|
4183
4164
|
import { getCoreConfig as getCoreConfig2 } from "@tokemak/config";
|
|
4184
|
-
import { readContract as
|
|
4165
|
+
import { readContract as readContract7 } from "@wagmi/core";
|
|
4185
4166
|
import { lensAbi as lensAbi2 } from "@tokemak/abis";
|
|
4186
4167
|
var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
4187
4168
|
chainId,
|
|
@@ -4189,7 +4170,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4189
4170
|
}) => {
|
|
4190
4171
|
try {
|
|
4191
4172
|
const coreConfig = getCoreConfig2(chainId);
|
|
4192
|
-
const userRewardsInfo = await
|
|
4173
|
+
const userRewardsInfo = await readContract7(wagmiConfig, {
|
|
4193
4174
|
address: coreConfig.lens,
|
|
4194
4175
|
abi: lensAbi2,
|
|
4195
4176
|
functionName: "getUserRewardInfo",
|
|
@@ -4379,7 +4360,7 @@ import {
|
|
|
4379
4360
|
import { TOKEMAK_SWAP_QUOTE_URL } from "@tokemak/constants";
|
|
4380
4361
|
|
|
4381
4362
|
// functions/getAddressFromSystemRegistry.ts
|
|
4382
|
-
import { readContract as
|
|
4363
|
+
import { readContract as readContract8 } from "@wagmi/core";
|
|
4383
4364
|
import { getCoreConfig as getCoreConfig3 } from "@tokemak/config";
|
|
4384
4365
|
import { systemRegistryAbi as systemRegistryAbi2 } from "@tokemak/abis";
|
|
4385
4366
|
var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
@@ -4387,7 +4368,7 @@ var getAddressFromSystemRegistry = async (wagmiConfig, {
|
|
|
4387
4368
|
functionName
|
|
4388
4369
|
}) => {
|
|
4389
4370
|
const { systemRegistry } = getCoreConfig3(chainId);
|
|
4390
|
-
return await
|
|
4371
|
+
return await readContract8(wagmiConfig, {
|
|
4391
4372
|
address: systemRegistry,
|
|
4392
4373
|
abi: systemRegistryAbi2,
|
|
4393
4374
|
functionName,
|
|
@@ -4447,7 +4428,7 @@ var getSwapQuote = async (config, { chainId, ...params }) => {
|
|
|
4447
4428
|
};
|
|
4448
4429
|
|
|
4449
4430
|
// functions/getDynamicSwap.ts
|
|
4450
|
-
import { getPublicClient, readContract as
|
|
4431
|
+
import { getPublicClient as getPublicClient2, readContract as readContract9 } from "@wagmi/core";
|
|
4451
4432
|
import { autopilotRouterAbi, autopoolEthAbi as autopoolEthAbi3 } from "@tokemak/abis";
|
|
4452
4433
|
import { getCoreConfig as getCoreConfig5 } from "@tokemak/config";
|
|
4453
4434
|
import { getLiquidations } from "@tokemak/autopilot-swap-route-calc";
|
|
@@ -4473,7 +4454,7 @@ var getDynamicSwap = async ({
|
|
|
4473
4454
|
let previewRedeem = 0n;
|
|
4474
4455
|
let dynamicSwaps;
|
|
4475
4456
|
let standardPreviewRedeem = false;
|
|
4476
|
-
const client = await
|
|
4457
|
+
const client = await getPublicClient2(config, { chainId });
|
|
4477
4458
|
try {
|
|
4478
4459
|
const { systemRegistry } = getCoreConfig5(chainId);
|
|
4479
4460
|
client.transport.retryCount = 0;
|
|
@@ -4543,7 +4524,7 @@ var getDynamicSwap = async ({
|
|
|
4543
4524
|
console.log(e);
|
|
4544
4525
|
}
|
|
4545
4526
|
}
|
|
4546
|
-
const previewRedeemOnChain = await
|
|
4527
|
+
const previewRedeemOnChain = await readContract9(config, {
|
|
4547
4528
|
address,
|
|
4548
4529
|
abi: autopoolEthAbi3,
|
|
4549
4530
|
functionName: "previewRedeem",
|
|
@@ -4565,7 +4546,7 @@ var getDynamicSwap = async ({
|
|
|
4565
4546
|
// functions/getAmountWithdrawn.ts
|
|
4566
4547
|
import { ETH_TOKEN as ETH_TOKEN7 } from "@tokemak/tokenlist";
|
|
4567
4548
|
import { getCoreConfig as getCoreConfig6 } from "@tokemak/config";
|
|
4568
|
-
import { readContract as
|
|
4549
|
+
import { readContract as readContract10 } from "@wagmi/core";
|
|
4569
4550
|
import { autopoolEthAbi as autopoolEthAbi4 } from "@tokemak/abis";
|
|
4570
4551
|
var getAmountWithdrawn = async ({
|
|
4571
4552
|
address,
|
|
@@ -4605,7 +4586,7 @@ var getAmountWithdrawn = async ({
|
|
|
4605
4586
|
const weth = getCoreConfig6(chainId).weth;
|
|
4606
4587
|
buyToken = weth;
|
|
4607
4588
|
}
|
|
4608
|
-
convertedAssets = await
|
|
4589
|
+
convertedAssets = await readContract10(config, {
|
|
4609
4590
|
address: autopool,
|
|
4610
4591
|
abi: autopoolEthAbi4,
|
|
4611
4592
|
functionName: "convertToAssets",
|
|
@@ -4645,7 +4626,7 @@ var getAmountWithdrawn = async ({
|
|
|
4645
4626
|
};
|
|
4646
4627
|
|
|
4647
4628
|
// functions/getAmountDeposited.ts
|
|
4648
|
-
import { readContract as
|
|
4629
|
+
import { readContract as readContract11 } from "@wagmi/core";
|
|
4649
4630
|
import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
|
|
4650
4631
|
import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as formatEtherNum9 } from "@tokemak/utils";
|
|
4651
4632
|
var getAmountDeposited = async ({
|
|
@@ -4660,7 +4641,7 @@ var getAmountDeposited = async ({
|
|
|
4660
4641
|
if (!address || !chainId || !amount || typeof slippage !== "number") {
|
|
4661
4642
|
throw new Error("Invalid parameters");
|
|
4662
4643
|
}
|
|
4663
|
-
const previewDeposit = await
|
|
4644
|
+
const previewDeposit = await readContract11(config, {
|
|
4664
4645
|
address,
|
|
4665
4646
|
abi: autopoolEthAbi5,
|
|
4666
4647
|
functionName: "previewDeposit",
|
|
@@ -4684,7 +4665,7 @@ var getAmountDeposited = async ({
|
|
|
4684
4665
|
};
|
|
4685
4666
|
|
|
4686
4667
|
// functions/getBridgeFee.ts
|
|
4687
|
-
import { readContract as
|
|
4668
|
+
import { readContract as readContract12 } from "@wagmi/core";
|
|
4688
4669
|
import { layerZeroEndpointAbi, oftAdapterAbi } from "@tokemak/abis";
|
|
4689
4670
|
import { toHex } from "viem";
|
|
4690
4671
|
import { addressToBytes32 } from "@layerzerolabs/lz-v2-utilities";
|
|
@@ -4697,13 +4678,13 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4697
4678
|
from
|
|
4698
4679
|
}) => {
|
|
4699
4680
|
try {
|
|
4700
|
-
const endpoint = await
|
|
4681
|
+
const endpoint = await readContract12(wagmiConfig, {
|
|
4701
4682
|
address: destAddress,
|
|
4702
4683
|
abi: oftAdapterAbi,
|
|
4703
4684
|
functionName: "endpoint",
|
|
4704
4685
|
chainId: destChainId
|
|
4705
4686
|
});
|
|
4706
|
-
const eid = await
|
|
4687
|
+
const eid = await readContract12(wagmiConfig, {
|
|
4707
4688
|
address: endpoint,
|
|
4708
4689
|
abi: layerZeroEndpointAbi,
|
|
4709
4690
|
functionName: "eid",
|
|
@@ -4721,7 +4702,7 @@ var getBridgeFee = async (wagmiConfig, {
|
|
|
4721
4702
|
composeMsg: "0x",
|
|
4722
4703
|
oftCmd: "0x"
|
|
4723
4704
|
};
|
|
4724
|
-
const feeQuote = await
|
|
4705
|
+
const feeQuote = await readContract12(wagmiConfig, {
|
|
4725
4706
|
address: sourceAddress,
|
|
4726
4707
|
abi: oftAdapterAbi,
|
|
4727
4708
|
functionName: "quoteSend",
|
|
@@ -4804,12 +4785,12 @@ import { sepolia as sepolia2 } from "viem/chains";
|
|
|
4804
4785
|
|
|
4805
4786
|
// functions/getCurrentCycleId.ts
|
|
4806
4787
|
import { accTokeV1Abi } from "@tokemak/abis";
|
|
4807
|
-
import { readContract as
|
|
4788
|
+
import { readContract as readContract13 } from "@wagmi/core";
|
|
4808
4789
|
var getCurrentCycleId = async (wagmiConfig, {
|
|
4809
4790
|
stoke,
|
|
4810
4791
|
chainId
|
|
4811
4792
|
}) => {
|
|
4812
|
-
return
|
|
4793
|
+
return readContract13(wagmiConfig, {
|
|
4813
4794
|
address: stoke,
|
|
4814
4795
|
abi: accTokeV1Abi,
|
|
4815
4796
|
chainId,
|
|
@@ -5019,7 +5000,7 @@ import {
|
|
|
5019
5000
|
formatTVL
|
|
5020
5001
|
} from "@tokemak/utils";
|
|
5021
5002
|
import { getCoreConfig as getCoreConfig8 } from "@tokemak/config";
|
|
5022
|
-
import { getNetwork as
|
|
5003
|
+
import { getNetwork as getNetwork2 } from "@tokemak/utils";
|
|
5023
5004
|
var getChainSToke = async (wagmiConfig, {
|
|
5024
5005
|
tokePrice,
|
|
5025
5006
|
chainId
|
|
@@ -5052,7 +5033,7 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
5052
5033
|
tvl: formatTVL(tvl),
|
|
5053
5034
|
rawTVL: tvl,
|
|
5054
5035
|
currentCycle,
|
|
5055
|
-
chain:
|
|
5036
|
+
chain: getNetwork2(chainId),
|
|
5056
5037
|
timeBeforeNextCycle: convertSecondsToRemainingTime2(
|
|
5057
5038
|
secondsLeftBeforeNextCycle
|
|
5058
5039
|
)
|
|
@@ -5103,8 +5084,8 @@ var getSToke = async (wagmiConfig, {
|
|
|
5103
5084
|
import { accTokeV1Abi as accTokeV1Abi4, managerV1Abi } from "@tokemak/abis";
|
|
5104
5085
|
import {
|
|
5105
5086
|
getBlockNumber,
|
|
5106
|
-
getPublicClient as
|
|
5107
|
-
readContract as
|
|
5087
|
+
getPublicClient as getPublicClient3,
|
|
5088
|
+
readContract as readContract14
|
|
5108
5089
|
} from "@wagmi/core";
|
|
5109
5090
|
var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
5110
5091
|
stoke,
|
|
@@ -5113,12 +5094,12 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
5113
5094
|
const scanPeriodInDays = 8;
|
|
5114
5095
|
const blockTime = 12;
|
|
5115
5096
|
try {
|
|
5116
|
-
const client =
|
|
5097
|
+
const client = getPublicClient3(wagmiConfig, { chainId });
|
|
5117
5098
|
if (!!client) {
|
|
5118
5099
|
const blockNumber = await getBlockNumber(wagmiConfig, {
|
|
5119
5100
|
chainId
|
|
5120
5101
|
});
|
|
5121
|
-
const manager = await
|
|
5102
|
+
const manager = await readContract14(wagmiConfig, {
|
|
5122
5103
|
functionName: "manager",
|
|
5123
5104
|
address: stoke,
|
|
5124
5105
|
abi: accTokeV1Abi4,
|
|
@@ -5327,30 +5308,9 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5327
5308
|
};
|
|
5328
5309
|
|
|
5329
5310
|
// functions/getTokenPrices.ts
|
|
5330
|
-
import {
|
|
5331
|
-
PRICED_TOKENS as PRICED_TOKENS2
|
|
5332
|
-
} from "@tokemak/tokenlist";
|
|
5311
|
+
import { PRICED_TOKENS as PRICED_TOKENS2 } from "@tokemak/tokenlist";
|
|
5333
5312
|
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) => {
|
|
5313
|
+
var getTokenPrices = async () => {
|
|
5354
5314
|
try {
|
|
5355
5315
|
const body = {
|
|
5356
5316
|
tokens: PRICED_TOKENS2.map((asset) => ({
|
|
@@ -5388,27 +5348,12 @@ var getTokenPrices = async (isCronJob = false) => {
|
|
|
5388
5348
|
}
|
|
5389
5349
|
};
|
|
5390
5350
|
} 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
|
-
}
|
|
5351
|
+
console.error("getTokenPrices failed:", e);
|
|
5352
|
+
return {
|
|
5353
|
+
prices: void 0,
|
|
5354
|
+
timestamp: void 0,
|
|
5355
|
+
isStale: false
|
|
5356
|
+
};
|
|
5412
5357
|
}
|
|
5413
5358
|
};
|
|
5414
5359
|
|
|
@@ -5469,7 +5414,7 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5469
5414
|
};
|
|
5470
5415
|
|
|
5471
5416
|
// functions/getCycleV1.ts
|
|
5472
|
-
import { readContract as
|
|
5417
|
+
import { readContract as readContract15 } from "@wagmi/core";
|
|
5473
5418
|
import { managerV1Abi as managerV1Abi2 } from "@tokemak/abis";
|
|
5474
5419
|
import { createPublicClient, http } from "viem";
|
|
5475
5420
|
import {
|
|
@@ -5491,7 +5436,7 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5491
5436
|
const { managerV1 } = getMainnetConfig7();
|
|
5492
5437
|
try {
|
|
5493
5438
|
if (currentBlockNumber && managerV1) {
|
|
5494
|
-
const currentCycleIndex = await
|
|
5439
|
+
const currentCycleIndex = await readContract15(wagmiConfig, {
|
|
5495
5440
|
address: managerV1,
|
|
5496
5441
|
abi: managerV1Abi2,
|
|
5497
5442
|
functionName: "getCurrentCycleIndex",
|
|
@@ -5613,21 +5558,20 @@ import { getSdkByChainId as getSdkByChainId17 } from "@tokemak/graph-cli";
|
|
|
5613
5558
|
|
|
5614
5559
|
// functions/getEthPriceAtBlock.ts
|
|
5615
5560
|
import { getCoreConfig as getCoreConfig10 } from "@tokemak/config";
|
|
5616
|
-
import { readContract as readContract17 } from "@wagmi/core";
|
|
5617
5561
|
import { rootPriceOracleAbi } from "@tokemak/abis";
|
|
5618
5562
|
import { USDC_TOKEN } from "@tokemak/tokenlist";
|
|
5619
|
-
var getEthPriceAtBlock = async (
|
|
5563
|
+
var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
|
|
5620
5564
|
const config = getCoreConfig10(chainId);
|
|
5621
5565
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5622
5566
|
const weth = config.weth;
|
|
5623
5567
|
const usdc = USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || USDC_TOKEN.address;
|
|
5624
|
-
const priceAtBlock = await
|
|
5568
|
+
const priceAtBlock = await client.readContract({
|
|
5625
5569
|
address: rootPriceOracle,
|
|
5626
5570
|
abi: rootPriceOracleAbi,
|
|
5627
5571
|
functionName: "getPriceInQuote",
|
|
5628
5572
|
args: [weth, usdc],
|
|
5629
5573
|
blockNumber,
|
|
5630
|
-
|
|
5574
|
+
account
|
|
5631
5575
|
});
|
|
5632
5576
|
return priceAtBlock;
|
|
5633
5577
|
};
|
|
@@ -5657,14 +5601,15 @@ function inferBaseAssetDecimals(rebalance, chainId) {
|
|
|
5657
5601
|
}
|
|
5658
5602
|
return USDC_TOKEN2.decimals;
|
|
5659
5603
|
}
|
|
5660
|
-
var getRebalanceValueUsd = async (rebalance, chainId,
|
|
5604
|
+
var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
|
|
5661
5605
|
const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
|
|
5662
5606
|
if (ethWei === 0n) return null;
|
|
5663
5607
|
try {
|
|
5664
5608
|
const price = await getEthPriceAtBlock(
|
|
5665
|
-
|
|
5609
|
+
client,
|
|
5666
5610
|
BigInt(rebalance.blockNumber),
|
|
5667
|
-
chainId
|
|
5611
|
+
chainId,
|
|
5612
|
+
account
|
|
5668
5613
|
);
|
|
5669
5614
|
const ethUsd = Number(formatUnitsNum8(price, USDC_TOKEN2.decimals));
|
|
5670
5615
|
const ethAmt = Number(formatEtherNum15(ethWei));
|
|
@@ -5675,7 +5620,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5675
5620
|
return null;
|
|
5676
5621
|
}
|
|
5677
5622
|
};
|
|
5678
|
-
var processRebalance = async (rebalance, chainId,
|
|
5623
|
+
var processRebalance = async (rebalance, chainId, client, account) => {
|
|
5679
5624
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5680
5625
|
const baseAssetAmount = Number(
|
|
5681
5626
|
formatUnitsNum8(
|
|
@@ -5686,7 +5631,8 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5686
5631
|
const ethPathUsd = await getRebalanceValueUsd(
|
|
5687
5632
|
rebalance,
|
|
5688
5633
|
chainId,
|
|
5689
|
-
|
|
5634
|
+
client,
|
|
5635
|
+
account
|
|
5690
5636
|
);
|
|
5691
5637
|
if (ethPathUsd != null) {
|
|
5692
5638
|
return {
|
|
@@ -5707,12 +5653,12 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5707
5653
|
valueInAsset: baseAssetAmount
|
|
5708
5654
|
};
|
|
5709
5655
|
};
|
|
5710
|
-
var processRebalancesInBatches = async (rebalances, chainId,
|
|
5656
|
+
var processRebalancesInBatches = async (rebalances, chainId, client, account) => {
|
|
5711
5657
|
const processedRebalances = [];
|
|
5712
5658
|
for (let i = 0; i < rebalances.length; i += BATCH_SIZE) {
|
|
5713
5659
|
const batch = rebalances.slice(i, i + BATCH_SIZE);
|
|
5714
5660
|
const batchPromises = batch.map(
|
|
5715
|
-
async (rebalance) => processRebalance(rebalance, chainId,
|
|
5661
|
+
async (rebalance) => processRebalance(rebalance, chainId, client, account)
|
|
5716
5662
|
);
|
|
5717
5663
|
const batchResults = await Promise.all(batchPromises);
|
|
5718
5664
|
processedRebalances.push(...batchResults);
|
|
@@ -5737,17 +5683,20 @@ var calculateRebalanceStats = (rebalances) => {
|
|
|
5737
5683
|
rebalances
|
|
5738
5684
|
};
|
|
5739
5685
|
};
|
|
5740
|
-
var getRebalanceStats = async (
|
|
5741
|
-
includeTestnet = false
|
|
5686
|
+
var getRebalanceStats = async (getClient, {
|
|
5687
|
+
includeTestnet = false,
|
|
5688
|
+
account
|
|
5742
5689
|
}) => {
|
|
5743
5690
|
const chains = getChainsForEnv({ includeTestnet });
|
|
5744
5691
|
const rebalances = await Promise.all(
|
|
5745
5692
|
chains.map(async (chain) => {
|
|
5746
5693
|
const rawRebalances = await fetchChainRebalances(chain.chainId);
|
|
5694
|
+
const client = getClient(chain.chainId);
|
|
5747
5695
|
return processRebalancesInBatches(
|
|
5748
5696
|
rawRebalances,
|
|
5749
5697
|
chain.chainId,
|
|
5750
|
-
|
|
5698
|
+
client,
|
|
5699
|
+
account
|
|
5751
5700
|
);
|
|
5752
5701
|
})
|
|
5753
5702
|
);
|
|
@@ -5756,6 +5705,7 @@ var getRebalanceStats = async (wagmiConfig, {
|
|
|
5756
5705
|
};
|
|
5757
5706
|
|
|
5758
5707
|
// functions/updateRebalanceStats.ts
|
|
5708
|
+
import { getPublicClient as getPublicClient4 } from "@wagmi/core";
|
|
5759
5709
|
var updateRebalanceStats = async (wagmiConfig, {
|
|
5760
5710
|
currentRebalances,
|
|
5761
5711
|
includeTestnet = false
|
|
@@ -5770,10 +5720,13 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5770
5720
|
)
|
|
5771
5721
|
);
|
|
5772
5722
|
if (newRawRebalances.length > 0) {
|
|
5723
|
+
const client = getPublicClient4(wagmiConfig, {
|
|
5724
|
+
chainId: chain.chainId
|
|
5725
|
+
});
|
|
5773
5726
|
return processRebalancesInBatches(
|
|
5774
5727
|
newRawRebalances,
|
|
5775
5728
|
chain.chainId,
|
|
5776
|
-
|
|
5729
|
+
client
|
|
5777
5730
|
);
|
|
5778
5731
|
}
|
|
5779
5732
|
return [];
|
|
@@ -5790,7 +5743,6 @@ import { getMainnetConfig as getMainnetConfig8 } from "@tokemak/config";
|
|
|
5790
5743
|
import {
|
|
5791
5744
|
convertAutoCycleToUnix,
|
|
5792
5745
|
convertSecondsToRemainingTime as convertSecondsToRemainingTime4,
|
|
5793
|
-
formatAmount,
|
|
5794
5746
|
formatCurrency as formatCurrency4,
|
|
5795
5747
|
formatEtherNum as formatEtherNum16
|
|
5796
5748
|
} from "@tokemak/utils";
|
|
@@ -5899,7 +5851,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5899
5851
|
return {
|
|
5900
5852
|
balance,
|
|
5901
5853
|
balanceUSD,
|
|
5902
|
-
balanceExcludingWithdrawal: hasBalance ?
|
|
5854
|
+
balanceExcludingWithdrawal: hasBalance ? formatEther5(balanceExcludingWithdrawal) : "0.00",
|
|
5903
5855
|
balanceExcludingWithdrawalUsd,
|
|
5904
5856
|
hasBalanceExcludingWithdrawal,
|
|
5905
5857
|
timeLeftBeforeUnlockRequestAvailable: convertSecondsToRemainingTime4(
|
|
@@ -6129,7 +6081,7 @@ var getUserMerklRewards = async (address) => {
|
|
|
6129
6081
|
|
|
6130
6082
|
// functions/getUserEthAutoLPRewards.ts
|
|
6131
6083
|
import { getAddress as getAddress5 } from "viem";
|
|
6132
|
-
import { formatAmount
|
|
6084
|
+
import { formatAmount, formatUnitsNum as formatUnitsNum9 } from "@tokemak/utils";
|
|
6133
6085
|
import {
|
|
6134
6086
|
TOKE_TOKEN as TOKE_TOKEN3
|
|
6135
6087
|
} from "@tokemak/tokenlist";
|
|
@@ -6142,7 +6094,7 @@ var getUserEthAutoLPRewards = async (address) => {
|
|
|
6142
6094
|
const amount = autoRewards?.amount;
|
|
6143
6095
|
const claimed = autoRewards?.claimed;
|
|
6144
6096
|
const claimable = Number(amount) - Number(claimed);
|
|
6145
|
-
const formattedClaimable =
|
|
6097
|
+
const formattedClaimable = formatAmount(
|
|
6146
6098
|
formatUnitsNum9(BigInt(claimable || 0), 18)
|
|
6147
6099
|
);
|
|
6148
6100
|
const users = [];
|