-
Notifications
You must be signed in to change notification settings - Fork 4
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(earn): Add dailyYieldRatePercentage to beefy dataProps response #620
Changes from 5 commits
d1fc0d4
5c1f311
ef67c5b
10d6d31
ba45549
256f67d
865d6f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,7 +21,7 @@ import { beefyV2AppMulticallAbi } from './abis/beefy-v2-app-multicall' | |||||
import { | ||||||
BaseBeefyVault, | ||||||
GovVault, | ||||||
getApys, | ||||||
getApyBreakdown, | ||||||
getBeefyPrices, | ||||||
getBeefyVaults, | ||||||
getTvls, | ||||||
|
@@ -30,7 +30,7 @@ import { TFunction } from 'i18next' | |||||
import { networkIdToNativeAssetAddress } from '../../runtime/isNative' | ||||||
|
||||||
type BeefyPrices = Awaited<ReturnType<typeof getBeefyPrices>> | ||||||
type BeefyApys = Awaited<ReturnType<typeof getApys>> | ||||||
type BeefyApyBreakdown = Awaited<ReturnType<typeof getApyBreakdown>> | ||||||
type BeefyTvls = Awaited<ReturnType<typeof getTvls>> | ||||||
|
||||||
// Fetched addresses from https://github.com/beefyfinance/beefy-v2/blob/main/src/config/config.tsx | ||||||
|
@@ -58,14 +58,14 @@ const beefyAppTokenDefinition = ({ | |||||
networkId, | ||||||
vault, | ||||||
prices, | ||||||
apys, | ||||||
apyBreakdown, | ||||||
tvls, | ||||||
t, | ||||||
}: { | ||||||
networkId: NetworkId | ||||||
vault: BaseBeefyVault | ||||||
prices: BeefyPrices | ||||||
apys: BeefyApys | ||||||
apyBreakdown: BeefyApyBreakdown | ||||||
tvls: BeefyTvls | ||||||
t: TFunction | ||||||
}): AppTokenPositionDefinition => { | ||||||
|
@@ -74,7 +74,7 @@ const beefyAppTokenDefinition = ({ | |||||
vault.tokenAddress?.toLowerCase() ?? | ||||||
networkIdToNativeAssetAddress[networkId] | ||||||
const tvl = tvls[vault.id] | ||||||
const apy = apys[vault.id] | ||||||
const apy = apyBreakdown[vault.id].totalApy || 0 | ||||||
return { | ||||||
type: 'app-token-definition', | ||||||
networkId, | ||||||
|
@@ -132,6 +132,10 @@ const beefyAppTokenDefinition = ({ | |||||
manageUrl: `${BEEFY_VAULT_BASE_URL}${vault.id}`, | ||||||
contractCreatedAt: new Date(vault.createdAt * 1000).toISOString(), | ||||||
claimType: ClaimType.Rewards, | ||||||
dailyYieldRatePercentage: getDailyYieldRatePercentage( | ||||||
apyBreakdown[vault.id], | ||||||
vault, | ||||||
), | ||||||
}, | ||||||
availableShortcutIds: ['deposit', 'withdraw', 'swap-deposit'], | ||||||
shortcutTriggerArgs: ({ tokensByTokenId }) => { | ||||||
|
@@ -160,6 +164,62 @@ const beefyAppTokenDefinition = ({ | |||||
} | ||||||
} | ||||||
|
||||||
// Based on https://github.com/beefyfinance/beefy-v2/blob/4413697f3d3cb5e090d8bb6958b621a673f0d739/src/features/data/actions/apy.ts#L46 | ||||||
function getDailyYieldRatePercentage( | ||||||
apyBreakdown: BeefyApyBreakdown[string], | ||||||
vault: BaseBeefyVault, | ||||||
) { | ||||||
// https://github.com/beefyfinance/beefy-v2/blob/4413697f3d3cb5e090d8bb6958b621a673f0d739/src/helpers/apy.ts#L103 | ||||||
const components = [ | ||||||
'vaultApr', | ||||||
'clmApr', | ||||||
'tradingApr', | ||||||
'merklApr', | ||||||
'stellaSwapApr', | ||||||
'liquidStakingApr', | ||||||
'composablePoolApr', | ||||||
'rewardPoolApr', | ||||||
'rewardPoolTradingApr', | ||||||
] | ||||||
|
||||||
let totalDaily = 0 | ||||||
// Calculate the total daily apy from components | ||||||
if (Object.keys(apyBreakdown).some((key) => components.includes(key))) { | ||||||
for (const component of components) { | ||||||
const apr = apyBreakdown[component] | ||||||
if (apr && !isNaN(Number(apr))) { | ||||||
totalDaily += apr / 365 | ||||||
} | ||||||
} | ||||||
} else { | ||||||
// "uncompound" apy to get daily apr | ||||||
totalDaily = _yearlyToDaily(apyBreakdown.totalApy) | ||||||
} | ||||||
|
||||||
// At some point the Beefy team decided to change this 'rewardPoolApr' on this specific vault type to be a soft-boost | ||||||
// instead of being calculated as regular APR, so to be backwards compatible they subtract it from the total daily APR | ||||||
if (vault.type === 'gov' && vault.subType === 'cowcentrated') { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vault.type itself can be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my comment (and the one about subtype values) was mainly because I was confused why something would have |
||||||
// anything in 'rewardPoolApr' (i.e. not in 'rewardPoolTradingApr') is considered a soft-boost on the pool | ||||||
const additionalApr = apyBreakdown.rewardPoolApr || 0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you did the opposite change 😄 |
||||||
totalDaily -= additionalApr / 365 | ||||||
} | ||||||
|
||||||
// TODO: handle merkl campaigns which are off-chain rewards | ||||||
// https://github.com/beefyfinance/beefy-v2/blob/4413697f3d3cb5e090d8bb6958b621a673f0d739/src/features/data/actions/apy.ts#L132 | ||||||
|
||||||
return totalDaily * 100 | ||||||
} | ||||||
|
||||||
const _yearlyToDaily = (apy: number) => { | ||||||
const dailyApy = Math.pow(10, Math.log10(apy + 1) / 365) - 1 | ||||||
|
||||||
if (isNaN(dailyApy)) { | ||||||
return 0 | ||||||
} | ||||||
|
||||||
return dailyApy | ||||||
} | ||||||
|
||||||
// CLM = Cowcentrated Liquidity Manager: https://docs.beefy.finance/beefy-products/clm | ||||||
interface ClmVaultBalanceInfo { | ||||||
token0: Address | ||||||
|
@@ -232,7 +292,7 @@ const beefyBaseVaultsPositions = async ({ | |||||
vaults, | ||||||
multicallAddress, | ||||||
prices, | ||||||
apys, | ||||||
apyBreakdown, | ||||||
tvls, | ||||||
t, | ||||||
}: { | ||||||
|
@@ -241,7 +301,7 @@ const beefyBaseVaultsPositions = async ({ | |||||
vaults: BaseBeefyVault[] | ||||||
multicallAddress: Address | ||||||
prices: BeefyPrices | ||||||
apys: BeefyApys | ||||||
apyBreakdown: BeefyApyBreakdown | ||||||
tvls: BeefyPrices | ||||||
t: TFunction | ||||||
}) => { | ||||||
|
@@ -310,7 +370,7 @@ const beefyBaseVaultsPositions = async ({ | |||||
networkId, | ||||||
vault, | ||||||
prices, | ||||||
apys, | ||||||
apyBreakdown, | ||||||
tvls, | ||||||
t, | ||||||
}) | ||||||
|
@@ -427,12 +487,13 @@ const hook: PositionsHook = { | |||||
return [] | ||||||
} | ||||||
|
||||||
const [{ vaults, govVaults }, prices, apys, tvls] = await Promise.all([ | ||||||
getBeefyVaults(networkId), | ||||||
getBeefyPrices(networkId), | ||||||
getApys(), | ||||||
getTvls(networkId), | ||||||
]) | ||||||
const [{ vaults, govVaults }, prices, apyBreakdown, tvls] = | ||||||
await Promise.all([ | ||||||
getBeefyVaults(networkId), | ||||||
getBeefyPrices(networkId), | ||||||
getApyBreakdown(), | ||||||
getTvls(networkId), | ||||||
]) | ||||||
|
||||||
return [ | ||||||
...(await beefyBaseVaultsPositions({ | ||||||
|
@@ -441,7 +502,7 @@ const hook: PositionsHook = { | |||||
vaults, | ||||||
multicallAddress, | ||||||
prices, | ||||||
apys, | ||||||
apyBreakdown, | ||||||
tvls, | ||||||
t, | ||||||
})), | ||||||
|
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.
is there a set of values that this can contain? Maybe we can use specific types for
type
andsubType
.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.
It appears there are, they are not all located in one place throughout the code in beefy. What would be the value in adding them in right now though?
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.
I was hoping it would be something like
type
above. Definitely not worth it reading through the code. Also is it optional? I don't see it here for example https://api.beefy.finance/gov-vaults/arbitrum