Skip to content

Commit

Permalink
EdenApr and externalApr calculation forward looking (#604)
Browse files Browse the repository at this point in the history
* edenApr and externalApr calculation forward looking

* fix GetDailyRewardsAmountForPool
  • Loading branch information
jelysn authored Jun 21, 2024
1 parent 3274b6c commit 221ed1f
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 1,547 deletions.
24 changes: 13 additions & 11 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42247,10 +42247,10 @@ paths:
title: Eden APR, updated at every distribution
dex_apr:
type: string
title: Dex APR, updated at every distribution
title: Dex APR, updated based on 24hr accumulation
gas_apr:
type: string
title: Gas APR, updated at every distribution
title: Gas APR, updated based on 24hr accumulation
external_incentive_apr:
type: string
title: External Incentive APR, updated at every distribution
Expand Down Expand Up @@ -44842,7 +44842,7 @@ paths:
type: string
tags:
- Query
/elys-network/elys/tier/leverage_lp_total/{user}/{realtime}:
/elys-network/elys/tier/leverage_lp_total/{user}:
get:
summary: Queries a list of LeverageLpTotal items.
operationId: ElysTierLeverageLpTotal
Expand All @@ -44851,6 +44851,9 @@ paths:
description: A successful response.
schema:
type: object
properties:
total:
type: string
default:
description: An unexpected error response.
schema:
Expand All @@ -44874,10 +44877,6 @@ paths:
in: path
required: true
type: string
- name: realtime
in: path
required: true
type: boolean
tags:
- Query
/elys-network/elys/tokenomics/airdrop:
Expand Down Expand Up @@ -87438,10 +87437,10 @@ definitions:
title: Eden APR, updated at every distribution
dex_apr:
type: string
title: Dex APR, updated at every distribution
title: Dex APR, updated based on 24hr accumulation
gas_apr:
type: string
title: Gas APR, updated at every distribution
title: Gas APR, updated based on 24hr accumulation
external_incentive_apr:
type: string
title: External Incentive APR, updated at every distribution
Expand Down Expand Up @@ -87583,10 +87582,10 @@ definitions:
title: Eden APR, updated at every distribution
dex_apr:
type: string
title: Dex APR, updated at every distribution
title: Dex APR, updated based on 24hr accumulation
gas_apr:
type: string
title: Gas APR, updated at every distribution
title: Gas APR, updated based on 24hr accumulation
external_incentive_apr:
type: string
title: External Incentive APR, updated at every distribution
Expand Down Expand Up @@ -89209,6 +89208,9 @@ definitions:
type: string
elys.tier.QueryLeverageLpTotalResponse:
type: object
properties:
total:
type: string
elys.tier.QueryParamsResponse:
type: object
properties:
Expand Down
45 changes: 0 additions & 45 deletions proto/elys/masterchef/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,3 @@ message SupportedRewardDenom {
(gogoproto.nullable) = false
];
}

