Skip to content

Commit

Permalink
Merge branch 'igor/advanced-staking-2-no-controller-update' into 'main'
Browse files Browse the repository at this point in the history
feat(dapp): support for adv. staking v2

See merge request pantherprotocol/panther-core!1019
  • Loading branch information
pycckuu committed Apr 13, 2023
2 parents 3d1f8d1 + e288427 commit c131cb9
Show file tree
Hide file tree
Showing 33 changed files with 375 additions and 452 deletions.
29 changes: 4 additions & 25 deletions dapp/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,11 @@ SUGGESTED_RPC_URL_31337="http://127.0.0.1:8545/"
#TOKEN_SYMBOL=none
TOKEN_SYMBOL=panther

# Times for the advanced staking program, in secs since UNIX epoch.
# These are used when there is no wallet/chain connection available
# for querying smart contracts, e.g. on the Welcome page.
#
# They should be kept in sync with the contracts via
#
# yarn amplify:check
# yarn amplify:sync
# yarn dotenv:check
# yarn dotenv:sync
#
# defined in dapp/package.json.

# Advanced staking opening time (should match terms.allowedSince)
ADVANCED_STAKING_T_START=1656378685

# Advanced staking closing time (should match terms.allowedTill)
ADVANCED_STAKING_T_END=1656383423

# Advanced staking unlock time (should match terms.lockedTill)
ADVANCED_STAKING_T_UNLOCK=1656381857

ADVANCED_STAKING_APY_START=70
ADVANCED_STAKING_APY_END=40
# current staking terms
ADVANCED_STAKING_APY=15
CURRENT_STAKING_TERM=advanced
APY_PRP=10

# Countries from which users are not allowed to use the application
BLOCKED_COUNTRIES=US

APY_PRP=10
6 changes: 2 additions & 4 deletions dapp/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ STAKING_TOKEN_CONTRACT_137=0x9A06Db14D639796B25A6ceC6A1bf614fd98815EC
SUBGRAPH_IDS_137=QmTi7Z7YoUpzYqwGytPuKYu2FuYPEhtPTsXti5dRxn8wHR,QmZPs5CFi5vpZW73DmwF5VMzt5CYvFX7vD9Ez9gkZteuRd
Z_ASSETS_REGISTRY_CONTRACT_137=0xb658B085144a0BEd098620BB829b676371B9B48c

ADVANCED_STAKING_APY_START=15
ADVANCED_STAKING_APY_END=15
ADVANCED_STAKING_T_START=1670522400
ADVANCED_STAKING_T_END=1680804000
ADVANCED_STAKING_APY=15
CURRENT_STAKING_TERM=advanced-v2
APY_PRP=10

# Faucet
Expand Down
8 changes: 2 additions & 6 deletions dapp/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,8 @@ ADVANCED_STAKE_REWARD_CONTROLLER_CONTRACT_80001=0xaEf203DB2d26615FeE0Dc045D11127
POOL_V0_CONTRACT_80001=0x15eABaed2474D584E739d390b4BEa4904CEeef9a
Z_ASSETS_REGISTRY_CONTRACT_80001=0x57c1cc66fAbB0F81037a552C04388089D75B9492

ADVANCED_STAKING_T_START=1666126800
ADVANCED_STAKING_T_END=1703106000
ADVANCED_STAKING_T_REDEMPTION=1662659100
ADVANCED_STAKING_T_UNLOCK=0
ADVANCED_STAKING_APY_START=70
ADVANCED_STAKING_APY_END=70
ADVANCED_STAKING_APY=70
CURRENT_STAKING_TERM=advanced
APY_PRP=10


