forked from pancakeswap/pancake-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Move APY calculator to /components (pancakeswap#875)
* chore(apr-calculator): Move out of views/farm and rename variables/functions * test(apr-calculator): Update tests to use new values
- Loading branch information
Showing
4 changed files
with
32 additions
and
28 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
const roundToTwoDp = (number) => Math.round(number * 100) / 100 | ||
|
||
export const calculateCakeEarnedPerThousandDollars = ({ numberOfDays, farmApy, cakePrice }) => { | ||
export const cakeEarnedPerThousandDollarsCompounding = ({ numberOfDays, farmApr, cakePrice }) => { | ||
// Everything here is worked out relative to a year, with the asset compounding daily | ||
const timesCompounded = 365 | ||
// We use decimal values rather than % in the math for both APY and the number of days being calculates as a proportion of the year | ||
const apyAsDecimal = farmApy / 100 | ||
const aprAsDecimal = farmApr / 100 | ||
const daysAsDecimalOfYear = numberOfDays / timesCompounded | ||
// Calculate the starting CAKE balance with a dollar balance of $1000. | ||
const principal = 1000 / cakePrice | ||
|
||
// This is a translation of the typical mathematical compounding APY formula. Details here: https://www.calculatorsoup.com/calculators/financial/compound-interest-calculator.php | ||
const finalAmount = principal * (1 + apyAsDecimal / timesCompounded) ** (timesCompounded * daysAsDecimalOfYear) | ||
const finalAmount = principal * (1 + aprAsDecimal / timesCompounded) ** (timesCompounded * daysAsDecimalOfYear) | ||
|
||
// To get the cake earned, deduct the amount after compounding (finalAmount) from the starting CAKE balance (principal) | ||
const interestEarned = finalAmount - principal | ||
return roundToTwoDp(interestEarned) | ||
} | ||
|
||
export const apyModalRoi = ({ amountEarned, amountInvested }) => { | ||
export const getRoi = ({ amountEarned, amountInvested }) => { | ||
const percentage = (amountEarned / amountInvested) * 100 | ||
return percentage.toFixed(2) | ||
} |
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