Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add haiVELO deposit strategy #175

Merged
merged 18 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/containers/Earn/StrategyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function StrategyTable({
const baseTokens = rewards.map(({ token }) => token)
const tokens: TokenKey[] =
earnPlatform === 'velodrome' ? ['VELO'] : isAPXETH ? [...baseTokens, 'APXETH'] : baseTokens

return (
<Table.Row
key={i}
Expand All @@ -91,7 +92,11 @@ export function StrategyTable({
</Text>
</Flex>
<RewardsTokenArray
tokens={strategyType == 'hold' ? ['HAI'] : tokens}
tokens={
strategyType == 'hold' || strategyType == 'deposit'
? ['HAI']
: tokens
}
tooltip={
<EarnEmissionTooltip
rewards={rewards}
Expand Down Expand Up @@ -142,7 +147,9 @@ export function StrategyTable({
content: (
<div style={{ flexDirection: 'row', display: 'flex', alignItems: 'center' }}>
<Text $fontWeight={700}>
{apy
{strategyType === 'deposit'
? '40% - 50%'
: apy
? formatNumberWithStyle(apy, {
style: 'percent',
scalingFactor: 100,
Expand Down Expand Up @@ -295,6 +302,20 @@ function EarnEmissionTooltip({ rewards, earnPlatform, earnLink, strategyType }:
)
}

if (strategyType == 'deposit') {
return (
<Flex $width="140px" $column $justify="flex-end" $align="flex-start" $gap={4}>
<Text $fontWeight={700}>
haiVELO depositors receive rewards in HAI based off the rewards the protocol receives from voting on
Velodrome propotional to their amount of haiVELO deposited.
<br />
<br />
Current APY (40% - 50%) is a rough estimate based on the current Velodrome voting rewards.
</Text>
</Flex>
)
}

return (
<Flex $width="140px" $column $justify="flex-end" $align="flex-start" $gap={4}>
<Text $fontWeight={700} $whiteSpace="nowrap">
Expand Down
31 changes: 29 additions & 2 deletions src/hooks/useEarnStrategies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { useStoreState } from '~/store'
import { useVelodromePrices } from '~/providers/VelodromePriceProvider'
import { useVelodrome, useVelodromePositions } from './useVelodrome'
import { useBalance } from '~/hooks'
import { useBalance, useMyVaults, useCollateralStats } from '~/hooks'
import { useAnalytics } from '~/providers/AnalyticsProvider'

const sortableHeaders: SortableHeader[] = [
Expand Down Expand Up @@ -49,6 +49,9 @@ export function useEarnStrategies() {
const { prices: veloPrices } = useVelodromePrices()

const { data, loading, error } = useQuery<{ collateralTypes: QueryCollateralType[] }>(ALL_COLLATERAL_TYPES_QUERY)

const { rows: myVaults } = useMyVaults()

const {
data: uniData,
loading: uniLoading,
Expand Down Expand Up @@ -197,11 +200,27 @@ export function useEarnStrategies() {
const haiBalance = useBalance('HAI')
const analytics = useAnalytics()
const {
data: { erc20Supply, annualRate },
data: { erc20Supply, annualRate, tokenAnalyticsData },
} = analytics
const rRateApr = Number(annualRate.raw)
const rRateApy = Math.pow(1 + rRateApr / 365, 365) - 1

const collateralStats = useCollateralStats()

const haiVeloTVL = collateralStats.rows.find((row) => row.token === 'HAIVELO')?.totalCollateral?.usdRaw ?? '0'

const myHaiVeloParticipation = useMemo(() => {
return (
(myVaults
.filter((vault) => vault.collateralName === 'HAIVELO')
.reduce((acc, vault) => {
return acc + parseFloat(vault.collateral)
}, 0) *
Number(tokenAnalyticsData?.find((token) => token.symbol === 'HAIVELO')?.currentPrice || 0)) /
10 ** 18
)
}, [myVaults])

const specialStrategies = [
{
pair: ['HAI'],
Expand All @@ -211,6 +230,14 @@ export function useEarnStrategies() {
userPosition: haiBalance?.raw,
strategyType: 'hold',
},
{
pair: ['HAIVELO'],
rewards: [],
tvl: haiVeloTVL,
apy: '0',
userPosition: myHaiVeloParticipation,
strategyType: 'deposit',
},
]

const strategies = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/types/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type Strategy = {
tvl: string
apy: number
userPosition?: string
strategyType: 'hold' | 'borrow' | 'farm'
strategyType: 'hold' | 'borrow' | 'farm' | 'deposit'
} & (
| {
earnPlatform?: undefined
Expand Down
Loading