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

feat: add deposit only switch #598

Merged
merged 6 commits into from
Oct 25, 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
33 changes: 32 additions & 1 deletion apps/vaults-v3/components/details/VaultActionsTabsWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
const {onSwitchSelectedOptions, isDepositing, actionParams} = useActionFlow();
const {address} = useWeb3();
const router = useRouter();
const {isAutoStakingEnabled, set_isAutoStakingEnabled} = useYearn();
const [unstakedBalance, set_unstakedBalance] = useState<TNormalizedBN | undefined>(undefined);
const [possibleTabs, set_possibleTabs] = useState<TTabsOptions[]>([tabs[0], tabs[1]]);
const [hasStakingRewardsLive, set_hasStakingRewardsLive] = useState(true);
Expand Down Expand Up @@ -300,6 +301,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
}
]
});

const hasLiveRewards = decodeAsBigInt(result[1]) > Math.floor(Date.now() / 1000);
const hasLiveRewardsFromYDaemon = (currentVault.staking.rewards || []).some(e => !e.isFinished);
set_unstakedBalance(toNormalizedBN(decodeAsBigInt(result[0]), currentVault.decimals));
Expand Down Expand Up @@ -359,6 +361,27 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
}
}, [currentVault?.migration?.available, currentVault?.info?.isRetired, actionParams.isReady, hasStakingRewards]);

/************************************************************************************************
* This effect manages the auto-staking feature based on staking rewards availability.
* It disables auto-staking if there are no staking rewards and the last reward ended over a week ago.
* Otherwise, it enables auto-staking.
*
* The check for rewards ending over a week ago helps prevent unnecessary auto-staking
* for vaults with expired or long-inactive staking programs.
************************************************************************************************/
useEffect(() => {
if (
!hasStakingRewards &&
currentVault.staking.rewards?.some(
el => Math.floor(Date.now() / 1000) - (el.finishedAt ?? 0) > 60 * 60 * 24 * 7
)
) {
set_isAutoStakingEnabled(false);
return;
}
set_isAutoStakingEnabled(true);
}, [currentVault.staking.rewards, hasStakingRewards, hasStakingRewardsLive, set_isAutoStakingEnabled]);

const isSonneRetiredVault =
toAddress(currentVault.address) === toAddress(`0x5b977577eb8a480f63e11fc615d6753adb8652ae`) ||
toAddress(currentVault.address) === toAddress(`0xad17a225074191d5c8a37b50fda1ae278a2ee6a2`) ||
Expand Down Expand Up @@ -514,8 +537,16 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
<p className={'hidden text-base md:inline'}>&nbsp;</p>
<div>
<VaultDetailsQuickActionsButtons currentVault={currentVault} />
{!hasStakingRewardsLive && (
<div className={'mt-1 flex justify-between'}>
<button
className={'font-number text-xxs text-neutral-900/50'}
onClick={(): void => set_isAutoStakingEnabled(!isAutoStakingEnabled)}>
{isAutoStakingEnabled ? 'Deposit only' : 'Deposit and Stake'}
</button>
</div>
)}
</div>
<legend className={'hidden text-xs md:inline'}>&nbsp;</legend>
</div>
</div>
)}
Expand Down
33 changes: 32 additions & 1 deletion apps/vaults/components/details/VaultActionsTabsWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '@vaults-v3/components/details/VaultActionsTabsWrapper';
import {readContracts} from '@wagmi/core';
import {parseMarkdown} from '@yearn-finance/web-lib/utils/helpers';
import {useYearn} from '@common/contexts/useYearn';
import {IconChevron} from '@common/icons/IconChevron';

import type {ReactElement} from 'react';
Expand All @@ -39,6 +40,7 @@ import type {TTabsOptions} from '@vaults-v3/components/details/VaultActionsTabsW
*************************************************************************************************/
export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonVault}): ReactElement {
const router = useRouter();
const {isAutoStakingEnabled, set_isAutoStakingEnabled} = useYearn();
const {address} = useWeb3();
const {onSwitchSelectedOptions, isDepositing, actionParams} = useActionFlow();
const [possibleTabs, set_possibleTabs] = useState<TTabsOptions[]>([tabs[0], tabs[1]]);
Expand Down Expand Up @@ -136,6 +138,27 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
}
}, [currentVault?.migration?.available, currentVault?.info?.isRetired, actionParams.isReady, hasStakingRewards]);

/************************************************************************************************
* This effect manages the auto-staking feature based on staking rewards availability.
* It disables auto-staking if there are no staking rewards and the last reward ended over a week ago.
* Otherwise, it enables auto-staking.
*
* The check for rewards ending over a week ago helps prevent unnecessary auto-staking
* for vaults with expired or long-inactive staking programs.
************************************************************************************************/
useEffect(() => {
if (
!hasStakingRewards &&
currentVault.staking.rewards?.some(
el => Math.floor(Date.now() / 1000) - (el.finishedAt ?? 0) > 60 * 60 * 24 * 7
)
) {
set_isAutoStakingEnabled(false);
return;
}
set_isAutoStakingEnabled(true);
}, [currentVault.staking.rewards, hasStakingRewards, hasStakingRewardsLive, set_isAutoStakingEnabled]);

