Skip to content

Commit

Permalink
chore: use decimal places with token values
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Jun 5, 2024
1 parent b63db68 commit 698ca68
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions src/pages/InterProtocol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import { ValueCardGrid } from '@/components/ValueCardGrid';
import { PageHeader } from '@/components/PageHeader';
import { PageContent } from '@/components/PageContent';
import { colors } from '@/components/palette';
import { formatPercent, roundPrice, formatPrice, formatIST, subQueryFetcher, fetchDataFromUrl } from '@/utils';
import { INTER_DASHBOARD_QUERY } from '@/queries';
import {
GET_INTERCHAIN_BALANCES_URL,
} from '@/constants';
formatPercent,
roundPrice,
formatPrice,
formatIST,
subQueryFetcher,
fetchDataFromUrl,
createNumberWithLeadingZeroes,
} from '@/utils';
import { INTER_DASHBOARD_QUERY } from '@/queries';
import { GET_INTERCHAIN_BALANCES_URL } from '@/constants';
import InterProtocolSkeleton from '@/components/InterProtocolSkeleton';
import { AccountData, InterProtocolResponse } from '@/types/interprotocol-types';
import { OraclePriceNode } from '@/types/vault-types';


const RADIAN = Math.PI / 180;

const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, payload }: any) => {
Expand All @@ -36,7 +41,6 @@ const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, per
);
};


function getInterchainBalance(data: AccountData[]): number {
const balanceList = data
.map((account) => ({
Expand Down Expand Up @@ -81,38 +85,61 @@ export function InterProtocol() {
{},
);

const psmMinted =
dashboardResponse.psmMetrics.nodes.reduce((agg, node) => agg + Number(node.mintedPoolBalance), 0) / 1_000_000;
const psmAnchor = dashboardResponse.psmMetrics.nodes.reduce(
(agg, node) => agg + Number(node.anchorPoolBalance) / 10 ** (boardAuxes[node.denom] || 6),
0,
);
const vaultMinted =
dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => agg + Number(node.totalDebt), 0) / 1_000_000;
const totalMinted = psmMinted + vaultMinted;
const psmMinted = dashboardResponse.psmMetrics.nodes.reduce((agg, node) => {
const decimalPlaces = (boardAuxes && boardAuxes[node.denom]) || 6;
const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces);
return (agg + Number(node.mintedPoolBalance)) / tokenDivisor;
}, 0);

const psmAnchor = dashboardResponse.psmMetrics.nodes.reduce((agg, node) => {
const decimalPlaces = (boardAuxes && boardAuxes[node.denom]) || 6;
const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces);
return (agg + Number(node.anchorPoolBalance)) / 10 ** tokenDivisor;
}, 0);

const vaultMinted = dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => {
const decimalPlaces = (boardAuxes && boardAuxes[node.liquidatingCollateralBrand]) || 6;
const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces);
return agg + Number(node.totalDebt) / tokenDivisor;
}, 0);

const totalMinted = psmMinted + vaultMinted;
const ISTDecimalPlaces = createNumberWithLeadingZeroes((boardAuxes && boardAuxes['IST']) || 6);
const vaultMintLimit =
dashboardResponse.vaultManagerGovernances.nodes.reduce((agg, node) => agg + Number(node.debtLimit), 0) / 1_000_000;
const psmMintLimit = dashboardResponse.psmGovernances.nodes.reduce((agg, node) => agg + Number(node.mintLimit), 0) / 1_000_000;
dashboardResponse.vaultManagerGovernances.nodes.reduce((agg, node) => agg + Number(node.debtLimit), 0) /
ISTDecimalPlaces;

const psmMintLimit = dashboardResponse.psmGovernances.nodes.reduce((agg, node) => {
const decimalPlaces = (boardAuxes && boardAuxes[node.denom]) || 6;
const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces);
return (agg + Number(node.mintLimit)) / tokenDivisor;
}, 0);

const totalMintLimit = vaultMintLimit + psmMintLimit;

// bottom cards
const totalReserve = dashboardResponse.reserveMetrics.nodes.reduce(
(agg, node) =>
agg +
node.allocations.nodes.reduce((agg_, node_) => {
const decimalPlaces = (boardAuxes && boardAuxes[node_.denom]) || 6;
const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces);
const allocationInUsd =
((Number(node_.value) / 1_000_000) * Number(oraclePrices[node_.denom]?.typeOutAmount || 1_000_000)) / 1_000_000;
((Number(node_.value) / tokenDivisor) * Number(oraclePrices[node_.denom]?.typeOutAmount || 0)) / tokenDivisor;
return agg_ + allocationInUsd;
}, 0),
0,
);
const reserveShortfall =
dashboardResponse.reserveMetrics.nodes.reduce((agg, node) => agg + Number(node.shortfallBalance), 0) / 1_000_000;
dashboardResponse.reserveMetrics.nodes.reduce((agg, node) => agg + Number(node.shortfallBalance), 0) /
ISTDecimalPlaces;
const totalLockedCollateral = dashboardResponse.vaultManagerMetrics.nodes.reduce((agg, node) => {
const decimalPlaces = (boardAuxes && boardAuxes[node.liquidatingCollateralBrand]) || 6;
const tokenDivisor = createNumberWithLeadingZeroes(decimalPlaces);

const collateralInUsd =
((Number(node.totalCollateral) / 1_000_000) *
Number(oraclePrices[node.liquidatingCollateralBrand]?.typeOutAmount) || 0) / 1_000_000;
((Number(node.totalCollateral) / tokenDivisor) *
Number(oraclePrices[node.liquidatingCollateralBrand]?.typeOutAmount) || 0) / tokenDivisor;
return agg + collateralInUsd;
}, 0);

Expand Down

0 comments on commit 698ca68

Please sign in to comment.