-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/incenitve param #279
Feat/incenitve param #279
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ func IncentiveKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { | |
nil, | ||
nil, | ||
nil, | ||
nil, | ||
"", | ||
"", | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ | |
package keeper | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
ctypes "github.com/elys-network/elys/x/commitment/types" | ||
"github.com/elys-network/elys/x/incentive/types" | ||
ptypes "github.com/elys-network/elys/x/parameter/types" | ||
) | ||
|
||
// EndBlocker of incentive module | ||
|
@@ -74,6 +76,12 @@ func (k Keeper) ProcessElysStakedTracking(ctx sdk.Context) { | |
|
||
// Rewards distribution | ||
func (k Keeper) ProcessRewardsDistribution(ctx sdk.Context) { | ||
// Read tokenomics time based inflation params and update incentive module params. | ||
if !k.ProcessUpdateIncentiveParams(ctx) { | ||
ctx.Logger().Error("Invalid tokenomics params", "error", errors.New("Invalid tokenomics params")) | ||
return | ||
} | ||
|
||
stakerEpoch, stakeIncentive := k.IsStakerRewardsDistributionEpoch(ctx) | ||
if stakerEpoch { | ||
err := k.UpdateStakersRewardsUnclaimed(ctx, stakeIncentive) | ||
|
@@ -91,24 +99,90 @@ func (k Keeper) ProcessRewardsDistribution(ctx sdk.Context) { | |
} | ||
} | ||
|
||
func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool { | ||
listTimeBasedInflations := k.tokenomicsKeeper.GetAllTimeBasedInflation(ctx) | ||
if len(listTimeBasedInflations) < 1 { | ||
return false | ||
} | ||
|
||
params := k.GetParams(ctx) | ||
|
||
for _, inflation := range listTimeBasedInflations { | ||
if inflation.StartBlockHeight > uint64(ctx.BlockHeight()) || inflation.EndBlockHeight < uint64(ctx.BlockHeight()) { | ||
continue | ||
} | ||
|
||
totalBlocksPerYear := sdk.NewInt(int64(inflation.EndBlockHeight - inflation.StartBlockHeight + 1)) | ||
allocationEpochInblocks := totalBlocksPerYear.Quo(sdk.NewInt(ptypes.DaysPerYear)) | ||
if len(params.LpIncentives) < 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to update this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it |
||
totalDistributionEpochPerYear := totalBlocksPerYear.Quo(sdk.NewInt(params.DistributionEpochForLpsInBlocks)) | ||
currentEpochInBlocks := sdk.NewInt(ctx.BlockHeight() - int64(inflation.StartBlockHeight)).Mul(totalDistributionEpochPerYear).Quo(totalBlocksPerYear) | ||
maxEdenPerAllocation := sdk.NewInt(int64(inflation.Inflation.LmRewards)).Mul(allocationEpochInblocks).Quo(totalBlocksPerYear) | ||
params.LpIncentives = append(params.LpIncentives, types.IncentiveInfo{ | ||
// reward amount in eden for 1 year | ||
EdenAmountPerYear: sdk.NewInt(int64(inflation.Inflation.LmRewards)), | ||
// starting block height of the distribution | ||
DistributionStartBlock: sdk.NewInt(int64(inflation.StartBlockHeight)), | ||
// distribution duration - block number per year | ||
TotalBlocksPerYear: totalBlocksPerYear, | ||
// we set block numbers in 24 hrs | ||
AllocationEpochInBlocks: allocationEpochInblocks, | ||
// maximum eden allocation per day that won't exceed 30% apr | ||
MaxEdenPerAllocation: maxEdenPerAllocation, | ||
// number of block intervals that distribute rewards. | ||
DistributionEpochInBlocks: sdk.NewInt(params.DistributionEpochForLpsInBlocks), | ||
// current epoch in block number | ||
CurrentEpochInBlocks: currentEpochInBlocks, | ||
// eden boost apr (0-1) range | ||
EdenBoostApr: sdk.NewDec(1), | ||
}) | ||
} | ||
|
||
if len(params.StakeIncentives) < 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to update this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it |
||
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(allocationEpochInblocks).Quo(totalBlocksPerYear) | ||
params.StakeIncentives = append(params.StakeIncentives, types.IncentiveInfo{ | ||
// reward amount in eden for 1 year | ||
EdenAmountPerYear: sdk.NewInt(int64(inflation.Inflation.IcsStakingRewards)), | ||
// starting block height of the distribution | ||
DistributionStartBlock: sdk.NewInt(int64(inflation.StartBlockHeight)), | ||
// distribution duration - block number per year | ||
TotalBlocksPerYear: totalBlocksPerYear, | ||
// we set block numbers in 24 hrs | ||
AllocationEpochInBlocks: allocationEpochInblocks, | ||
// maximum eden allocation per day that won't exceed 30% apr | ||
MaxEdenPerAllocation: maxEdenPerAllocation, | ||
// number of block intervals that distribute rewards. | ||
DistributionEpochInBlocks: sdk.NewInt(params.DistributionEpochForStakersInBlocks), | ||
// current epoch in block number | ||
CurrentEpochInBlocks: currentEpochInBlocks, | ||
// eden boost apr (0-1) range | ||
EdenBoostApr: sdk.NewDec(1), | ||
}) | ||
} | ||
|
||
break | ||
} | ||
|
||
k.SetParams(ctx, params) | ||
return true | ||
} | ||
|
||
func (k Keeper) IsStakerRewardsDistributionEpoch(ctx sdk.Context) (bool, types.IncentiveInfo) { | ||
// Fetch incentive params | ||
params := k.GetParams(ctx) | ||
if ctx.BlockHeight() < 1 { | ||
return false, types.IncentiveInfo{} | ||
} | ||
|
||
// Update params | ||
defer k.SetParams(ctx, params) | ||
|
||
// If we don't have enough params | ||
if len(params.StakeIncentives) < 1 { | ||
return false, types.IncentiveInfo{} | ||
} | ||
|
||
// Incentive params initialize | ||
stakeIncentive := params.StakeIncentives[0] | ||
|
||
if ctx.BlockHeight()%stakeIncentive.DistributionEpochInBlocks.Int64() != 0 { | ||
return false, types.IncentiveInfo{} | ||
} | ||
|
@@ -120,14 +194,21 @@ func (k Keeper) IsStakerRewardsDistributionEpoch(ctx sdk.Context) (bool, types.I | |
|
||
// Increase current epoch of Stake incentive param | ||
stakeIncentive.CurrentEpochInBlocks = stakeIncentive.CurrentEpochInBlocks.Add(stakeIncentive.DistributionEpochInBlocks) | ||
if stakeIncentive.CurrentEpochInBlocks.GTE(stakeIncentive.TotalBlocksPerYear) { | ||
if stakeIncentive.CurrentEpochInBlocks.GTE(stakeIncentive.TotalBlocksPerYear) || curBlockHeight.GT(stakeIncentive.TotalBlocksPerYear.Add(stakeIncentive.DistributionStartBlock)) { | ||
if len(params.StakeIncentives) > 1 { | ||
params.StakeIncentives = params.StakeIncentives[1:] | ||
k.SetParams(ctx, params) | ||
return false, types.IncentiveInfo{} | ||
} else { | ||
params.StakeIncentives = []types.IncentiveInfo(nil) | ||
k.SetParams(ctx, params) | ||
return false, types.IncentiveInfo{} | ||
} | ||
} | ||
|
||
params.StakeIncentives[0].CurrentEpochInBlocks = stakeIncentive.CurrentEpochInBlocks | ||
k.SetParams(ctx, params) | ||
|
||
// return found, stake incentive params | ||
return true, stakeIncentive | ||
} | ||
|
@@ -139,9 +220,6 @@ func (k Keeper) IsLPRewardsDistributionEpoch(ctx sdk.Context) (bool, types.Incen | |
return false, types.IncentiveInfo{} | ||
} | ||
|
||
// Update params | ||
defer k.SetParams(ctx, params) | ||
|
||
// If we don't have enough params | ||
if len(params.LpIncentives) < 1 { | ||
return false, types.IncentiveInfo{} | ||
|
@@ -160,14 +238,21 @@ func (k Keeper) IsLPRewardsDistributionEpoch(ctx sdk.Context) (bool, types.Incen | |
|
||
// Increase current epoch of Stake incentive param | ||
lpIncentive.CurrentEpochInBlocks = lpIncentive.CurrentEpochInBlocks.Add(lpIncentive.DistributionEpochInBlocks) | ||
if lpIncentive.CurrentEpochInBlocks.GTE(lpIncentive.TotalBlocksPerYear) { | ||
if len(params.StakeIncentives) > 1 { | ||
if lpIncentive.CurrentEpochInBlocks.GTE(lpIncentive.TotalBlocksPerYear) || curBlockHeight.GT(lpIncentive.TotalBlocksPerYear.Add(lpIncentive.DistributionStartBlock)) { | ||
if len(params.LpIncentives) > 1 { | ||
params.LpIncentives = params.LpIncentives[1:] | ||
k.SetParams(ctx, params) | ||
return false, types.IncentiveInfo{} | ||
} else { | ||
params.LpIncentives = []types.IncentiveInfo(nil) | ||
k.SetParams(ctx, params) | ||
return false, types.IncentiveInfo{} | ||
} | ||
} | ||
|
||
params.LpIncentives[0].CurrentEpochInBlocks = lpIncentive.CurrentEpochInBlocks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any case LpIncentives[1] is used as well? It would be nice to add comments on what is LpIncentives[0] and what are the rest of [1:] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LpIncentives[0] - this year |
||
k.SetParams(ctx, params) | ||
|
||
// return found, lp incentive params | ||
return true, lpIncentive | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenta-elys any reasons we are not getting rid of those params as you are using the ones from tokenomics now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cosmic-vagabond I am still using the params in incentive module and filling in the value from tokenmocis module. Tokenmocis module params aren't enough to handle current incentive codebase. Let me think more if we can get rid of this.