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

Spacebean/UI/bs3 bugs #1151

Merged
merged 8 commits into from
Oct 16, 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
8 changes: 7 additions & 1 deletion projects/dex-ui/src/wells/wellLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ const WELL_BLACKLIST: Record<number, WellAddresses> = {
"0x0adf75da6980fee8f848d52a7af1f8d6f34a8169".toLowerCase(), // BEAN:WETH duplicate,
"0xc22dd977c50812f754c14319de84493cc18b6cf0".toLowerCase(), // BEAN:WETH duplicate
"0x15d7a96c3dbf6b267fae741d15c3a72f331418fe".toLowerCase(), // BEAN:WETH duplicate
"0xd902f7bd849da907202d177fafc1bd39f6bbadc4".toLowerCase(), // BEAN:WETH duplicate
"0xb968de36ce9c61371a82a78b715af660c2209d11".toLowerCase(), // BEAN:wstETH duplicate
"0x430837acc8cfe4726453b09b8d782730654899e0".toLowerCase(), // BEAN:wstETH duplicate
"0x4731431430e7febd8df6a4aa7d28867927e827a6".toLowerCase(), // BEAN:wstETH duplicate
"0xc49b38dff421622628258683444f4977078cb96b".toLowerCase(), // BEAN:wstETH duplicate
"0x8d74ff8e729b4e78898488775b619c05d1ecb5e5".toLowerCase(), // BEAN:weETH duplicate
"0x65709d322f9c762f9435a326c653e7393807c0bc".toLowerCase(), // BEAN:weETH duplicate
"0x8dc6400022ac4304b3236f4d073053056ac24086".toLowerCase(), // BEAN:weETH duplicate
"0x45f6af24e6eb8371571dde1464a458770cbbbb65".toLowerCase(), // BEAN:weETH duplicate
"0x370062BE2d6Fc8d02948fEA75fAfe471F74854CF".toLowerCase(), // BEAN:WBTC duplicate
"0xee950139d7730706695a4613198ecac26e69e12d".toLowerCase(), // BEAN:WBTC duplicate
"0xb147ff6e2fd05ad3db185028beb3cce4dcb12b72".toLowerCase(), // BEAN:WBTC duplicate
"0xd4baa4197aa17c7f27a2465073de33690d77ec7e".toLowerCase(), // BEAN:WBTC duplicate
"0x157219b5D112F2D8aaFD3c7F3bA5D4c73343cc96".toLowerCase(), // BEAN:USDC duplicate
"0xdc29769db1caa5cab41835ef9a42becde80de028".toLowerCase(), // BEAN:USDC duplicate
"0xde1a4b24aa46286739c1879612c5e5445382d93d".toLowerCase(), // BEAN:USDC duplicate
"0xeaddd2848e962817fd565ea269a7fedb0588b3f4".toLowerCase(), // BEAN:USDC duplicate
"0xF3e4FC5c53D5500989e68F81d070094525caC240".toLowerCase(), // BEAN:USDT duplicate
"0xacfb4644b708043ad6eff1cc323fda374fe6d3ce".toLowerCase(), // BEAN:USDT duplicate
"0x704e68281325242a60515616228c668e4865694c".toLowerCase() // BEAN:USDT duplicate
"0x704e68281325242a60515616228c668e4865694c".toLowerCase(), // BEAN:USDT duplicate
"0xde8317a2a31a1684e2e4becedec17700718630d8".toLowerCase() // BEAN:USDT duplicate
]
};

