Skip to content

Commit

Permalink
Merge pull request #1209 from yieldprotocol/feat/v2_1-strategies
Browse files Browse the repository at this point in the history
Feat/v2 1 strategies
  • Loading branch information
brucedonovan authored Jun 5, 2023
2 parents 8237acb + a9c265b commit 26da2b3
Show file tree
Hide file tree
Showing 79 changed files with 32,467 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ REACT_APP_VERSION=$npm_package_version
REACT_APP_RPC_URL_1='https://eth-mainnet.g.alchemy.com/v2/ZXDCq5iy0KrKR0XjsqC6E4QG7Z_FuXDv'
REACT_APP_RPC_URL_42161='https://arb-mainnet.g.alchemy.com/v2/vtMM4_eLnOvkjkdckprVw3cIa64EVkDZ'

REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/aeabe871-354c-4a8d-998f-4a1c4b24d590'
REACT_APP_DEFAULT_FORK_RPC_URL='https://rpc.tenderly.co/fork/679cb075-9657-494c-bd6c-7f3fa8ec6a8f'
REACT_APP_LOCALHOST_RPC_URL='http://127.0.0.1:8545'

REACT_APP_RPC_URL_421611='https://arb-rinkeby.g.alchemy.com/v2/AY_Q_Uy-Kcfwmf5In5qwG636vaOIoA8L'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app-v2",
"version": "2.5.21",
"version": "2.5.22",
"private": true,
"dependencies": {
"@ethersproject/providers": "^5.6.8",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const YieldHeader = ({ actionList }: IYieldHeaderProps) => {

// eslint-disable-next-line react/display-name
const YieldIcon = forwardRef(({ onClick, href }: any, ref: any) => (
<a href={href} onClick={onClick} ref={ref}>
// <a href={href} onClick={onClick} ref={ref}>
<StyledAvatar
background="hoverBackground"
size="3rem"
Expand All @@ -63,7 +63,7 @@ const YieldHeader = ({ actionList }: IYieldHeaderProps) => {
<YieldMark colors={colorScheme === 'dark' ? ['white'] : ['black']} height="1.75rem" />
)}
</StyledAvatar>
</a>
// </a>
));

return (
Expand Down
6 changes: 5 additions & 1 deletion src/components/PositionAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import styled from 'styled-components';
import { UserContext } from '../contexts/UserContext';
import { IVault, ISeries, IAsset, IStrategy, ActionType } from '../types';
import Logo from './logos/Logo';
import { StrategyType } from '../config/strategies';
import { FaExclamationCircle } from 'react-icons/fa';

const Outer = styled(Box)`
position: relative;
Expand All @@ -30,10 +32,12 @@ function PositionAvatar({
position,
condensed,
actionType,
type
}: {
position: IVault | ISeries | IStrategy;
actionType: ActionType;
condensed?: boolean;
type?: any;
}) {
const isVault = position?.id.length > 15;

Expand Down Expand Up @@ -67,7 +71,7 @@ function PositionAvatar({
)}
{actionType === ActionType.POOL && (
<Avatar background="lightBackground" size={ilkBorderSize}>
{series?.seriesIsMature ? <FiClock /> : <MdAutorenew />}
{type !== StrategyType.V2_1 ? <FaExclamationCircle /> : <MdAutorenew />}
</Avatar>
)}
</Inner>
Expand Down
5 changes: 3 additions & 2 deletions src/components/PublicNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const PublicNotification = ({ children }: PublicNotificationProps) => {
const chainId = useChainId();
return (
<>
{/* {chainId === 1 ? ( */}
{ chainId === 1 ?
<Box direction="row" align="center" justify="between">
<Box
direction="row"
Expand All @@ -30,7 +30,8 @@ const PublicNotification = ({ children }: PublicNotificationProps) => {
</Text>
</Box>
</Box>
{/* ) : null} */}
: null
}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/positionItems/StrategyItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function StrategyItem({ strategy, index, condensed }: { strategy: IStrategy; ind
return (
<ItemWrap action={() => handleSelect(strategy)} index={index}>
<Box direction="row" gap="small" align="center" pad="small" height={condensed ? '3rem' : undefined}>
<PositionAvatar position={strategy.currentSeries!} condensed={condensed} actionType={ActionType.POOL} />
<PositionAvatar position={strategy.currentSeries!} condensed={condensed} actionType={ActionType.POOL} type={strategy.type} />
<Box
fill={condensed ? 'horizontal' : undefined}
justify={condensed ? 'between' : undefined}
Expand Down
41 changes: 22 additions & 19 deletions src/components/selectors/StrategySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Skeleton from '../wraps/SkeletonWrap';
import { SettingsContext } from '../../contexts/SettingsContext';
import { ZERO_BN } from '../../utils/constants';
import useStrategyReturns, { IReturns } from '../../hooks/useStrategyReturns';
import { StrategyType } from '../../config/strategies';

const StyledBox = styled(Box)`
-webkit-transition: transform 0.3s ease-in-out;
Expand Down Expand Up @@ -81,17 +82,17 @@ const StrategySelectItem = ({
</Box>
</Box>

{strategy.rewardsRate!.gt(ZERO_BN) && (
{strategy.rewardsRate?.gt(ZERO_BN) && (
<Box
round
background="red"
pad={{ horizontal: 'small', vertical: 'xsmall' }}
style={{ position: 'absolute', marginTop: '-1em', marginLeft: '17em' }}
elevation="small"
>
<Text size="small" color="white" textAlign="center">
+{returns?.rewardsAPY}%
</Text>
<Text size="small" color="white" textAlign="center">
+{returns?.rewardsAPY}%
</Text>
</Box>
)}

Expand Down Expand Up @@ -131,7 +132,10 @@ const StrategySelector = ({ inputValue }: IStrategySelectorProps) => {
settingsState: { diagnostics },
} = useContext(SettingsContext);

const { userState, userActions } = useContext(UserContext);
const {
userState,
userActions: { setSelectedSeries, setSelectedStrategy },
} = useContext(UserContext);

const { selectedStrategy, selectedBase, strategiesLoading, strategyMap, seriesMap } = userState;
const [options, setOptions] = useState<IStrategy[]>([]);
Expand All @@ -140,19 +144,20 @@ const StrategySelector = ({ inputValue }: IStrategySelectorProps) => {
useEffect(() => {
const opts = Array.from(strategyMap?.values()!);
const filteredOpts = opts
.filter((_st) => _st.type === 'V2' || (_st.type === 'V1' && !_st.associatedStrategy))
.filter((_st) => !_st.currentSeries?.hideSeries && _st.active)
.filter((_st) => _st.type === StrategyType.V2_1)
.filter((_st) => !_st.currentSeries?.hideSeries || !_st.disabled)
.filter((_st) => _st.baseId === selectedBase?.proxyId && !_st.currentSeries?.seriesIsMature)
.sort((a, b) => a.currentSeries?.maturity! - b.currentSeries?.maturity!);

setOptions(filteredOpts);
}, [selectedBase, strategyMap, selectedStrategy]);

const handleSelect = (_strategy: IStrategy) => {
diagnostics && console.log('SELECTED: ', _strategy.address, 'VERSION: ', _strategy.type);
if (_strategy.active) {
if (!_strategy.disabled) {
diagnostics && console.log('Strategy selected: ', _strategy.address);
userActions.setSelectedStrategy(_strategy);
userActions.setSelectedSeries(_strategy.currentSeries!);
setSelectedStrategy(_strategy);
setSelectedSeries(_strategy.currentSeries!);
} else {
toast.info('Strategy coming soon');
}
Expand All @@ -163,25 +168,25 @@ const StrategySelector = ({ inputValue }: IStrategySelectorProps) => {
/* if strategy already selected, no need to set explicitly again */
if (selectedStrategy) return;
const opts: IStrategy[] = Array.from(strategyMap.values())
.filter((_st) => _st.type === 'V2' || (_st.type === 'V1' && !_st.associatedStrategy))
.filter((_st) => !_st.currentSeries?.hideSeries && _st.active)
.filter((_st: IStrategy) => _st.baseId === selectedBase?.proxyId && !_st.currentSeries?.seriesIsMature);
.filter((_st) => _st.type === StrategyType.V2_1) // we only want to show V2.1 strategies in the selector for now.
.filter((_st) => !_st.currentSeries?.hideSeries || !_st.disabled)
.filter((_st) => _st.baseId === selectedBase?.proxyId && !_st.currentSeries?.seriesIsMature);

/* select strategy with rewards */
const strategyWithRewards = opts.find((s) => s.rewardsRate?.gt(ZERO_BN));
if (strategyWithRewards) {
userActions.setSelectedStrategy(strategyWithRewards);
setSelectedStrategy(strategyWithRewards);
return;
}
/* select strategy with existing balance */
const strategyWithBalance = opts.find((_st) => _st?.accountBalance?.gt(ZERO_BN));
if (strategyWithBalance) {
userActions.setSelectedStrategy(strategyWithBalance);
setSelectedStrategy(strategyWithBalance);
return;
}
/* else set a random one as a last resort */
userActions.setSelectedStrategy(opts[Math.floor(Math.random() * opts.length)]);
}, [selectedBase, strategyMap]);
setSelectedStrategy(opts[Math.floor(Math.random() * opts.length)]);
}, [selectedBase, selectedStrategy, setSelectedStrategy, strategyMap]);

return (
<Box>
Expand All @@ -207,8 +212,6 @@ const StrategySelector = ({ inputValue }: IStrategySelectorProps) => {
selected={selected}
displayName={displayName}
returns={returns}
// apy={returns.blendedAPY}
// extra={ returns.}
/>
);
})}
Expand Down
8 changes: 2 additions & 6 deletions src/components/views/Pool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Pool() {
setPoolDisabled(true);
/* this is simply a check that we don't add to a v1 strategy that has a v2 verison) */
console.log('Strategy: ', selectedStrategy);
if (selectedStrategy?.type === StrategyType.V1 && selectedStrategy.associatedStrategy) {
if (selectedStrategy?.type !== StrategyType.V2_1) {
console.log('config error: Trying to add to an old strategy');
toast.warning('Trying to add Liquidity to an old Strategy version. Please refresh your browser and try again.');
return;
Expand Down Expand Up @@ -320,11 +320,7 @@ function Pool() {
secondary
label={<Text size={mobile ? 'small' : undefined}>Next Step</Text>}
onClick={() => handleNavAction(stepPosition + 1)}
disabled={
stepDisabled ||
!selectedStrategy ||
(selectedStrategy.associatedStrategy && selectedStrategy.type === StrategyType.V1)
}
disabled={stepDisabled || !selectedStrategy || selectedStrategy.type !== StrategyType.V2_1}
errorLabel={poolError}
/>
)}
Expand Down
37 changes: 28 additions & 9 deletions src/components/views/PoolPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import GeneralButton from '../buttons/GeneralButton';
import { MdShortcut } from 'react-icons/md';
import { ZERO_BN } from '@yield-protocol/ui-math';
import useAccountPlus from '../../hooks/useAccountPlus';
import { StrategyType } from '../../config/strategies';
import { FaExclamationCircle } from 'react-icons/fa';

const PoolPosition = () => {
const mobile: boolean = useContext<any>(ResponsiveContext) === 'small';
Expand Down Expand Up @@ -170,7 +172,9 @@ const PoolPosition = () => {

/* ACTION DISABLING LOGIC - if ANY conditions are met: block action */
useEffect(() => {
!removeInput || removeError || !selectedSeries ? setRemoveDisabled(true) : setRemoveDisabled(false);
!removeInput || removeError || (selectedStrategy?.type === StrategyType.V2_1 && !selectedSeries)
? setRemoveDisabled(true)
: setRemoveDisabled(false);
+selectedStrategy?.accountRewards_! === 0 ? setClaimDisabled(true) : setClaimDisabled(false);
}, [selectedStrategy, activeAccount, forceDisclaimerChecked, removeError, removeInput, selectedSeries]);

Expand Down Expand Up @@ -201,7 +205,11 @@ const PoolPosition = () => {
pad={{ top: mobile ? 'medium' : undefined }}
>
<Box direction="row" align="center" gap="medium">
<PositionAvatar position={selectedSeries!} actionType={ActionType.POOL} />
<PositionAvatar
position={selectedSeries!}
actionType={ActionType.POOL}
type={selectedStrategy?.type}
/>
<Box>
<Text size={mobile ? 'medium' : 'large'}> {formatStrategyName(_selectedStrategy?.name)}</Text>
<CopyWrap hash={_selectedStrategy.address}>
Expand All @@ -220,12 +228,14 @@ const PoolPosition = () => {
/>
<InfoBite
label="Strategy Token Balance"
value={`${cleanValue(
_selectedStrategy?.accountBalance_,
selectedBase?.digitFormat!
)} tokens (${cleanValue(removeBaseReceivedMax_, selectedBase?.digitFormat!)} ${
selectedBase?.symbol
})`}
value={`${cleanValue(_selectedStrategy?.accountBalance_, selectedBase?.digitFormat!)} tokens${
removeBaseReceivedMax_
? ` (${cleanValue(removeBaseReceivedMax_, selectedBase?.digitFormat!)} ${
selectedBase?.symbol
})`
: ``
}
`}
icon={<YieldMark height="1em" colors={[selectedSeries?.startColor!]} />}
loading={seriesLoading}
/>
Expand Down Expand Up @@ -275,6 +285,15 @@ const PoolPosition = () => {
/>
)}

{selectedStrategy?.type !== StrategyType.V2_1 && (
<InfoBite
label="This strategy contract has been upgraded"
value="No action required"
icon={<FaExclamationCircle />}
loading={false}
/>
)}

{selectedStrategy?.accountRewards?.gt(ZERO_BN) && selectedStrategy?.rewardsTokenAddress && (
<Box direction="row" gap="large" justify="between">
<InfoBite
Expand Down Expand Up @@ -345,7 +364,7 @@ const PoolPosition = () => {
/>
</InputWrap>

{removeInput && !partialRemoveRequired && !removeError && (
{removeInput && !partialRemoveRequired && !removeError && removeBaseReceived_ && (
<InputInfoWrap>
<Text color="text-weak" alignSelf="end" size="small">
Approx. return {cleanValue(removeBaseReceived_, selectedBase?.digitFormat)}{' '}
Expand Down
3 changes: 3 additions & 0 deletions src/config/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum ContractNames {
WRAP_ETHER_MODULE = 'WrapEtherModule',
CONVEX_LADLE_MODULE = 'ConvexLadleModule',
TRANSFER_1155_MODULE = 'Transfer1155Module',
ASSERT = 'Assert',
}

export type ContractMap = Map<ContractNames, Contract>;
Expand All @@ -28,6 +29,7 @@ const contractAddresses: ContractAddresses = {
[ContractNames.TRANSFER_1155_MODULE, '0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06'],
[ContractNames.WRAP_ETHER_MODULE, '0x22768FCaFe7BB9F03e31cb49823d1Ece30C0b8eA'],
[ContractNames.CONVEX_LADLE_MODULE, '0x9Bf195997581C99cef8be95a3a816Ca19Cf1A3e6'],
[ContractNames.ASSERT, '0x40f0b18c7a41c04f848c033ed7f9178d9c5a80d8'],
]),
],
[
Expand All @@ -38,6 +40,7 @@ const contractAddresses: ContractAddresses = {
[ContractNames.WITCH, '0x08173D0885B00BDD640aaE57D05AbB74cd00d669'],
[ContractNames.WITCHV2, '0x07c2c74811cb14a5003c3ccff7ec436d504fffb6'],
[ContractNames.WRAP_ETHER_MODULE, '0x4cd01ed221d6d198e2656c16c32803bf78134568'],
[ContractNames.ASSERT, '0x40f0b18c7a41c04f848c033ed7f9178d9c5a80d8'],
]),
],
]),
Expand Down
Loading

0 comments on commit 26da2b3

Please sign in to comment.