Skip to content

Commit

Permalink
Revert "Incentive module refactoring" (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond authored Jan 23, 2024
1 parent e3acaba commit 42e7532
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 159 deletions.
80 changes: 14 additions & 66 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39454,53 +39454,6 @@ paths:
type: boolean
tags:
- Query
/elys-network/elys/incentive/apr/{withdraw_type}/{denom}:
get:
summary: Calculate APR
operationId: ElysIncentiveApr
responses:
'200':
description: A successful response.
schema:
type: object
properties:
apr:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: withdraw_type
in: path
required: true
type: string
enum:
- ALL_PROGRAM
- USDC_PROGRAM
- ELYS_PROGRAM
- EDEN_PROGRAM
- EDENB_PROGRAM
- name: denom
in: path
required: true
type: string
tags:
- Query
/elys-network/elys/incentive/community_pool:
get:
summary: Queries a list of CommunityPool items.
Expand Down Expand Up @@ -39578,9 +39531,9 @@ paths:
total_blocks_per_year:
type: string
title: distribution duration - block number per year
epoch_num_blocks:
allocation_epoch_in_blocks:
type: string
title: we set block count in 24 hrs
title: we set block numbers in 24 hrs
max_eden_per_allocation:
type: string
title: >-
Expand Down Expand Up @@ -39610,9 +39563,9 @@ paths:
total_blocks_per_year:
type: string
title: distribution duration - block number per year
epoch_num_blocks:
allocation_epoch_in_blocks:
type: string
title: we set block count in 24 hrs
title: we set block numbers in 24 hrs
max_eden_per_allocation:
type: string
title: >-
Expand Down Expand Up @@ -83984,9 +83937,9 @@ definitions:
total_blocks_per_year:
type: string
title: distribution duration - block number per year
epoch_num_blocks:
allocation_epoch_in_blocks:
type: string
title: we set block count in 24 hrs
title: we set block numbers in 24 hrs
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
Expand Down Expand Up @@ -84031,9 +83984,9 @@ definitions:
total_blocks_per_year:
type: string
title: distribution duration - block number per year
epoch_num_blocks:
allocation_epoch_in_blocks:
type: string
title: we set block count in 24 hrs
title: we set block numbers in 24 hrs
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
Expand Down Expand Up @@ -84061,9 +84014,9 @@ definitions:
total_blocks_per_year:
type: string
title: distribution duration - block number per year
epoch_num_blocks:
allocation_epoch_in_blocks:
type: string
title: we set block count in 24 hrs
title: we set block numbers in 24 hrs
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
Expand Down Expand Up @@ -84200,11 +84153,6 @@ definitions:
format: uint64
multiplier:
type: string
elys.incentive.QueryAprResponse:
type: object
properties:
apr:
type: string
elys.incentive.QueryCommunityPoolResponse:
type: object
properties:
Expand Down Expand Up @@ -84244,9 +84192,9 @@ definitions:
total_blocks_per_year:
type: string
title: distribution duration - block number per year
epoch_num_blocks:
allocation_epoch_in_blocks:
type: string
title: we set block count in 24 hrs
title: we set block numbers in 24 hrs
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
Expand Down Expand Up @@ -84274,9 +84222,9 @@ definitions:
total_blocks_per_year:
type: string
title: distribution duration - block number per year
epoch_num_blocks:
allocation_epoch_in_blocks:
type: string
title: we set block count in 24 hrs
title: we set block numbers in 24 hrs
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
Expand Down
4 changes: 2 additions & 2 deletions proto/elys/incentive/incentive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ message IncentiveInfo {
// distribution duration - block number per year
string total_blocks_per_year = 3
[ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
// we set block count in 24 hrs
string epoch_num_blocks = 4
// we set block numbers in 24 hrs
string allocation_epoch_in_blocks = 4
[ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
// maximum eden allocation per day that won't exceed 30% apr
string max_eden_per_allocation = 5
Expand Down
14 changes: 7 additions & 7 deletions x/incentive/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {

// ------------- LP Incentive parameter -------------
// ptypes.DaysPerYear is guaranteed to be positive as it is defined as a constant
EpochNumBlocks := totalBlocksPerYear.Quo(sdk.NewInt(ptypes.DaysPerYear))
allocationEpochInblocks := totalBlocksPerYear.Quo(sdk.NewInt(ptypes.DaysPerYear))
totalDistributionEpochPerYear := totalBlocksPerYear.Quo(sdk.NewInt(params.DistributionEpochForLpsInBlocks))
// If totalDistributionEpochPerYear is zero, we skip this inflation to avoid division by zero
if totalBlocksPerYear == sdk.ZeroInt() {
continue
}
currentEpochInBlocks := sdk.NewInt(ctx.BlockHeight() - int64(inflation.StartBlockHeight)).Mul(totalDistributionEpochPerYear).Quo(totalBlocksPerYear)
maxEdenPerAllocation := sdk.NewInt(int64(inflation.Inflation.LmRewards)).Mul(EpochNumBlocks).Quo(totalBlocksPerYear)
maxEdenPerAllocation := sdk.NewInt(int64(inflation.Inflation.LmRewards)).Mul(allocationEpochInblocks).Quo(totalBlocksPerYear)
incentiveInfo := types.IncentiveInfo{
// reward amount in eden for 1 year
EdenAmountPerYear: sdk.NewInt(int64(inflation.Inflation.LmRewards)),
Expand All @@ -121,7 +121,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
// distribution duration - block number per year
TotalBlocksPerYear: totalBlocksPerYear,
// we set block numbers in 24 hrs
EpochNumBlocks: EpochNumBlocks,
AllocationEpochInBlocks: allocationEpochInblocks,
// maximum eden allocation per day that won't exceed 30% apr
MaxEdenPerAllocation: maxEdenPerAllocation,
// number of block intervals that distribute rewards.
Expand All @@ -144,15 +144,15 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
params.LpIncentives[0].EdenAmountPerYear = incentiveInfo.EdenAmountPerYear
params.LpIncentives[0].DistributionStartBlock = incentiveInfo.DistributionStartBlock
params.LpIncentives[0].TotalBlocksPerYear = incentiveInfo.TotalBlocksPerYear
params.LpIncentives[0].EpochNumBlocks = incentiveInfo.EpochNumBlocks
params.LpIncentives[0].AllocationEpochInBlocks = incentiveInfo.AllocationEpochInBlocks
params.LpIncentives[0].DistributionEpochInBlocks = incentiveInfo.DistributionEpochInBlocks
params.LpIncentives[0].EdenBoostApr = incentiveInfo.EdenBoostApr
}

// ------------- Stakers parameter -------------
totalDistributionEpochPerYear = totalBlocksPerYear.Quo(sdk.NewInt(params.DistributionEpochForStakersInBlocks))
currentEpochInBlocks = sdk.NewInt(ctx.BlockHeight() - int64(inflation.StartBlockHeight)).Mul(totalDistributionEpochPerYear).Quo(totalBlocksPerYear)
maxEdenPerAllocation = sdk.NewInt(int64(inflation.Inflation.IcsStakingRewards)).Mul(EpochNumBlocks).Quo(totalBlocksPerYear)
maxEdenPerAllocation = sdk.NewInt(int64(inflation.Inflation.IcsStakingRewards)).Mul(allocationEpochInblocks).Quo(totalBlocksPerYear)
incentiveInfo = types.IncentiveInfo{
// reward amount in eden for 1 year
EdenAmountPerYear: sdk.NewInt(int64(inflation.Inflation.IcsStakingRewards)),
Expand All @@ -161,7 +161,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
// distribution duration - block number per year
TotalBlocksPerYear: totalBlocksPerYear,
// we set block numbers in 24 hrs
EpochNumBlocks: EpochNumBlocks,
AllocationEpochInBlocks: allocationEpochInblocks,
// maximum eden allocation per day that won't exceed 30% apr
MaxEdenPerAllocation: maxEdenPerAllocation,
// number of block intervals that distribute rewards.
Expand All @@ -184,7 +184,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
params.StakeIncentives[0].EdenAmountPerYear = incentiveInfo.EdenAmountPerYear
params.StakeIncentives[0].DistributionStartBlock = incentiveInfo.DistributionStartBlock
params.StakeIncentives[0].TotalBlocksPerYear = incentiveInfo.TotalBlocksPerYear
params.StakeIncentives[0].EpochNumBlocks = incentiveInfo.EpochNumBlocks
params.StakeIncentives[0].AllocationEpochInBlocks = incentiveInfo.AllocationEpochInBlocks
params.StakeIncentives[0].DistributionEpochInBlocks = incentiveInfo.DistributionEpochInBlocks
params.StakeIncentives[0].EdenBoostApr = incentiveInfo.EdenBoostApr
}
Expand Down
38 changes: 19 additions & 19 deletions x/incentive/keeper/apr.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk
// Calculate stable stake pool share.
poolShare := k.CalculatePoolShareForStableStakeLPs(ctx, totalProxyTVL, baseCurrency)

// Eden amount for LP in 24hrs = EpochNumBlocks is the number of block for 24 hrs
epochEdenAmount := lpIncentive.EdenAmountPerYear.Mul(lpIncentive.EpochNumBlocks).Quo(lpIncentive.TotalBlocksPerYear)
// Eden amount for LP in 24hrs = AllocationEpochInBlocks is the number of block for 24 hrs
edenAmountPerDay := lpIncentive.EdenAmountPerYear.Mul(lpIncentive.AllocationEpochInBlocks).Quo(lpIncentive.TotalBlocksPerYear)

epochLpsMaxEdenAmount := params.MaxEdenRewardAprLps.Mul(totalProxyTVL).MulInt(lpIncentive.EpochNumBlocks).QuoInt(lpIncentive.TotalBlocksPerYear)
maxEdenAmountPerLps := params.MaxEdenRewardAprLps.Mul(totalProxyTVL).MulInt(lpIncentive.AllocationEpochInBlocks).QuoInt(lpIncentive.TotalBlocksPerYear)

// Use min amount (eden allocation from tokenomics and max apr based eden amount)
epochEdenAmount = sdk.MinInt(epochEdenAmount, epochLpsMaxEdenAmount.TruncateInt())
edenAmountPerDay = sdk.MinInt(edenAmountPerDay, maxEdenAmountPerLps.TruncateInt())

// Eden amount for stable stake LP in 24hrs
epochStableStakeEdenAmount := sdk.NewDecFromInt(epochEdenAmount).Mul(poolShare)
edenAmountPerStableStakePerDay := sdk.NewDecFromInt(edenAmountPerDay).Mul(poolShare)

// Calc Eden price in usdc
// We put Elys as denom as Eden won't be avaialble in amm pool and has the same value as Elys
Expand All @@ -66,7 +66,7 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk

// Eden Apr for usdc earn program = {(Eden allocated for stable stake pool per day*365*price{eden/usdc}/(total usdc deposit)}*100
// we divide 100000 as we have use 100000elys as input in the price estimation
apr := epochStableStakeEdenAmount.
apr := edenAmountPerStableStakePerDay.
MulInt(sdk.NewInt(ptypes.DaysPerYear)).
MulInt(edenPrice).
MulInt(sdk.NewInt(100)).
Expand All @@ -86,22 +86,22 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk
}

// Calculate
epochStakersEdenAmount := stkIncentive.EdenAmountPerYear.
Mul(stkIncentive.EpochNumBlocks).
edenAmountPerEpochStakersPerDay := stkIncentive.EdenAmountPerYear.
Mul(stkIncentive.AllocationEpochInBlocks).
Quo(stkIncentive.TotalBlocksPerYear)

// Maximum eden based per distribution epoch on maximum APR - 30% by default
// Allocated for staking per day = (0.3/365)* ( total elys staked + total Eden committed + total Eden boost committed)
epochStakersMaxEdenAmount := params.MaxEdenRewardAprStakers.
maxEdenAmountPerStakers := params.MaxEdenRewardAprStakers.
MulInt(totalStakedSnapshot).
MulInt(stkIncentive.EpochNumBlocks).
MulInt(stkIncentive.AllocationEpochInBlocks).
QuoInt(stkIncentive.TotalBlocksPerYear)

// Use min amount (eden allocation from tokenomics and max apr based eden amount)
epochStakersEdenAmount = sdk.MinInt(epochStakersEdenAmount, epochStakersMaxEdenAmount.TruncateInt())
edenAmountPerEpochStakersPerDay = sdk.MinInt(edenAmountPerEpochStakersPerDay, maxEdenAmountPerStakers.TruncateInt())

// For Eden reward Apr for elys staking = {(amount of Eden allocated for staking per day)*365/( total elys staked + total Eden committed + total Eden boost committed)}*100
apr := epochStakersEdenAmount.
apr := edenAmountPerEpochStakersPerDay.
Mul(sdk.NewInt(ptypes.DaysPerYear)).
Mul(sdk.NewInt(100)).
Quo(totalStakedSnapshot)
Expand All @@ -116,8 +116,8 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk
} else {
// Elys staking, Eden committed, EdenB committed.
params := k.GetParams(ctx)
amount := params.DexRewardsStakers.Amount
if amount.IsZero() {
amt := params.DexRewardsStakers.Amount
if amt.IsZero() {
return sdk.ZeroInt(), nil
}

Expand All @@ -126,6 +126,10 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk
return sdk.ZeroInt(), nil
}

// DexReward amount per day = amount distributed / duration(in seconds) * total seconds per day.
// AllocationEpochInBlocks is the number of the block per day
amtDexRewardPerDay := amt.MulInt(stkIncentive.AllocationEpochInBlocks).QuoInt(params.DexRewardsStakers.NumBlocks)

// Calc Eden price in usdc
// We put Elys as denom as Eden won't be avaialble in amm pool and has the same value as Elys
edenPrice := k.EstimatePrice(ctx, sdk.NewCoin(ptypes.Elys, sdk.NewInt(1000000)), baseCurrency)
Expand All @@ -142,13 +146,9 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk
return sdk.ZeroInt(), nil
}

// DexReward amount per day = amount distributed / duration(in seconds) * total seconds per day.
// EpochNumBlocks is the number of the block per day
dailyDexRewardAmount := amount.MulInt(stkIncentive.EpochNumBlocks).QuoInt(params.DexRewardsStakers.NumBlocks)

// Usdc apr for elys staking = (24 hour dex rewards in USDC generated for stakers) * 365*100/ {price ( elys/usdc)*( sum of (elys staked, Eden committed, Eden boost committed))}
// we multiply 10 as we have use 10elys as input in the price estimation
apr := dailyDexRewardAmount.
apr := amtDexRewardPerDay.
MulInt(sdk.NewInt(ptypes.DaysPerYear)).
MulInt(sdk.NewInt(100)).
MulInt(sdk.NewInt(1000000)).
Expand Down
Loading

0 comments on commit 42e7532

Please sign in to comment.