Skip to content

Commit

Permalink
feat: update liq by state
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Oct 21, 2024
1 parent 4f85ac6 commit 0df932d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 37 deletions.
26 changes: 15 additions & 11 deletions projects/ui/src/components/Analytics/MiniCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Time } from 'lightweight-charts';
import { useQueries } from '@tanstack/react-query';
import { fetchAllSeasonData } from '~/util/Graph';
import { RESEED_SEASON } from '~/constants';
import { exists, mayFunctionToValue } from '~/util';
import ChartV2 from './ChartV2';
import { useChartSetupData } from './useChartSetupData';

Expand Down Expand Up @@ -43,6 +44,8 @@ const MiniCharts: FC<{}> = () => {
const valueFormatter = params.valueFormatter;
const priceKey = params.priceScaleKey;

const timestamps = new Set<number>();

return {
queryKey: ['analytics', 'mini', params.id, season.toNumber()],
queryFn: async () => {
Expand All @@ -53,16 +56,17 @@ const MiniCharts: FC<{}> = () => {
);
const output = allSeasonData.map((seasonData) => {
const time = Number(seasonData[params.timeScaleKey]);
const data = dataFormatter
? dataFormatter?.(seasonData)
: seasonData;
const _value = valueFormatter(data[priceKey]);
let value;
if (typeof _value === 'function') {
value = _value(season.lte(RESEED_SEASON - 2) ? 'l1' : 'l2');
} else {
value = _value;
}
const data = dataFormatter ? dataFormatter?.(seasonData) : seasonData;

const value = mayFunctionToValue<number>(
valueFormatter(data[priceKey]),
seasonData.season <= RESEED_SEASON - 1 ? 'l1' : 'l2'
);

const invalidTime = !exists(time) || timestamps.has(time) || time <= 0;
if (invalidTime || !exists(value)) return undefined;

timestamps.add(time);

return {
time,
Expand All @@ -72,7 +76,7 @@ const MiniCharts: FC<{}> = () => {
},
} as QueryData;
});
return [output.filter(Boolean)];
return [output.filter(Boolean)] as QueryData[][];
},
enabled: season.gt(0),
staleTime: Infinity,
Expand Down
14 changes: 7 additions & 7 deletions projects/ui/src/components/Common/Balances/BeanstalkBalances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import BigNumber from 'bignumber.js';
import ResizablePieChart, {
PieDataPoint,
} from '~/components/Common/Charts/PieChart';
import { displayBN, displayFullBN } from '~/util';
import { displayBN, displayFullBN, tokenIshEqual } from '~/util';
import useBeanstalkSiloBreakdown, {
StateID,
STATE_CONFIG,
} from '~/hooks/beanstalk/useBeanstalkBalancesBreakdown';
import useWhitelist from '~/hooks/beanstalk/useWhitelist';
import TokenRow from '~/components/Common/Balances/TokenRow';
import useChainConstant from '~/hooks/chain/useChainConstant';
import { BEAN, UNRIPE_BEAN, UNRIPE_BEAN_WSTETH } from '~/constants/tokens';
import { FC } from '~/types';
import { useAppSelector } from '~/state';
import useGetChainToken from '~/hooks/chain/useGetChainToken';
import useUnripeUnderlyingMap from '~/hooks/beanstalk/useUnripeUnderlying';
import { ERC20Token } from '~/classes/Token';

import useSiloTokenToFiat from '~/hooks/beanstalk/useSiloTokenToFiat';
import { useWhitelistedTokens, TokenInstance } from '~/hooks/beanstalk/useTokens';
import StatHorizontal from '../StatHorizontal';

const BeanstalkBalances: FC<{
breakdown: ReturnType<typeof useBeanstalkSiloBreakdown>;
}> = ({ breakdown }) => {
// Constants
const WHITELIST = useWhitelist();
const { tokenMap: WHITELIST } = useWhitelistedTokens();
const getChainToken = useGetChainToken();
const Bean = useChainConstant(BEAN);
const urBean = getChainToken(UNRIPE_BEAN);
Expand Down Expand Up @@ -85,7 +85,7 @@ const BeanstalkBalances: FC<{
const hoverToken = hoverAddress ? WHITELIST[hoverAddress] : undefined;
const assetLabel = hoverToken?.name || 'Token';

function getUnripeBreakdown(token: ERC20Token, amount: BigNumber) {
function getUnripeBreakdown(token: TokenInstance, amount: BigNumber) {
if (!token || !amount || !isTokenUnripe(token.address) || loadingUnripe)
return { bdv: BigNumber(0), usd: BigNumber(0) };

Expand All @@ -99,7 +99,7 @@ const BeanstalkBalances: FC<{
}

function amountTooltip(
token: ERC20Token,
token: TokenInstance,
amount: BigNumber,
isBreakdown?: boolean
) {
Expand Down Expand Up @@ -267,7 +267,7 @@ const BeanstalkBalances: FC<{
2
)}
labelTooltip={STATE_CONFIG[state][2](
hoverToken === Bean ? 'Beans' : hoverToken.symbol
tokenIshEqual(hoverToken, Bean) ? 'Beans' : hoverToken.symbol
)}
amountTooltip={amountTooltip(
hoverToken,
Expand Down
19 changes: 0 additions & 19 deletions projects/ui/src/components/Forecast/LiquidityByState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { NEW_BN } from '~/constants';
import { FC } from '~/types';
import { useBeanstalkTokens } from '~/hooks/beanstalk/useTokens';
import BigNumber from 'bignumber.js';
import useSdk from '~/hooks/sdk';
import { displayFullBN } from '~/util';
import Stat from '~/components/Common/Stat';

Expand All @@ -18,32 +17,14 @@ import Stat from '~/components/Common/Stat';
}

const LiquidityByState: FC<CardProps> = ({ sx }) => {
const sdk = useSdk();
const totalBeanSupply = useAppSelector((s) => s._bean.token.supply);
const beanstalkField = useAppSelector((s) => s._beanstalk.field);
const beanstalkSilo = useAppSelector((s) => s._beanstalk.silo);
const beanstalkBarn = useAppSelector((s) => s._beanstalk.barn);

React.useEffect(() => {
console.log({
totalBeanSupply: totalBeanSupply.toNumber(),
beanstalkField: beanstalkField.podLine.toNumber(),
beanstalkSilo: beanstalkSilo.stalk.total.toNumber(),
beanstalkBarn: beanstalkBarn.unfertilized.toNumber(),
});
}, [totalBeanSupply, beanstalkField, beanstalkSilo, beanstalkBarn]);

React.useEffect(() => {
console.log(sdk);
}, [sdk]);

const { STALK, SPROUTS, PODS } = useBeanstalkTokens();
const breakdown = useBeanstalkSiloBreakdown();

React.useEffect(() => {
console.log(breakdown);
}, [breakdown]);

/// Total Balances
const STAT_ITEMS: StatItem[] = [
{
Expand Down

0 comments on commit 0df932d

Please sign in to comment.