Skip to content
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
14 changes: 8 additions & 6 deletions processes/apr/forward.convex.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ func calculateConvexForwardAPY(args TCalculateConvexAPYDataStruct) TStrategyAPY
** 3. Adding the pool APY
** 4. Adding the CVX APR
**********************************************************************************************/
keepCRVRatio := bigNumber.NewFloat(0).Sub(storage.ONE, keepCrv) // 1 - keepCRV
grossAPY := bigNumber.NewFloat(0).Mul(crvAPY, keepCRVRatio) // 1 - baseAPY * keepCRV
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, rewardsAPY) // 2 - (baseAPY * keepCRV) + rewardAPR
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, args.poolWeeklyAPY) // 3 - (baseAPY * keepCRV) + rewardAPR + poolAPY
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, cvxAPY) // 4 - (baseAPY * keepCRV) + rewardAPR + poolAPY + cvxAPR
keepCRVRatio := bigNumber.NewFloat(0).Sub(storage.ONE, keepCrv) // 1 - keepCRV
grossAPY := bigNumber.NewFloat(0).Mul(crvAPY, keepCRVRatio) // 1 - baseAPY * keepCRV
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, rewardsAPY) // 2 - (baseAPY * keepCRV) + rewardAPR
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, cvxAPY) // 4 - (baseAPY * keepCRV) + rewardAPR + poolAPY + cvxAPR

/**********************************************************************************************
** Calculate the CRV Net APR:
Expand All @@ -72,8 +71,11 @@ func calculateConvexForwardAPY(args TCalculateConvexAPYDataStruct) TStrategyAPY
netAPY := bigNumber.NewFloat(0).Mul(grossAPY, oneMinusPerfFee) // grossAPR * (1 - perfFee)
if netAPY.Gt(vaultManagementFee) {
netAPY = bigNumber.NewFloat(0).Sub(netAPY, vaultManagementFee) // (grossAPR * (1 - perfFee)) - managementFee
netAPRFloat64, _ := netAPY.Float64()
netAPY = bigNumber.NewFloat(0).SetFloat64(convertFloatAPRToAPY(netAPRFloat64, 52))
netAPY = bigNumber.NewFloat(0).Add(netAPY, args.poolWeeklyAPY)
} else {
netAPY = bigNumber.NewFloat(0)
netAPY = bigNumber.NewFloat(0).Add(bigNumber.NewFloat(0), args.poolWeeklyAPY)
}

apyStruct := TStrategyAPY{
Expand Down
9 changes: 3 additions & 6 deletions processes/apr/forward.convex.helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func getConvexRewardAPY(
totalRewardsAPR = bigNumber.NewFloat(0).Add(totalRewardsAPR, rewardAPR)
}
}
totalRewardsAPRFloat64, _ := totalRewardsAPR.Float64()
totalRewardsAPY := bigNumber.NewFloat(0).SetFloat64(convertFloatAPRToAPY(totalRewardsAPRFloat64, 365/15))
totalRewardsAPY := bigNumber.NewFloat(0).Add(bigNumber.NewFloat(0), totalRewardsAPR)
return totalRewardsAPR, totalRewardsAPY
}

Expand Down Expand Up @@ -220,10 +219,8 @@ func getCVXPoolAPY(
crvAPR = bigNumber.NewFloat(0).Mul(crvPerUnderlyingPerYear, crvPrice)
cvxAPR = bigNumber.NewFloat(0).Mul(cvxPerYear, cvxPrice)

crvAPRFloat64, _ := crvAPR.Float64()
cvxAPRFloat64, _ := cvxAPR.Float64()
crvAPY = bigNumber.NewFloat(0).SetFloat64(convertFloatAPRToAPY(crvAPRFloat64, 365/15))
cvxAPY = bigNumber.NewFloat(0).SetFloat64(convertFloatAPRToAPY(cvxAPRFloat64, 365/15))
crvAPY = bigNumber.NewFloat(0).Add(bigNumber.NewFloat(0), crvAPR)
cvxAPY = bigNumber.NewFloat(0).Add(bigNumber.NewFloat(0), cvxAPR)

return crvAPR, cvxAPR, crvAPY, cvxAPY
}
Expand Down
14 changes: 8 additions & 6 deletions processes/apr/forward.curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func calculateCurveForwardAPY(args TCalculateCurveAPYDataStruct) TStrategyAPY {
** The CRV APR is simply the baseAPR (aka how much CRV we get from the gauge) scaled by the
** yBoost. We then add the extraRewards which are incentives/bribes on top of the base rewards.
**********************************************************************************************/
crvAPY := bigNumber.NewFloat(0).Mul(args.baseAPY, yBoost) // baseAPR * yBoost
crvAPY := bigNumber.NewFloat(0).Mul(args.baseAPY, yBoost) // baseAPR * yBoost
crvAPY = bigNumber.NewFloat(0).Add(crvAPY, args.rewardAPY) // (baseAPR * yBoost) + rewardAPY

