Skip to content

Commit

Permalink
Incentive remove usage of multiple epoch values, fix usdc reward not …
Browse files Browse the repository at this point in the history
…claim issue (#439)

* remove usage of multiple epoch values on incentive module

* fix usdc reward not claim issue

* Add missing CLI commands for tracking slippage

---------

Co-authored-by: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com>
  • Loading branch information
jelysn and cosmic-vagabond authored Apr 1, 2024
1 parent acea93f commit dea67d2
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 144 deletions.
42 changes: 14 additions & 28 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39794,17 +39794,15 @@ paths:
title: distribution duration - block number per year
epoch_num_blocks:
type: string
title: we set block count in 24 hrs
title: unused
max_eden_per_allocation:
type: string
title: >-
maximum eden allocation per day that won't exceed 30%
apr
distribution_epoch_in_blocks:
type: string
title: >-
number of block intervals that distribute rewards, set
from params.distribution_interval
title: unused
current_epoch_in_blocks:
type: string
title: current epoch in block number
Expand All @@ -39823,17 +39821,15 @@ paths:
title: distribution duration - block number per year
epoch_num_blocks:
type: string
title: we set block count in 24 hrs
title: unused
max_eden_per_allocation:
type: string
title: >-
maximum eden allocation per day that won't exceed 30%
apr
distribution_epoch_in_blocks:
type: string
title: >-
number of block intervals that distribute rewards, set
from params.distribution_interval
title: unused
current_epoch_in_blocks:
type: string
title: current epoch in block number
Expand Down Expand Up @@ -84504,15 +84500,13 @@ definitions:
title: distribution duration - block number per year
epoch_num_blocks:
type: string
title: we set block count in 24 hrs
title: unused
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
distribution_epoch_in_blocks:
type: string
title: >-
number of block intervals that distribute rewards, set from
params.distribution_interval
title: unused
current_epoch_in_blocks:
type: string
title: current epoch in block number
Expand Down Expand Up @@ -84548,15 +84542,13 @@ definitions:
title: distribution duration - block number per year
epoch_num_blocks:
type: string
title: we set block count in 24 hrs
title: unused
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
distribution_epoch_in_blocks:
type: string
title: >-
number of block intervals that distribute rewards, set from
params.distribution_interval
title: unused
current_epoch_in_blocks:
type: string
title: current epoch in block number
Expand All @@ -84575,15 +84567,13 @@ definitions:
title: distribution duration - block number per year
epoch_num_blocks:
type: string
title: we set block count in 24 hrs
title: unused
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
distribution_epoch_in_blocks:
type: string
title: >-
number of block intervals that distribute rewards, set from
params.distribution_interval
title: unused
current_epoch_in_blocks:
type: string
title: current epoch in block number
Expand Down Expand Up @@ -84794,15 +84784,13 @@ definitions:
title: distribution duration - block number per year
epoch_num_blocks:
type: string
title: we set block count in 24 hrs
title: unused
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
distribution_epoch_in_blocks:
type: string
title: >-
number of block intervals that distribute rewards, set from
params.distribution_interval
title: unused
current_epoch_in_blocks:
type: string
title: current epoch in block number
Expand All @@ -84821,15 +84809,13 @@ definitions:
title: distribution duration - block number per year
epoch_num_blocks:
type: string
title: we set block count in 24 hrs
title: unused
max_eden_per_allocation:
type: string
title: maximum eden allocation per day that won't exceed 30% apr
distribution_epoch_in_blocks:
type: string
title: >-
number of block intervals that distribute rewards, set from
params.distribution_interval
title: unused
current_epoch_in_blocks:
type: string
title: current epoch in block number
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,13 +16,13 @@ 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
// unused
string epoch_num_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
[ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
// number of block intervals that distribute rewards, set from params.distribution_interval
// unused
string distribution_epoch_in_blocks = 6
[ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
// current epoch in block number
Expand Down
2 changes: 2 additions & 0 deletions x/amm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdSwapEstimationByDenom())
cmd.AddCommand(CmdJoinPoolEstimation())
cmd.AddCommand(CmdExitPoolEstimation())
cmd.AddCommand(CmdTrackedSlippage())
cmd.AddCommand(CmdTrackedSlippageAll())

// this line is used by starport scaffolding # 1

Expand Down
26 changes: 6 additions & 20 deletions x/incentive/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,8 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
DistributionStartBlock: sdk.NewInt(int64(inflation.StartBlockHeight)),
// distribution duration - block number per year
TotalBlocksPerYear: totalBlocksPerYear,
// we set block numbers in 24 hrs
EpochNumBlocks: EpochNumBlocks,
// maximum eden allocation per day that won't exceed 30% apr
MaxEdenPerAllocation: maxEdenPerAllocation,
// number of block intervals that distribute rewards.
DistributionEpochInBlocks: sdk.NewInt(params.DistributionInterval),
// current epoch in block number
CurrentEpochInBlocks: currentEpochInBlocks,
}
Expand All @@ -129,15 +125,12 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
} else {
// If any of block number related parameter changed, we re-calculate the current epoch
if params.LpIncentives.DistributionStartBlock != incentiveInfo.DistributionStartBlock ||
params.LpIncentives.TotalBlocksPerYear != incentiveInfo.TotalBlocksPerYear ||
params.LpIncentives.DistributionEpochInBlocks != incentiveInfo.DistributionEpochInBlocks {
params.LpIncentives.TotalBlocksPerYear != incentiveInfo.TotalBlocksPerYear {
params.LpIncentives.CurrentEpochInBlocks = currentEpochInBlocks
}
params.LpIncentives.EdenAmountPerYear = incentiveInfo.EdenAmountPerYear
params.LpIncentives.DistributionStartBlock = incentiveInfo.DistributionStartBlock
params.LpIncentives.TotalBlocksPerYear = incentiveInfo.TotalBlocksPerYear
params.LpIncentives.EpochNumBlocks = incentiveInfo.EpochNumBlocks
params.LpIncentives.DistributionEpochInBlocks = incentiveInfo.DistributionEpochInBlocks
}

// ------------- Stakers parameter -------------
Expand All @@ -151,12 +144,8 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
DistributionStartBlock: sdk.NewInt(int64(inflation.StartBlockHeight)),
// distribution duration - block number per year
TotalBlocksPerYear: totalBlocksPerYear,
// we set block numbers in 24 hrs
EpochNumBlocks: EpochNumBlocks,
// maximum eden allocation per day that won't exceed 30% apr
MaxEdenPerAllocation: maxEdenPerAllocation,
// number of block intervals that distribute rewards.
DistributionEpochInBlocks: sdk.NewInt(params.DistributionInterval),
// current epoch in block number
CurrentEpochInBlocks: currentEpochInBlocks,
}
Expand All @@ -166,15 +155,12 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool {
} else {
// If any of block number related parameter changed, we re-calculate the current epoch
if params.StakeIncentives.DistributionStartBlock != incentiveInfo.DistributionStartBlock ||
params.StakeIncentives.TotalBlocksPerYear != incentiveInfo.TotalBlocksPerYear ||
params.StakeIncentives.DistributionEpochInBlocks != incentiveInfo.DistributionEpochInBlocks {
params.StakeIncentives.TotalBlocksPerYear != incentiveInfo.TotalBlocksPerYear {
params.StakeIncentives.CurrentEpochInBlocks = currentEpochInBlocks
}
params.StakeIncentives.EdenAmountPerYear = incentiveInfo.EdenAmountPerYear
params.StakeIncentives.DistributionStartBlock = incentiveInfo.DistributionStartBlock
params.StakeIncentives.TotalBlocksPerYear = incentiveInfo.TotalBlocksPerYear
params.StakeIncentives.EpochNumBlocks = incentiveInfo.EpochNumBlocks
params.StakeIncentives.DistributionEpochInBlocks = incentiveInfo.DistributionEpochInBlocks
}
break
}
Expand All @@ -197,7 +183,7 @@ func (k Keeper) IsStakerRewardsDistributionEpoch(ctx sdk.Context) (bool, *types.

// Incentive params initialize
stakeIncentive := params.StakeIncentives
if ctx.BlockHeight()%stakeIncentive.DistributionEpochInBlocks.Int64() != 0 {
if ctx.BlockHeight()%params.DistributionInterval != 0 {
return false, nil
}

Expand All @@ -207,7 +193,7 @@ func (k Keeper) IsStakerRewardsDistributionEpoch(ctx sdk.Context) (bool, *types.
}

// Increase current epoch of Stake incentive param
stakeIncentive.CurrentEpochInBlocks = stakeIncentive.CurrentEpochInBlocks.Add(stakeIncentive.DistributionEpochInBlocks)
stakeIncentive.CurrentEpochInBlocks = stakeIncentive.CurrentEpochInBlocks.Add(sdk.NewInt(params.DistributionInterval))
if stakeIncentive.CurrentEpochInBlocks.GTE(stakeIncentive.TotalBlocksPerYear) || curBlockHeight.GT(stakeIncentive.TotalBlocksPerYear.Add(stakeIncentive.DistributionStartBlock)) {
params.StakeIncentives = nil
k.SetParams(ctx, params)
Expand Down Expand Up @@ -235,7 +221,7 @@ func (k Keeper) IsLPRewardsDistributionEpoch(ctx sdk.Context) (bool, *types.Ince

// Incentive params initialize
lpIncentive := params.LpIncentives
if ctx.BlockHeight()%lpIncentive.DistributionEpochInBlocks.Int64() != 0 {
if ctx.BlockHeight()%params.DistributionInterval != 0 {
return false, nil
}

Expand All @@ -245,7 +231,7 @@ func (k Keeper) IsLPRewardsDistributionEpoch(ctx sdk.Context) (bool, *types.Ince
}

// Increase current epoch of Stake incentive param
lpIncentive.CurrentEpochInBlocks = lpIncentive.CurrentEpochInBlocks.Add(lpIncentive.DistributionEpochInBlocks)
lpIncentive.CurrentEpochInBlocks = lpIncentive.CurrentEpochInBlocks.Add(sdk.NewInt(params.DistributionInterval))
if lpIncentive.CurrentEpochInBlocks.GTE(lpIncentive.TotalBlocksPerYear) || curBlockHeight.GT(lpIncentive.TotalBlocksPerYear.Add(lpIncentive.DistributionStartBlock)) {
params.LpIncentives = nil
k.SetParams(ctx, params)
Expand Down
10 changes: 5 additions & 5 deletions x/incentive/keeper/apr.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (mat

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

edenDenomPrice := k.GetEdenDenomPrice(ctx, baseCurrency)
epochLpsMaxEdenAmount := params.MaxEdenRewardAprLps.
Mul(totalProxyTVL).
MulInt(lpIncentive.EpochNumBlocks).
MulInt64(params.DistributionInterval).
QuoInt(lpIncentive.TotalBlocksPerYear).
Quo(edenDenomPrice)

Expand Down Expand Up @@ -86,14 +86,14 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (mat

// Calculate
epochStakersEdenAmount := stkIncentive.EdenAmountPerYear.
Mul(stkIncentive.EpochNumBlocks).
Mul(sdk.NewInt(params.DistributionInterval)).
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.
MulInt(totalStakedSnapshot).
MulInt(stkIncentive.EpochNumBlocks).
MulInt64(params.DistributionInterval).
QuoInt(stkIncentive.TotalBlocksPerYear)

// Use min amount (eden allocation from tokenomics and max apr based eden amount)
Expand Down Expand Up @@ -147,7 +147,7 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (mat

// 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)
dailyDexRewardAmount := amount.MulInt64(params.DistributionInterval).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
Expand Down
Loading

0 comments on commit dea67d2

Please sign in to comment.