Expand Down
3 changes: 1 addition & 2 deletions projects/ui/src/components/Common/Form/TokenInputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const TokenInput: FC<TokenInputProps & FieldProps> = ({
balance: balance?.toString(),
});
if (!amount) return undefined; // if no amount, exit
if (min?.gt(amount)) return min; // clamp @ min
if (amount.gt(0) && min?.gt(amount)) return min; // clamp @ min
if (!allowNegative && amount?.lt(ZERO_BN)) return ZERO_BN; // clamp negative
if (max?.lt(amount)) return max; // clamp @ max
return amount; // no max; always return amount
Expand All @@ -239,7 +239,6 @@ const TokenInput: FC<TokenInputProps & FieldProps> = ({
///
/// FIXME: throws an error if e.target.value === '.'
const newValue = e.target.value ? new BigNumber(e.target.value) : null;

/// Always update the display amount right away.
setDisplayAmount(newValue?.toString() || '');

Expand Down
13 changes: 7 additions & 6 deletions projects/ui/src/components/Common/Form/TokenSelectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
StyledDialogContent,
StyledDialogTitle,
} from '~/components/Common/Dialog';
import { displayBN } from '~/util';
import { displayBN, getTokenIndex } from '~/util';
import { ZERO_BN } from '~/constants';
import { FarmerBalances } from '~/state/farmer/balances';
import { FarmerSilo } from '~/state/farmer/silo';
Expand Down Expand Up @@ -116,17 +116,18 @@ const TokenSelectDialog: TokenSelectDialogC = React.memo(
);

const getBalance = useCallback(
(addr: string) => {
(token: TokenInstance) => {
if (!_balances) return ZERO_BN;
if (balancesType === 'farm')
return (
(_balances as TokenBalanceMode['farm'])?.[addr]?.[
(_balances as TokenBalanceMode['farm'])?.[getTokenIndex(token)]?.[
balanceFromInternal
] || ZERO_BN
);
return (
(_balances as TokenBalanceMode['silo-deposits'])?.[addr]?.deposited
?.amount || ZERO_BN
(_balances as TokenBalanceMode['silo-deposits'])?.[
getTokenIndex(token)
]?.deposited?.amount || ZERO_BN
);
},
[_balances, balancesType, balanceFromInternal]
Expand Down Expand Up @@ -245,7 +246,7 @@ const TokenSelectDialog: TokenSelectDialogC = React.memo(
<List sx={{ p: 0 }}>
{filteredTokenList
? filteredTokenList.map((_token) => {
const tokenBalance = getBalance(_token.address);
const tokenBalance = getBalance(_token);
return (
<ListItem
key={_token.address}
Expand Down
4 changes: 4 additions & 0 deletions projects/ui/src/components/Field/Actions/Sow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import FormTxnProvider from '~/components/Common/Form/FormTxnProvider';
import useFormTxnContext from '~/hooks/sdk/useFormTxnContext';
import { ClaimAndDoX, SowFarmStep } from '~/lib/Txn';
import useTemperature from '~/hooks/beanstalk/useTemperature';
import { useMinTokensIn } from '~/hooks/beanstalk/useMinTokensIn';

type SowFormValues = FormStateWithSwapQuote & {
settings: SlippageSettingsFragment & {
Expand Down Expand Up @@ -182,6 +183,8 @@ const SowForm: FC<
);
const maxAmountUsed = maxAmountIn ? totalBeansAmount.div(maxAmountIn) : null;

const minTokenIn = useMinTokensIn(tokenIn, sdk.tokens.BEAN);

const txnActions = useFarmerFormTxnsActions({
showGraphicOnClaim: Bean.equals(tokenIn),
claimBeansState: values.claimableBeans,
Expand Down Expand Up @@ -298,6 +301,7 @@ const SowForm: FC<
maxAmountIn || ZERO_BN,
tokenInBalance?.[values.balanceFrom] || ZERO_BN
)}
min={minTokenIn}
balance={tokenInBalance || undefined}
state={values.tokens[0]}
showTokenSelect={showTokenSelect}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const MorningTemperature: React.FC<{
titleTooltip={
<Box>
The interest rate for Sowing Beans. Beanstalk logarithmically
increases the Temperature for the first 25 blocks of each Season up
increases the Temperature for the first 5 minutes of each Season up
to the Max Temperature.
</Box>
}
Expand Down
3 changes: 1 addition & 2 deletions projects/ui/src/components/Nav/Buttons/PriceButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { useTokens } from '~/hooks/beanstalk/useTokens';
import { Token } from '@beanstalk/sdk';
import BigNumber from 'bignumber.js';
import useChainId from '~/hooks/chain/useChainId';
import { IS_DEV } from '~/util';
import FolderMenu from '../FolderMenu';

type TokenPriceEntry = {
Expand Down Expand Up @@ -290,7 +289,7 @@ const PriceButton: FC<ButtonProps> = ({ ...props }) => {
poolState={beanPools[pool.address]}
useTWA={showTWA}
ButtonProps={{
href: `${IS_DEV ? 'http://localhost:2424/#/wells' : BASIN_WELL_LINK}/${chainId}/${pool.address}`,
href: `${BASIN_WELL_LINK}${chainId}/${pool.address}`,
target: '_blank',
rel: 'noreferrer',
}}
Expand Down
4 changes: 2 additions & 2 deletions projects/ui/src/components/Silo/Token/TokenAbout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BigNumber from 'bignumber.js';
import { Link } from 'react-router-dom';
import Row from '~/components/Common/Row';
import { useAppSelector } from '~/state';
import { BASIN_WELL_LINK, ZERO_BN } from '~/constants';
import { BASE_ARBISCAN_ADDR_LINK, BASIN_WELL_LINK, ZERO_BN } from '~/constants';
import { InfoOutlined } from '@mui/icons-material';
import usePools from '~/hooks/beanstalk/usePools';
import useSdk from '~/hooks/sdk';
Expand Down Expand Up @@ -42,7 +42,7 @@ const TokenAbout = ({ token }: { token: Token }) => {
<Row justifyContent="space-between">
<Typography variant="subtitle1">Token address</Typography>
<Typography
to={`https://etherscan.io/address/${token.address}`}
to={`${BASE_ARBISCAN_ADDR_LINK}${token.address}`}
rel="noopener noreferrer"
target="_blank"
component={Link}
Expand Down
4 changes: 4 additions & 0 deletions projects/ui/src/components/Silo/Token/TokenDepositRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import BigNumber from 'bignumber.js';
import { InfoOutlined } from '@mui/icons-material';
import { BeanstalkPalette, FontWeight } from '~/components/App/muiTheme';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import { useNavigate } from 'react-router-dom';

const TokenDepositRewards = ({ token }: { token: Token }) => {
const seedReward = new BigNumber(token.rewards?.seeds?.toHuman() || '0');
const stalkReward = new BigNumber(token.rewards?.stalk?.toHuman() || '0');
const navigate = useNavigate();

return (
<Stack gap={2}>
Expand All @@ -26,6 +28,7 @@ const TokenDepositRewards = ({ token }: { token: Token }) => {
color="secondary"
size="small"
endIcon={<OpenInNewIcon sx={{ height: '16px', width: 'auto' }} />}
onClick={() => navigate('/analytics')}
>
<Typography fontWeight="inherit">
View rewards
Expand Down Expand Up @@ -90,6 +93,7 @@ const TokenDepositRewards = ({ token }: { token: Token }) => {
color="secondary"
size="small"
endIcon={<OpenInNewIcon sx={{ height: '16px', width: 'auto' }} />}
onClick={() => navigate('/analytics')}
>
View Bean Supply
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ const TokenDepositsOverview = ({ token }: Props) => {
<Typography
component="span"
fontWeight="inherit"
ml={0.3}
display={{ xs: 'none', md: 'inline' }}
>
{' Deposits'}
Deposits
</Typography>
</Button>
{!isBEAN && (
Expand All @@ -87,9 +88,10 @@ const TokenDepositsOverview = ({ token }: Props) => {
<Typography
fontWeight="inherit"
component="span"
ml={0.3}
display={{ xs: 'none', md: 'inline' }}
>
{' Deposits'}
Deposits
</Typography>
</Button>
)}
Expand Down
41 changes: 30 additions & 11 deletions projects/ui/src/components/Swap/Actions/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
NativeToken,
BeanSwapNodeQuote,
BeanSwapOperation,
BeanstalkSDK,
} from '@beanstalk/sdk';
import {
FormApprovingState,
Expand All @@ -35,14 +36,13 @@ import {
import { TokenSelectMode } from '~/components/Common/Form/TokenSelectDialog';
import TokenInputField from '~/components/Common/Form/TokenInputField';
import FarmModeField from '~/components/Common/Form/FarmModeField';
import { Beanstalk } from '~/generated/index';
import { ZERO_BN } from '~/constants';
import { useBeanstalkContract } from '~/hooks/ledger/useContract';
import useFarmerBalances from '~/hooks/farmer/useFarmerBalances';
import { useSigner } from '~/hooks/ledger/useSigner';

import useAccount from '~/hooks/ledger/useAccount';
import { MinBN, tokenIshEqual } from '~/util';
import { getTokenIndex, MinBN, tokenIshEqual } from '~/util';
import { IconSize } from '~/components/App/muiTheme';
import TransactionToast from '~/components/Common/TxnToast';
import { useFetchFarmerBalances } from '~/state/farmer/balances/updater';
Expand All @@ -62,6 +62,7 @@ import useQuoteWithParams, {
QuoteHandlerResultNew,
QuoteHandlerWithParams,
} from '~/hooks/ledger/useQuoteWithParams';
import { useMinTokensIn } from '~/hooks/beanstalk/useMinTokensIn';

/// ---------------------------------------------------------------

Expand Down Expand Up @@ -113,7 +114,7 @@ const Quoting = (
const SwapForm: FC<
FormikProps<SwapFormValues> & {
balances: ReturnType<typeof useFarmerBalances>;
beanstalk: Beanstalk;
beanstalk: BeanstalkSDK['contracts']['beanstalk'];
tokenList: (ERC20Token | NativeToken)[];
defaultValues: SwapFormValues;
}
Expand Down Expand Up @@ -161,15 +162,17 @@ const SwapForm: FC<
[balances]
);

const minTokenIn = useMinTokensIn(tokenIn, tokenOut);

const [balanceIn, balanceInInput, balanceInMax] = useMemo(() => {
const _balanceIn = balances[tokenIn.address];
const _balanceIn = balances[getTokenIndex(tokenIn)];
if (tokensMatch) {
const _balanceInMax =
_balanceIn[modeIn === FarmFromMode.INTERNAL ? 'internal' : 'external'];
return [_balanceIn, _balanceInMax, _balanceInMax] as const;
}
return [_balanceIn, _balanceIn, _balanceIn?.total || ZERO_BN] as const;
}, [balances, modeIn, tokenIn.address, tokensMatch]);
}, [balances, modeIn, tokenIn, tokensMatch]);

const [getAmountsBySource] = useGetBalancesUsedBySource({
tokens: values.tokensIn,
Expand Down Expand Up @@ -197,12 +200,14 @@ const SwapForm: FC<
? FarmFromMode.INTERNAL
: FarmFromMode.EXTERNAL
);
} else if (tokenIn.equals(sdk.tokens.ETH)) {
setFromOptions([BalanceFrom.EXTERNAL]);
} else {
setFromOptions([BalanceFrom.TOTAL]);
setBalanceFromIn(BalanceFrom.TOTAL);
setFieldValue('modeIn', FarmFromMode.INTERNAL_EXTERNAL);
}
}, [tokensMatch, modeIn, modeOut, setFieldValue]);
}, [tokensMatch, modeIn, modeOut, tokenIn, sdk, setFieldValue]);

const noBalance = !balanceInMax?.gt(0);
const expectedFromMode = balanceIn
Expand Down Expand Up @@ -237,6 +242,7 @@ const SwapForm: FC<
inputToken.fromHuman(_amountIn.toString()),
slippage
);

if (!quoteData) {
throw new Error('No route found.');
}
Expand Down Expand Up @@ -399,8 +405,21 @@ const SwapForm: FC<
/// Flip destinations.
setFieldValue('modeIn', modeOut);
setFieldValue('modeOut', modeIn);
} else {
setFieldValue('tokensIn.0', { ...values.tokenOut });
setFieldValue('tokenOut', {
...values.tokensIn[0],
amount: undefined,
});
}
}, [modeIn, modeOut, setFieldValue, tokensMatch]);
}, [
modeIn,
modeOut,
setFieldValue,
tokensMatch,
values.tokenOut,
values.tokensIn,
]);

// if tokenIn && tokenOut are equal and no balances are found, reverse positions.
// This prevents setting of internal balance of given token when there is none
Expand All @@ -420,8 +439,8 @@ const SwapForm: FC<
(_tokens: Set<TokenInstance>) => {
if (tokenSelect === 'tokenOut') {
const newTokenOut = Array.from(_tokens)[0];
setFieldValue('tokenOut.token', newTokenOut);
if (tokenIn === newTokenOut) handleTokensEqual();
setFieldValue('tokenOut.token', newTokenOut);
} else if (tokenSelect === 'tokensIn') {
const newTokenIn = Array.from(_tokens)[0];
setFieldValue('tokensIn.0.token', newTokenIn);
Expand Down Expand Up @@ -512,6 +531,7 @@ const SwapForm: FC<
]
: undefined
}
min={minTokenIn}
balance={balanceInInput}
quote={quotingOut ? Quoting : undefined}
onChange={handleChangeAmountIn}
Expand Down Expand Up @@ -811,13 +831,12 @@ function getBeanSwapOperation(
'Output token does not match quote. Please refresh the quote.'
);
}
if (!quote.sellAmount.eq(amountIn.toNumber())) {
if (!amountIn.eq(quote.sellAmount.toHuman())) {
throw new Error(
"Input amount doesn't match quote. Please refresh the quote."
);
}
const formFmountOutTV = tokenOut.fromHuman(amountOut.toString());
if (!quote.buyAmount.eq(formFmountOutTV)) {
if (!amountOut.eq(quote.buyAmount.toHuman())) {
throw new Error(
"Output amount doesn't match quote. Please refresh the quote."
);
Expand Down
2 changes: 2 additions & 0 deletions projects/ui/src/constants/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const HOW_TO_MM_PATH =
/* Base Links */
export const BASE_ETHERSCAN_TX_LINK = 'https://etherscan.io/tx/';
export const BASE_ETHERSCAN_ADDR_LINK = 'https://etherscan.io/address/';
export const BASE_ARBISCAN_TX_LINK = 'https://arbiscan.io/tx/';
export const BASE_ARBISCAN_ADDR_LINK = 'https://arbiscan.io/address/';

/* Informational Links */
export const MEDIUM_INTEREST_LINK =
Expand Down
Loading
Loading