Skip to content

Instantly share code, notes, and snippets.

@korrio
Created October 11, 2021 15:59
Show Gist options
  • Select an option

  • Save korrio/516330275583b7c230c3855b8aa162af to your computer and use it in GitHub Desktop.

Select an option

Save korrio/516330275583b7c230c3855b8aa162af to your computer and use it in GitHub Desktop.
apr-fee.js
const aprToApy = (apr, frequency = BLOCKS_IN_A_YEAR) => ((1 + apr / 100 / frequency) ** frequency - 1) * 100
const feeApyPerYear = aprToApy((((((pairVolumeUSD - (pair1wVolumeUSD ?? 0)) * 0.0025) / 7) * 365) / pairReserveUSD) * 100, 3650) / 100
const feeApyPerMonth = feeApyPerYear / 12
const feeApyPerDay = feeApyPerMonth / 30
const feeApyPerHour = feeApyPerDay / blocksPerHour
const sushiPerBlock = pool?.owner?.sushiPerBlock / 1e18 ||
(pool?.owner?.sushiPerSecond / 1e18) * averageBlockTime ||
masterChefV1SushiPerBlock
const baseRewardPerBlock = (pool.allocPoint / pool.owner.totalAllocPoint) * sushiPerBlock
const rewardPerBlock = isMasterChefV1BonusActive ? baseRewardPerBlock * (masterChefV1BonusMultiplier ?? 1) : baseRewardPerBlock
const defaultReward = {
token: 'xVUSD',
icon: 'https://x.vonderswap.finance/xVUSD.png',
rewardPerBlock,
rewardPerDay: rewardPerBlock * blocksPerDay,
rewardPrice: 1,
}
const roiPerBlock =
rewards.reduce((previousValue, currentValue) => {
return previousValue + currentValue.rewardPerBlock * currentValue.rewardPrice
}, 0) / tvl
const rewardAprPerHour = roiPerBlock * blocksPerHour
const rewardAprPerDay = rewardAprPerHour * 24
const rewardAprPerMonth = rewardAprPerDay * 30
const rewardAprPerYear = rewardAprPerMonth * 12
const roiPerHour = rewardAprPerHour + feeApyPerHour
const roiPerMonth = rewardAprPerMonth + feeApyPerMonth
const roiPerDay = rewardAprPerDay + feeApyPerDay
const roiPerYear = rewardAprPerYear + feeApyPerYear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment