Skip to content

Commit b50cac0

Browse files
committed
fix(uni): fix uni in circulation calculation and make uni button always show up
1 parent 1ac1658 commit b50cac0

4 files changed

Lines changed: 124 additions & 75 deletions

File tree

src/components/Header/UniBalanceContent.tsx

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import tokenLogo from '../../assets/images/token-logo.png'
66
import { UNI } from '../../constants'
77
import { useTotalSupply } from '../../data/TotalSupply'
88
import { useActiveWeb3React } from '../../hooks'
9+
import { useMerkleDistributorContract } from '../../hooks/useContract'
910
import useCurrentBlockTimestamp from '../../hooks/useCurrentBlockTimestamp'
1011
import { useTotalUniEarned } from '../../state/stake/hooks'
1112
import { useAggregateUniBalance, useTokenBalance } from '../../state/wallet/hooks'
@@ -45,15 +46,18 @@ export default function UniBalanceContent({ setShowUniBalanceModal }: { setShowU
4546

4647
const total = useAggregateUniBalance()
4748
const uniBalance: TokenAmount | undefined = useTokenBalance(account ?? undefined, uni)
48-
const uniUnHarvested: TokenAmount | undefined = useTotalUniEarned()
49+
const uniToClaim: TokenAmount | undefined = useTotalUniEarned()
4950

5051
const totalSupply: TokenAmount | undefined = useTotalSupply(uni)
5152
const uniPrice = useUSDCPrice(uni)
5253
const blockTimestamp = useCurrentBlockTimestamp()
54+
const unclaimedUni = useTokenBalance(useMerkleDistributorContract()?.address, uni)
5355
const circulation: TokenAmount | undefined = useMemo(
5456
() =>
55-
blockTimestamp && uni && chainId === ChainId.MAINNET ? computeUniCirculation(uni, blockTimestamp) : totalSupply,
56-
[blockTimestamp, chainId, totalSupply, uni]
57+
blockTimestamp && uni && chainId === ChainId.MAINNET
58+
? computeUniCirculation(uni, blockTimestamp, unclaimedUni)
59+
: totalSupply,
60+
[blockTimestamp, chainId, totalSupply, unclaimedUni, uni]
5761
)
5862

5963
return (
@@ -63,37 +67,41 @@ export default function UniBalanceContent({ setShowUniBalanceModal }: { setShowU
6367
<CardNoise />
6468
<CardSection gap="md">
6569
<RowBetween>
66-
<TYPE.white color="white">Your UNI Breakdown</TYPE.white>{' '}
70+
<TYPE.white color="white">Your UNI Breakdown</TYPE.white>
6771
<StyledClose stroke="white" onClick={() => setShowUniBalanceModal(false)} />
6872
</RowBetween>
6973
</CardSection>
7074
<Break />
71-
<CardSection gap="sm">
72-
<AutoColumn gap="md" justify="center">
73-
<UniTokenAnimated width="48px" src={tokenLogo} />{' '}
74-
<TYPE.white fontSize={48} fontWeight={600} color="white">
75-
{total?.toFixed(2, { groupSeparator: ',' })}
76-
</TYPE.white>
77-
</AutoColumn>
78-
<AutoColumn gap="md">
79-
<RowBetween>
80-
<TYPE.white color="white">Balance:</TYPE.white>
81-
<TYPE.white color="white">{uniBalance?.toFixed(2, { groupSeparator: ',' })}</TYPE.white>
82-
</RowBetween>
83-
<RowBetween>
84-
<TYPE.white color="white">Unclaimed:</TYPE.white>
85-
<TYPE.white color="white">
86-
{uniUnHarvested?.toFixed(4, { groupSeparator: ',' })}{' '}
87-
{uniUnHarvested && (
88-
<StyledInternalLink onClick={() => setShowUniBalanceModal(false)} to="/uni">
89-
(claim)
90-
</StyledInternalLink>
91-
)}
92-
</TYPE.white>
93-
</RowBetween>
94-
</AutoColumn>
95-
</CardSection>
96-
<Break />
75+
{account && (
76+
<>
77+
<CardSection gap="sm">
78+
<AutoColumn gap="md" justify="center">
79+
<UniTokenAnimated width="48px" src={tokenLogo} />{' '}
80+
<TYPE.white fontSize={48} fontWeight={600} color="white">
81+
{total?.toFixed(2, { groupSeparator: ',' })}
82+
</TYPE.white>
83+
</AutoColumn>
84+
<AutoColumn gap="md">
85+
<RowBetween>
86+
<TYPE.white color="white">Balance:</TYPE.white>
87+
<TYPE.white color="white">{uniBalance?.toFixed(2, { groupSeparator: ',' })}</TYPE.white>
88+
</RowBetween>
89+
<RowBetween>
90+
<TYPE.white color="white">Unclaimed:</TYPE.white>
91+
<TYPE.white color="white">
92+
{uniToClaim?.toFixed(4, { groupSeparator: ',' })}{' '}
93+
{uniToClaim && uniToClaim.greaterThan('0') && (
94+
<StyledInternalLink onClick={() => setShowUniBalanceModal(false)} to="/uni">
95+
(claim)
96+
</StyledInternalLink>
97+
)}
98+
</TYPE.white>
99+
</RowBetween>
100+
</AutoColumn>
101+
</CardSection>
102+
<Break />
103+
</>
104+
)}
97105
<CardSection gap="sm">
98106
<AutoColumn gap="md">
99107
<RowBetween>

src/components/Header/index.tsx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ChainId, TokenAmount, JSBI } from '@uniswap/sdk'
1+
import { ChainId, TokenAmount } from '@uniswap/sdk'
22
import React, { useState } from 'react'
33
import { Text } from 'rebass'
4-
import { NavLink, withRouter } from 'react-router-dom'
4+
import { NavLink } from 'react-router-dom'
55
import { darken } from 'polished'
66
import { useTranslation } from 'react-i18next'
77

@@ -264,7 +264,7 @@ const NETWORK_LABELS: { [chainId in ChainId]?: string } = {
264264
[ChainId.KOVAN]: 'Kovan'
265265
}
266266

267-
function Header({ history }: { history: any }) {
267+
export default function Header() {
268268
const { account, chainId } = useActiveWeb3React()
269269
const { t } = useTranslation()
270270

@@ -292,34 +292,32 @@ function Header({ history }: { history: any }) {
292292
<UniBalanceContent setShowUniBalanceModal={setShowUniBalanceModal} />
293293
</Modal>
294294
<HeaderRow>
295-
<Title href="." style={{}}>
295+
<Title href=".">
296296
<UniIcon>
297297
<img width={'24px'} src={isDark ? LogoDark : Logo} alt="logo" />
298298
</UniIcon>
299299
</Title>
300300
<HeaderLinks>
301-
<StyledNavLink id={`swap-nav-link`} to={'/swap'} isActive={() => history.location.pathname.includes('/swap')}>
301+
<StyledNavLink id={`swap-nav-link`} to={'/swap'}>
302302
{t('swap')}
303303
</StyledNavLink>
304304
<StyledNavLink
305305
id={`pool-nav-link`}
306306
to={'/pool'}
307-
isActive={() =>
308-
history.location.pathname.includes('/pool') ||
309-
history.location.pathname.includes('/add') ||
310-
history.location.pathname.includes('/remove')
307+
isActive={(match, { pathname }) =>
308+
Boolean(match) ||
309+
pathname.startsWith('/add') ||
310+
pathname.startsWith('/remove') ||
311+
pathname.startsWith('/create') ||
312+
pathname.startsWith('/find')
311313
}
312314
>
313315
{t('pool')}
314316
</StyledNavLink>
315-
<StyledNavLink id={`stake-nav-link`} to={'/uni'} isActive={() => history.location.pathname.includes('/uni')}>
317+
<StyledNavLink id={`stake-nav-link`} to={'/uni'}>
316318
UNI
317319
</StyledNavLink>
318-
<StyledNavLink
319-
id={`stake-nav-link`}
320-
to={'/vote'}
321-
isActive={() => history.location.pathname.includes('/vote')}
322-
>
320+
<StyledNavLink id={`stake-nav-link`} to={'/vote'}>
323321
Vote
324322
</StyledNavLink>
325323
<StyledExternalLink id={`stake-nav-link`} href={'https://uniswap.info'}>
@@ -344,26 +342,28 @@ function Header({ history }: { history: any }) {
344342
<CardNoise />
345343
</UNIWrapper>
346344
)}
347-
{!availableClaim && aggregateBalance && JSBI.greaterThan(aggregateBalance.raw, JSBI.BigInt(0)) && (
345+
{!availableClaim && aggregateBalance && (
348346
<UNIWrapper onClick={() => setShowUniBalanceModal(true)}>
349347
<UNIAmount active={!!account && !availableClaim} style={{ pointerEvents: 'auto' }}>
350-
<HideSmall>
351-
<TYPE.white
352-
style={{
353-
paddingRight: '.4rem'
354-
}}
355-
>
356-
<CountUp
357-
key={countUpValue}
358-
isCounting
359-
start={parseFloat(countUpValuePrevious)}
360-
end={parseFloat(countUpValue)}
361-
thousandsSeparator={','}
362-
duration={1}
363-
/>
364-
</TYPE.white>
365-
</HideSmall>
366-
{'UNI'}
348+
{account && (
349+
<HideSmall>
350+
<TYPE.white
351+
style={{
352+
paddingRight: '.4rem'
353+
}}
354+
>
355+
<CountUp
356+
key={countUpValue}
357+
isCounting
358+
start={parseFloat(countUpValuePrevious)}
359+
end={parseFloat(countUpValue)}
360+
thousandsSeparator={','}
361+
duration={1}
362+
/>
363+
</TYPE.white>
364+
</HideSmall>
365+
)}
366+
UNI
367367
</UNIAmount>
368368
<CardNoise />
369369
</UNIWrapper>
@@ -385,5 +385,3 @@ function Header({ history }: { history: any }) {
385385
</HeaderFrame>
386386
)
387387
}
388-
389-
export default withRouter(Header)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ChainId, JSBI, Token, TokenAmount } from '@uniswap/sdk'
2+
import { BigNumber } from 'ethers'
3+
import { ZERO_ADDRESS } from '../constants'
4+
import { computeUniCirculation } from './computeUniCirculation'
5+
6+
describe('computeUniCirculation', () => {
7+
const token = new Token(ChainId.RINKEBY, ZERO_ADDRESS, 18)
8+
9+
function expandTo18Decimals(num: JSBI | string | number) {
10+
return JSBI.multiply(JSBI.BigInt(num), JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(18)))
11+
}
12+
13+
function tokenAmount(num: JSBI | string | number) {
14+
return new TokenAmount(token, expandTo18Decimals(num))
15+
}
16+
17+
it('before staking', () => {
18+
expect(computeUniCirculation(token, BigNumber.from(0), undefined)).toEqual(tokenAmount(150_000_000))
19+
expect(computeUniCirculation(token, BigNumber.from(1600387200), undefined)).toEqual(tokenAmount(150_000_000))
20+
})
21+
it('mid staking', () => {
22+
expect(computeUniCirculation(token, BigNumber.from(1600387200 + 15 * 24 * 60 * 60), undefined)).toEqual(
23+
tokenAmount(155_000_000)
24+
)
25+
})
26+
it('after staking and treasury vesting cliff', () => {
27+
expect(computeUniCirculation(token, BigNumber.from(1600387200 + 60 * 24 * 60 * 60), undefined)).toEqual(
28+
tokenAmount(224_575_341)
29+
)
30+
})
31+
it('subtracts unclaimed uni', () => {
32+
expect(computeUniCirculation(token, BigNumber.from(1600387200 + 15 * 24 * 60 * 60), tokenAmount(1000))).toEqual(
33+
tokenAmount(154_999_000)
34+
)
35+
})
36+
})
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,27 @@ function withVesting(before: JSBI, time: BigNumber, amount: number, start: numbe
3838
if (time.gt(start)) {
3939
if (time.gte(end)) {
4040
return JSBI.add(before, JSBI.BigInt(amount))
41-
} else if (cliff && time.gte(cliff)) {
42-
return JSBI.add(
43-
before,
44-
JSBI.divide(
45-
JSBI.multiply(JSBI.BigInt(amount), JSBI.BigInt(time.sub(start).toString())),
46-
JSBI.subtract(JSBI.BigInt(end), JSBI.BigInt(start))
41+
} else {
42+
if ((typeof cliff === 'number' && time.gte(cliff)) || typeof cliff === 'undefined') {
43+
return JSBI.add(
44+
before,
45+
JSBI.divide(
46+
JSBI.multiply(JSBI.BigInt(amount), JSBI.BigInt(time.sub(start).toString())),
47+
JSBI.subtract(JSBI.BigInt(end), JSBI.BigInt(start))
48+
)
4749
)
48-
)
50+
}
4951
}
5052
}
5153
return before
5254
}
5355

54-
export function computeUniCirculation(uni: Token, blockTimestamp: BigNumber): TokenAmount {
55-
let wholeAmount = JSBI.BigInt(USERS_AMOUNT) // users, 15%
56+
export function computeUniCirculation(
57+
uni: Token,
58+
blockTimestamp: BigNumber,
59+
unclaimedUni: TokenAmount | undefined
60+
): TokenAmount {
61+
let wholeAmount = JSBI.BigInt(USERS_AMOUNT)
5662

5763
// staking rewards
5864
wholeAmount = withVesting(wholeAmount, blockTimestamp, STAKING_REWARDS_AMOUNT, STAKING_GENESIS, STAKING_END)
@@ -101,5 +107,6 @@ export function computeUniCirculation(uni: Token, blockTimestamp: BigNumber): To
101107
wholeAmount = withVesting(wholeAmount, blockTimestamp, TEAM_YEAR_3_AMOUNT, TREASURY_BEGIN_YEAR_3, TREASURY_END_YEAR_3)
102108
wholeAmount = withVesting(wholeAmount, blockTimestamp, TEAM_YEAR_4_AMOUNT, TREASURY_BEGIN_YEAR_4, TREASURY_END_YEAR_4)
103109

104-
return new TokenAmount(uni, JSBI.multiply(wholeAmount, JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(18))))
110+
const total = new TokenAmount(uni, JSBI.multiply(wholeAmount, JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(18))))
111+
return unclaimedUni ? total.subtract(unclaimedUni) : total
105112
}

0 commit comments

Comments
 (0)