Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,15 @@ func NewElysApp(
)
stablestake := stablestake.NewAppModule(appCodec, app.StablestakeKeeper, app.AccountKeeper, app.BankKeeper)

app.TokenomicsKeeper = *tokenomicsmodulekeeper.NewKeeper(
appCodec,
keys[tokenomicsmoduletypes.StoreKey],
keys[tokenomicsmoduletypes.MemStoreKey],
app.GetSubspace(tokenomicsmoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
tokenomicsModule := tokenomicsmodule.NewAppModule(appCodec, app.TokenomicsKeeper, app.AccountKeeper, app.BankKeeper)

app.IncentiveKeeper = *incentivemodulekeeper.NewKeeper(
appCodec,
keys[incentivemoduletypes.StoreKey],
Expand All @@ -766,6 +775,7 @@ func NewElysApp(
app.AssetprofileKeeper,
app.EpochsKeeper,
app.StablestakeKeeper,
app.TokenomicsKeeper,
authtypes.FeeCollectorName,
DexRevenueCollectorName,
)
Expand All @@ -779,15 +789,6 @@ func NewElysApp(

commitmentModule := commitmentmodule.NewAppModule(appCodec, app.CommitmentKeeper, app.AccountKeeper, app.BankKeeper)

app.TokenomicsKeeper = *tokenomicsmodulekeeper.NewKeeper(
appCodec,
keys[tokenomicsmoduletypes.StoreKey],
keys[tokenomicsmoduletypes.MemStoreKey],
app.GetSubspace(tokenomicsmoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
tokenomicsModule := tokenomicsmodule.NewAppModule(appCodec, app.TokenomicsKeeper, app.AccountKeeper, app.BankKeeper)

app.BurnerKeeper = *burnermodulekeeper.NewKeeper(
appCodec,
keys[burnermoduletypes.StoreKey],
Expand Down
20 changes: 2 additions & 18 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,24 +287,8 @@ genesis:
amount: "200000"
incentive:
params:
lp_incentives:
- eden_amount_per_year: "10000000000000"
distribution_start_block: "1"
total_blocks_per_year: "10512000"
allocation_epoch_in_blocks: "28800"
max_eden_per_allocation: "27397238400"
distribution_epoch_in_blocks: "10"
current_epoch_in_blocks: "0"
eden_boost_apr: "1"
stake_incentives:
- eden_amount_per_year: "10000000000000"
distribution_start_block: "1"
total_blocks_per_year: "10512000"
allocation_epoch_in_blocks: "28800"
max_eden_per_allocation: "27397238400"
distribution_epoch_in_blocks: "20"
current_epoch_in_blocks: "0"
eden_boost_apr: "1"
lp_incentives: []
stake_incentives: []
Copy link
Contributor

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?

Copy link
Contributor Author

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.

community_tax: "0.00"
withdraw_addr_enabled: true
reward_portion_for_lps: "0.65"
Expand Down
24 changes: 24 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39625,6 +39625,14 @@ paths:
max_eden_reward_apr:
type: string
title: Maximum eden reward apr
distribution_epoch_for_lps_in_blocks:
type: string
format: int64
title: Distribution epochs for LPs in blocks
distribution_epoch_for_stakers_in_blocks:
type: string
format: int64
title: Distribution epochs for stakers in blocks
description: >-
QueryParamsResponse is response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -84535,6 +84543,14 @@ definitions:
max_eden_reward_apr:
type: string
title: Maximum eden reward apr
distribution_epoch_for_lps_in_blocks:
type: string
format: int64
title: Distribution epochs for LPs in blocks
distribution_epoch_for_stakers_in_blocks:
type: string
format: int64
title: Distribution epochs for stakers in blocks
description: Params defines the parameters for the module.
elys.incentive.PoolInfo:
type: object
Expand Down Expand Up @@ -84689,6 +84705,14 @@ definitions:
max_eden_reward_apr:
type: string
title: Maximum eden reward apr
distribution_epoch_for_lps_in_blocks:
type: string
format: int64
title: Distribution epochs for LPs in blocks
distribution_epoch_for_stakers_in_blocks:
type: string
format: int64
title: Distribution epochs for stakers in blocks
description: QueryParamsResponse is response type for the Query/Params RPC method.
elys.leveragelp.IsWhitelistedResponse:
type: object
Expand Down
5 changes: 5 additions & 0 deletions proto/elys/incentive/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Distribution epochs for LPs in blocks
int64 distribution_epoch_for_lps_in_blocks = 11;
// Distribution epochs for stakers in blocks
int64 distribution_epoch_for_stakers_in_blocks = 12;
}
1 change: 1 addition & 0 deletions testutil/keeper/incentive.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func IncentiveKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
nil,
nil,
nil,
nil,
"",
"",
)
Expand Down
105 changes: 95 additions & 10 deletions x/incentive/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to update this to == 0 for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to update this to == 0 for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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{}
}
Expand All @@ -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
}
Expand All @@ -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{}
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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:]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LpIncentives[0] - this year
LpIncentives[1] - next year

k.SetParams(ctx, params)

// return found, lp incentive params
return true, lpIncentive
}
Loading
Loading