6 changes: 3 additions & 3 deletions dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"prettier:check": "cd .. && yarn prettier --check dapp",
"prettier:fix": "cd .. && yarn prettier --write dapp",
"prettier:list-different": "cd .. && yarn prettier --list-different dapp",
"test": "yarn test:base && yarn test:ipfs",
"test:base": "TZ=UTC DOTENV_CONFIG_PATH=.env.test jest",
"test:ipfs": "TEST_ENV=node yarn test:base tests/scripts/deploy-ipfs.test.ts",
"test": "yarn test:ipfs && yarn test:jest",
"test:jest": "TZ=UTC DOTENV_CONFIG_PATH=.env.test jest",
"test:ipfs": "TEST_ENV=node yarn test:jest tests/scripts/deploy-ipfs.test.ts",
"env:sync": "yarn ts-node scripts/syncEnv.ts",
"amplify:check": "yarn env:sync",
"amplify:sync": "yarn env:sync --write",
Expand Down
10 changes: 5 additions & 5 deletions dapp/src/components/AdvancedStakingRewards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
totalVestedRewardsSelector,
} from 'redux/slices/staking/totals-of-advanced-stakes';
import {getAdvStakingAPY} from 'services/rewards';
import {StakeType} from 'types/staking';
import {currentStakeTerm} from 'services/staking';

import ClaimedProgress from '../../components/ClaimedProgress';
import {formatRemainingPeriod} from '../../lib/format';
import {useAppSelector} from '../../redux/hooks';
import {termsSelector} from '../../redux/slices/staking/stake-terms';
import {termsPropertySelector} from '../../redux/slices/staking/stake-terms';

import './styles.scss';