/**********************************************************************************************
Expand All @@ -48,10 +48,9 @@ func calculateCurveForwardAPY(args TCalculateCurveAPYDataStruct) TStrategyAPY {
** 3. Adding the pool APY
**********************************************************************************************/
keepCRVRatio := bigNumber.NewFloat(0).Sub(storage.ONE, keepCrv) // 1 - keepCRV
grossAPY := bigNumber.NewFloat(0).Mul(args.baseAPY, yBoost) // 1 - baseAPR * yBoost
grossAPY = bigNumber.NewFloat(0).Mul(grossAPY, keepCRVRatio) // 1 - baseAPR * yBoost * keepCRV
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, args.rewardAPY) // 2 - (baseAPR * yBoost * keepCRV) + rewardAPY
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, args.poolAPY) // 3 - (baseAPR * yBoost * keepCRV) + rewardAPY + poolAPY
grossAPY := bigNumber.NewFloat(0).Mul(args.baseAPY, yBoost) // 1 - baseAPR * yBoost
grossAPY = bigNumber.NewFloat(0).Mul(grossAPY, keepCRVRatio) // 1 - baseAPR * yBoost * keepCRV
grossAPY = bigNumber.NewFloat(0).Add(grossAPY, args.rewardAPY) // 2 - (baseAPR * yBoost * keepCRV) + rewardAPY

/**********************************************************************************************
** Calculate the CRV Net APR:
Expand All @@ -60,8 +59,11 @@ func calculateCurveForwardAPY(args TCalculateCurveAPYDataStruct) TStrategyAPY {
netAPY := bigNumber.NewFloat(0).Mul(grossAPY, oneMinusPerfFee) // grossAPY * (1 - perfFee)
if netAPY.Gt(vaultManagementFee) {
netAPY = bigNumber.NewFloat(0).Sub(netAPY, vaultManagementFee) // (grossAPY * (1 - perfFee)) - managementFee
netAPRFloat64, _ := netAPY.Float64()
netAPY = bigNumber.NewFloat(0).SetFloat64(convertFloatAPRToAPY(netAPRFloat64, 52))
netAPY = bigNumber.NewFloat(0).Add(netAPY, args.poolAPY)
} else {
netAPY = bigNumber.NewFloat(0)
netAPY = bigNumber.NewFloat(0).Add(bigNumber.NewFloat(0), args.poolAPY)
}

apyStruct := TStrategyAPY{
Expand Down
3 changes: 1 addition & 2 deletions processes/apr/forward.curve.helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ func calculateGaugeBaseAPR(
baseAPR = bigNumber.NewFloat(0).Mul(baseAPR, bigNumber.NewFloat(0).Div(perMaxBoost, poolPrice))
baseAPR = bigNumber.NewFloat(0).Mul(baseAPR, crvPrice)
baseAPR = bigNumber.NewFloat(0).Div(baseAPR, baseAssetPrice)
baseAPRFloat64, _ := baseAPR.Float64()
baseAPY := bigNumber.NewFloat(0).SetFloat64(convertFloatAPRToAPY(baseAPRFloat64, 365/15))
baseAPY := bigNumber.NewFloat(0).Add(bigNumber.NewFloat(0), baseAPR)

return baseAPR, baseAPY
}
Expand Down
14 changes: 3 additions & 11 deletions processes/apr/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ import (
"github.com/yearn/ydaemon/common/logs"
)


func convertFloatAPRToAPY(apr float64, periodsPerYear float64) float64 {

// Convert APR to decimal form
aprDecimal := apr / 100.0

// APY = (1 + r/n)^n - 1
// where r is the APR in decimal form and n is the number of compounding periods
apy := math.Pow(1+(aprDecimal/periodsPerYear), periodsPerYear) - 1

// Convert back to percentage
return apy * 100
// APR is expected as a decimal (e.g. 0.56 for 56%).
// APY = (1 + r/n)^n - 1, where r is the APR in decimal form.
return math.Pow(1+(apr/periodsPerYear), periodsPerYear) - 1
}

/**************************************************************************************************
Expand Down