Skip to content

Commit

Permalink
feat: use balances subgraph for trv market value & benchmarked equity (
Browse files Browse the repository at this point in the history
…#1045)

* Use balances for totalMarketValueUSD & benchmarkedEquityUSD

* Update use-dashboardv2-metrics.ts

* fix: use external balances for homepage TVL

* fix: use balances subgraph for tpi on homepage

---------

Co-authored-by: pocin <[email protected]>
  • Loading branch information
medariox and pocin authored Jun 25, 2024
1 parent 06c2e9f commit 8c8b40f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
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

0 comments on commit 8c8b40f

Please sign in to comment.