Skip to content

Commit

Permalink
v5.0.2
Browse files Browse the repository at this point in the history
v5.0.2
  • Loading branch information
platschi authored Nov 17, 2022
2 parents 85f3c78 + cbe50d8 commit bebbc08
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
39 changes: 11 additions & 28 deletions hooks/useStakingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ const useStakingData = () => {
};

const [epochPeriod, setEpochPeriod] = useState(0);
const [weekCounter, setWeekCounter] = useState(1);
const { walletAddress } = Connector.useContainer();
const [kwentaBalance, setKwentaBalance] = useState(zeroBN);
const [escrowedBalance, setEscrowedBalance] = useState(zeroBN);
const [stakedNonEscrowedBalance, setStakedNonEscrowedBalance] = useState(zeroBN);
const [stakedEscrowedBalance, setStakedEscrowedBalance] = useState(zeroBN);
const [totalStakedBalance, setTotalStakedBalance] = useState(zeroBN);
const [claimableBalance, setClaimableBalance] = useState(zeroBN);
const [apy, setApy] = useState(zeroBN);
const [vKwentaBalance, setVKwentaBalance] = useState(zeroBN);
const [vKwentaAllowance, setVKwentaAllowance] = useState(zeroBN);
const [kwentaAllowance, setKwentaAllowance] = useState(zeroBN);
Expand Down Expand Up @@ -138,14 +138,6 @@ const useStakingData = () => {
functionName: 'balanceOf',
args: [walletAddress ?? undefined],
},
{
...supplyScheduleContract,
functionName: 'DECAY_RATE',
},
{
...supplyScheduleContract,
functionName: 'INITIAL_WEEKLY_SUPPLY',
},
{
...supplyScheduleContract,
functionName: 'weekCounter',
Expand Down Expand Up @@ -195,24 +187,14 @@ const useStakingData = () => {
setStakedEscrowedBalance(wei(data[2] ?? zeroBN));
setClaimableBalance(wei(data[3] ?? zeroBN));
setKwentaBalance(wei(data[4] ?? zeroBN));
setTotalStakedBalance(wei(data[8] ?? zeroBN));
const supplyRate = wei(1).sub(wei(data[5] ?? zeroBN));
const initialWeeklySupply = wei(data[6] ?? zeroBN);
const weekCounter = Number(data[7] ?? zeroBN);
const startWeeklySupply = initialWeeklySupply.mul(supplyRate.pow(weekCounter));
const yearlyRewards =
totalStakedBalance.gt(zeroBN) && supplyRate.gt(zeroBN)
? startWeeklySupply.mul(wei(1).sub(supplyRate.pow(52))).div(wei(1).sub(supplyRate))
: zeroBN;
setApy(
totalStakedBalance.gt(zeroBN) ? yearlyRewards.div(totalStakedBalance).div(100) : zeroBN
);
setVKwentaBalance(wei(data[9] ?? zeroBN));
setVKwentaAllowance(wei(data[10] ?? zeroBN));
setKwentaAllowance(wei(data[11] ?? zeroBN));
setEpochPeriod(Number(data[12] ?? 0) ?? 0);
setVEKwentaBalance(wei(data[13] ?? zeroBN));
setVEKwentaAllowance(wei(data[14] ?? zeroBN));
setWeekCounter(Number(data[5] ?? 1) ?? 1);
setTotalStakedBalance(wei(data[6] ?? zeroBN));
setVKwentaBalance(wei(data[7] ?? zeroBN));
setVKwentaAllowance(wei(data[8] ?? zeroBN));
setKwentaAllowance(wei(data[9] ?? zeroBN));
setEpochPeriod(Number(data[10] ?? 0) ?? 0);
setVEKwentaBalance(wei(data[11] ?? zeroBN));
setVEKwentaAllowance(wei(data[12] ?? zeroBN));
}
},
});
Expand Down Expand Up @@ -348,6 +330,8 @@ const useStakingData = () => {
resetStakingState,
resetVesting,
resetVestingClaimable,
weekCounter,
totalStakedBalance: Number(totalStakedBalance),
periods,
resetTime,
epochPeriod,
Expand All @@ -358,7 +342,6 @@ const useStakingData = () => {
stakedEscrowedBalance,
claimableBalance,
kwentaBalance,
apy,
vKwentaBalance,
veKwentaBalance,
vKwentaAllowance,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kwenta",
"version": "5.0.1",
"version": "5.0.2",
"scripts": {
"dev": "next",
"build": "next build",
Expand Down
11 changes: 11 additions & 0 deletions queries/staking/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export const EPOCH_START: Record<number, number> = {
};

export const WEEK = 604800;
export const DECAY_RATE = 0.0205;
export const INITIAL_WEEKLY_SUPPLY = 14463.36923076923076923;
export const STAKING_REWARDS_RATIO = 0.6;

export function getEpochDetails(networkId: number, epoch: number) {
const currentEpochTime = EPOCH_START[networkId]
Expand All @@ -15,3 +18,11 @@ export function getEpochDetails(networkId: number, epoch: number) {
epochEnd: epochEndTime,
};
}

export function getStakingApy(totalStakedBalance: number, weekCounter: number) {
const supplyRate = 1 - DECAY_RATE;
const initialWeeklySupply = INITIAL_WEEKLY_SUPPLY;
const startWeeklySupply = initialWeeklySupply * supplyRate ** weekCounter;
const yearlyRewards = (startWeeklySupply * (1 - supplyRate ** 52)) / (1 - supplyRate);
return totalStakedBalance > 0 ? (yearlyRewards * STAKING_REWARDS_RATIO) / totalStakedBalance : 0;
}
15 changes: 14 additions & 1 deletion sections/dashboard/Stake/StakingTab.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import { useContractWrite } from 'wagmi';

import Button from 'components/Button';
import { monitorTransaction } from 'contexts/RelayerContext';
import { useStakingContext } from 'contexts/StakingContext';
import { getStakingApy } from 'queries/staking/utils';
import media from 'styles/media';
import { formatPercent, truncateNumbers } from 'utils/formatters/number';

Expand All @@ -13,7 +15,18 @@ import StakeInputCard from './InputCards/StakeInputCard';

const StakingTab = () => {
const { t } = useTranslation();
const { claimableBalance, apy, getRewardConfig, resetStakingState } = useStakingContext();
const {
claimableBalance,
totalStakedBalance,
weekCounter,
getRewardConfig,
resetStakingState,
} = useStakingContext();

const apy = useMemo(() => getStakingApy(totalStakedBalance, weekCounter), [
totalStakedBalance,
weekCounter,
]);

const { writeAsync: getReward } = useContractWrite(getRewardConfig);

Expand Down

1 comment on commit bebbc08

@vercel
Copy link

@vercel vercel bot commented on bebbc08 Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kwenta – ./

kwenta.io
kwenta-git-main-kwenta.vercel.app
kwenta-kwenta.vercel.app

Please sign in to comment.