Skip to content

Commit

Permalink
Merge feat/bondPrecommit
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowgh0st committed Mar 1, 2022
2 parents 7135c2a + 030f6fd commit 46a333e
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/artifacts/abi/3poolMetaPool/index.js

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

4 changes: 3 additions & 1 deletion src/artifacts/js/vaderBonds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ const bonds = [
},
},
{
'name': 'Reserve Bond',
'name': 'Reserve Bond 1',
'address':'0x74876acb3D2a007687c285B5A75A0d7b470B3D69',
'precommit': '0x0c6ad91DD183f953389D0bf5687025340a19E6e0',
'precommitzap': '0xdfdbeFa9A5E93a369cd0fCcA7820C5C5caB3082f',
'discount': 0.25,
'token0': {
'name':'ETHER',
'symbol':'ETH',
Expand All @@ -58,6 +59,7 @@ const bonds = [
'address':'0xbea19c6AB7F5C90481147Ad69Ff0De2Dba879b5C',
'precommit': '0x3db19DE4263284c957B09efe53Cb0e7042228C59',
'precommitzap': '0xD936219f3acA9CA1fa675aA69752FaD2BE85A90a',
'discount': 0.5,
'token0': {
'name':'ETHER',
'symbol':'ETH',
Expand Down
21 changes: 20 additions & 1 deletion src/common/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import IUSDV from '../artifacts/abi/IUSDV'
import preCommit from '../artifacts/abi/preCommit'
import preCommitZapAbi from '../artifacts/abi/precommitZap'
import stakingRewards from '../artifacts/abi/stakingRewards'
import threePoolMetaPool from '../artifacts/abi/3poolMetaPool'

const approveERC20ToSpend = async (tokenAddress, spenderAddress, amount, provider) => {
const contract = new ethers.Contract(
Expand Down Expand Up @@ -584,6 +585,24 @@ const getStakingRewardsEarned = async (address) => {
return await contract.earned(address)
}

const getRewardRate = async () => {
const contract = new ethers.Contract(
defaults.address.stakingRewards,
stakingRewards,
defaults.network.provider,
)
return await contract.rewardRate()
}

const getVirtualPrice = async () => {
const contract = new ethers.Contract(
defaults.address.usdv3crvf,
threePoolMetaPool,
defaults.network.provider,
)
return await contract.get_virtual_price()
}

export {
approveERC20ToSpend, getERC20BalanceOf, resolveUnknownERC20,
estimateGasCost, getERC20Allowance,
Expand All @@ -604,5 +623,5 @@ export {
getPreCommitMinAmountIn, getPreCommitTokenIn, getPreCommitTotal,
getPrecommitOpen, preCommitZap, unCommit, stakeForRewards,
getStakingRewards, exitStakingRewards, getStakingRewardsBalanceOf,
getStakingRewardsEarned,
getStakingRewardsEarned, getRewardRate, getVirtualPrice,
}
44 changes: 29 additions & 15 deletions src/components/BondItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const BondItem = (props) => {
const marketPrice = (Number(usdcEth?.pairs?.[0]?.token0Price) * Number(vaderEth?.pairs?.[0]?.token1Price))
const roi = calculateDifference(marketPrice, bondInitPrice)
const roiPercentage = isFinite(roi) ? getPercentage(roi)?.replace('-0', '0') : ''
const preCommit = usePreCommit(props.bond.precommit)
const preCommit = usePreCommit(props?.bond?.precommit)

return (
<>
Expand Down Expand Up @@ -113,24 +113,38 @@ export const BondItem = (props) => {
gridGap='0.7rem'
>
{price && usdcEth?.pairs?.[0]?.token0Price && principalEth?.principalPrice &&
<>
<Tag
fontSize={{ base: '0.67rem', md: '0.83rem' }}
colorScheme='gray'>
{prettifyCurrency(
props.bond.principal ? (Number(ethers.utils.formatUnits(price, 18)) *
(Number(usdcEth?.pairs?.[0]?.token0Price) *
Number(principalEth?.principalPrice))) : (Number(ethers.utils.formatUnits(price, 18)) *
(Number(usdcEth?.pairs?.[0]?.token0Price))),
0, 5)}
</Tag>
</>
<>
<Tag
fontSize={{ base: '0.67rem', md: '0.83rem' }}
colorScheme='gray'>
{prettifyCurrency(
props.bond.principal ? (Number(ethers.utils.formatUnits(price, 18)) *
(Number(usdcEth?.pairs?.[0]?.token0Price) *
Number(principalEth?.principalPrice))) : (Number(ethers.utils.formatUnits(price, 18)) *
(Number(usdcEth?.pairs?.[0]?.token0Price))),
0, 5)}
</Tag>
</>
}
{roiPercentage &&
{((preCommit?.open?.data &&
props?.bond?.discount) ||
(!preCommit?.open?.data &&
roiPercentage > 0)) &&
<Tag
fontSize={{ base: '0.67rem', md: '0.83rem' }}
colorScheme='gray'>
{roiPercentage}
{preCommit?.open?.data &&
props?.bond?.discount &&
<>
{getPercentage(props?.bond?.discount)}
</>
}
{!preCommit?.open?.data &&
roiPercentage &&
<>
{roiPercentage}
</>
}
</Tag>
}
</Flex>
Expand Down
55 changes: 55 additions & 0 deletions src/hooks/useRewardsAPY.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable no-unused-vars */
import { useQuery as useApolloQuery, gql } from '@apollo/client'
import { useQuery } from 'react-query'
import { getRewardRate, getVirtualPrice } from '../common/ethereum'
import defaults from '../common/defaults'
import { useUniswapTWAP } from './useUniswapTWAP'
import { useERC20Balance } from '../hooks/useERC20Balance'
import { utils } from 'ethers'

export const useRewardsAPY = (rpc = true, pollInterval = defaults.api.graphql.pollInterval, staleTime = defaults.api.staleTime) => {

const TWAprice = useUniswapTWAP()
const balance = useERC20Balance(defaults.address.usdv3crvf, defaults.address.stakingRewards)


if (!rpc) {
// GQL 2 DO
}
else {

const virtualPrice = useQuery(`viretualPrice_${defaults.address.usdv3crvf}`,
async () => {
return await getVirtualPrice()
}, {
staleTime: defaults.api.staleTime,
},
)

const rewardRate = useQuery(`rewardRate_${defaults.address.stakingRewards}`,
async () => {
return await getRewardRate()
}, {
staleTime: defaults.api.staleTime,
},
)

if (TWAprice?.data &&
balance?.data &&
virtualPrice?.data &&
rewardRate?.data) {

const year = 31536000
const tvl = balance?.data?.div(virtualPrice?.data)
const price = utils.formatEther(TWAprice?.data)
const rewardRatePerUSDperSecond = utils.formatEther(rewardRate?.data?.div(tvl))

const APRperYear = Number(rewardRatePerUSDperSecond) * year * Number(price)
const APYperYear = ((1 + (APRperYear / year)) ** year) - 1

return APYperYear

}
}

}
33 changes: 33 additions & 0 deletions src/hooks/useRewardsTVL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable no-unused-vars */
import { useQuery as useApolloQuery, gql } from '@apollo/client'
import { useQuery } from 'react-query'
import { getVirtualPrice } from '../common/ethereum'
import defaults from '../common/defaults'
import { useERC20Balance } from './useERC20Balance'

export const useRewardsTVL = (rpc = true, pollInterval = defaults.api.graphql.pollInterval, staleTime = defaults.api.staleTime) => {

const balance = useERC20Balance(defaults.address.usdv3crvf, defaults.address.stakingRewards)

if (!rpc) {
// GQL 2 DO
}
else {

const virtualPrice = useQuery(`viretualPrice_${defaults.address.usdv3crvf}`,
async () => {
return await getVirtualPrice()
}, {
staleTime: defaults.api.staleTime,
},
)

if (balance?.data &&
virtualPrice?.data) {

return balance?.data?.div(virtualPrice?.data)

}
}

}
2 changes: 1 addition & 1 deletion src/hooks/useStakingRewardsBalanceOf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import { useQuery as useApolloQuery, gql } from '@apollo/client'
import { useQuery } from 'react-query'
import { getERC20BalanceOf, getStakingRewardsBalanceOf } from '../common/ethereum'
import { getStakingRewardsBalanceOf } from '../common/ethereum'
import defaults from '../common/defaults'

export const useStakingRewardsBalanceOf = (address, rpc = true, pollInterval = defaults.api.graphql.pollInterval, staleTime = defaults.api.staleTime) => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useStakingRewardsEarned.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import { useQuery as useApolloQuery, gql } from '@apollo/client'
import { useQuery } from 'react-query'
import { getERC20BalanceOf, getStakingRewardsBalanceOf } from '../common/ethereum'
import { getStakingRewardsEarned } from '../common/ethereum'
import defaults from '../common/defaults'

export const useStakingRewardsEarned = (address, rpc = true, pollInterval = defaults.api.graphql.pollInterval, staleTime = defaults.api.staleTime) => {
Expand All @@ -14,7 +14,7 @@ export const useStakingRewardsEarned = (address, rpc = true, pollInterval = defa
const earned = useQuery(`${defaults.address.stakingRewards}_stakingRewardsEarned_${address}`,
async () => {
if (address) {
return await getStakingRewardsBalanceOf(
return await getStakingRewardsEarned(
address,
)
}
Expand Down
Loading

1 comment on commit 46a333e

@vercel
Copy link

@vercel vercel bot commented on 46a333e Mar 1, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.