message LegacyDexRewardsTracker {
// Number of blocks since start of epoch (distribution epoch)
string num_blocks = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// Accumulated amount at distribution epoch - recalculated at every
// distribution epoch
string amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// Params defines the parameters for the module.
message LegacyParams {
option (gogoproto.goproto_stringer) = false;
IncentiveInfo lp_incentives = 1;

// gas fees and swap fees portion for lps, `100 - reward_portion_for_lps -
// reward_portion_for_stakers = revenue percent for protocol`.
string reward_portion_for_lps = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// gas fees and swap fees portion for stakers, `100 - reward_portion_for_lps -
// reward_portion_for_stakers = revenue percent for protocol`.
string reward_portion_for_stakers = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Tracking dex rewards given to LPs
LegacyDexRewardsTracker dex_rewards_lps = 4 [ (gogoproto.nullable) = false ];

// Maximum eden reward apr for lps - [0 - 0.3]
string max_eden_reward_apr_lps = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
repeated SupportedRewardDenom supported_reward_denoms = 6;
string protocol_revenue_address = 7;
}
38 changes: 2 additions & 36 deletions proto/elys/masterchef/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ message PoolInfo {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Dex APR, updated at every distribution
// Dex APR, updated based on 24hr accumulation
string dex_apr = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Gas APR, updated at every distribution
// Gas APR, updated based on 24hr accumulation
string gas_apr = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
Expand Down Expand Up @@ -79,37 +79,3 @@ message PoolRewardsAccum {
(gogoproto.nullable) = false
];
}

message LegacyPoolInfo {
uint64 pool_id = 1;
string reward_wallet = 2;
string multiplier = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string num_blocks = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string dex_reward_amount_given = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string eden_reward_amount_given = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string eden_apr = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string dex_apr = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string external_incentive_apr = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
repeated string external_reward_denoms = 10;
}
2 changes: 1 addition & 1 deletion x/incentive/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (k Keeper) GetDailyRewardsAmountForPool(ctx sdk.Context, poolId uint64) (sd
dailyGasRewardsTotal := math.LegacyZeroDec()
dailyEdenRewardsTotal := math.LegacyZeroDec()
firstAccum := k.masterchef.FirstPoolRewardsAccum(ctx, poolId)
lastAccum := k.masterchef.FirstPoolRewardsAccum(ctx, poolId)
lastAccum := k.masterchef.LastPoolRewardsAccum(ctx, poolId)
if lastAccum.Timestamp != 0 {
if firstAccum.Timestamp == lastAccum.Timestamp {
dailyDexRewardsTotal = lastAccum.DexReward
Expand Down
18 changes: 7 additions & 11 deletions x/masterchef/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ func (k Keeper) UpdateLPRewards(ctx sdk.Context) error {
}
k.DeletePoolRewardsAccum(ctx, firstAccum)
}

pool.EdenApr = newEdenAllocatedForPool.
MulInt64(totalBlocksPerYear).
Mul(edenDenomPrice).
Quo(tvl)

k.SetPool(ctx, pool)
}

// Update APR for amm pools
Expand Down Expand Up @@ -547,11 +554,6 @@ func (k Keeper) UpdateAmmPoolAPR(ctx sdk.Context, totalBlocksPerYear int64, tota
MulInt64(totalBlocksPerYear).
Mul(usdcDenomPrice).
Quo(tvl)

poolInfo.EdenApr = lastAccum.EdenReward.
MulInt(sdk.NewInt(totalBlocksPerYear)).
Mul(edenDenomPrice).
Quo(tvl)
} else {
duration := lastAccum.Timestamp - firstAccum.Timestamp
secondsInYear := int64(86400 * 360)
Expand All @@ -567,12 +569,6 @@ func (k Keeper) UpdateAmmPoolAPR(ctx sdk.Context, totalBlocksPerYear int64, tota
QuoInt64(int64(duration)).
Mul(usdcDenomPrice).
Quo(tvl)

poolInfo.EdenApr = lastAccum.EdenReward.Sub(firstAccum.EdenReward).
MulInt64(secondsInYear).
QuoInt64(int64(duration)).
Mul(edenDenomPrice).
Quo(tvl)
}
k.SetPool(ctx, poolInfo)
return false
Expand Down
13 changes: 0 additions & 13 deletions x/masterchef/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,3 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
b := k.cdc.MustMarshal(&params)
store.Set([]byte(types.ParamsKey), b)
}

// GetParams get all parameters as types.Params
func (k Keeper) GetLegacyParams(ctx sdk.Context) (params types.LegacyParams) {
store := ctx.KVStore(k.storeKey)

b := store.Get([]byte(types.ParamsKey))
if b == nil {
return
}

k.cdc.MustUnmarshal(b, &params)
return
}
15 changes: 0 additions & 15 deletions x/masterchef/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,3 @@ func (k Keeper) UpdatePoolMultipliers(ctx sdk.Context, poolMultipliers []types.P

return true
}

func (k Keeper) GetAllLegacyPools(ctx sdk.Context) (list []types.LegacyPoolInfo) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoolInfoKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.LegacyPoolInfo
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}
28 changes: 0 additions & 28 deletions x/masterchef/migrations/v2_migration.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
package migrations

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/masterchef/types"
)

func (m Migrator) V2Migration(ctx sdk.Context) error {
// migrate params
legacy := m.keeper.GetLegacyParams(ctx)
params := types.NewParams(
legacy.LpIncentives,
legacy.RewardPortionForLps,
legacy.RewardPortionForStakers,
legacy.MaxEdenRewardAprLps,
legacy.ProtocolRevenueAddress,
)
m.keeper.SetParams(ctx, params)

// migrate pools
legacyPools := m.keeper.GetAllLegacyPools(ctx)
for _, legacyPool := range legacyPools {
m.keeper.SetPool(ctx, types.PoolInfo{
PoolId: legacyPool.PoolId,
RewardWallet: legacyPool.RewardWallet,
Multiplier: legacyPool.Multiplier,
EdenApr: legacyPool.EdenApr,
DexApr: legacyPool.DexApr,
GasApr: math.LegacyZeroDec(),
ExternalIncentiveApr: legacyPool.ExternalIncentiveApr,
ExternalRewardDenoms: legacyPool.ExternalRewardDenoms,
})
}

return nil
}
6 changes: 0 additions & 6 deletions x/masterchef/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,3 @@ func validateDexRewardsLps(i interface{}) error {

return nil
}

// String implements the Stringer interface.
func (p LegacyParams) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
Loading

0 comments on commit 221ed1f

Please sign in to comment.