Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use balances subgraph for trv market value & benchmarked equity #1045

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,22 @@ export default function useDashboardV2Metrics(dashboardData: DashboardData) {
fetchGenericSubgraph<any>(
env.subgraph.templeV2,
`{
treasuryReservesVaults {
totalMarketValueUSD
treasuryPriceIndex
principalUSD
accruedInterestUSD
benchmarkedEquityUSD
}
}`
treasuryReservesVaults {
treasuryPriceIndex
principalUSD
accruedInterestUSD
}
}`
),
// includes the external balances so has to come from the second subgraph
fetchGenericSubgraph<any>(
env.subgraph.templeV2Balances,
`{
treasuryReservesVaults {
totalMarketValueUSD
benchmarkedEquityUSD
}
}`
),
getBenchmarkRate(),
getTempleCirculatingSupply(),
Expand All @@ -200,6 +208,7 @@ export default function useDashboardV2Metrics(dashboardData: DashboardData) {

const [
trvSubgraphResponse,
responseExternalBalances,
benchmarkRate,
templeCirculatingSupply,
templeSpotPrice,
Expand All @@ -208,15 +217,18 @@ export default function useDashboardV2Metrics(dashboardData: DashboardData) {
const trvSubgraphData =
trvSubgraphResponse?.data?.treasuryReservesVaults[0];

const externalBalancesData =
responseExternalBalances?.data?.treasuryReservesVaults[0];

metrics = {
totalMarketValue: parseFloat(trvSubgraphData.totalMarketValueUSD),
totalMarketValue: parseFloat(externalBalancesData.totalMarketValueUSD),
spotPrice: parseFloat(templeSpotPrice),
treasuryPriceIndex: parseFloat(trvSubgraphData.treasuryPriceIndex),
circulatingSupply: parseFloat(templeCirculatingSupply),
benchmarkRate: parseFloat(benchmarkRate),
principal: parseFloat(trvSubgraphData.principalUSD),
accruedInterest: parseFloat(trvSubgraphData.accruedInterestUSD),
benchmarkedEquity: parseFloat(trvSubgraphData.benchmarkedEquityUSD),
benchmarkedEquity: parseFloat(externalBalancesData.benchmarkedEquityUSD),
};
} catch (error) {
console.info(error);
Expand Down
35 changes: 11 additions & 24 deletions apps/dapp/src/components/Pages/Core/NewUI/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,14 @@ const Home = ({ tlc }: { tlc?: boolean }) => {
useEffect(() => {
const fetchMetrics = async () => {
const { data: treasuryData } = await fetchGenericSubgraph<any>(
env.subgraph.protocolMetrics,
env.subgraph.templeV2Balances,
`{
metrics {
treasuryValueUSD
}
}`
);
const { data: arbitrumTreasuryData } = await fetchGenericSubgraph<any>(
env.subgraph.protocolMetricsArbitrum,
`{
metrics {
treasuryValueUSD
}
}`
treasuryReservesVaults {
principalUSD
benchmarkedEquityUSD
treasuryPriceIndex
}
}`
);
const { data: ramosData } = await fetchGenericSubgraph<any>(
env.subgraph.ramos,
Expand All @@ -130,20 +124,13 @@ const Home = ({ tlc }: { tlc?: boolean }) => {
}`
);

const { data: tpiData } = await fetchGenericSubgraph<any>(
env.subgraph.templeV2,
`{
tpiOracles {
currentTpi
}
}`
);
const treasuryMetrics = treasuryData.treasuryReservesVaults[0];
setMetrics({
price: parseFloat(ramosData.metrics[0].spotPrice),
tpi: parseFloat(tpiData.tpiOracles[0].currentTpi),
tpi: parseFloat(treasuryMetrics.treasuryPriceIndex),
treasury:
parseFloat(treasuryData.metrics[0].treasuryValueUSD) +
parseFloat(arbitrumTreasuryData.metrics[0].treasuryValueUSD),
parseFloat(treasuryMetrics.principalUSD) +
parseFloat(treasuryMetrics.benchmarkedEquityUSD),
});
};
fetchMetrics();
Expand Down
Loading