@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.js
CHANGED
|
@@ -274,6 +274,9 @@ var getTokePrice = async () => {
|
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
276
|
|
|
277
|
+
// functions/getAutopools.ts
|
|
278
|
+
var import_core = require("@wagmi/core");
|
|
279
|
+
|
|
277
280
|
// utils/getExchangeNames.ts
|
|
278
281
|
function getExchangeNames(destinationVaults) {
|
|
279
282
|
const uniqueNamesSet = /* @__PURE__ */ new Set();
|
|
@@ -624,22 +627,8 @@ async function paginateQuery(queryFn, arrayKey, options = {}) {
|
|
|
624
627
|
return results;
|
|
625
628
|
}
|
|
626
629
|
|
|
627
|
-
// functions/getPoolsAndDestinationsBackup.ts
|
|
628
|
-
var import_utils2 = require("@tokemak/utils");
|
|
629
|
-
var getPoolsAndDestinationsBackup = async (chainId) => {
|
|
630
|
-
try {
|
|
631
|
-
const networkName = (0, import_utils2.getNetwork)(chainId)?.name.toLowerCase();
|
|
632
|
-
const backupData = await getBlobData(
|
|
633
|
-
`${networkName}-getPoolsAndDestinations-latest-success.json`
|
|
634
|
-
);
|
|
635
|
-
return backupData?.data;
|
|
636
|
-
} catch (e) {
|
|
637
|
-
console.error(e);
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
630
|
// functions/getChainAutopools.ts
|
|
642
|
-
var
|
|
631
|
+
var import_utils4 = require("@tokemak/utils");
|
|
643
632
|
var import_viem2 = require("viem");
|
|
644
633
|
|
|
645
634
|
// constants/tokenOrders.ts
|
|
@@ -741,16 +730,20 @@ var import_chains2 = require("viem/chains");
|
|
|
741
730
|
|
|
742
731
|
// functions/getPoolsAndDestinations.ts
|
|
743
732
|
var import_config = require("@tokemak/config");
|
|
744
|
-
var import_core = require("@wagmi/core");
|
|
745
733
|
var import_abis = require("@tokemak/abis");
|
|
746
|
-
var getPoolsAndDestinations = async (
|
|
734
|
+
var getPoolsAndDestinations = async (client, {
|
|
735
|
+
chainId,
|
|
736
|
+
account,
|
|
737
|
+
blockNumber
|
|
738
|
+
}) => {
|
|
747
739
|
try {
|
|
748
740
|
const { lens } = (0, import_config.getCoreConfig)(chainId);
|
|
749
|
-
const { autoPools, destinations } = await
|
|
741
|
+
const { autoPools, destinations } = await client.readContract({
|
|
750
742
|
address: lens,
|
|
751
743
|
abi: import_abis.lensAbi,
|
|
752
744
|
functionName: "getPoolsAndDestinations",
|
|
753
|
-
|
|
745
|
+
account,
|
|
746
|
+
blockNumber
|
|
754
747
|
});
|
|
755
748
|
const autopoolsAndDestinations = mergeArraysWithKey(
|
|
756
749
|
autoPools,
|
|
@@ -763,32 +756,13 @@ var getPoolsAndDestinations = async (wagmiConfig, { chainId }) => {
|
|
|
763
756
|
}
|
|
764
757
|
};
|
|
765
758
|
|
|
766
|
-
// functions/getBackupApr.ts
|
|
767
|
-
var import_utils4 = require("@tokemak/utils");
|
|
768
|
-
var getBackupApr = async (chainId, poolAddress) => {
|
|
769
|
-
try {
|
|
770
|
-
const networkName = (0, import_utils4.getNetwork)(chainId)?.name.toLowerCase();
|
|
771
|
-
const backupData = await getBlobData(
|
|
772
|
-
`${networkName}-getChainAutopools-latest-success.json`
|
|
773
|
-
);
|
|
774
|
-
if (backupData) {
|
|
775
|
-
const backupApr = backupData.data.find(
|
|
776
|
-
(item) => item.poolAddress.toLowerCase() === poolAddress.toLowerCase()
|
|
777
|
-
)?.apr.base;
|
|
778
|
-
return backupApr || 0;
|
|
779
|
-
}
|
|
780
|
-
} catch (e) {
|
|
781
|
-
console.error(e);
|
|
782
|
-
return 0;
|
|
783
|
-
}
|
|
784
|
-
return null;
|
|
785
|
-
};
|
|
786
|
-
|
|
787
759
|
// functions/getChainAutopools.ts
|
|
788
760
|
var import_constants6 = require("@tokemak/constants");
|
|
789
|
-
var getChainAutopools = async (
|
|
761
|
+
var getChainAutopools = async (client, {
|
|
790
762
|
chainId,
|
|
791
|
-
prices
|
|
763
|
+
prices,
|
|
764
|
+
account,
|
|
765
|
+
blockNumber
|
|
792
766
|
}) => {
|
|
793
767
|
const { GetVaultAddeds, GetAutopoolsInactiveDestinations } = (0, import_graph_cli.getSdkByChainId)(chainId);
|
|
794
768
|
try {
|
|
@@ -800,24 +774,24 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
800
774
|
const genStratAprs = await getGenStratAprs({
|
|
801
775
|
chainId
|
|
802
776
|
});
|
|
803
|
-
|
|
804
|
-
chainId
|
|
777
|
+
const autopoolsAndDestinations = await getPoolsAndDestinations(client, {
|
|
778
|
+
chainId,
|
|
779
|
+
account,
|
|
780
|
+
blockNumber
|
|
805
781
|
});
|
|
806
782
|
if (!autopoolsAndDestinations) {
|
|
807
|
-
|
|
808
|
-
if (backupData) {
|
|
809
|
-
autopoolsAndDestinations = backupData;
|
|
810
|
-
} else {
|
|
811
|
-
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
812
|
-
}
|
|
783
|
+
throw new Error(`No autopools and destinations found for ${chainId}`);
|
|
813
784
|
}
|
|
814
|
-
const vaultAddedMapping = vaultAddeds.reduce(
|
|
815
|
-
acc
|
|
816
|
-
|
|
817
|
-
|
|
785
|
+
const vaultAddedMapping = vaultAddeds.reduce(
|
|
786
|
+
(acc, vaultAdded) => {
|
|
787
|
+
acc[vaultAdded.vault.toLowerCase()] = Number(vaultAdded.blockTimestamp);
|
|
788
|
+
return acc;
|
|
789
|
+
},
|
|
790
|
+
{}
|
|
791
|
+
);
|
|
818
792
|
const autopools = await Promise.all(
|
|
819
793
|
autopoolsAndDestinations.map(async (autopool) => {
|
|
820
|
-
let baseAsset = (0,
|
|
794
|
+
let baseAsset = (0, import_utils4.getToken)(autopool.baseAsset);
|
|
821
795
|
if (!baseAsset?.symbol) {
|
|
822
796
|
console.error(
|
|
823
797
|
"FIX THIS BEFORE PROD: base asset not found",
|
|
@@ -832,18 +806,18 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
832
806
|
}) || 0;
|
|
833
807
|
}
|
|
834
808
|
const timestamp = vaultAddedMapping[autopool.poolAddress.toLowerCase()];
|
|
835
|
-
const totalAssets = (0,
|
|
809
|
+
const totalAssets = (0, import_utils4.formatUnitsNum)(
|
|
836
810
|
autopool.totalAssets,
|
|
837
811
|
baseAsset.decimals
|
|
838
812
|
);
|
|
839
813
|
const tvl = totalAssets * baseAssetPrice;
|
|
840
|
-
const totalIdleAssets = (0,
|
|
814
|
+
const totalIdleAssets = (0, import_utils4.formatUnitsNum)(
|
|
841
815
|
autopool.totalIdle,
|
|
842
816
|
baseAsset.decimals
|
|
843
817
|
);
|
|
844
818
|
const exchangeValues = {};
|
|
845
819
|
const destinations = autopool.destinations.map((destination) => {
|
|
846
|
-
const debtValueHeldByVaultEth = (0,
|
|
820
|
+
const debtValueHeldByVaultEth = (0, import_utils4.formatUnitsNum)(
|
|
847
821
|
destination.debtValueHeldByVault,
|
|
848
822
|
baseAsset.decimals
|
|
849
823
|
);
|
|
@@ -856,8 +830,8 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
856
830
|
destination.underlyingTokenValueHeld
|
|
857
831
|
);
|
|
858
832
|
let underlyingTokens = tokensWithValue.map((token) => {
|
|
859
|
-
const tokenDetails = (0,
|
|
860
|
-
let value = (0,
|
|
833
|
+
const tokenDetails = (0, import_utils4.getToken)(token.tokenAddress);
|
|
834
|
+
let value = (0, import_utils4.formatUnitsNum)(
|
|
861
835
|
token.valueHeldInEth,
|
|
862
836
|
baseAsset.decimals
|
|
863
837
|
);
|
|
@@ -873,7 +847,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
873
847
|
if (underlyingTokenAddress) {
|
|
874
848
|
underlyingTokens = [
|
|
875
849
|
{
|
|
876
|
-
...(0,
|
|
850
|
+
...(0, import_utils4.getToken)(underlyingTokenAddress, chainId),
|
|
877
851
|
valueUsd: debtValueHeldByVaultEth * baseAssetPrice,
|
|
878
852
|
value: debtValueHeldByVaultEth
|
|
879
853
|
}
|
|
@@ -885,11 +859,11 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
885
859
|
...destination,
|
|
886
860
|
debtValueHeldByVaultUsd: debtValueHeldByVaultEth * baseAssetPrice,
|
|
887
861
|
debtValueHeldByVaultEth,
|
|
888
|
-
compositeReturn: isGenStrat ? genStratAprs?.[autopool.poolAddress]?.[destination.vaultAddress]?.apr || 0 : (0,
|
|
862
|
+
compositeReturn: isGenStrat ? genStratAprs?.[autopool.poolAddress]?.[destination.vaultAddress]?.apr || 0 : (0, import_utils4.formatEtherNum)(destination.compositeReturn),
|
|
889
863
|
debtValueHeldByVaultAllocation: debtValueHeldByVaultEth / totalAssets,
|
|
890
864
|
underlyingTokens,
|
|
891
|
-
poolName: (0,
|
|
892
|
-
exchange: (0,
|
|
865
|
+
poolName: (0, import_utils4.formatPoolName)(destination.lpTokenName),
|
|
866
|
+
exchange: (0, import_utils4.getProtocol)(destination.exchangeName)
|
|
893
867
|
};
|
|
894
868
|
});
|
|
895
869
|
const HIDDEN_DESTINATION_SYMBOLS = ["USR", "WSTUSR"];
|
|
@@ -900,7 +874,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
900
874
|
);
|
|
901
875
|
const uniqueExchanges = Array.from(
|
|
902
876
|
new Set(
|
|
903
|
-
filteredDestinations.map((d) => (0,
|
|
877
|
+
filteredDestinations.map((d) => (0, import_utils4.getProtocol)(d.exchangeName)).filter(Boolean)
|
|
904
878
|
)
|
|
905
879
|
);
|
|
906
880
|
const uniqueExchangesWithValueHeld = uniqueExchanges.map((exchange) => {
|
|
@@ -936,15 +910,18 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
936
910
|
},
|
|
937
911
|
[]
|
|
938
912
|
);
|
|
939
|
-
const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
|
|
940
|
-
|
|
941
|
-
acc[token.address]
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
913
|
+
const uniqueTokensWithValueHeldMap = filteredDestinations.flatMap((d) => d.underlyingTokens).reduce(
|
|
914
|
+
(acc, token) => {
|
|
915
|
+
if (acc[token.address]) {
|
|
916
|
+
acc[token.address].valueUsd += token.valueUsd;
|
|
917
|
+
acc[token.address].value += token.value;
|
|
918
|
+
} else {
|
|
919
|
+
acc[token.address] = { ...token };
|
|
920
|
+
}
|
|
921
|
+
return acc;
|
|
922
|
+
},
|
|
923
|
+
{}
|
|
924
|
+
);
|
|
948
925
|
const HIDDEN_TOKEN_SYMBOLS = ["USR", "WSTUSR"];
|
|
949
926
|
const uniqueTokens = Object.values(uniqueTokensWithValueHeldMap).filter(
|
|
950
927
|
(token) => !HIDDEN_TOKEN_SYMBOLS.includes(token.symbol?.toUpperCase())
|
|
@@ -973,24 +950,12 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
973
950
|
const aprs = autopoolsApr.find(
|
|
974
951
|
(autopoolApr) => (0, import_viem2.getAddress)(autopoolApr.id) === (0, import_viem2.getAddress)(autopool.poolAddress)
|
|
975
952
|
);
|
|
976
|
-
|
|
953
|
+
const baseApr = aprs?.baseApy !== void 0 ? aprs.baseApy / 100 : void 0;
|
|
977
954
|
let extraApr = 0;
|
|
978
|
-
if (baseApr === void 0) {
|
|
979
|
-
try {
|
|
980
|
-
const backupApr = await getBackupApr(chainId, autopool.poolAddress);
|
|
981
|
-
if (backupApr) {
|
|
982
|
-
baseApr = backupApr;
|
|
983
|
-
console.log("using backup apr", backupApr);
|
|
984
|
-
}
|
|
985
|
-
} catch (e) {
|
|
986
|
-
console.error(e);
|
|
987
|
-
console.log("unable to retrieve backup apr");
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
955
|
let extraRewards = [];
|
|
991
956
|
if (aprs?.rewards && aprs.rewards.length > 0) {
|
|
992
957
|
extraRewards = aprs.rewards.map((reward) => {
|
|
993
|
-
const token = (0,
|
|
958
|
+
const token = (0, import_utils4.getToken)(reward.rewardToken, chainId);
|
|
994
959
|
return {
|
|
995
960
|
...token,
|
|
996
961
|
apr: reward.rewardApy / 100
|
|
@@ -998,8 +963,8 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
998
963
|
});
|
|
999
964
|
}
|
|
1000
965
|
extraApr = extraRewards.reduce((acc, reward) => acc + reward.apr, 0);
|
|
1001
|
-
|
|
1002
|
-
const combinedApr =
|
|
966
|
+
const baseForMath = baseApr ?? 0;
|
|
967
|
+
const combinedApr = baseForMath + extraApr;
|
|
1003
968
|
let denominatedToken = import_tokenlist3.ETH_TOKEN;
|
|
1004
969
|
let useDenominatedValues = false;
|
|
1005
970
|
const denominationData = autopoolsDenomination.find(
|
|
@@ -1009,7 +974,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1009
974
|
if (denominatedIn?.symbol?.toLowerCase() === "weth") {
|
|
1010
975
|
denominatedToken = import_tokenlist3.ETH_TOKEN;
|
|
1011
976
|
} else {
|
|
1012
|
-
denominatedToken = (0,
|
|
977
|
+
denominatedToken = (0, import_utils4.getToken)(denominatedIn?.id);
|
|
1013
978
|
if (denominatedToken) {
|
|
1014
979
|
useDenominatedValues = true;
|
|
1015
980
|
}
|
|
@@ -1024,12 +989,12 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1024
989
|
tokenAddress: denominatedToken.address
|
|
1025
990
|
}) || 0;
|
|
1026
991
|
}
|
|
1027
|
-
const navPerShareBaseAsset = (0,
|
|
992
|
+
const navPerShareBaseAsset = (0, import_utils4.formatUnitsNum)(
|
|
1028
993
|
autopool.navPerShare,
|
|
1029
994
|
baseAsset.decimals
|
|
1030
995
|
);
|
|
1031
996
|
const assets = convertBaseAssetToTokenPricesAndDenom(
|
|
1032
|
-
(0,
|
|
997
|
+
(0, import_utils4.formatUnitsNum)(autopool.totalAssets, baseAsset.decimals),
|
|
1033
998
|
baseAssetPrice,
|
|
1034
999
|
denominatedTokenPrice,
|
|
1035
1000
|
prices
|
|
@@ -1054,7 +1019,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1054
1019
|
prices
|
|
1055
1020
|
);
|
|
1056
1021
|
const baseDailyEarnings = convertBaseAssetToTokenPricesAndDenom(
|
|
1057
|
-
totalAssets *
|
|
1022
|
+
totalAssets * baseForMath / import_constants6.DAYS_PER_YEAR,
|
|
1058
1023
|
baseAssetPrice,
|
|
1059
1024
|
denominatedTokenPrice,
|
|
1060
1025
|
prices
|
|
@@ -1062,36 +1027,39 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1062
1027
|
const tokenOrder = [UIBaseAsset.symbol, ...UITokenOrder].filter(
|
|
1063
1028
|
(value, index, array) => array.indexOf(value) === index
|
|
1064
1029
|
);
|
|
1065
|
-
const UITokens = uniqueTokens.reduce(
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1030
|
+
const UITokens = uniqueTokens.reduce(
|
|
1031
|
+
(acc, token) => {
|
|
1032
|
+
try {
|
|
1033
|
+
const parentAsset = token.extensions?.parentAsset;
|
|
1034
|
+
if (parentAsset) {
|
|
1035
|
+
const parentToken = import_tokenlist3.ALL_TOKENS.find(
|
|
1036
|
+
(t) => t.symbol.toLowerCase() === parentAsset.toLowerCase()
|
|
1037
|
+
);
|
|
1038
|
+
if (parentToken && !acc.some(
|
|
1039
|
+
(t) => t?.address?.toLowerCase() === parentToken?.address?.toLowerCase()
|
|
1040
|
+
)) {
|
|
1041
|
+
acc.push({
|
|
1042
|
+
...parentToken,
|
|
1043
|
+
valueUsd: 0,
|
|
1044
|
+
value: 0,
|
|
1045
|
+
allocation: 0
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
} else if (!acc.some(
|
|
1049
|
+
(t) => t?.address?.toLowerCase() === token?.address?.toLowerCase()
|
|
1074
1050
|
)) {
|
|
1075
|
-
acc.push(
|
|
1076
|
-
...parentToken,
|
|
1077
|
-
valueUsd: 0,
|
|
1078
|
-
value: 0,
|
|
1079
|
-
allocation: 0
|
|
1080
|
-
});
|
|
1051
|
+
acc.push(token);
|
|
1081
1052
|
}
|
|
1082
|
-
}
|
|
1083
|
-
(
|
|
1084
|
-
|
|
1085
|
-
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
console.warn(
|
|
1055
|
+
`Error processing token: ${token?.symbol || "unknown"}`,
|
|
1056
|
+
error
|
|
1057
|
+
);
|
|
1086
1058
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
);
|
|
1092
|
-
}
|
|
1093
|
-
return acc;
|
|
1094
|
-
}, []).sort((a, b) => {
|
|
1059
|
+
return acc;
|
|
1060
|
+
},
|
|
1061
|
+
[]
|
|
1062
|
+
).sort((a, b) => {
|
|
1095
1063
|
try {
|
|
1096
1064
|
const aIndex = tokenOrder.indexOf(a.symbol.toUpperCase());
|
|
1097
1065
|
const bIndex = tokenOrder.indexOf(b.symbol.toUpperCase());
|
|
@@ -1134,7 +1102,7 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1134
1102
|
});
|
|
1135
1103
|
const autopoolInfo = getAutopoolInfo(autopool.symbol);
|
|
1136
1104
|
if (autopoolInfo && !autopoolInfo.description) {
|
|
1137
|
-
autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${(0,
|
|
1105
|
+
autopoolInfo.description = `Autopool featuring ${UIBaseAsset.symbol} deployed across integrated DEXs and lending protocols on ${(0, import_utils4.getNetwork)(chainId)?.name}.`;
|
|
1138
1106
|
}
|
|
1139
1107
|
return {
|
|
1140
1108
|
...autopool,
|
|
@@ -1160,9 +1128,9 @@ var getChainAutopools = async (wagmiConfig, {
|
|
|
1160
1128
|
UITokens,
|
|
1161
1129
|
UIExchanges: finalUIExchanges,
|
|
1162
1130
|
tokens: uniqueTokens,
|
|
1163
|
-
chain: (0,
|
|
1131
|
+
chain: (0, import_utils4.getNetwork)(chainId),
|
|
1164
1132
|
apr: {
|
|
1165
|
-
base: baseApr,
|
|
1133
|
+
base: baseApr ?? null,
|
|
1166
1134
|
extraAprs: extraRewards,
|
|
1167
1135
|
combined: combinedApr,
|
|
1168
1136
|
hasExtraAprs: extraRewards.length > 0
|
|
@@ -1200,12 +1168,13 @@ var getAutopools = async (wagmiConfig, {
|
|
|
1200
1168
|
try {
|
|
1201
1169
|
const chains = getChainsForEnv({ includeTestnet });
|
|
1202
1170
|
const autopools = (await Promise.all(
|
|
1203
|
-
chains.map(
|
|
1204
|
-
|
|
1171
|
+
chains.map((chain) => {
|
|
1172
|
+
const chainId = chain?.chainId;
|
|
1173
|
+
return getChainAutopools((0, import_core.getPublicClient)(wagmiConfig, { chainId }), {
|
|
1205
1174
|
prices,
|
|
1206
|
-
chainId
|
|
1207
|
-
})
|
|
1208
|
-
)
|
|
1175
|
+
chainId
|
|
1176
|
+
});
|
|
1177
|
+
})
|
|
1209
1178
|
)).flat();
|
|
1210
1179
|
const sortedAutopoolsByTimestamp = autopools.sort(
|
|
1211
1180
|
(a, b) => b.timestamp - a.timestamp
|
|
@@ -1252,7 +1221,7 @@ var getAutopoolsRebalances = async (chainId = 1) => {
|
|
|
1252
1221
|
|
|
1253
1222
|
// functions/getAutopoolDayData.ts
|
|
1254
1223
|
var import_viem4 = require("viem");
|
|
1255
|
-
var
|
|
1224
|
+
var import_utils8 = require("@tokemak/utils");
|
|
1256
1225
|
var import_constants7 = require("@tokemak/constants");
|
|
1257
1226
|
var import_graph_cli4 = require("@tokemak/graph-cli");
|
|
1258
1227
|
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_constants7.TOKEMAK_LAUNCH_TIMESTAMP) => {
|
|
@@ -1267,10 +1236,10 @@ var getAutopoolDayData = async (address, chainId = 1, startTimestamp = import_co
|
|
|
1267
1236
|
const navPerShare = Number(autoPoolDayData.nav) / Number(autoPoolDayData.totalSupply) * Math.pow(10, 18 - baseDecimals);
|
|
1268
1237
|
let baseApy = autoPoolDayData.autopoolApy;
|
|
1269
1238
|
let rewarderApy = 0;
|
|
1270
|
-
const formattedRewarder7DayMAApy = (0,
|
|
1239
|
+
const formattedRewarder7DayMAApy = (0, import_utils8.formatEtherNum)(
|
|
1271
1240
|
BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
|
|
1272
1241
|
);
|
|
1273
|
-
const formattedRewarder30DayMAApy = (0,
|
|
1242
|
+
const formattedRewarder30DayMAApy = (0, import_utils8.formatEtherNum)(
|
|
1274
1243
|
BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
|
|
1275
1244
|
);
|
|
1276
1245
|
if (formattedRewarder7DayMAApy) {
|
|
@@ -1398,7 +1367,7 @@ var getAutopoolsHistory = async (autopools, days, includeTestnet = false) => {
|
|
|
1398
1367
|
var import_viem6 = require("viem");
|
|
1399
1368
|
var import_core2 = require("@wagmi/core");
|
|
1400
1369
|
var import_abis2 = require("@tokemak/abis");
|
|
1401
|
-
var
|
|
1370
|
+
var import_utils10 = require("@tokemak/utils");
|
|
1402
1371
|
var getAutopoolUser = async (config, {
|
|
1403
1372
|
autopool,
|
|
1404
1373
|
address,
|
|
@@ -1440,14 +1409,14 @@ var getAutopoolUser = async (config, {
|
|
|
1440
1409
|
args: [address],
|
|
1441
1410
|
chainId: autopool?.chain?.chainId
|
|
1442
1411
|
});
|
|
1443
|
-
const stakedShares = (0,
|
|
1412
|
+
const stakedShares = (0, import_utils10.formatEtherNum)(stakedPoolShares);
|
|
1444
1413
|
const staked = convertBaseAssetToTokenPricesAndDenom(
|
|
1445
1414
|
stakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
1446
1415
|
autopool?.baseAsset.price,
|
|
1447
1416
|
autopool?.denomination.price,
|
|
1448
1417
|
prices
|
|
1449
1418
|
);
|
|
1450
|
-
const unstakedShares = (0,
|
|
1419
|
+
const unstakedShares = (0, import_utils10.formatEtherNum)(unstakedPoolShares || 0n);
|
|
1451
1420
|
const unstaked = convertBaseAssetToTokenPricesAndDenom(
|
|
1452
1421
|
unstakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
1453
1422
|
autopool?.baseAsset.price,
|
|
@@ -1462,7 +1431,7 @@ var getAutopoolUser = async (config, {
|
|
|
1462
1431
|
prices
|
|
1463
1432
|
);
|
|
1464
1433
|
const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
|
|
1465
|
-
(0,
|
|
1434
|
+
(0, import_utils10.formatUnitsNum)(
|
|
1466
1435
|
userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
|
|
1467
1436
|
autopool?.baseAsset.decimals
|
|
1468
1437
|
),
|
|
@@ -1471,7 +1440,7 @@ var getAutopoolUser = async (config, {
|
|
|
1471
1440
|
prices
|
|
1472
1441
|
);
|
|
1473
1442
|
const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
|
|
1474
|
-
(0,
|
|
1443
|
+
(0, import_utils10.formatUnitsNum)(
|
|
1475
1444
|
userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
|
|
1476
1445
|
autopool?.baseAsset.decimals
|
|
1477
1446
|
),
|
|
@@ -1496,7 +1465,7 @@ var getAutopoolUser = async (config, {
|
|
|
1496
1465
|
);
|
|
1497
1466
|
let lastDeposit;
|
|
1498
1467
|
if (poolEvents && poolEvents?.length > 0) {
|
|
1499
|
-
lastDeposit = (0,
|
|
1468
|
+
lastDeposit = (0, import_utils10.convertTimestampToDate)(
|
|
1500
1469
|
poolEvents[poolEvents.length - 1].timestamp
|
|
1501
1470
|
).toLocaleDateString("en-US", {
|
|
1502
1471
|
day: "2-digit",
|
|
@@ -1530,7 +1499,7 @@ var getAutopoolUser = async (config, {
|
|
|
1530
1499
|
|
|
1531
1500
|
// functions/getAutopoolUserActivity.ts
|
|
1532
1501
|
var import_graph_cli6 = require("@tokemak/graph-cli");
|
|
1533
|
-
var
|
|
1502
|
+
var import_utils13 = require("@tokemak/utils");
|
|
1534
1503
|
var getAutopoolUserActivity = async ({
|
|
1535
1504
|
autopool,
|
|
1536
1505
|
userAddress
|
|
@@ -1592,7 +1561,7 @@ var getAutopoolUserActivity = async ({
|
|
|
1592
1561
|
} else {
|
|
1593
1562
|
eventType = "Unknown";
|
|
1594
1563
|
}
|
|
1595
|
-
const netDeposits = (0,
|
|
1564
|
+
const netDeposits = (0, import_utils13.formatUnitsNum)(
|
|
1596
1565
|
userActivityTotals[activity.vaultAddress].totalDeposits - userActivityTotals[activity.vaultAddress].totalWithdrawals,
|
|
1597
1566
|
autopool.baseAsset.decimals
|
|
1598
1567
|
);
|
|
@@ -1620,7 +1589,7 @@ var getAutopoolUserActivity = async ({
|
|
|
1620
1589
|
var import_graph_cli7 = require("@tokemak/graph-cli");
|
|
1621
1590
|
var import_constants8 = require("@tokemak/constants");
|
|
1622
1591
|
var import_chains3 = require("viem/chains");
|
|
1623
|
-
var
|
|
1592
|
+
var import_utils15 = require("@tokemak/utils");
|
|
1624
1593
|
var getAutopoolUserHistory = async ({
|
|
1625
1594
|
userAddress,
|
|
1626
1595
|
autopool,
|
|
@@ -1671,8 +1640,8 @@ var getAutopoolUserHistory = async ({
|
|
|
1671
1640
|
const matchingAutopoolDayData = autopoolDayData.find(
|
|
1672
1641
|
(autopoolDay) => autopoolDay.date.toDateString() === userVaultDayData.date.toDateString()
|
|
1673
1642
|
);
|
|
1674
|
-
const userPortionOfVault = (0,
|
|
1675
|
-
const userNav = userPortionOfVault * (0,
|
|
1643
|
+
const userPortionOfVault = (0, import_utils15.formatEtherNum)(userVaultDayData.totalShares) / (0, import_utils15.formatEtherNum)(matchingAutopoolDayData?.totalSupply);
|
|
1644
|
+
const userNav = userPortionOfVault * (0, import_utils15.formatUnitsNum)(
|
|
1676
1645
|
BigInt(matchingAutopoolDayData?.nav || 0),
|
|
1677
1646
|
autopool?.baseAsset.decimals
|
|
1678
1647
|
);
|
|
@@ -2852,7 +2821,7 @@ var getRewardsPayloadV1 = async (cycleHash, account, rewardsV1Url) => {
|
|
|
2852
2821
|
// functions/getUserAutoEthRewards.ts
|
|
2853
2822
|
var import_abis4 = require("@tokemak/abis");
|
|
2854
2823
|
var import_core6 = require("@wagmi/core");
|
|
2855
|
-
var
|
|
2824
|
+
var import_utils17 = require("@tokemak/utils");
|
|
2856
2825
|
var getAutoEthRewards = async (wagmiConfig, {
|
|
2857
2826
|
account,
|
|
2858
2827
|
currentCycleIndex,
|
|
@@ -2890,7 +2859,7 @@ var getAutoEthRewards = async (wagmiConfig, {
|
|
|
2890
2859
|
const currentAmount = Number(drippingHashPayload?.summary?.currentAmount);
|
|
2891
2860
|
const previousAmount = Number(drippingHashPayload?.summary?.previousAmount);
|
|
2892
2861
|
const cycleDuration = 604800;
|
|
2893
|
-
const lastCycleStart = (0,
|
|
2862
|
+
const lastCycleStart = (0, import_utils17.convertChainCycleToUnix)(Number(currentCycleIndex));
|
|
2894
2863
|
const timeSinceCycleStart = Date.now() / 1e3 - lastCycleStart;
|
|
2895
2864
|
const currentUserRewards = currentAmount * Math.min(timeSinceCycleStart, cycleDuration) / cycleDuration + previousAmount;
|
|
2896
2865
|
const lastWeekRewards = Number(lastWeekHashPayload?.summary?.currentAmount);
|
|
@@ -2911,7 +2880,7 @@ var getUserAutoEthRewards = async (wagmiConfig, rewardsV1Url, rewardsHash, addre
|
|
|
2911
2880
|
rewardsHash,
|
|
2912
2881
|
chainId
|
|
2913
2882
|
});
|
|
2914
|
-
const currentUserRewardsUsd = (0,
|
|
2883
|
+
const currentUserRewardsUsd = (0, import_utils17.formatCurrency)(
|
|
2915
2884
|
ethPrice * (autoETHRewards?.currentUserRewards || 0)
|
|
2916
2885
|
);
|
|
2917
2886
|
return { ...autoETHRewards, currentUserRewardsUsd };
|
|
@@ -3099,11 +3068,11 @@ var getChainUserAutopoolsHistory = async ({
|
|
|
3099
3068
|
};
|
|
3100
3069
|
|
|
3101
3070
|
// functions/getUserAutopoolsHistory.ts
|
|
3102
|
-
var
|
|
3071
|
+
var import_utils21 = require("@tokemak/utils");
|
|
3103
3072
|
|
|
3104
3073
|
// functions/getTokenValueDayDatas.ts
|
|
3105
3074
|
var import_chains10 = require("viem/chains");
|
|
3106
|
-
var
|
|
3075
|
+
var import_utils18 = require("@tokemak/utils");
|
|
3107
3076
|
var import_viem10 = require("viem");
|
|
3108
3077
|
var import_graph_cli10 = require("@tokemak/graph-cli");
|
|
3109
3078
|
var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainnet.id) => {
|
|
@@ -3113,7 +3082,7 @@ var getTokenValueDayDatas = async (tokenAddress, chainId = import_chains10.mainn
|
|
|
3113
3082
|
tokenAddress: tokenAddress.toLowerCase()
|
|
3114
3083
|
});
|
|
3115
3084
|
const historicalPrice = tokenValueDayDatas.map((tokenValueDayData) => {
|
|
3116
|
-
const date = (0,
|
|
3085
|
+
const date = (0, import_utils18.convertTimestampToDate)(
|
|
3117
3086
|
tokenValueDayData.lastSnapshotTimestamp
|
|
3118
3087
|
);
|
|
3119
3088
|
const usdPrice = (0, import_viem10.formatUnits)(tokenValueDayData.priceInUsd, 8);
|
|
@@ -3273,7 +3242,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3273
3242
|
Math.floor(sharesRatio * Number(SCALE))
|
|
3274
3243
|
);
|
|
3275
3244
|
const navBigInt = sharesRatioBigInt * BigInt(dayData.nav) / SCALE;
|
|
3276
|
-
const navNum = (0,
|
|
3245
|
+
const navNum = (0, import_utils21.formatUnitsNum)(
|
|
3277
3246
|
navBigInt,
|
|
3278
3247
|
dayData.baseAsset.decimals
|
|
3279
3248
|
);
|
|
@@ -3344,7 +3313,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3344
3313
|
let finalAggregatedHistoryArray = Object.keys(aggregatedHistoryArray).map(
|
|
3345
3314
|
(dateKey) => ({
|
|
3346
3315
|
date: aggregatedHistoryArray[dateKey].date,
|
|
3347
|
-
formattedDate: (0,
|
|
3316
|
+
formattedDate: (0, import_utils21.formatDateToReadable)(aggregatedHistoryArray[dateKey].date),
|
|
3348
3317
|
nav: {
|
|
3349
3318
|
ETH: aggregatedHistoryArray[dateKey].nav.ETH,
|
|
3350
3319
|
USD: aggregatedHistoryArray[dateKey].nav.USD,
|
|
@@ -3392,7 +3361,7 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
3392
3361
|
return sum;
|
|
3393
3362
|
}
|
|
3394
3363
|
const decimals = vault.baseAsset.decimals;
|
|
3395
|
-
const assetChangeNum = (0,
|
|
3364
|
+
const assetChangeNum = (0, import_utils21.formatUnitsNum)(
|
|
3396
3365
|
BigInt(event.assetChange || 0n),
|
|
3397
3366
|
decimals
|
|
3398
3367
|
);
|
|
@@ -3636,13 +3605,13 @@ var getChainUserAutopools = async ({
|
|
|
3636
3605
|
};
|
|
3637
3606
|
|
|
3638
3607
|
// functions/getUserAutopools.ts
|
|
3639
|
-
var
|
|
3608
|
+
var import_utils23 = require("@tokemak/utils");
|
|
3640
3609
|
var import_tokenlist7 = require("@tokemak/tokenlist");
|
|
3641
3610
|
|
|
3642
3611
|
// functions/getUserAutopool.tsx
|
|
3643
3612
|
var import_viem11 = require("viem");
|
|
3644
3613
|
var import_core12 = require("@wagmi/core");
|
|
3645
|
-
var
|
|
3614
|
+
var import_utils22 = require("@tokemak/utils");
|
|
3646
3615
|
var import_abis10 = require("@tokemak/abis");
|
|
3647
3616
|
var getUserAutopool = async (wagmiConfig, {
|
|
3648
3617
|
address,
|
|
@@ -3691,10 +3660,10 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3691
3660
|
args: [address],
|
|
3692
3661
|
chainId: autopool?.chain?.chainId
|
|
3693
3662
|
});
|
|
3694
|
-
const stakedShares = (0,
|
|
3663
|
+
const stakedShares = (0, import_utils22.formatEtherNum)(stakedPoolShares);
|
|
3695
3664
|
const stakedNav = stakedShares * (autopool?.navPerShare.baseAsset || 0);
|
|
3696
3665
|
const stakedNavUsd = stakedShares * (autopool?.navPerShare.USD || 0);
|
|
3697
|
-
const unstakedShares = (0,
|
|
3666
|
+
const unstakedShares = (0, import_utils22.formatEtherNum)(unstakedPoolShares || 0n);
|
|
3698
3667
|
const unstakedNav = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
3699
3668
|
const unstakedNavUsd = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
3700
3669
|
const totalShares = unstakedShares + stakedShares;
|
|
@@ -3715,7 +3684,7 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
3715
3684
|
});
|
|
3716
3685
|
pastRewarderBalances = pastRewards.map(({ result }, index) => {
|
|
3717
3686
|
const balance = result;
|
|
3718
|
-
const shares = (0,
|
|
3687
|
+
const shares = (0, import_utils22.formatEtherNum)(result);
|
|
3719
3688
|
const nav = shares * (autopool?.navPerShare.baseAsset || 0);
|
|
3720
3689
|
const navUsd = shares * (autopool?.navPerShare.USD || 0);
|
|
3721
3690
|
return {
|
|
@@ -3833,14 +3802,14 @@ var getUserAutopools = async ({
|
|
|
3833
3802
|
);
|
|
3834
3803
|
if (autopoolData) {
|
|
3835
3804
|
const isDOLA = autopoolData.symbol === "autoDOLA" && userAutoDOLA;
|
|
3836
|
-
const userShares = isDOLA ? userAutoDOLA?.totalShares : (0,
|
|
3837
|
-
const totalVaultShares = (0,
|
|
3805
|
+
const userShares = isDOLA ? userAutoDOLA?.totalShares : (0, import_utils23.formatEtherNum)(userAutopool?.totalShares);
|
|
3806
|
+
const totalVaultShares = (0, import_utils23.formatEtherNum)(autopoolData?.totalSupply);
|
|
3838
3807
|
const userShareOfVault = userShares / totalVaultShares;
|
|
3839
|
-
const totalDeposits = (0,
|
|
3808
|
+
const totalDeposits = (0, import_utils23.formatUnitsNum)(
|
|
3840
3809
|
userActivity?.totals[userAutopool.vaultAddress]?.totalDeposits || 0n,
|
|
3841
3810
|
autopoolData?.baseAsset.decimals
|
|
3842
3811
|
);
|
|
3843
|
-
const totalWithdrawals = (0,
|
|
3812
|
+
const totalWithdrawals = (0, import_utils23.formatUnitsNum)(
|
|
3844
3813
|
userActivity?.totals[userAutopool.vaultAddress]?.totalWithdrawals || 0n,
|
|
3845
3814
|
autopoolData?.baseAsset.decimals
|
|
3846
3815
|
);
|
|
@@ -3849,7 +3818,7 @@ var getUserAutopools = async ({
|
|
|
3849
3818
|
);
|
|
3850
3819
|
let lastDeposit;
|
|
3851
3820
|
if (poolEvents && poolEvents?.length > 0) {
|
|
3852
|
-
lastDeposit = (0,
|
|
3821
|
+
lastDeposit = (0, import_utils23.convertTimestampToDate)(
|
|
3853
3822
|
poolEvents[poolEvents.length - 1].timestamp
|
|
3854
3823
|
).toLocaleDateString("en-US", {
|
|
3855
3824
|
day: "2-digit",
|
|
@@ -3949,7 +3918,7 @@ var getUserAutopools = async ({
|
|
|
3949
3918
|
totalWithdrawals: prev.totalWithdrawals + totalWithdrawals
|
|
3950
3919
|
};
|
|
3951
3920
|
const stakedBalance = isDOLA ? userAutoDOLA?.staked.balance : BigInt(userAutopool?.stakedShares);
|
|
3952
|
-
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0,
|
|
3921
|
+
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : (0, import_utils23.formatEtherNum)(stakedBalance);
|
|
3953
3922
|
const stakedNav = stakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
3954
3923
|
const staked = convertBaseAssetToTokenPrices(
|
|
3955
3924
|
stakedNav,
|
|
@@ -3957,7 +3926,7 @@ var getUserAutopools = async ({
|
|
|
3957
3926
|
prices
|
|
3958
3927
|
);
|
|
3959
3928
|
const unstakedBalance = isDOLA ? userAutoDOLA?.unstaked.balance : BigInt(userAutopool?.walletShares);
|
|
3960
|
-
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0,
|
|
3929
|
+
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : (0, import_utils23.formatEtherNum)(unstakedBalance);
|
|
3961
3930
|
const unstakedNav = unstakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
3962
3931
|
const unstaked = convertBaseAssetToTokenPrices(
|
|
3963
3932
|
unstakedNav,
|
|
@@ -3966,7 +3935,7 @@ var getUserAutopools = async ({
|
|
|
3966
3935
|
);
|
|
3967
3936
|
const stakedRatio = stakedShares / userShares;
|
|
3968
3937
|
const unstakedRatio = 1 - stakedRatio;
|
|
3969
|
-
const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * autopoolData?.apr?.base;
|
|
3938
|
+
const blendedApr = stakedRatio * autopoolData?.apr?.combined + unstakedRatio * (autopoolData?.apr?.base ?? 0);
|
|
3970
3939
|
return {
|
|
3971
3940
|
name: autopoolData?.name,
|
|
3972
3941
|
symbol: autopoolData?.symbol,
|
|
@@ -4008,13 +3977,16 @@ var getUserAutopools = async ({
|
|
|
4008
3977
|
denominatedToken = autopoolWithDenomination?.denomination;
|
|
4009
3978
|
}
|
|
4010
3979
|
}
|
|
4011
|
-
const nav = Object.values(categories).reduce(
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
3980
|
+
const nav = Object.values(categories).reduce(
|
|
3981
|
+
(acc, { nav: nav2 }) => {
|
|
3982
|
+
return Object.keys(nav2).reduce((sumAcc, key) => {
|
|
3983
|
+
const typedKey = key;
|
|
3984
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + nav2[typedKey];
|
|
3985
|
+
return sumAcc;
|
|
3986
|
+
}, acc);
|
|
3987
|
+
},
|
|
3988
|
+
{}
|
|
3989
|
+
);
|
|
4018
3990
|
const idleWithTokenPrices = userAutopoolsWithData.reduce(
|
|
4019
3991
|
(acc, userAutopool) => {
|
|
4020
3992
|
if (!userAutopool) return acc;
|
|
@@ -4042,20 +4014,26 @@ var getUserAutopools = async ({
|
|
|
4042
4014
|
...idle2,
|
|
4043
4015
|
allocation: idle2.USD / nav.USD
|
|
4044
4016
|
}));
|
|
4045
|
-
const returns = Object.values(categories).reduce(
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4017
|
+
const returns = Object.values(categories).reduce(
|
|
4018
|
+
(acc, { returns: returns2 }) => {
|
|
4019
|
+
return Object.keys(returns2).reduce((sumAcc, key) => {
|
|
4020
|
+
const typedKey = key;
|
|
4021
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + returns2[typedKey];
|
|
4022
|
+
return sumAcc;
|
|
4023
|
+
}, acc);
|
|
4024
|
+
},
|
|
4025
|
+
{}
|
|
4026
|
+
);
|
|
4027
|
+
const supplied = Object.values(categories).reduce(
|
|
4028
|
+
(acc, { supplied: supplied2 }) => {
|
|
4029
|
+
return Object.keys(supplied2).reduce((sumAcc, key) => {
|
|
4030
|
+
const typedKey = key;
|
|
4031
|
+
sumAcc[typedKey] = (sumAcc[typedKey] || 0) + supplied2[typedKey];
|
|
4032
|
+
return sumAcc;
|
|
4033
|
+
}, acc);
|
|
4034
|
+
},
|
|
4035
|
+
{}
|
|
4036
|
+
);
|
|
4059
4037
|
const userExchangesWithAllocations = Object.values(userExchanges).map(
|
|
4060
4038
|
(userExchange) => {
|
|
4061
4039
|
return {
|
|
@@ -4117,11 +4095,14 @@ var getUserAutopools = async ({
|
|
|
4117
4095
|
categories[categoryKey] = {
|
|
4118
4096
|
...categoryData,
|
|
4119
4097
|
apr,
|
|
4120
|
-
avgDailyReturns: Object.keys(categoryData.nav).reduce(
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4098
|
+
avgDailyReturns: Object.keys(categoryData.nav).reduce(
|
|
4099
|
+
(acc, key) => {
|
|
4100
|
+
const typedKey = key;
|
|
4101
|
+
acc[typedKey] = dailyRate * categoryData.nav[typedKey];
|
|
4102
|
+
return acc;
|
|
4103
|
+
},
|
|
4104
|
+
{}
|
|
4105
|
+
)
|
|
4125
4106
|
};
|
|
4126
4107
|
});
|
|
4127
4108
|
return {
|
|
@@ -4314,7 +4295,7 @@ var getChainUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4314
4295
|
};
|
|
4315
4296
|
|
|
4316
4297
|
// functions/getUserAutopoolsRewards.ts
|
|
4317
|
-
var
|
|
4298
|
+
var import_utils27 = require("@tokemak/utils");
|
|
4318
4299
|
var import_tokenlist9 = require("@tokemak/tokenlist");
|
|
4319
4300
|
var import_chains11 = require("viem/chains");
|
|
4320
4301
|
var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
@@ -4345,7 +4326,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4345
4326
|
return [];
|
|
4346
4327
|
}
|
|
4347
4328
|
return autopool.extraRewarders.map((extraRewards2) => {
|
|
4348
|
-
const rewarderToken = (0,
|
|
4329
|
+
const rewarderToken = (0, import_utils27.getToken)(
|
|
4349
4330
|
extraRewards2.rewardToken?.id,
|
|
4350
4331
|
autopool.chain?.chainId
|
|
4351
4332
|
);
|
|
@@ -4354,7 +4335,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4354
4335
|
if (rewarderToken.symbol === "XSILO") {
|
|
4355
4336
|
price = tokenPrices[import_tokenlist9.SILO_TOKEN.symbol] || 0;
|
|
4356
4337
|
}
|
|
4357
|
-
const formattedAmount = (0,
|
|
4338
|
+
const formattedAmount = (0, import_utils27.formatUnitsNum)(
|
|
4358
4339
|
claimableAmount,
|
|
4359
4340
|
rewarderToken.decimals || 18
|
|
4360
4341
|
);
|
|
@@ -4372,7 +4353,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4372
4353
|
const tokenRewards = {};
|
|
4373
4354
|
Object.values(chainUserRewards).forEach((autopoolRewards) => {
|
|
4374
4355
|
Object.entries(autopoolRewards).forEach(([tokenAddress, amount]) => {
|
|
4375
|
-
const token = (0,
|
|
4356
|
+
const token = (0, import_utils27.getToken)(tokenAddress, chainId);
|
|
4376
4357
|
const tokenSymbol = token.symbol;
|
|
4377
4358
|
if (!tokenRewards[tokenSymbol]) {
|
|
4378
4359
|
tokenRewards[tokenSymbol] = {
|
|
@@ -4392,7 +4373,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4392
4373
|
if (tokenSymbol === "XSILO") {
|
|
4393
4374
|
price = tokenPrices[import_tokenlist9.SILO_TOKEN.symbol] || 0;
|
|
4394
4375
|
}
|
|
4395
|
-
const formattedAmount = (0,
|
|
4376
|
+
const formattedAmount = (0, import_utils27.formatUnitsNum)(amount, decimals || 18);
|
|
4396
4377
|
tokenRewards[tokenSymbol] = {
|
|
4397
4378
|
amount,
|
|
4398
4379
|
formattedAmount,
|
|
@@ -4463,7 +4444,7 @@ var getUserAutopoolsRewards = async (wagmiConfig, {
|
|
|
4463
4444
|
|
|
4464
4445
|
// functions/getAmountWithdrawn.ts
|
|
4465
4446
|
var import_viem16 = require("viem");
|
|
4466
|
-
var
|
|
4447
|
+
var import_utils29 = require("@tokemak/utils");
|
|
4467
4448
|
|
|
4468
4449
|
// functions/getSwapQuote.ts
|
|
4469
4450
|
var import_constants16 = require("@tokemak/constants");
|
|
@@ -4677,7 +4658,7 @@ var getAmountWithdrawn = async ({
|
|
|
4677
4658
|
let quote;
|
|
4678
4659
|
let convertedAssets;
|
|
4679
4660
|
if (!!dynamicSwap?.previewRedeem) {
|
|
4680
|
-
const minAmountWithSlippage = (0,
|
|
4661
|
+
const minAmountWithSlippage = (0, import_utils29.calculateMinAmountWithSlippage)(
|
|
4681
4662
|
dynamicSwap?.previewRedeem,
|
|
4682
4663
|
slippage
|
|
4683
4664
|
);
|
|
@@ -4701,7 +4682,7 @@ var getAmountWithdrawn = async ({
|
|
|
4701
4682
|
buyToken,
|
|
4702
4683
|
sellToken,
|
|
4703
4684
|
sellAmount: dynamicSwap?.previewRedeem,
|
|
4704
|
-
slippageBps: (0,
|
|
4685
|
+
slippageBps: (0, import_utils29.convertNumToBps)(slippage),
|
|
4705
4686
|
chainId,
|
|
4706
4687
|
includeSources: "0xV2",
|
|
4707
4688
|
sellAll: true
|
|
@@ -4729,7 +4710,7 @@ var getAmountWithdrawn = async ({
|
|
|
4729
4710
|
// functions/getAmountDeposited.ts
|
|
4730
4711
|
var import_core18 = require("@wagmi/core");
|
|
4731
4712
|
var import_abis15 = require("@tokemak/abis");
|
|
4732
|
-
var
|
|
4713
|
+
var import_utils30 = require("@tokemak/utils");
|
|
4733
4714
|
var getAmountDeposited = async ({
|
|
4734
4715
|
address,
|
|
4735
4716
|
chainId,
|
|
@@ -4750,13 +4731,13 @@ var getAmountDeposited = async ({
|
|
|
4750
4731
|
chainId
|
|
4751
4732
|
});
|
|
4752
4733
|
if (!isSwap) {
|
|
4753
|
-
let minAmountWithSlippage = (0,
|
|
4734
|
+
let minAmountWithSlippage = (0, import_utils30.calculateMinAmountWithSlippage)(
|
|
4754
4735
|
previewDeposit,
|
|
4755
4736
|
slippage
|
|
4756
4737
|
);
|
|
4757
|
-
return (0,
|
|
4738
|
+
return (0, import_utils30.formatEtherNum)(minAmountWithSlippage);
|
|
4758
4739
|
} else {
|
|
4759
|
-
return (0,
|
|
4740
|
+
return (0, import_utils30.formatEtherNum)(previewDeposit);
|
|
4760
4741
|
}
|
|
4761
4742
|
} catch (e) {
|
|
4762
4743
|
console.error(e);
|
|
@@ -4874,7 +4855,7 @@ var waitForMessageReceived = async ({
|
|
|
4874
4855
|
// functions/getChainUserSToke.ts
|
|
4875
4856
|
var import_abis18 = require("@tokemak/abis");
|
|
4876
4857
|
var import_config13 = require("@tokemak/config");
|
|
4877
|
-
var
|
|
4858
|
+
var import_utils31 = require("@tokemak/utils");
|
|
4878
4859
|
var import_core21 = require("@wagmi/core");
|
|
4879
4860
|
var import_viem18 = require("viem");
|
|
4880
4861
|
var import_chains13 = require("viem/chains");
|
|
@@ -4950,8 +4931,8 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4950
4931
|
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
4951
4932
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
4952
4933
|
}
|
|
4953
|
-
const withdrawalAmountUsd = (0,
|
|
4954
|
-
(0,
|
|
4934
|
+
const withdrawalAmountUsd = (0, import_utils31.formatCurrency)(
|
|
4935
|
+
(0, import_utils31.formatEtherNum)(withdrawalAmount) * tokePrice
|
|
4955
4936
|
);
|
|
4956
4937
|
const lockDuration = Number(depositLockDuration);
|
|
4957
4938
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -4972,16 +4953,16 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4972
4953
|
const withdrawAvailable = lockRenew - 1;
|
|
4973
4954
|
const hasAddedLockedToke = depositAmount > 0n && depositAmount > rolloverDepositAmount;
|
|
4974
4955
|
const addedLockedToke = depositAmount - rolloverDepositAmount;
|
|
4975
|
-
const balanceUSD = (0,
|
|
4956
|
+
const balanceUSD = (0, import_utils31.formatCurrency)(
|
|
4976
4957
|
Number((0, import_viem18.formatEther)(balanceExcludingWithdrawal)) * tokePrice
|
|
4977
4958
|
);
|
|
4978
|
-
const balanceExcludingWithdrawalUsd = (0,
|
|
4979
|
-
(0,
|
|
4959
|
+
const balanceExcludingWithdrawalUsd = (0, import_utils31.formatCurrency)(
|
|
4960
|
+
(0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * tokePrice
|
|
4980
4961
|
);
|
|
4981
4962
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
4982
4963
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
4983
|
-
const unlockRequestPeriodStartUnix = (0,
|
|
4984
|
-
const unlockRequestPeriodEndUnix = (0,
|
|
4964
|
+
const unlockRequestPeriodStartUnix = (0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) - Date.now() / 1e3;
|
|
4965
|
+
const unlockRequestPeriodEndUnix = (0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) - Date.now() / 1e3;
|
|
4985
4966
|
const hasBalance = balance > 0n;
|
|
4986
4967
|
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
4987
4968
|
const hasUnlockableBalance = withdrawalMinCycle <= currentCycle && withdrawalAmount > 0n;
|
|
@@ -4991,8 +4972,8 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
4991
4972
|
lockDurationInMonths = lockDuration - 1;
|
|
4992
4973
|
}
|
|
4993
4974
|
const unlockPeriodDateRangeArray = [
|
|
4994
|
-
new Date((0,
|
|
4995
|
-
new Date((0,
|
|
4975
|
+
new Date((0, import_utils31.convertChainCycleToUnix)(withdrawAvailable, chainId) * 1e3),
|
|
4976
|
+
new Date((0, import_utils31.convertChainCycleToUnix)(lockRenew, chainId) * 1e3)
|
|
4996
4977
|
];
|
|
4997
4978
|
const {
|
|
4998
4979
|
unlockPeriodDateRange,
|
|
@@ -5004,18 +4985,18 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
5004
4985
|
unlockPeriodDateRangeArray,
|
|
5005
4986
|
chainId === import_chains13.sepolia.id ? "time" : "date"
|
|
5006
4987
|
);
|
|
5007
|
-
const totalActiveUserCredits = (0,
|
|
5008
|
-
const totalUserCredits = (0,
|
|
4988
|
+
const totalActiveUserCredits = (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
4989
|
+
const totalUserCredits = (0, import_utils31.formatEtherNum)(balance) * lockDurationInMonths;
|
|
5009
4990
|
return {
|
|
5010
4991
|
balance,
|
|
5011
4992
|
balanceUSD,
|
|
5012
4993
|
balanceExcludingWithdrawal: hasBalance ? (0, import_viem18.formatEther)(balanceExcludingWithdrawal) : "0.00",
|
|
5013
4994
|
balanceExcludingWithdrawalUsd,
|
|
5014
4995
|
hasBalanceExcludingWithdrawal,
|
|
5015
|
-
timeLeftBeforeUnlockRequestAvailable: (0,
|
|
4996
|
+
timeLeftBeforeUnlockRequestAvailable: (0, import_utils31.convertSecondsToRemainingTime)(
|
|
5016
4997
|
unlockRequestPeriodStartUnix
|
|
5017
4998
|
),
|
|
5018
|
-
timeLeftBeforeUnlockRequestUnavailable: (0,
|
|
4999
|
+
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils31.convertSecondsToRemainingTime)(
|
|
5019
5000
|
unlockRequestPeriodEndUnix
|
|
5020
5001
|
),
|
|
5021
5002
|
withdrawalAmount,
|
|
@@ -5032,7 +5013,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
5032
5013
|
unlockRenewalDate,
|
|
5033
5014
|
lockDurationInMonths,
|
|
5034
5015
|
boost: lockDuration,
|
|
5035
|
-
points: (0,
|
|
5016
|
+
points: (0, import_utils31.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
5036
5017
|
totalActiveCredits: totalActiveUserCredits,
|
|
5037
5018
|
totalCredits: totalUserCredits
|
|
5038
5019
|
};
|
|
@@ -5044,7 +5025,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
5044
5025
|
};
|
|
5045
5026
|
|
|
5046
5027
|
// functions/getUserSToke.ts
|
|
5047
|
-
var
|
|
5028
|
+
var import_utils33 = require("@tokemak/utils");
|
|
5048
5029
|
var getUserSToke = async (wagmiConfig, {
|
|
5049
5030
|
address,
|
|
5050
5031
|
tokePrice,
|
|
@@ -5071,8 +5052,8 @@ var getUserSToke = async (wagmiConfig, {
|
|
|
5071
5052
|
}
|
|
5072
5053
|
return acc;
|
|
5073
5054
|
}, 0n);
|
|
5074
|
-
const totalBalance = (0,
|
|
5075
|
-
const totalBalanceUsd = (0,
|
|
5055
|
+
const totalBalance = (0, import_utils33.formatEtherNum)(totalBalanceRaw || 0n);
|
|
5056
|
+
const totalBalanceUsd = (0, import_utils33.formatCurrency)(totalBalance * tokePrice);
|
|
5076
5057
|
const hasBalance = totalBalance > 0;
|
|
5077
5058
|
return {
|
|
5078
5059
|
chains: { ...userSToke },
|
|
@@ -5089,9 +5070,9 @@ var getUserSToke = async (wagmiConfig, {
|
|
|
5089
5070
|
var import_viem19 = require("viem");
|
|
5090
5071
|
var import_core22 = require("@wagmi/core");
|
|
5091
5072
|
var import_abis19 = require("@tokemak/abis");
|
|
5092
|
-
var
|
|
5073
|
+
var import_utils35 = require("@tokemak/utils");
|
|
5093
5074
|
var import_config14 = require("@tokemak/config");
|
|
5094
|
-
var
|
|
5075
|
+
var import_utils36 = require("@tokemak/utils");
|
|
5095
5076
|
var getChainSToke = async (wagmiConfig, {
|
|
5096
5077
|
tokePrice,
|
|
5097
5078
|
chainId
|
|
@@ -5117,15 +5098,15 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
5117
5098
|
]
|
|
5118
5099
|
});
|
|
5119
5100
|
const tvl = Number((0, import_viem19.formatEther)(totalSupply || 0n)) * tokePrice;
|
|
5120
|
-
const secondsLeftBeforeNextCycle = (0,
|
|
5101
|
+
const secondsLeftBeforeNextCycle = (0, import_utils35.convertChainCycleToUnix)(Number(currentCycle) + 1, chainId) - Date.now() / 1e3;
|
|
5121
5102
|
return {
|
|
5122
5103
|
rawTotalSupply: totalSupply,
|
|
5123
|
-
totalSupply: (0,
|
|
5124
|
-
tvl: (0,
|
|
5104
|
+
totalSupply: (0, import_utils35.formatLargeNumber)((0, import_viem19.formatEther)(totalSupply || 0n)),
|
|
5105
|
+
tvl: (0, import_utils35.formatTVL)(tvl),
|
|
5125
5106
|
rawTVL: tvl,
|
|
5126
5107
|
currentCycle,
|
|
5127
|
-
chain: (0,
|
|
5128
|
-
timeBeforeNextCycle: (0,
|
|
5108
|
+
chain: (0, import_utils36.getNetwork)(chainId),
|
|
5109
|
+
timeBeforeNextCycle: (0, import_utils35.convertSecondsToRemainingTime)(
|
|
5129
5110
|
secondsLeftBeforeNextCycle
|
|
5130
5111
|
)
|
|
5131
5112
|
};
|
|
@@ -5136,7 +5117,7 @@ var getChainSToke = async (wagmiConfig, {
|
|
|
5136
5117
|
};
|
|
5137
5118
|
|
|
5138
5119
|
// functions/getSToke.ts
|
|
5139
|
-
var
|
|
5120
|
+
var import_utils37 = require("@tokemak/utils");
|
|
5140
5121
|
var import_viem20 = require("viem");
|
|
5141
5122
|
var getSToke = async (wagmiConfig, {
|
|
5142
5123
|
tokePrice,
|
|
@@ -5156,14 +5137,14 @@ var getSToke = async (wagmiConfig, {
|
|
|
5156
5137
|
}
|
|
5157
5138
|
return acc;
|
|
5158
5139
|
}, 0n);
|
|
5159
|
-
const totalSupply = (0,
|
|
5140
|
+
const totalSupply = (0, import_utils37.formatLargeNumber)((0, import_viem20.formatEther)(totalSupplyBigInt || 0n));
|
|
5160
5141
|
let tvlNum = Object.values(sToke).reduce((acc, item) => {
|
|
5161
5142
|
if (item && item.rawTVL) {
|
|
5162
5143
|
return acc + item.rawTVL;
|
|
5163
5144
|
}
|
|
5164
5145
|
return acc;
|
|
5165
5146
|
}, 0);
|
|
5166
|
-
const tvl = (0,
|
|
5147
|
+
const tvl = (0, import_utils37.formatTVL)(tvlNum);
|
|
5167
5148
|
return { totalSupply, rawTotalSupply: totalSupplyBigInt, tvl, rawTVL: tvlNum, chains: { ...sToke } };
|
|
5168
5149
|
} catch (e) {
|
|
5169
5150
|
console.error(e);
|
|
@@ -5217,7 +5198,7 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
5217
5198
|
// functions/getChainSTokeRewards.ts
|
|
5218
5199
|
var import_config15 = require("@tokemak/config");
|
|
5219
5200
|
var import_viem21 = require("viem");
|
|
5220
|
-
var
|
|
5201
|
+
var import_utils39 = require("@tokemak/utils");
|
|
5221
5202
|
var import_graph_cli15 = require("@tokemak/graph-cli");
|
|
5222
5203
|
var getChainSTokeRewards = async ({
|
|
5223
5204
|
chainId
|
|
@@ -5241,9 +5222,9 @@ var getChainSTokeRewards = async ({
|
|
|
5241
5222
|
if (!whitelistedPools.includes(pool.id.toLowerCase())) {
|
|
5242
5223
|
continue;
|
|
5243
5224
|
}
|
|
5244
|
-
const convertedBalance = (0,
|
|
5225
|
+
const convertedBalance = (0, import_utils39.formatEtherNum)(pool.balance);
|
|
5245
5226
|
const convertedBalanceUSD = Number((0, import_viem21.formatUnits)(pool.balanceUSD, 8));
|
|
5246
|
-
const convertedApr = (0,
|
|
5227
|
+
const convertedApr = (0, import_utils39.formatEtherNum)(pool.currentAprPerCredit);
|
|
5247
5228
|
if (minApr === null || convertedApr < minApr) {
|
|
5248
5229
|
minApr = convertedApr;
|
|
5249
5230
|
}
|
|
@@ -5317,7 +5298,7 @@ var getSTokeRewards = async ({
|
|
|
5317
5298
|
|
|
5318
5299
|
// functions/getChainUserSTokeRewards.ts
|
|
5319
5300
|
var import_config16 = require("@tokemak/config");
|
|
5320
|
-
var
|
|
5301
|
+
var import_utils42 = require("@tokemak/utils");
|
|
5321
5302
|
var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
5322
5303
|
address,
|
|
5323
5304
|
chainId,
|
|
@@ -5368,14 +5349,14 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5368
5349
|
throw fallbackError;
|
|
5369
5350
|
}
|
|
5370
5351
|
}
|
|
5371
|
-
const claimableNum = (0,
|
|
5352
|
+
const claimableNum = (0, import_utils42.formatEtherNum)(tokeRewards?.claimable || 0n);
|
|
5372
5353
|
const claimableUsd = tokePrice * claimableNum;
|
|
5373
5354
|
const hasClaimable = claimableNum > 0n;
|
|
5374
|
-
const pendingRewards = (0,
|
|
5355
|
+
const pendingRewards = (0, import_utils42.formatEtherNum)(
|
|
5375
5356
|
tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
5376
5357
|
);
|
|
5377
5358
|
const pendingRewardsUsd = tokePrice * pendingRewards;
|
|
5378
|
-
const totalRewardsReceived = (0,
|
|
5359
|
+
const totalRewardsReceived = (0, import_utils42.formatEtherNum)(
|
|
5379
5360
|
tokeRewards.rewardsPayload.payload.amount || 0n
|
|
5380
5361
|
);
|
|
5381
5362
|
const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
|
|
@@ -5394,26 +5375,7 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
5394
5375
|
// functions/getTokenPrices.ts
|
|
5395
5376
|
var import_tokenlist12 = require("@tokemak/tokenlist");
|
|
5396
5377
|
var import_constants18 = require("@tokemak/constants");
|
|
5397
|
-
|
|
5398
|
-
// functions/getBackupTokenPrices.ts
|
|
5399
|
-
var getBackupTokenPrices = async () => {
|
|
5400
|
-
try {
|
|
5401
|
-
const backupData = await getBlobData(`getTokenPrices-latest-success.json`);
|
|
5402
|
-
if (backupData) {
|
|
5403
|
-
return backupData;
|
|
5404
|
-
}
|
|
5405
|
-
} catch (e) {
|
|
5406
|
-
console.error(e);
|
|
5407
|
-
return void 0;
|
|
5408
|
-
}
|
|
5409
|
-
return void 0;
|
|
5410
|
-
};
|
|
5411
|
-
|
|
5412
|
-
// functions/getTokenPrices.ts
|
|
5413
|
-
var isStale = (timestamp) => {
|
|
5414
|
-
return timestamp - Math.floor(Date.now() / 1e3) > 5 * 60;
|
|
5415
|
-
};
|
|
5416
|
-
var getTokenPrices = async (isCronJob = false) => {
|
|
5378
|
+
var getTokenPrices = async () => {
|
|
5417
5379
|
try {
|
|
5418
5380
|
const body = {
|
|
5419
5381
|
tokens: import_tokenlist12.PRICED_TOKENS.map((asset) => ({
|
|
@@ -5451,27 +5413,12 @@ var getTokenPrices = async (isCronJob = false) => {
|
|
|
5451
5413
|
}
|
|
5452
5414
|
};
|
|
5453
5415
|
} catch (e) {
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
} else {
|
|
5461
|
-
const backupPrices = await getBackupTokenPrices();
|
|
5462
|
-
if (backupPrices) {
|
|
5463
|
-
return {
|
|
5464
|
-
prices: backupPrices.prices,
|
|
5465
|
-
timestamp: backupPrices.timestamp,
|
|
5466
|
-
isStale: isStale(backupPrices.timestamp)
|
|
5467
|
-
};
|
|
5468
|
-
}
|
|
5469
|
-
return {
|
|
5470
|
-
prices: void 0,
|
|
5471
|
-
timestamp: void 0,
|
|
5472
|
-
isStale: false
|
|
5473
|
-
};
|
|
5474
|
-
}
|
|
5416
|
+
console.error("getTokenPrices failed:", e);
|
|
5417
|
+
return {
|
|
5418
|
+
prices: void 0,
|
|
5419
|
+
timestamp: void 0,
|
|
5420
|
+
isStale: false
|
|
5421
|
+
};
|
|
5475
5422
|
}
|
|
5476
5423
|
};
|
|
5477
5424
|
|
|
@@ -5535,7 +5482,7 @@ var getSubgraphStatus = async (includeTestnet = false) => {
|
|
|
5535
5482
|
var import_core24 = require("@wagmi/core");
|
|
5536
5483
|
var import_abis21 = require("@tokemak/abis");
|
|
5537
5484
|
var import_viem22 = require("viem");
|
|
5538
|
-
var
|
|
5485
|
+
var import_utils44 = require("@tokemak/utils");
|
|
5539
5486
|
var import_config17 = require("@tokemak/config");
|
|
5540
5487
|
var import_chains14 = require("viem/chains");
|
|
5541
5488
|
var publicClient = (0, import_viem22.createPublicClient)({
|
|
@@ -5569,11 +5516,11 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5569
5516
|
});
|
|
5570
5517
|
const rolloverEvents = await publicClient.getFilterLogs({ filter });
|
|
5571
5518
|
const cycleRolloverBlockNumber = chainId === 1 ? rolloverEvents[rolloverEvents.length - 1]?.blockNumber : rolloverEvents[rolloverEvents.length - 1]?.blockNumber || currentBlockNumber;
|
|
5572
|
-
const secondsLeftBeforeNextCycle = (0,
|
|
5519
|
+
const secondsLeftBeforeNextCycle = (0, import_utils44.convertChainCycleToUnix)(Number(currentCycleIndex) + 1) - Date.now() / 1e3;
|
|
5573
5520
|
return {
|
|
5574
5521
|
currentCycleIndex,
|
|
5575
5522
|
cycleRolloverBlockNumber,
|
|
5576
|
-
timeBeforeNextCycle: (0,
|
|
5523
|
+
timeBeforeNextCycle: (0, import_utils44.convertSecondsToRemainingTime)(
|
|
5577
5524
|
secondsLeftBeforeNextCycle
|
|
5578
5525
|
)
|
|
5579
5526
|
};
|
|
@@ -5584,7 +5531,7 @@ var getCycleV1 = async (wagmiConfig, {
|
|
|
5584
5531
|
};
|
|
5585
5532
|
|
|
5586
5533
|
// functions/getProtocolStats.ts
|
|
5587
|
-
var
|
|
5534
|
+
var import_utils45 = require("@tokemak/utils");
|
|
5588
5535
|
var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
5589
5536
|
try {
|
|
5590
5537
|
if (!autopools || !stoke || !sushiLP) {
|
|
@@ -5614,12 +5561,12 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
|
5614
5561
|
Object.entries(categories).map(([key, value]) => [
|
|
5615
5562
|
key,
|
|
5616
5563
|
{
|
|
5617
|
-
tvl: (0,
|
|
5618
|
-
supply: (0,
|
|
5564
|
+
tvl: (0, import_utils45.formatTVL)(value.tvl),
|
|
5565
|
+
supply: (0, import_utils45.formatLargeNumber)(value.supply || 0)
|
|
5619
5566
|
}
|
|
5620
5567
|
])
|
|
5621
5568
|
);
|
|
5622
|
-
const tvl = (0,
|
|
5569
|
+
const tvl = (0, import_utils45.formatTVL)(
|
|
5623
5570
|
autopoolTVL + stoke.rawTVL + (sushiLP?.tvl || 0) + (EthAutoLP?.tvlUsd || 0) + (sauto?.rawTVL || 0)
|
|
5624
5571
|
);
|
|
5625
5572
|
const vaultAddresses = autopools?.flatMap(
|
|
@@ -5628,33 +5575,33 @@ var getProtocolStats = async (autopools, stoke, sushiLP, sauto, EthAutoLP) => {
|
|
|
5628
5575
|
const uniqueVaultAddresses = [...new Set(vaultAddresses)];
|
|
5629
5576
|
const totalDestinations = uniqueVaultAddresses.length;
|
|
5630
5577
|
const stakedTVL = {
|
|
5631
|
-
totalSupply: (0,
|
|
5632
|
-
(0,
|
|
5578
|
+
totalSupply: (0, import_utils45.formatLargeNumber)(
|
|
5579
|
+
(0, import_utils45.formatEtherNum)(
|
|
5633
5580
|
(sauto?.rawTotalSupply || 0n) + (stoke.rawTotalSupply || 0n)
|
|
5634
5581
|
)
|
|
5635
5582
|
),
|
|
5636
|
-
tvl: (0,
|
|
5583
|
+
tvl: (0, import_utils45.formatTVL)((sauto?.rawTVL || 0) + stoke.rawTVL)
|
|
5637
5584
|
};
|
|
5638
5585
|
return {
|
|
5639
5586
|
autopools: {
|
|
5640
|
-
tvl: (0,
|
|
5587
|
+
tvl: (0, import_utils45.formatTVL)(autopoolTVL),
|
|
5641
5588
|
tvlNum: autopoolTVL,
|
|
5642
5589
|
categories: formattedCategories
|
|
5643
5590
|
},
|
|
5644
5591
|
stoke: {
|
|
5645
|
-
tvl: (0,
|
|
5592
|
+
tvl: (0, import_utils45.formatTVL)(stoke.rawTVL),
|
|
5646
5593
|
tvlNum: stoke.rawTVL,
|
|
5647
5594
|
totalSupply: `${stoke.totalSupply} TOKE`
|
|
5648
5595
|
},
|
|
5649
5596
|
sushiLP: {
|
|
5650
|
-
tvl: (0,
|
|
5597
|
+
tvl: (0, import_utils45.formatTVL)(sushiLP?.tvl || 0),
|
|
5651
5598
|
totalSupply: sushiLP?.totalSupply || 0
|
|
5652
5599
|
},
|
|
5653
5600
|
EthAutoLP: {
|
|
5654
|
-
tvl: (0,
|
|
5601
|
+
tvl: (0, import_utils45.formatTVL)(EthAutoLP?.tvlUsd || 0)
|
|
5655
5602
|
},
|
|
5656
5603
|
sauto: {
|
|
5657
|
-
tvl: (0,
|
|
5604
|
+
tvl: (0, import_utils45.formatTVL)(sauto?.rawTVL || 0),
|
|
5658
5605
|
tvlNum: sauto?.rawTVL || 0,
|
|
5659
5606
|
totalSupply: `${sauto?.totalSupply} AUTO`
|
|
5660
5607
|
},
|
|
@@ -5673,27 +5620,26 @@ var import_graph_cli17 = require("@tokemak/graph-cli");
|
|
|
5673
5620
|
|
|
5674
5621
|
// functions/getEthPriceAtBlock.ts
|
|
5675
5622
|
var import_config18 = require("@tokemak/config");
|
|
5676
|
-
var import_core25 = require("@wagmi/core");
|
|
5677
5623
|
var import_abis22 = require("@tokemak/abis");
|
|
5678
5624
|
var import_tokenlist13 = require("@tokemak/tokenlist");
|
|
5679
|
-
var getEthPriceAtBlock = async (
|
|
5625
|
+
var getEthPriceAtBlock = async (client, blockNumber, chainId, account) => {
|
|
5680
5626
|
const config = (0, import_config18.getCoreConfig)(chainId);
|
|
5681
5627
|
const rootPriceOracle = config.rootPriceOracle;
|
|
5682
5628
|
const weth = config.weth;
|
|
5683
5629
|
const usdc = import_tokenlist13.USDC_TOKEN.extensions?.bridgeInfo?.[chainId]?.tokenAddress || import_tokenlist13.USDC_TOKEN.address;
|
|
5684
|
-
const priceAtBlock = await
|
|
5630
|
+
const priceAtBlock = await client.readContract({
|
|
5685
5631
|
address: rootPriceOracle,
|
|
5686
5632
|
abi: import_abis22.rootPriceOracleAbi,
|
|
5687
5633
|
functionName: "getPriceInQuote",
|
|
5688
5634
|
args: [weth, usdc],
|
|
5689
5635
|
blockNumber,
|
|
5690
|
-
|
|
5636
|
+
account
|
|
5691
5637
|
});
|
|
5692
5638
|
return priceAtBlock;
|
|
5693
5639
|
};
|
|
5694
5640
|
|
|
5695
5641
|
// functions/getRebalanceStats.ts
|
|
5696
|
-
var
|
|
5642
|
+
var import_utils47 = require("@tokemak/utils");
|
|
5697
5643
|
var import_tokenlist14 = require("@tokemak/tokenlist");
|
|
5698
5644
|
var import_chains15 = require("viem/chains");
|
|
5699
5645
|
var BATCH_SIZE = 500;
|
|
@@ -5717,17 +5663,18 @@ function inferBaseAssetDecimals(rebalance, chainId) {
|
|
|
5717
5663
|
}
|
|
5718
5664
|
return import_tokenlist14.USDC_TOKEN.decimals;
|
|
5719
5665
|
}
|
|
5720
|
-
var getRebalanceValueUsd = async (rebalance, chainId,
|
|
5666
|
+
var getRebalanceValueUsd = async (rebalance, chainId, client, account) => {
|
|
5721
5667
|
const ethWei = BigInt(rebalance.tokenOutValueInEth || "0");
|
|
5722
5668
|
if (ethWei === 0n) return null;
|
|
5723
5669
|
try {
|
|
5724
5670
|
const price = await getEthPriceAtBlock(
|
|
5725
|
-
|
|
5671
|
+
client,
|
|
5726
5672
|
BigInt(rebalance.blockNumber),
|
|
5727
|
-
chainId
|
|
5673
|
+
chainId,
|
|
5674
|
+
account
|
|
5728
5675
|
);
|
|
5729
|
-
const ethUsd = Number((0,
|
|
5730
|
-
const ethAmt = Number((0,
|
|
5676
|
+
const ethUsd = Number((0, import_utils47.formatUnitsNum)(price, import_tokenlist14.USDC_TOKEN.decimals));
|
|
5677
|
+
const ethAmt = Number((0, import_utils47.formatEtherNum)(ethWei));
|
|
5731
5678
|
const usd = ethAmt * ethUsd;
|
|
5732
5679
|
return usd;
|
|
5733
5680
|
} catch (e) {
|
|
@@ -5735,10 +5682,10 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5735
5682
|
return null;
|
|
5736
5683
|
}
|
|
5737
5684
|
};
|
|
5738
|
-
var processRebalance = async (rebalance, chainId,
|
|
5685
|
+
var processRebalance = async (rebalance, chainId, client, account) => {
|
|
5739
5686
|
const baseDecimals = inferBaseAssetDecimals(rebalance, chainId);
|
|
5740
5687
|
const baseAssetAmount = Number(
|
|
5741
|
-
(0,
|
|
5688
|
+
(0, import_utils47.formatUnitsNum)(
|
|
5742
5689
|
BigInt(rebalance.tokenOutValueBaseAsset || "0"),
|
|
5743
5690
|
baseDecimals
|
|
5744
5691
|
)
|
|
@@ -5746,7 +5693,8 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5746
5693
|
const ethPathUsd = await getRebalanceValueUsd(
|
|
5747
5694
|
rebalance,
|
|
5748
5695
|
chainId,
|
|
5749
|
-
|
|
5696
|
+
client,
|
|
5697
|
+
account
|
|
5750
5698
|
);
|
|
5751
5699
|
if (ethPathUsd != null) {
|
|
5752
5700
|
return {
|
|
@@ -5767,12 +5715,12 @@ var processRebalance = async (rebalance, chainId, wagmiConfig) => {
|
|
|
5767
5715
|
valueInAsset: baseAssetAmount
|
|
5768
5716
|
};
|
|
5769
5717
|
};
|
|
5770
|
-
var processRebalancesInBatches = async (rebalances, chainId,
|
|
5718
|
+
var processRebalancesInBatches = async (rebalances, chainId, client, account) => {
|
|
5771
5719
|
const processedRebalances = [];
|
|
5772
5720
|
for (let i = 0; i < rebalances.length; i += BATCH_SIZE) {
|
|
5773
5721
|
const batch = rebalances.slice(i, i + BATCH_SIZE);
|
|
5774
5722
|
const batchPromises = batch.map(
|
|
5775
|
-
async (rebalance) => processRebalance(rebalance, chainId,
|
|
5723
|
+
async (rebalance) => processRebalance(rebalance, chainId, client, account)
|
|
5776
5724
|
);
|
|
5777
5725
|
const batchResults = await Promise.all(batchPromises);
|
|
5778
5726
|
processedRebalances.push(...batchResults);
|
|
@@ -5797,17 +5745,20 @@ var calculateRebalanceStats = (rebalances) => {
|
|
|
5797
5745
|
rebalances
|
|
5798
5746
|
};
|
|
5799
5747
|
};
|
|
5800
|
-
var getRebalanceStats = async (
|
|
5801
|
-
includeTestnet = false
|
|
5748
|
+
var getRebalanceStats = async (getClient, {
|
|
5749
|
+
includeTestnet = false,
|
|
5750
|
+
account
|
|
5802
5751
|
}) => {
|
|
5803
5752
|
const chains = getChainsForEnv({ includeTestnet });
|
|
5804
5753
|
const rebalances = await Promise.all(
|
|
5805
5754
|
chains.map(async (chain) => {
|
|
5806
5755
|
const rawRebalances = await fetchChainRebalances(chain.chainId);
|
|
5756
|
+
const client = getClient(chain.chainId);
|
|
5807
5757
|
return processRebalancesInBatches(
|
|
5808
5758
|
rawRebalances,
|
|
5809
5759
|
chain.chainId,
|
|
5810
|
-
|
|
5760
|
+
client,
|
|
5761
|
+
account
|
|
5811
5762
|
);
|
|
5812
5763
|
})
|
|
5813
5764
|
);
|
|
@@ -5816,6 +5767,7 @@ var getRebalanceStats = async (wagmiConfig, {
|
|
|
5816
5767
|
};
|
|
5817
5768
|
|
|
5818
5769
|
// functions/updateRebalanceStats.ts
|
|
5770
|
+
var import_core25 = require("@wagmi/core");
|
|
5819
5771
|
var updateRebalanceStats = async (wagmiConfig, {
|
|
5820
5772
|
currentRebalances,
|
|
5821
5773
|
includeTestnet = false
|
|
@@ -5830,10 +5782,13 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5830
5782
|
)
|
|
5831
5783
|
);
|
|
5832
5784
|
if (newRawRebalances.length > 0) {
|
|
5785
|
+
const client = (0, import_core25.getPublicClient)(wagmiConfig, {
|
|
5786
|
+
chainId: chain.chainId
|
|
5787
|
+
});
|
|
5833
5788
|
return processRebalancesInBatches(
|
|
5834
5789
|
newRawRebalances,
|
|
5835
5790
|
chain.chainId,
|
|
5836
|
-
|
|
5791
|
+
client
|
|
5837
5792
|
);
|
|
5838
5793
|
}
|
|
5839
5794
|
return [];
|
|
@@ -5847,7 +5802,7 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
5847
5802
|
// functions/getUserSAuto.ts
|
|
5848
5803
|
var import_abis23 = require("@tokemak/abis");
|
|
5849
5804
|
var import_config19 = require("@tokemak/config");
|
|
5850
|
-
var
|
|
5805
|
+
var import_utils49 = require("@tokemak/utils");
|
|
5851
5806
|
var import_core26 = require("@wagmi/core");
|
|
5852
5807
|
var import_viem23 = require("viem");
|
|
5853
5808
|
var import_chains16 = require("viem/chains");
|
|
@@ -5909,8 +5864,8 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5909
5864
|
if (withdrawalAmount > 0n && cycleIndex >= withdrawalMinCycle) {
|
|
5910
5865
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
5911
5866
|
}
|
|
5912
|
-
const withdrawalAmountUsd = (0,
|
|
5913
|
-
(0,
|
|
5867
|
+
const withdrawalAmountUsd = (0, import_utils49.formatCurrency)(
|
|
5868
|
+
(0, import_utils49.formatEtherNum)(withdrawalAmount) * autoPrice
|
|
5914
5869
|
);
|
|
5915
5870
|
const lockDuration = Number(depositLockDuration);
|
|
5916
5871
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -5920,24 +5875,24 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5920
5875
|
const nextCycleRenewIncrement = Math.ceil((currentCycle - lockStart) / lockDuration) * lockDuration;
|
|
5921
5876
|
const lockRenew = currentCycle - lockStart > lockDuration ? currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : lockStart + nextCycleRenewIncrement : currentCycle === lockStart + nextCycleRenewIncrement ? lockStart + nextCycleRenewIncrement + lockDuration : firstLockEnd;
|
|
5922
5877
|
const withdrawAvailable = lockRenew - 1;
|
|
5923
|
-
const balanceUSD = (0,
|
|
5878
|
+
const balanceUSD = (0, import_utils49.formatCurrency)(
|
|
5924
5879
|
Number((0, import_viem23.formatEther)(balanceExcludingWithdrawal)) * autoPrice
|
|
5925
5880
|
);
|
|
5926
|
-
const balanceExcludingWithdrawalUsd = (0,
|
|
5927
|
-
(0,
|
|
5881
|
+
const balanceExcludingWithdrawalUsd = (0, import_utils49.formatCurrency)(
|
|
5882
|
+
(0, import_utils49.formatEtherNum)(balanceExcludingWithdrawal) * autoPrice
|
|
5928
5883
|
);
|
|
5929
5884
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
5930
5885
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
5931
|
-
const unlockRequestPeriodStartUnix = (0,
|
|
5932
|
-
const unlockRequestPeriodEndUnix = (0,
|
|
5886
|
+
const unlockRequestPeriodStartUnix = (0, import_utils49.convertAutoCycleToUnix)(withdrawAvailable) - Date.now() / 1e3;
|
|
5887
|
+
const unlockRequestPeriodEndUnix = (0, import_utils49.convertAutoCycleToUnix)(lockRenew) - Date.now() / 1e3;
|
|
5933
5888
|
const hasBalance = balance > 0n;
|
|
5934
5889
|
const hasBalanceExcludingWithdrawal = balanceExcludingWithdrawal > 0n;
|
|
5935
5890
|
const hasUnlockableBalance = withdrawalMinCycle <= BigInt(currentCycle) && withdrawalAmount > 0n;
|
|
5936
5891
|
const cyclesInAMonth = 4;
|
|
5937
5892
|
const lockDurationInMonths = lockDuration / cyclesInAMonth;
|
|
5938
5893
|
const unlockPeriodDateRangeArray = [
|
|
5939
|
-
new Date((0,
|
|
5940
|
-
new Date((0,
|
|
5894
|
+
new Date((0, import_utils49.convertAutoCycleToUnix)(withdrawAvailable) * 1e3),
|
|
5895
|
+
new Date((0, import_utils49.convertAutoCycleToUnix)(lockRenew) * 1e3)
|
|
5941
5896
|
];
|
|
5942
5897
|
const {
|
|
5943
5898
|
unlockPeriodDateRange,
|
|
@@ -5946,20 +5901,20 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5946
5901
|
unlockPeriodStartDate,
|
|
5947
5902
|
unlockRenewalDate
|
|
5948
5903
|
} = formatDateRange(unlockPeriodDateRangeArray, "date");
|
|
5949
|
-
const totalActiveUserCredits = (0,
|
|
5950
|
-
const totalUserCredits = (0,
|
|
5904
|
+
const totalActiveUserCredits = (0, import_utils49.formatEtherNum)(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
5905
|
+
const totalUserCredits = (0, import_utils49.formatEtherNum)(balance) * lockDurationInMonths;
|
|
5951
5906
|
const hasAddedLockedAuto = depositAmount > 0n;
|
|
5952
5907
|
const addedLockedAuto = depositAmount;
|
|
5953
5908
|
return {
|
|
5954
5909
|
balance,
|
|
5955
5910
|
balanceUSD,
|
|
5956
|
-
balanceExcludingWithdrawal: hasBalance ? (0,
|
|
5911
|
+
balanceExcludingWithdrawal: hasBalance ? (0, import_viem23.formatEther)(balanceExcludingWithdrawal) : "0.00",
|
|
5957
5912
|
balanceExcludingWithdrawalUsd,
|
|
5958
5913
|
hasBalanceExcludingWithdrawal,
|
|
5959
|
-
timeLeftBeforeUnlockRequestAvailable: (0,
|
|
5914
|
+
timeLeftBeforeUnlockRequestAvailable: (0, import_utils49.convertSecondsToRemainingTime)(
|
|
5960
5915
|
unlockRequestPeriodStartUnix
|
|
5961
5916
|
),
|
|
5962
|
-
timeLeftBeforeUnlockRequestUnavailable: (0,
|
|
5917
|
+
timeLeftBeforeUnlockRequestUnavailable: (0, import_utils49.convertSecondsToRemainingTime)(
|
|
5963
5918
|
unlockRequestPeriodEndUnix
|
|
5964
5919
|
),
|
|
5965
5920
|
withdrawalAmount,
|
|
@@ -5976,7 +5931,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5976
5931
|
unlockRenewalDate,
|
|
5977
5932
|
lockDurationInMonths,
|
|
5978
5933
|
boost: lockDuration,
|
|
5979
|
-
points: (0,
|
|
5934
|
+
points: (0, import_utils49.formatEtherNum)(balanceExcludingWithdrawal) * lockDuration,
|
|
5980
5935
|
totalActiveCredits: totalActiveUserCredits,
|
|
5981
5936
|
totalCredits: totalUserCredits,
|
|
5982
5937
|
hasBalance
|
|
@@ -5991,7 +5946,7 @@ var getUserSAuto = async (wagmiConfig, {
|
|
|
5991
5946
|
var import_viem24 = require("viem");
|
|
5992
5947
|
var import_core27 = require("@wagmi/core");
|
|
5993
5948
|
var import_abis24 = require("@tokemak/abis");
|
|
5994
|
-
var
|
|
5949
|
+
var import_utils51 = require("@tokemak/utils");
|
|
5995
5950
|
var import_config20 = require("@tokemak/config");
|
|
5996
5951
|
var import_chains17 = require("viem/chains");
|
|
5997
5952
|
var getSAuto = async (wagmiConfig, {
|
|
@@ -6019,14 +5974,14 @@ var getSAuto = async (wagmiConfig, {
|
|
|
6019
5974
|
]
|
|
6020
5975
|
});
|
|
6021
5976
|
const tvl = Number((0, import_viem24.formatEther)(totalSupply || 0n)) * autoPrice;
|
|
6022
|
-
const secondsLeftBeforeNextCycle = (0,
|
|
5977
|
+
const secondsLeftBeforeNextCycle = (0, import_utils51.convertAutoCycleToUnix)(Number(currentCycle) + 1) - Date.now() / 1e3;
|
|
6023
5978
|
return {
|
|
6024
5979
|
rawTotalSupply: totalSupply,
|
|
6025
|
-
totalSupply: (0,
|
|
6026
|
-
tvl: (0,
|
|
5980
|
+
totalSupply: (0, import_utils51.formatLargeNumber)((0, import_viem24.formatEther)(totalSupply || 0n)),
|
|
5981
|
+
tvl: (0, import_utils51.formatTVL)(tvl),
|
|
6027
5982
|
rawTVL: tvl,
|
|
6028
5983
|
currentCycle,
|
|
6029
|
-
timeBeforeNextCycle: (0,
|
|
5984
|
+
timeBeforeNextCycle: (0, import_utils51.convertSecondsToRemainingTime)(
|
|
6030
5985
|
secondsLeftBeforeNextCycle
|
|
6031
5986
|
)
|
|
6032
5987
|
};
|
|
@@ -6038,7 +5993,7 @@ var getSAuto = async (wagmiConfig, {
|
|
|
6038
5993
|
|
|
6039
5994
|
// functions/getSAutoRewards.ts
|
|
6040
5995
|
var import_viem25 = require("viem");
|
|
6041
|
-
var
|
|
5996
|
+
var import_utils52 = require("@tokemak/utils");
|
|
6042
5997
|
var import_graph_cli18 = require("@tokemak/graph-cli");
|
|
6043
5998
|
var import_chains18 = require("viem/chains");
|
|
6044
5999
|
var getSAutoRewards = async () => {
|
|
@@ -6050,7 +6005,7 @@ var getSAutoRewards = async () => {
|
|
|
6050
6005
|
"globalRewardsBalanceDayDatas"
|
|
6051
6006
|
);
|
|
6052
6007
|
const totalEarnings = globalRewardsBalances.reduce((acc, balance) => {
|
|
6053
|
-
return acc + (0,
|
|
6008
|
+
return acc + (0, import_utils52.formatEtherNum)(balance.balance);
|
|
6054
6009
|
}, 0);
|
|
6055
6010
|
const totalEarningsUsd = globalRewardsBalances.reduce((acc, balance) => {
|
|
6056
6011
|
return acc + Number((0, import_viem25.formatUnits)(balance.balanceUSD, 8));
|
|
@@ -6058,13 +6013,13 @@ var getSAutoRewards = async () => {
|
|
|
6058
6013
|
const historicalRewards = allGlobalRewardsBalanceDayDatas.map(
|
|
6059
6014
|
(dayData) => ({
|
|
6060
6015
|
timestamp: String(dayData.timestamp),
|
|
6061
|
-
balance: (0,
|
|
6016
|
+
balance: (0, import_utils52.formatEtherNum)(dayData.balance),
|
|
6062
6017
|
balanceUSD: Number((0, import_viem25.formatUnits)(dayData.balanceUSD, 8)),
|
|
6063
|
-
earned: (0,
|
|
6018
|
+
earned: (0, import_utils52.formatEtherNum)(dayData.earned),
|
|
6064
6019
|
earnedUSD: Number((0, import_viem25.formatUnits)(dayData.earnedUSD, 8)),
|
|
6065
|
-
dayAprPerCredit: (0,
|
|
6066
|
-
formattedDate: (0,
|
|
6067
|
-
(0,
|
|
6020
|
+
dayAprPerCredit: (0, import_utils52.formatEtherNum)(dayData.dayAprPerCredit),
|
|
6021
|
+
formattedDate: (0, import_utils52.formatDateToReadable)(
|
|
6022
|
+
(0, import_utils52.convertTimestampToDate)(Number(dayData.timestamp))
|
|
6068
6023
|
)
|
|
6069
6024
|
})
|
|
6070
6025
|
);
|
|
@@ -6081,7 +6036,7 @@ var getSAutoRewards = async () => {
|
|
|
6081
6036
|
|
|
6082
6037
|
// functions/getUserSAutoRewards.ts
|
|
6083
6038
|
var import_config21 = require("@tokemak/config");
|
|
6084
|
-
var
|
|
6039
|
+
var import_utils54 = require("@tokemak/utils");
|
|
6085
6040
|
var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
6086
6041
|
const { rewardsV1Url, sAutoRewardsHash, sAutoRewards, sAuto } = (0, import_config21.getMainnetConfig)();
|
|
6087
6042
|
const currentCycle = await getCurrentCycleId(wagmiConfig, {
|
|
@@ -6127,19 +6082,19 @@ var getUserSAutoRewards = async (wagmiConfig, { address, autoPrice }) => {
|
|
|
6127
6082
|
return null;
|
|
6128
6083
|
}
|
|
6129
6084
|
}
|
|
6130
|
-
const claimableNum = (0,
|
|
6085
|
+
const claimableNum = (0, import_utils54.formatEtherNum)(autoRewards?.claimable || 0n);
|
|
6131
6086
|
const claimableUsd = autoPrice * claimableNum;
|
|
6132
6087
|
const hasClaimable = claimableNum > 0;
|
|
6133
|
-
let pendingRewards = (0,
|
|
6088
|
+
let pendingRewards = (0, import_utils54.formatEtherNum)(
|
|
6134
6089
|
autoRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
6135
6090
|
);
|
|
6136
6091
|
if (currentCycle === 4242n) {
|
|
6137
|
-
pendingRewards = (0,
|
|
6092
|
+
pendingRewards = (0, import_utils54.formatEtherNum)(
|
|
6138
6093
|
autoRewards?.rewardsPayload.payload.amount || 0n
|
|
6139
6094
|
);
|
|
6140
6095
|
}
|
|
6141
6096
|
const pendingRewardsUsd = autoPrice * pendingRewards;
|
|
6142
|
-
const totalRewardsReceived = (0,
|
|
6097
|
+
const totalRewardsReceived = (0, import_utils54.formatEtherNum)(
|
|
6143
6098
|
autoRewards.rewardsPayload.payload.amount || 0n
|
|
6144
6099
|
);
|
|
6145
6100
|
const totalRewardsReceivedUsd = autoPrice * totalRewardsReceived;
|
|
@@ -6174,7 +6129,7 @@ var getUserMerklRewards = async (address) => {
|
|
|
6174
6129
|
|
|
6175
6130
|
// functions/getUserEthAutoLPRewards.ts
|
|
6176
6131
|
var import_viem26 = require("viem");
|
|
6177
|
-
var
|
|
6132
|
+
var import_utils55 = require("@tokemak/utils");
|
|
6178
6133
|
var import_tokenlist15 = require("@tokemak/tokenlist");
|
|
6179
6134
|
var getUserEthAutoLPRewards = async (address) => {
|
|
6180
6135
|
const rewards = await getUserMerklRewards(address);
|
|
@@ -6185,8 +6140,8 @@ var getUserEthAutoLPRewards = async (address) => {
|
|
|
6185
6140
|
const amount = autoRewards?.amount;
|
|
6186
6141
|
const claimed = autoRewards?.claimed;
|
|
6187
6142
|
const claimable = Number(amount) - Number(claimed);
|
|
6188
|
-
const formattedClaimable = (0,
|
|
6189
|
-
(0,
|
|
6143
|
+
const formattedClaimable = (0, import_utils55.formatAmount)(
|
|
6144
|
+
(0, import_utils55.formatUnitsNum)(BigInt(claimable || 0), 18)
|
|
6190
6145
|
);
|
|
6191
6146
|
const users = [];
|
|
6192
6147
|
const tokens = [];
|
|
@@ -6240,7 +6195,7 @@ async function getMerklPoolApr({
|
|
|
6240
6195
|
// functions/getSAutoApr.ts
|
|
6241
6196
|
var import_graph_cli19 = require("@tokemak/graph-cli");
|
|
6242
6197
|
var import_chains19 = require("viem/chains");
|
|
6243
|
-
var
|
|
6198
|
+
var import_utils56 = require("@tokemak/utils");
|
|
6244
6199
|
var getSAutoApr = async () => {
|
|
6245
6200
|
try {
|
|
6246
6201
|
const { GetSAutoApr } = (0, import_graph_cli19.getSdkByChainId)(import_chains19.mainnet.id);
|
|
@@ -6259,12 +6214,12 @@ var getSAutoApr = async () => {
|
|
|
6259
6214
|
aprFormatted: void 0
|
|
6260
6215
|
};
|
|
6261
6216
|
}
|
|
6262
|
-
const aprPerCredit = (0,
|
|
6217
|
+
const aprPerCredit = (0, import_utils56.formatEtherNum)(rawApr);
|
|
6263
6218
|
const lockDuration = 16;
|
|
6264
6219
|
const apr = aprPerCredit * lockDuration;
|
|
6265
6220
|
return {
|
|
6266
6221
|
apr,
|
|
6267
|
-
aprFormatted: (0,
|
|
6222
|
+
aprFormatted: (0, import_utils56.formatPercent)(apr)
|
|
6268
6223
|
};
|
|
6269
6224
|
} catch (error) {
|
|
6270
6225
|
console.error("Error fetching sAUTO APR:", error);
|