Skip to content

Commit

Permalink
feat: fix unripe underlying
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Oct 9, 2024
1 parent fdd5245 commit 637ed46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion projects/ui/src/components/Silo/Whitelist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const Whitelist: FC<{
const underlyingToken = isUnripe
? unripeUnderlyingTokens[token.address]
: null;

const pctUnderlyingDeposited = isUnripe
? (
beanstalkSilo.balances[token.address]?.deposited.amount ||
Expand Down Expand Up @@ -493,7 +494,7 @@ const Whitelist: FC<{
<Fiat
token={underlyingToken!}
amount={pctUnderlyingDeposited.times(
unripeTokens[token.address]?.underlying ||
unripeTokens[token.address]?.underlying ??
ZERO_BN
)}
truncate
Expand Down
27 changes: 18 additions & 9 deletions projects/ui/src/hooks/beanstalk/useUnripeUnderlying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@ import { useMemo } from 'react';
import { AddressMap } from '~/constants';
import useTokenList from '~/hooks/chain/useTokenList';
import { ERC20Token } from '@beanstalk/sdk';
import { BEAN, BEAN_WSTETH_WELL_LP } from '~/constants/tokens';
import useSdk from '../sdk';
import { useGetChainConstant } from '../chain/useChainConstant';
import { ERC20TokenInstance } from './useTokens';

export default function useUnripeUnderlyingMap(
keyedBy: 'unripe' | 'ripe' = 'unripe'
) {
const sdk = useSdk();
const getChainConstant = useGetChainConstant();
const unripe = useTokenList(sdk.tokens.unripeTokens as Set<ERC20Token>);
const underlying = useTokenList(
sdk.tokens.unripeUnderlyingTokens as Set<ERC20Token>
);
const underlying = useTokenList([
getChainConstant(BEAN),
getChainConstant(BEAN_WSTETH_WELL_LP),
]);
return useMemo(
() =>
unripe.reduce<AddressMap<ERC20Token>>((prev, unripeToken, index) => {
if (keyedBy === 'unripe') prev[unripeToken.address] = underlying[index];
// address => Ripe Token
else prev[underlying[index].address] = unripeToken; // address => Unripe Token
return prev;
}, {}),
unripe.reduce<AddressMap<ERC20TokenInstance>>(
(prev, unripeToken, index) => {
if (keyedBy === 'unripe')
prev[unripeToken.address] = underlying[index];
// address => Ripe Token
else prev[underlying[index].address] = unripeToken; // address => Unripe Token
return prev;
},
{}
),
[keyedBy, underlying, unripe]
);
}

0 comments on commit 637ed46

Please sign in to comment.