-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
236 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
46a333e
There was a problem hiding this comment.
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: