Skip to content

Commit

Permalink
fix: forwardAPR with fees
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 17, 2023
1 parent 9eeae99 commit a51d9f4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
24 changes: 15 additions & 9 deletions common/env/chain.ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ var ETHEREUM = TChain{
common.HexToAddress("0xD725F5742047B4B4A3110D0b38284227fcaB041e"), // LP Yearn BAL Vault - Disabled for now
common.HexToAddress("0xD61e198e139369a40818FE05F5d5e6e045Cd6eaF"), // Balancer yBAL Stable Pool - Disabled for now
//
// common.HexToAddress(`0x39CAF13a104FF567f71fd2A4c68C026FDB6E740B`),
// common.HexToAddress(`0x4560b99C904aAD03027B5178CCa81584744AC01f`),
// common.HexToAddress(`0x5c0A86A32c129538D62C106Eb8115a8b02358d57`),
// common.HexToAddress(`0x2D5D4869381C4Fce34789BC1D38aCCe747E295AE`),
// common.HexToAddress(`0xd88dBBA3f9c4391Ee46f5FF548f289054db6E51C`),
// common.HexToAddress(`0xC4dAf3b5e2A9e93861c3FBDd25f1e943B8D87417`),
// common.HexToAddress(`0x801Ab06154Bf539dea4385a39f5fa8534fB53073`),
// common.HexToAddress(`0xF59D66c1d593Fb10e2f8c2a6fD2C958792434B9c`),
// common.HexToAddress(`0x341bb10D8f5947f3066502DC8125d9b8949FD3D6`),
// common.HexToAddress(`0x39CAF13a104FF567f71fd2A4c68C026FDB6E740B`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x4560b99C904aAD03027B5178CCa81584744AC01f`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x5c0A86A32c129538D62C106Eb8115a8b02358d57`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x2D5D4869381C4Fce34789BC1D38aCCe747E295AE`), //DebtRatio 0 - To retire
// common.HexToAddress(`0xd88dBBA3f9c4391Ee46f5FF548f289054db6E51C`), //DebtRatio 0 - To retire
// common.HexToAddress(`0xC4dAf3b5e2A9e93861c3FBDd25f1e943B8D87417`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x801Ab06154Bf539dea4385a39f5fa8534fB53073`), //DebtRatio 0 - To retire
// common.HexToAddress(`0xF59D66c1d593Fb10e2f8c2a6fD2C958792434B9c`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x341bb10D8f5947f3066502DC8125d9b8949FD3D6`), //DebtRatio 0 - To retire
// common.HexToAddress(`0xb4D1Be44BfF40ad6e506edf43156577a3f8672eC`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x7AB4a7BE740131BdE216521B54ADddD672F44A05`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x59518884EeBFb03e90a18ADBAAAB770d4666471e`), //DebtRatio 0 - To retire
// common.HexToAddress(`0xdb25cA703181E7484a155DD612b06f57E12Be5F0`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x1b905331F7dE2748F4D6a0678e1521E20347643F`), //DebtRatio 0 - To retire
// common.HexToAddress(`0x9d409a0A012CFbA9B15F6D4B36Ac57A46966Ab9a`), //DebtRatio 0 - To retire
},
ExtraTokens: []common.Address{
common.HexToAddress("0x34fe2a45D8df28459d7705F37eD13d7aE4382009"), // yvWBTC
Expand Down
4 changes: 2 additions & 2 deletions external/vaults/route.vaults.allchains.simplified.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func (y Controller) GetAllVaultsForAllChainsSimplified(c *gin.Context) {
**
** limit: A uint64 value that represents the number of vaults to be returned per page. It is
** obtained from the 'limit' query parameter in the request. If the parameter is not provided,
** it defaults to 50.
** it defaults to 200.
**************************************************************************************************/
page := helpers.SafeStringToUint64(getQuery(c, `page`), 1)
limit := helpers.SafeStringToUint64(getQuery(c, `limit`), 50)
limit := helpers.SafeStringToUint64(getQuery(c, `limit`), 200)

/** 🔵 - Yearn *************************************************************************************
** chainsStr: A string that represents the chain IDs for which the vaults are to be returned. It is
Expand Down
8 changes: 6 additions & 2 deletions processes/apy/forward.convex.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ func calculateConvexForwardAPR(args TCalculateConvexAPYDataStruct) TStrategyAPR
** Calculate the CRV Net APR:
** Take the gross APR and remove the performance fee and the management fee
**********************************************************************************************/
netAPR := bigNumber.NewFloat(0).Mul(grossAPR, oneMinusPerfFee)
netAPR = bigNumber.NewFloat(0).Sub(netAPR, vaultManagementFee)
netAPR := bigNumber.NewFloat(0).Mul(grossAPR, oneMinusPerfFee) // grossAPR * (1 - perfFee)
if netAPR.Gt(vaultManagementFee) {
netAPR = bigNumber.NewFloat(0).Sub(netAPR, vaultManagementFee) // (grossAPR * (1 - perfFee)) - managementFee
} else {
netAPR = bigNumber.NewFloat(0)
}

apyStruct := TStrategyAPR{
Type: "convex",
Expand Down
6 changes: 5 additions & 1 deletion processes/apy/forward.curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func calculateCurveForwardAPR(args TCalculateCurveAPYDataStruct) TStrategyAPR {
** Take the gross APR and remove the performance fee and the management fee
**********************************************************************************************/
netAPR := bigNumber.NewFloat(0).Mul(grossAPR, oneMinusPerfFee) // grossAPR * (1 - perfFee)
netAPR = bigNumber.NewFloat(0).Sub(netAPR, vaultManagementFee) // (grossAPR * (1 - perfFee)) - managementFee
if netAPR.Gt(vaultManagementFee) {
netAPR = bigNumber.NewFloat(0).Sub(netAPR, vaultManagementFee) // (grossAPR * (1 - perfFee)) - managementFee
} else {
netAPR = bigNumber.NewFloat(0)
}

/**********************************************************************************************
** Calculate the final boost
Expand Down
6 changes: 1 addition & 5 deletions processes/apy/forward.curve.helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ import (
** TLDR; check if name contains curve or convex
**************************************************************************************************/
func isCurveVault(strategies []*models.TStrategy) bool {
if len(strategies) > 3 {
return false
}
isCurveOrConvexStrategy := false
for _, strategy := range strategies {
strategyName := strings.ToLower(strategy.Name)
if strings.Contains(strategyName, `curve`) || strings.Contains(strategyName, `convex`) {
if strings.Contains(strategyName, `curve`) || strings.Contains(strategyName, `convex`) && strategy.DebtRatio.Gt(bigNumber.NewInt(0)) {
isCurveOrConvexStrategy = true
break
}
Expand Down Expand Up @@ -197,7 +194,6 @@ func calculateCurveLikeStrategyAPR(

if subgraphItem.LatestWeeklyApy == 0 {
logs.Warning(`No APY data for vault ` + vault.Address.Hex())
// return TStrategyAPR{}
}

/**********************************************************************************************
Expand Down
6 changes: 5 additions & 1 deletion processes/apy/forward.velodrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func calculateVeloLikeStrategyAPR(
** Take the gross APR and remove the performance fee and the management fee
**********************************************************************************************/
netAPR := bigNumber.NewFloat(0).Mul(grossAPR, oneMinusPerfFee) // grossAPR * (1 - perfFee)
netAPR = bigNumber.NewFloat(0).Sub(netAPR, vaultManagementFee) // (grossAPR * (1 - perfFee)) - managementFee
if netAPR.Gt(vaultManagementFee) {
netAPR = bigNumber.NewFloat(0).Sub(netAPR, vaultManagementFee) // (grossAPR * (1 - perfFee)) - managementFee
} else {
netAPR = bigNumber.NewFloat(0)
}

/**********************************************************************************************
** Calculate the strategy Net APY:
Expand Down

0 comments on commit a51d9f4

Please sign in to comment.