const isSonneRetiredVault =
toAddress(currentVault.address) === toAddress(`0x5b977577eb8a480f63e11fc615d6753adb8652ae`) ||
toAddress(currentVault.address) === toAddress(`0xad17a225074191d5c8a37b50fda1ae278a2ee6a2`) ||
Expand Down Expand Up @@ -302,8 +325,16 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
<p className={'hidden text-base md:inline'}>&nbsp;</p>
<div>
<VaultDetailsQuickActionsButtons currentVault={currentVault} />
{!hasStakingRewardsLive && (
<div className={'mt-1 flex justify-between'}>
<button
className={'font-number text-xxs text-neutral-900/50'}
onClick={(): void => set_isAutoStakingEnabled(!isAutoStakingEnabled)}>
{isAutoStakingEnabled ? 'Deposit only' : 'Deposit and Stake'}
</button>
</div>
)}
</div>
<legend className={'hidden text-xs md:inline'}>&nbsp;</legend>
</div>
</div>
)}
Expand Down
Binary file added bun.lockb
Binary file not shown.
170 changes: 85 additions & 85 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
{
"name": "yearnfi",
"version": "0.3.7",
"scripts": {
"dev": "next",
"inspect": "NODE_OPTIONS='--inspect' next",
"dev:ts": "tsc --watch",
"start": "tsc && next build && next start",
"build": "tsc && next build",
"export": "tsc && next build && next export -o ipfs",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"prettier": "prettier --check \"./**/**/*.{json,js,ts,tsx,scss}\"",
"prettier-format": "prettier --config .prettierrc \"./**/**/*.{json,js,ts,tsx,scss,md}\" --write",
"tslint": "tsc -p tsconfig.json --noEmit",
"bump": "bump",
"test": "vitest run"
},
"dependencies": {
"@builtbymom/web3": "0.0.202",
"@cowprotocol/cow-sdk": "2.1.0",
"@headlessui/react": "^2.0.4",
"@rainbow-me/rainbowkit": "2.1.3",
"@tailwindcss/typography": "^0.5.13",
"@tanstack/react-query": "^5.51.11",
"@wagmi/core": "^2.11.7",
"@yearn-finance/web-lib": "^4.1.3",
"axios": "^1.7.2",
"ethers": "5.7.2",
"framer-motion": "^11.2.10",
"graphql": "^16.8.2",
"graphql-request": "^7.0.1",
"next": "^14.2.5",
"next-plausible": "^3.12.0",
"next-pwa": "^5.6.0",
"nprogress": "^0.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-paginate": "^8.2.0",
"recharts": "^2.12.7",
"swr": "^2.2.5",
"viem": "2.17.3",
"vite": "^5.2.13",
"wagmi": "2.10.10",
"xxhashjs": "^0.2.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.2.4",
"@next/eslint-plugin-next": "^14.2.4",
"@testing-library/react": "^16.0.0",
"@types/node": "^20.14.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.19",
"babel-loader": "^9.1.3",
"bump": "^0.2.5",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.4",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-brackets": "^0.1.3",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-tailwindcss": "^3.17.3",
"eslint-plugin-unused-imports": "^4.0.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"next-transpile-modules": "^10.0.1",
"postcss": "^8.4.38",
"postcss-import": "^16.1.0",
"postcss-nesting": "^12.1.5",
"prettier": "^3.3.2",
"sass": "^1.77.5",
"stylelint": "^16.6.1",
"stylelint-config-standard": "^36.0.0",
"tailwindcss": "^3.4.4",
"ts-loader": "^9.5.1",
"typescript": "^5.5.3",
"vitest": "^1.6.0",
"webpack": "^5.92.1"
}
"name": "yearnfi",
"version": "0.3.7",
"scripts": {
"dev": "next",
"inspect": "NODE_OPTIONS='--inspect' next",
"dev:ts": "tsc --watch",
"start": "tsc && next build && next start",
"build": "tsc && next build",
"export": "tsc && next build && next export -o ipfs",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"prettier": "prettier --check \"./**/**/*.{json,js,ts,tsx,scss}\"",
"prettier-format": "prettier --config .prettierrc \"./**/**/*.{json,js,ts,tsx,scss,md}\" --write",
"tslint": "tsc -p tsconfig.json --noEmit",
"bump": "bump",
"test": "vitest run"
},
"dependencies": {
"@builtbymom/web3": "0.0.202",
"@cowprotocol/cow-sdk": "2.1.0",
"@headlessui/react": "^2.0.4",
"@rainbow-me/rainbowkit": "2.1.3",
"@tailwindcss/typography": "^0.5.13",
"@tanstack/react-query": "^5.51.11",
"@wagmi/core": "^2.11.7",
"@yearn-finance/web-lib": "^4.1.4",
"axios": "^1.7.2",
"ethers": "5.7.2",
"framer-motion": "^11.2.10",
"graphql": "^16.8.2",
"graphql-request": "^7.0.1",
"next": "^14.2.5",
"next-plausible": "^3.12.0",
"next-pwa": "^5.6.0",
"nprogress": "^0.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-paginate": "^8.2.0",
"recharts": "^2.12.7",
"swr": "^2.2.5",
"viem": "2.17.3",
"vite": "^5.2.13",
"wagmi": "2.10.10",
"xxhashjs": "^0.2.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.2.4",
"@next/eslint-plugin-next": "^14.2.4",
"@testing-library/react": "^16.0.0",
"@types/node": "^20.14.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.19",
"babel-loader": "^9.1.3",
"bump": "^0.2.5",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.4",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-brackets": "^0.1.3",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-tailwindcss": "^3.17.3",
"eslint-plugin-unused-imports": "^4.0.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"next-transpile-modules": "^10.0.1",
"postcss": "^8.4.38",
"postcss-import": "^16.1.0",
"postcss-nesting": "^12.1.5",
"prettier": "^3.3.2",
"sass": "^1.77.5",
"stylelint": "^16.6.1",
"stylelint-config-standard": "^36.0.0",
"tailwindcss": "^3.4.4",
"ts-loader": "^9.5.1",
"typescript": "^5.5.3",
"vitest": "^1.6.0",
"webpack": "^5.92.1"
}
}
Loading