Expand All @@ -28,7 +28,7 @@ dayjs.extend(isBetween);
function AdvancedStakingRewards() {
const claimed = useAppSelector(totalClaimedRewardsSelector);
const total = useAppSelector(totalVestedRewardsSelector);
const advancedStakingAPY = getAdvStakingAPY(new Date().getTime());
const advancedStakingAPY = getAdvStakingAPY();

return (
<Box
Expand Down Expand Up @@ -79,11 +79,11 @@ function RemainingDays() {
const {chainId} = context;

let allowedSince = useAppSelector(
termsSelector(chainId!, StakeType.Advanced, 'allowedSince'),
termsPropertySelector(chainId!, currentStakeTerm(), 'allowedSince'),
);

let allowedTill = useAppSelector(
termsSelector(chainId!, StakeType.Advanced, 'allowedTill'),
termsPropertySelector(chainId!, currentStakeTerm(), 'allowedTill'),
);

// Falling back to env variables if terms are not loaded
Expand Down
2 changes: 0 additions & 2 deletions dapp/src/components/LogoutButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React, {useCallback} from 'react';
import {useWeb3React} from '@web3-react/core';
import {WalletHeaderActionButton} from 'components/common/WalletHeaderActionButton';
import {useAppDispatch} from 'redux/hooks';
import {resetUnclaimedClassicRewards} from 'redux/slices/staking/total-unclaimed-classic-rewards';
import {resetZkpStakedBalance} from 'redux/slices/staking/zkp-staked-balance';
import {setDisconnected} from 'redux/slices/ui/is-wallet-connected';
import {resetZkpTokenBalance} from 'redux/slices/wallet/zkp-token-balance';
Expand All @@ -21,7 +20,6 @@ export const LogoutButton = () => {
deactivate();
dispatch(resetZkpTokenBalance);
dispatch(resetZkpStakedBalance);
dispatch(resetUnclaimedClassicRewards);
dispatch(setDisconnected);
}
}, [active, chainId, deactivate, dispatch]);
Expand Down
4 changes: 3 additions & 1 deletion dapp/src/components/StakeList/StakeItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import React from 'react';

import {CLASSIC_TYPE_HEX} from 'constants/stake-terms';

import {Box, IconButton, Tooltip, Typography} from '@mui/material';
import {classnames} from 'components/common/classnames';
import ExactValueTooltip from 'components/common/ExactValueTooltip';
Expand All @@ -15,7 +17,7 @@ import useScreenSize from 'hooks/screen';
import infoIcon from 'images/info-icon.svg';
import {formatCurrency, getFormattedFractions} from 'lib/format';
import {isClassic} from 'services/rewards';
import {CLASSIC_TYPE_HEX, StakeRow} from 'services/staking';
import {StakeRow} from 'services/staking';
import {
AdvancedStakeRewardsBN,
ClassicStakeRewardBN,
Expand Down
2 changes: 0 additions & 2 deletions dapp/src/components/StakeList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import usePagination from 'hooks/pagination';
import {awaitConfirmationAndRetrieveEvent} from 'lib/events';
import {useAppDispatch} from 'redux/hooks';
import {getStakes, useStakes} from 'redux/slices/staking/stakes';
import {getTotalUnclaimedClassicRewards} from 'redux/slices/staking/total-unclaimed-classic-rewards';
import {getTotalsOfAdvancedStakes} from 'redux/slices/staking/totals-of-advanced-stakes';
import {getZkpStakedBalance} from 'redux/slices/staking/zkp-staked-balance';
import {
Expand Down Expand Up @@ -157,7 +156,6 @@ export default function StakeList() {
dispatch(registerWalletActionSuccess, 'signMessage');
dispatch(getTotalsOfAdvancedStakes, context);
dispatch(getZkpStakedBalance, context);
dispatch(getTotalUnclaimedClassicRewards, context);
dispatch(getZkpTokenBalance, context);
dispatch(getChainBalance, context);
dispatch(getStakes, context);
Expand Down
2 changes: 0 additions & 2 deletions dapp/src/components/StakeTab/StakingBtn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from 'redux/slices/staking/advanced-stake-predicted-rewards';
import {resetStakeAmount} from 'redux/slices/staking/stake-amount';
import {getStakes} from 'redux/slices/staking/stakes';
import {getTotalUnclaimedClassicRewards} from 'redux/slices/staking/total-unclaimed-classic-rewards';
import {
getTotalsOfAdvancedStakes,
totalLeftRewardsSelector,
Expand Down Expand Up @@ -303,7 +302,6 @@ const StakingBtn = (props: {
dispatch(getTotalsOfAdvancedStakes, context);
dispatch(getZkpStakedBalance, context);
dispatch(getZkpTokenBalance, context);
dispatch(getTotalUnclaimedClassicRewards, context);
dispatch(getChainBalance, context);
dispatch(resetStakeAmount);
dispatch(resetRewards);
Expand Down
15 changes: 8 additions & 7 deletions dapp/src/components/StakeTab/StakingInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {useAppSelector} from 'redux/hooks';
import {
isStakingOpenSelector,
isStakingPostCloseSelector,
termsSelector,
termsPropertySelector,
} from 'redux/slices/staking/stake-terms';
import {chainHasAdvancedStaking} from 'services/contracts';
import {currentStakeTerm} from 'services/staking';
import {StakeType} from 'types/staking';

import './styles.scss';
Expand All @@ -25,27 +26,27 @@ export default function StakingInfo() {
const {chainId} = context;

const isAdvancedStakingOpen = useAppSelector(
isStakingOpenSelector(chainId!, StakeType.Advanced),
isStakingOpenSelector(chainId!, currentStakeTerm()),
);

const isAdvancedStakingPostClose = useAppSelector(
isStakingPostCloseSelector(chainId!, StakeType.Advanced),
isStakingPostCloseSelector(chainId!, currentStakeTerm()),
);

const stakeType = chainHasAdvancedStaking(chainId)
? StakeType.Advanced
? currentStakeTerm()
: StakeType.Classic;

const allowedSince = useAppSelector(
termsSelector(chainId!, stakeType, 'allowedSince'),
termsPropertySelector(chainId!, stakeType, 'allowedSince'),
);

const allowedTill = useAppSelector(
termsSelector(chainId!, stakeType, 'allowedTill'),
termsPropertySelector(chainId!, stakeType, 'allowedTill'),
);

const minLockPeriod = useAppSelector(
termsSelector(chainId!, stakeType, 'minLockPeriod'),
termsPropertySelector(chainId!, stakeType, 'minLockPeriod'),
);

const getAdvancedStakingPreCloseText = useCallback((): {
Expand Down
30 changes: 24 additions & 6 deletions dapp/src/components/StakeTab/StakingInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
setStakeAmount,
} from 'redux/slices/staking/stake-amount';
import {
termsSelector,
termsPropertySelector,
isStakingOpenSelector,
} from 'redux/slices/staking/stake-terms';
import {zkpTokenBalanceSelector} from 'redux/slices/wallet/zkp-token-balance';
import {StakeType} from 'types/staking';
import {currentStakeTerm} from 'services/staking';

import {StakingInputProps} from './StakingInput.interface';

Expand All @@ -38,10 +38,16 @@ export default function StakingInput(props: StakingInputProps) {

const tokenBalance = useAppSelector(zkpTokenBalanceSelector);
const isStakingOpen = useAppSelector(
isStakingOpenSelector(chainId, StakeType.Advanced),
isStakingOpenSelector(chainId, currentStakeTerm()),
);
const minLockPeriod = useAppSelector(
termsSelector(chainId!, StakeType.Advanced, 'minLockPeriod'),
termsPropertySelector(chainId!, currentStakeTerm(), 'minLockPeriod'),
);
const allowedSince = useAppSelector(
termsPropertySelector(chainId!, currentStakeTerm(), 'allowedSince'),
);
const allowedTill = useAppSelector(
termsPropertySelector(chainId!, currentStakeTerm(), 'allowedTill'),
);
const disabled = !account || !isStakingOpen;

Expand All @@ -56,13 +62,25 @@ export default function StakingInput(props: StakingInputProps) {
const bn = safeParseUnits(amount);
if (bn) {
dispatch(setStakeAmount, amount as string);
dispatch(calculateRewards, [bn.toString(), minLockPeriod]);
dispatch(calculateRewards, [
bn.toString(),
minLockPeriod,
allowedSince,
allowedTill,
]);
return;
}
}
clearStakedValue();
},
[tokenBalance, dispatch, minLockPeriod, clearStakedValue],
[
tokenBalance,
clearStakedValue,
dispatch,
minLockPeriod,
allowedSince,
allowedTill,
],
);

useEffect(() => {
Expand Down
8 changes: 4 additions & 4 deletions dapp/src/components/StakeTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {useAppSelector} from 'redux/hooks';
import {stakeAmountSelector} from 'redux/slices/staking/stake-amount';
import {
isStakingOpenSelector,
termsSelector,
termsPropertySelector,
} from 'redux/slices/staking/stake-terms';
import {zkpTokenBalanceSelector} from 'redux/slices/wallet/zkp-token-balance';
import {isWrongNetwork} from 'services/connectors';
import {CHAIN_IDS} from 'services/env';
import {currentStakeTerm} from 'services/staking';
import {switchNetwork} from 'services/wallet';
import {StakeType} from 'types/staking';

import {ExpectedRewardsCard} from './ExpectedRewardsCard';
import StakingBtn from './StakingBtn';
Expand All @@ -34,11 +34,11 @@ export default function StakeTab() {
const {account, library, chainId, active, error} = context;
const tokenBalance = useAppSelector(zkpTokenBalanceSelector);
const minStake = useAppSelector(
termsSelector(chainId, StakeType.Advanced, 'minAmountScaled'),
termsPropertySelector(chainId, currentStakeTerm(), 'minAmountScaled'),
);

const isAdvancedStakingOpen = useAppSelector(
isStakingOpenSelector(chainId, StakeType.Advanced),
isStakingOpenSelector(chainId, currentStakeTerm()),
);
const amountToStake = useAppSelector(stakeAmountSelector);
const [wrongNetwork, setWrongNetwork] = useState(false);
Expand Down
59 changes: 0 additions & 59 deletions dapp/src/components/UnstakeTab/TotalUnclaimedRewards/index.tsx

This file was deleted.

Loading

0 comments on commit c131cb9

Please sign in to comment.