From f75430ce05c9a6c4c66fc305f43f907f0b3a8a89 Mon Sep 17 00:00:00 2001 From: kenta-elys Date: Thu, 23 Nov 2023 12:45:54 +0000 Subject: [PATCH 1/5] chore: refactor incentive to handle lp and stake in different epoch and based on blocks --- app/app.go | 1 - config.yml | 6 +- docs/static/openapi.yml | 264 +++++++----- .../elys/incentive/dex_rewards_stakers.proto | 13 +- proto/elys/incentive/incentive.proto | 34 +- proto/elys/incentive/params.proto | 5 +- x/incentive/keeper/abci.go | 110 +++++ x/incentive/keeper/apr.go | 51 +-- x/incentive/keeper/hooks_epoch.go | 53 --- x/incentive/keeper/keeper.go | 212 +++++++--- x/incentive/keeper/keeper_stakers.go | 10 +- x/incentive/keeper/params.go | 52 --- x/incentive/types/dex_rewards_stakers.pb.go | 179 +++++--- x/incentive/types/incentive.pb.go | 393 ++++++++++++------ x/incentive/types/params.go | 84 ++-- x/incentive/types/params.pb.go | 124 ++++-- x/incentive/types/params_test.go | 28 +- 17 files changed, 1028 insertions(+), 591 deletions(-) delete mode 100644 x/incentive/keeper/hooks_epoch.go diff --git a/app/app.go b/app/app.go index 7c4181d4b..6a6b4dc0a 100644 --- a/app/app.go +++ b/app/app.go @@ -1003,7 +1003,6 @@ func NewElysApp( // insert epoch hooks receivers here app.OracleKeeper.Hooks(), app.CommitmentKeeper.Hooks(), - app.IncentiveKeeper.Hooks(), app.BurnerKeeper.Hooks(), app.MarginKeeper.Hooks(), ), diff --git a/config.yml b/config.yml index 2a4b899da..15d81d106 100644 --- a/config.yml +++ b/config.yml @@ -289,15 +289,15 @@ genesis: start_time: "2023-04-20T12:34:56.789Z" num_epochs: "3154000" current_epoch: "0" - eden_boost_apr: "100" + eden_boost_apr: "1" stake_incentives: - amount: "100000000000" epoch_identifier: tenseconds start_time: "2023-04-20T12:34:56.789Z" num_epochs: "3154000" current_epoch: "0" - eden_boost_apr: "100" - community_tax: "0.02" + eden_boost_apr: "1" + community_tax: "0.00" withdraw_addr_enabled: true reward_portion_for_lps: "0.65" pool_infos: [] diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index e0ed21ebf..5218a0033 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -39510,52 +39510,64 @@ paths: items: type: object properties: - amount: + eden_amount_per_year: type: string - title: reward amount - epoch_identifier: + title: reward amount in eden for 1 year + distribution_start_block: type: string - title: epoch identifier - start_time: + title: starting block height of the distribution + total_blocks_per_year: type: string - format: date-time - title: start_time of the distribution - num_epochs: + title: distribution duration - block number per year + allocation_epoch_in_blocks: type: string - format: int64 - title: distribution duration - current_epoch: + title: we set block numbers in 24 hrs + max_eden_per_allocation: type: string - format: int64 + title: >- + maximum eden allocation per day that won't exceed + 30% apr + distribution_epoch_in_blocks: + type: string + description: number of block intervals that distribute rewards. + current_epoch_in_blocks: + type: string + title: current epoch in block number eden_boost_apr: type: string - format: int64 + title: eden boost apr (0-1) range title: Incentive Info stake_incentives: type: array items: type: object properties: - amount: + eden_amount_per_year: type: string - title: reward amount - epoch_identifier: + title: reward amount in eden for 1 year + distribution_start_block: type: string - title: epoch identifier - start_time: + title: starting block height of the distribution + total_blocks_per_year: type: string - format: date-time - title: start_time of the distribution - num_epochs: + title: distribution duration - block number per year + allocation_epoch_in_blocks: type: string - format: int64 - title: distribution duration - current_epoch: + title: we set block numbers in 24 hrs + max_eden_per_allocation: type: string - format: int64 + title: >- + maximum eden allocation per day that won't exceed + 30% apr + distribution_epoch_in_blocks: + type: string + description: number of block intervals that distribute rewards. + current_epoch_in_blocks: + type: string + title: current epoch in block number eden_boost_apr: type: string - format: int64 + title: eden boost apr (0-1) range title: Incentive Info community_tax: type: string @@ -39592,10 +39604,22 @@ paths: title: Tracking dex rewards given to stakers type: object properties: - epoch_identifier: + num_blocks: type: string amount: type: string + amount_collected_by_other_tracker: + type: string + dex_rewards_lps: + title: Tracking dex rewards given to LPs + type: object + properties: + num_blocks: + type: string + amount: + type: string + amount_collected_by_other_tracker: + type: string description: >- QueryParamsResponse is response type for the Query/Params RPC method. @@ -84294,37 +84318,43 @@ definitions: - EDEN_PROGRAM - EDENB_PROGRAM default: ALL_PROGRAM - elys.incentive.DexRewardsStakers: + elys.incentive.DexRewardsTracker: type: object properties: - epoch_identifier: + num_blocks: type: string amount: type: string - title: Track DexRewardsStakers + amount_collected_by_other_tracker: + type: string + title: DexRewardsTracker elys.incentive.IncentiveInfo: type: object properties: - amount: + eden_amount_per_year: type: string - title: reward amount - epoch_identifier: + title: reward amount in eden for 1 year + distribution_start_block: type: string - title: epoch identifier - start_time: + title: starting block height of the distribution + total_blocks_per_year: type: string - format: date-time - title: start_time of the distribution - num_epochs: + title: distribution duration - block number per year + allocation_epoch_in_blocks: type: string - format: int64 - title: distribution duration - current_epoch: + title: we set block numbers in 24 hrs + max_eden_per_allocation: type: string - format: int64 + title: maximum eden allocation per day that won't exceed 30% apr + distribution_epoch_in_blocks: + type: string + description: number of block intervals that distribute rewards. + current_epoch_in_blocks: + type: string + title: current epoch in block number eden_boost_apr: type: string - format: int64 + title: eden boost apr (0-1) range title: Incentive Info elys.incentive.MsgWithdrawRewardsResponse: type: object @@ -84344,52 +84374,60 @@ definitions: items: type: object properties: - amount: + eden_amount_per_year: type: string - title: reward amount - epoch_identifier: + title: reward amount in eden for 1 year + distribution_start_block: type: string - title: epoch identifier - start_time: + title: starting block height of the distribution + total_blocks_per_year: type: string - format: date-time - title: start_time of the distribution - num_epochs: + title: distribution duration - block number per year + allocation_epoch_in_blocks: type: string - format: int64 - title: distribution duration - current_epoch: + title: we set block numbers in 24 hrs + max_eden_per_allocation: type: string - format: int64 + title: maximum eden allocation per day that won't exceed 30% apr + distribution_epoch_in_blocks: + type: string + description: number of block intervals that distribute rewards. + current_epoch_in_blocks: + type: string + title: current epoch in block number eden_boost_apr: type: string - format: int64 + title: eden boost apr (0-1) range title: Incentive Info stake_incentives: type: array items: type: object properties: - amount: + eden_amount_per_year: type: string - title: reward amount - epoch_identifier: + title: reward amount in eden for 1 year + distribution_start_block: type: string - title: epoch identifier - start_time: + title: starting block height of the distribution + total_blocks_per_year: type: string - format: date-time - title: start_time of the distribution - num_epochs: + title: distribution duration - block number per year + allocation_epoch_in_blocks: type: string - format: int64 - title: distribution duration - current_epoch: + title: we set block numbers in 24 hrs + max_eden_per_allocation: type: string - format: int64 + title: maximum eden allocation per day that won't exceed 30% apr + distribution_epoch_in_blocks: + type: string + description: number of block intervals that distribute rewards. + current_epoch_in_blocks: + type: string + title: current epoch in block number eden_boost_apr: type: string - format: int64 + title: eden boost apr (0-1) range title: Incentive Info community_tax: type: string @@ -84426,10 +84464,22 @@ definitions: title: Tracking dex rewards given to stakers type: object properties: - epoch_identifier: + num_blocks: type: string amount: type: string + amount_collected_by_other_tracker: + type: string + dex_rewards_lps: + title: Tracking dex rewards given to LPs + type: object + properties: + num_blocks: + type: string + amount: + type: string + amount_collected_by_other_tracker: + type: string description: Params defines the parameters for the module. elys.incentive.PoolInfo: type: object @@ -84475,52 +84525,60 @@ definitions: items: type: object properties: - amount: + eden_amount_per_year: type: string - title: reward amount - epoch_identifier: + title: reward amount in eden for 1 year + distribution_start_block: type: string - title: epoch identifier - start_time: + title: starting block height of the distribution + total_blocks_per_year: type: string - format: date-time - title: start_time of the distribution - num_epochs: + title: distribution duration - block number per year + allocation_epoch_in_blocks: type: string - format: int64 - title: distribution duration - current_epoch: + title: we set block numbers in 24 hrs + max_eden_per_allocation: type: string - format: int64 + title: maximum eden allocation per day that won't exceed 30% apr + distribution_epoch_in_blocks: + type: string + description: number of block intervals that distribute rewards. + current_epoch_in_blocks: + type: string + title: current epoch in block number eden_boost_apr: type: string - format: int64 + title: eden boost apr (0-1) range title: Incentive Info stake_incentives: type: array items: type: object properties: - amount: + eden_amount_per_year: type: string - title: reward amount - epoch_identifier: + title: reward amount in eden for 1 year + distribution_start_block: type: string - title: epoch identifier - start_time: + title: starting block height of the distribution + total_blocks_per_year: type: string - format: date-time - title: start_time of the distribution - num_epochs: + title: distribution duration - block number per year + allocation_epoch_in_blocks: type: string - format: int64 - title: distribution duration - current_epoch: + title: we set block numbers in 24 hrs + max_eden_per_allocation: type: string - format: int64 + title: maximum eden allocation per day that won't exceed 30% apr + distribution_epoch_in_blocks: + type: string + description: number of block intervals that distribute rewards. + current_epoch_in_blocks: + type: string + title: current epoch in block number eden_boost_apr: type: string - format: int64 + title: eden boost apr (0-1) range title: Incentive Info community_tax: type: string @@ -84557,10 +84615,22 @@ definitions: title: Tracking dex rewards given to stakers type: object properties: - epoch_identifier: + num_blocks: type: string amount: type: string + amount_collected_by_other_tracker: + type: string + dex_rewards_lps: + title: Tracking dex rewards given to LPs + type: object + properties: + num_blocks: + type: string + amount: + type: string + amount_collected_by_other_tracker: + type: string description: QueryParamsResponse is response type for the Query/Params RPC method. elys.leveragelp.IsWhitelistedResponse: type: object diff --git a/proto/elys/incentive/dex_rewards_stakers.proto b/proto/elys/incentive/dex_rewards_stakers.proto index 7a60b5714..afeccca24 100644 --- a/proto/elys/incentive/dex_rewards_stakers.proto +++ b/proto/elys/incentive/dex_rewards_stakers.proto @@ -6,12 +6,19 @@ option (gogoproto.equal_all) = true; import "gogoproto/gogo.proto"; -// Track DexRewardsStakers -message DexRewardsStakers { - string epoch_identifier = 1; +// DexRewardsTracker +message DexRewardsTracker { + string num_blocks = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; string amount = 2 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; + string amount_collected_by_other_tracker = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } \ No newline at end of file diff --git a/proto/elys/incentive/incentive.proto b/proto/elys/incentive/incentive.proto index 3ed7cbd49..cbe6dfe79 100644 --- a/proto/elys/incentive/incentive.proto +++ b/proto/elys/incentive/incentive.proto @@ -7,16 +7,28 @@ option go_package = "github.com/elys-network/elys/x/incentive/types"; // Incentive Info message IncentiveInfo { - // reward amount - string amount = 1 + // reward amount in eden for 1 year + string eden_amount_per_year = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; - // epoch identifier - string epoch_identifier = 2; - // start_time of the distribution - google.protobuf.Timestamp start_time = 3 - [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - // distribution duration - int64 num_epochs = 4; - int64 current_epoch = 5; - int64 eden_boost_apr = 6; + // starting block height of the distribution + string distribution_start_block = 2 + [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; + // 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 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 + [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; + // number of block intervals that distribute rewards. + string distribution_epoch_in_blocks = 6 + [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; + // current epoch in block number + string current_epoch_in_blocks = 7 + [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; + // eden boost apr (0-1) range + string eden_boost_apr = 8 + [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; } \ No newline at end of file diff --git a/proto/elys/incentive/params.proto b/proto/elys/incentive/params.proto index 6b88071c3..c4392c3e6 100644 --- a/proto/elys/incentive/params.proto +++ b/proto/elys/incentive/params.proto @@ -33,5 +33,8 @@ message Params { int64 elys_stake_tracking_rate = 7; // Tracking dex rewards given to stakers - DexRewardsStakers dex_rewards_stakers = 8 [(gogoproto.nullable) = false]; + DexRewardsTracker dex_rewards_stakers = 8 [(gogoproto.nullable) = false]; + + // Tracking dex rewards given to LPs + DexRewardsTracker dex_rewards_lps = 9 [(gogoproto.nullable) = false]; } diff --git a/x/incentive/keeper/abci.go b/x/incentive/keeper/abci.go index 150059152..ad49e3c61 100644 --- a/x/incentive/keeper/abci.go +++ b/x/incentive/keeper/abci.go @@ -29,6 +29,16 @@ import ( // EndBlocker of incentive module func (k Keeper) EndBlocker(ctx sdk.Context) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + + // Elys staked amount tracking + k.ProcessElysStakedTracking(ctx) + + // Rewards distribution + k.ProcessRewardsDistribution(ctx) +} + +// Elys staked amount tracking +func (k Keeper) ProcessElysStakedTracking(ctx sdk.Context) { params := k.GetParams(ctx) // Update Elys staked amount every n blocks if params.ElysStakeTrackingRate == 0 || ctx.BlockHeight()%params.ElysStakeTrackingRate != 0 { @@ -61,3 +71,103 @@ func (k Keeper) EndBlocker(ctx sdk.Context) { }, ) } + +// Rewards distribution +func (k Keeper) ProcessRewardsDistribution(ctx sdk.Context) { + stakerEpoch, stakeIncentive := k.IsStakerRewardsDistributionEpoch(ctx) + if stakerEpoch { + err := k.UpdateStakersRewardsUnclaimed(ctx, stakeIncentive) + if err != nil { + ctx.Logger().Error("Failed to update staker rewards unclaimed", "error", err) + } + } + + lpsEpoch, lpIncentive := k.IsStakerRewardsDistributionEpoch(ctx) + if lpsEpoch { + err := k.UpdateLPRewardsUnclaimed(ctx, lpIncentive) + if err != nil { + ctx.Logger().Error("Failed to update lp rewards unclaimed", "error", err) + } + } +} + +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{} + } + + curBlockHeight := sdk.NewInt(ctx.BlockHeight()) + if stakeIncentive.DistributionStartBlock.LT(curBlockHeight) { + return false, types.IncentiveInfo{} + } + + // Increase current epoch of Stake incentive param + stakeIncentive.CurrentEpochInBlocks = stakeIncentive.CurrentEpochInBlocks.Add(stakeIncentive.DistributionEpochInBlocks) + if stakeIncentive.CurrentEpochInBlocks.GTE(stakeIncentive.TotalBlocksPerYear) { + if len(params.StakeIncentives) > 1 { + params.StakeIncentives = params.StakeIncentives[1:] + } else { + return false, types.IncentiveInfo{} + } + } + + // return found, stake, lp incentive params + return true, stakeIncentive +} + +func (k Keeper) IsLPRewardsDistributionEpoch(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.LpIncentives) < 1 { + return false, types.IncentiveInfo{} + } + + // Incentive params initialize + lpIncentive := params.LpIncentives[0] + if ctx.BlockHeight()%lpIncentive.DistributionEpochInBlocks.Int64() != 0 { + return false, types.IncentiveInfo{} + } + + curBlockHeight := sdk.NewInt(ctx.BlockHeight()) + if lpIncentive.DistributionStartBlock.LT(curBlockHeight) { + return false, types.IncentiveInfo{} + } + + // 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 { + params.LpIncentives = params.LpIncentives[1:] + } else { + return false, types.IncentiveInfo{} + } + } + + // return found, stake, lp incentive params + return true, lpIncentive +} diff --git a/x/incentive/keeper/apr.go b/x/incentive/keeper/apr.go index 638c50481..a6059ff93 100644 --- a/x/incentive/keeper/apr.go +++ b/x/incentive/keeper/apr.go @@ -31,23 +31,12 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk lpIncentive := params.LpIncentives[0] stkIncentive := params.StakeIncentives[0] - if lpIncentive.NumEpochs < 1 || stkIncentive.NumEpochs < 1 { + if lpIncentive.TotalBlocksPerYear.IsZero() || stkIncentive.TotalBlocksPerYear.IsZero() { return sdk.ZeroInt(), sdkerrors.Wrap(types.ErrNoNonInflationaryParams, "invalid inflationary params") } - // Eden amount for LPs at a single epoch. - edenAmountPerEpochLPs := lpIncentive.Amount.Quo(sdk.NewInt(lpIncentive.NumEpochs)) - - // Eden amount for Stakers at a single epoch. - edenAmountPerEpochStakers := stkIncentive.Amount.Quo(sdk.NewInt(stkIncentive.NumEpochs)) - if query.Denom == ptypes.Eden { if query.WithdrawType == commitmenttypes.EarnType_USDC_PROGRAM { - epoch, found := k.epochsKeeper.GetEpochInfo(ctx, lpIncentive.EpochIdentifier) - if !found { - return sdk.ZeroInt(), sdkerrors.Wrap(types.ErrNoNonInflationaryParams, "no inflationary params available") - } - totalUSDCDeposit := k.bankKeeper.GetBalance(ctx, stabletypes.PoolAddress(), baseCurrency) if totalUSDCDeposit.Amount.IsZero() { return sdk.ZeroInt(), nil @@ -59,42 +48,29 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk // Calculate stable stake pool share. poolShare := k.CalculatePoolShareForStableStakeLPs(ctx, totalProxyTVL, baseCurrency) - // Epoch count in 24 hrs. - epochDuration := int64(epoch.Duration.Seconds()) - - // Eden amount for LP in 24hrs = Eden amount per a single epoch for LPs * number of epochs in a day - edenAmountPerDay := edenAmountPerEpochLPs.Mul(sdk.NewInt(ptypes.SecondsPerDay)).Quo(sdk.NewInt(epochDuration)) + // Eden amount for LP in 24hrs = AllocationEpochInBlocks is the number of block for 24 hrs + edenAmountPerDay := lpIncentive.EdenAmountPerYear.Quo(lpIncentive.AllocationEpochInBlocks) // Eden amount for stable stake LP in 24hrs 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 - edenPrice := k.EstimatePrice(ctx, sdk.NewCoin(ptypes.Elys, sdk.NewInt(10)), baseCurrency) + edenPrice := k.EstimatePrice(ctx, sdk.NewCoin(ptypes.Elys, sdk.NewInt(100000)), baseCurrency) // Eden Apr for usdc earn program = {(Eden allocated for stable stake pool per day*365*price{eden/usdc}/(total usdc deposit)}*100 - // we multiply 10 as we have use 10elys as input in the price estimation - apr := edenAmountPerStableStakePerDay.MulInt(sdk.NewInt(10)).MulInt(sdk.NewInt(ptypes.DaysPerYear)).MulInt(edenPrice).QuoInt(totalUSDCDeposit.Amount) + // we divide 100000 as we have use 100000elys as input in the price estimation + apr := edenAmountPerStableStakePerDay.MulInt(sdk.NewInt(ptypes.DaysPerYear)).MulInt(edenPrice).QuoInt(totalUSDCDeposit.Amount).QuoInt(sdk.NewInt(100000)) return apr.TruncateInt(), nil } else { // Elys staking, Eden committed, EdenB committed. - epoch, found := k.epochsKeeper.GetEpochInfo(ctx, stkIncentive.EpochIdentifier) - if !found { - return sdk.ZeroInt(), sdkerrors.Wrap(types.ErrNoNonInflationaryParams, "no inflationary params available") - } - - // Epoch count in 24 hrs. - epochDuration := int64(epoch.Duration.Seconds()) - - // Eden amount for LP in 24hrs = Eden amount per a single epoch for LPs * number of epochs in a day - edenAmountPerDay := edenAmountPerEpochStakers.Mul(sdk.NewInt(ptypes.SecondsPerDay)).Quo(sdk.NewInt(epochDuration)) // Update total committed states k.UpdateTotalCommitmentInfo(ctx, baseCurrency) totalStakedSnapshot := k.tci.TotalElysBonded.Add(k.tci.TotalEdenEdenBoostCommitted) // 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 := edenAmountPerDay.Mul(sdk.NewInt(100)).Mul(sdk.NewInt(ptypes.DaysPerYear)).Quo(totalStakedSnapshot) + apr := stkIncentive.EdenAmountPerYear.Mul(sdk.NewInt(100)).Quo(totalStakedSnapshot) return apr, nil } } else if query.Denom == ptypes.BaseCurrency { @@ -110,16 +86,9 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk return sdk.ZeroInt(), nil } - epoch, found := k.epochsKeeper.GetEpochInfo(ctx, params.DexRewardsStakers.EpochIdentifier) - if !found { - return sdk.ZeroInt(), sdkerrors.Wrap(types.ErrNoNonInflationaryParams, "no inflationary params available") - } - - // Epoch duration - epochDuration := int64(epoch.Duration.Seconds()) - // DexReward amount per day = amount distributed / duration(in seconds) * total seconds per day. - amtDexRewardPerDay := amt.MulInt(sdk.NewInt(ptypes.SecondsPerDay)).QuoInt(sdk.NewInt(epochDuration)) + // 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 @@ -136,7 +105,7 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk return apr.TruncateInt(), nil } } else if query.Denom == ptypes.EdenB { - apr := sdk.NewInt(lpIncentive.EdenBoostApr) + apr := lpIncentive.EdenBoostApr.MulInt(sdk.NewInt(100)).TruncateInt() return apr, nil } diff --git a/x/incentive/keeper/hooks_epoch.go b/x/incentive/keeper/hooks_epoch.go deleted file mode 100644 index 015d76f2f..000000000 --- a/x/incentive/keeper/hooks_epoch.go +++ /dev/null @@ -1,53 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - epochstypes "github.com/elys-network/elys/x/epochs/types" -) - -// BeforeEpochStart performs a no-op -func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { - -} - -// AfterEpochEnd distributes vested tokens at the end of each epoch -func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64) { - // Find out incentive param using epochIdentifier and current block timestamp - foundIncentive, stakeIncentive, lpIncentive := k.GetProperIncentiveParam(ctx, epochIdentifier) - - // If there is no incentive available with the current epoch and timestamp, - if !foundIncentive { - return - } - - // Update unclaimed token amount - err := k.UpdateRewardsUnclaimed(ctx, epochIdentifier, stakeIncentive, lpIncentive) - if err != nil { - ctx.Logger().Error("Failed to update rewards unclaimed", "error", err) - return - } -} - -// ___________________________________________________________________________________________________ - -// Hooks wrapper struct for incentive keeper -type Hooks struct { - k Keeper -} - -var _ epochstypes.EpochHooks = Hooks{} - -// Return the wrapper struct -func (k Keeper) Hooks() Hooks { - return Hooks{k} -} - -// BeforeEpochStart implements EpochHooks -func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { - h.k.BeforeEpochStart(ctx, epochIdentifier, epochNumber) -} - -// AfterEpochEnd implements EpochHooks -func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) { - h.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber) -} diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index ae3f66725..d170d67cc 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -88,7 +88,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // Update unclaimed token amount // Called back through epoch hook -func (k Keeper) UpdateRewardsUnclaimed(ctx sdk.Context, epochIdentifier string, stakeIncentive types.IncentiveInfo, lpIncentive types.IncentiveInfo) error { +func (k Keeper) UpdateStakersRewardsUnclaimed(ctx sdk.Context, stakeIncentive types.IncentiveInfo) error { entry, found := k.apKeeper.GetEntry(ctx, ptypes.BaseCurrency) if !found { return sdkerrors.Wrapf(assetprofiletypes.ErrAssetProfileNotFound, "asset %s not found", ptypes.BaseCurrency) @@ -125,27 +125,25 @@ func (k Keeper) UpdateRewardsUnclaimed(ctx sdk.Context, epochIdentifier string, gasFeesLPsAmt := gasFeesForLps.AmountOf(baseCurrency) // Calculate eden amount per epoch - edenAmountPerEpochStakers := stakeIncentive.Amount.Quo(sdk.NewInt(stakeIncentive.NumEpochs)) - edenAmountPerEpochLPs := lpIncentive.Amount.Quo(sdk.NewInt(lpIncentive.NumEpochs)) + edenAmountPerEpochStakers := stakeIncentive.EdenAmountPerYear.Quo(stakeIncentive.TotalBlocksPerYear).Mul(stakeIncentive.DistributionEpochInBlocks) edenBoostAPR := stakeIncentive.EdenBoostApr // Track the DEX rewards distribution for stakers params := k.GetParams(ctx) - params.DexRewardsStakers.EpochIdentifier = stakeIncentive.EpochIdentifier - params.DexRewardsStakers.Amount = dexRevenueStakersAmt + // Add dexRevenue amount that was tracked by Lp tracker + dexRevenueStakersAmt = dexRevenueStakersAmt.Add(params.DexRewardsStakers.AmountCollectedByOtherTracker) + // Increase block number + params.DexRewardsStakers.NumBlocks = params.DexRewardsStakers.NumBlocks.Add(stakeIncentive.DistributionEpochInBlocks) + // Incrase total dex rewards given + params.DexRewardsStakers.Amount = params.DexRewardsStakers.Amount.Add(dexRevenueStakersAmt) + // Reset amount from other tracker + params.DexRewardsStakers.AmountCollectedByOtherTracker = sdk.ZeroDec() + // Don't increase Lps rewards blocks, it will be increased whenever LP distribution epoch happens. + params.DexRewardsLps.AmountCollectedByOtherTracker = params.DexRewardsLps.AmountCollectedByOtherTracker.Add(dexRevenueLPsAmt).Add(gasFeesLPsAmt) k.SetParams(ctx, params) - // Proxy TVL - // Multiplier on each liquidity pool - // We have 3 pools of 20, 30, 40 TVL - // We have mulitplier of 0.3, 0.5, 1.0 - // Proxy TVL = 20*0.3+30*0.5+40*1.0 - totalProxyTVL := k.CalculateProxyTVL(ctx, baseCurrency) - totalEdenGiven := sdk.ZeroInt() - totalEdenGivenLP := sdk.ZeroInt() totalRewardsGiven := sdk.ZeroInt() - totalRewardsGivenLP := sdk.ZeroInt() // Process to increase uncomitted token amount of Eden & Eden boost k.cmk.IterateCommitments( ctx, func(commitments ctypes.Commitments) bool { @@ -228,41 +226,7 @@ func (k Keeper) UpdateRewardsUnclaimed(ctx sdk.Context, epochIdentifier string, // ---------------------------------------------------------- // ---------------------------------------------------------- - // Calculate new unclaimed Eden tokens from LpTokens committed, Dex rewards distribution - // Distribute gas fees to LPs - // ---------------------------------------------------------- - // ---------------------------------------------------------- - newUnclaimedEdenTokensLp, dexRewardsLp := k.CalculateRewardsForLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLPs, gasFeesLPsAmt) - // Total - totalEdenGivenLP = totalEdenGivenLP.Add(newUnclaimedEdenTokensLp) - totalRewardsGivenLP = totalRewardsGivenLP.Add(dexRewardsLp) - - // Sum for each loop - newSumEdenRewardsUnClaimed = newSumEdenRewardsUnClaimed.Add(newUnclaimedEdenTokensLp) - newSumDexRewardsUnClaimed = newSumDexRewardsUnClaimed.Add(dexRewardsLp) - // ---------------------------------------------------------- - // ---------------------------------------------------------- - - // Calculate new unclaimed Eden tokens from stable stake LpTokens committed, Dex rewards distribution - // Distribute gas fees to LPs - // ---------------------------------------------------------- - // ---------------------------------------------------------- - newUnclaimedEdenTokensStableLp, dexRewardsStableLp := k.CalculateRewardsForStableStakeLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLPs, gasFeesLPsAmt, baseCurrency) - - // Total - totalEdenGivenLP = totalEdenGivenLP.Add(newUnclaimedEdenTokensStableLp) - totalRewardsGivenLP = totalRewardsGivenLP.Add(dexRewardsStableLp) - - // Sum for each loop - newSumEdenRewardsUnClaimed = newSumEdenRewardsUnClaimed.Add(newUnclaimedEdenTokensStableLp) - newSumDexRewardsUnClaimed = newSumDexRewardsUnClaimed.Add(dexRewardsStableLp) - - // Sub bucket - rewardsByUSDCDeposit = rewardsByUSDCDeposit.Add(sdk.NewCoin(ptypes.Eden, newUnclaimedEdenTokensStableLp)) - rewardsByUSDCDeposit = rewardsByUSDCDeposit.Add(sdk.NewCoin(baseCurrency, dexRewardsStableLp)) - // ---------------------------------------------------------- // ---------------------------------------------------------- - // Give commission to validators ( Eden from stakers and Dex rewards from stakers. ) // ---------------------------------------------------------- // ---------------------------------------------------------- @@ -291,7 +255,7 @@ func (k Keeper) UpdateRewardsUnclaimed(ctx sdk.Context, epochIdentifier string, // Calculate new unclaimed Eden-Boost tokens for staker and Eden token holders // ---------------------------------------------------------- // ---------------------------------------------------------- - newUnclaimedEdenBoostTokens, newUnclaimedEdenBoostFromElysStaking, newUnclaimedEdenBoostFromEdenCommited := k.CalculateEdenBoostRewards(ctx, delegatedAmt, commitments, epochIdentifier, edenBoostAPR) + newUnclaimedEdenBoostTokens, newUnclaimedEdenBoostFromElysStaking, newUnclaimedEdenBoostFromEdenCommited := k.CalculateEdenBoostRewards(ctx, delegatedAmt, commitments, stakeIncentive, edenBoostAPR) rewardsByElysStaking = rewardsByElysStaking.Add(sdk.NewCoin(ptypes.EdenB, newUnclaimedEdenBoostFromElysStaking)) rewardsByEdenCommitted = rewardsByEdenCommitted.Add(sdk.NewCoin(ptypes.EdenB, newUnclaimedEdenBoostFromEdenCommited)) @@ -310,14 +274,158 @@ func (k Keeper) UpdateRewardsUnclaimed(ctx sdk.Context, epochIdentifier string, // Calcualte the remainings edenRemained := edenAmountPerEpochStakers.Sub(totalEdenGiven) - edenRemainedLP := edenAmountPerEpochLPs.Sub(totalEdenGivenLP) dexRewardsRemained := dexRevenueStakersAmt.Sub(sdk.NewDecFromInt(totalRewardsGiven)) + + // Fund community the remain coins + // ---------------------------------- + edenRemainedCoin := sdk.NewDecCoin(ptypes.Eden, edenRemained) + dexRewardsRemainedCoin := sdk.NewDecCoinFromDec(baseCurrency, dexRewardsRemained) + + feePool := k.GetFeePool(ctx) + feePool.CommunityPool = feePool.CommunityPool.Add(edenRemainedCoin) + feePool.CommunityPool = feePool.CommunityPool.Add(dexRewardsRemainedCoin) + k.SetFeePool(ctx, feePool) + // ---------------------------------- + + return nil +} + +// Update unclaimed token amount +// Called back through epoch hook +func (k Keeper) UpdateLPRewardsUnclaimed(ctx sdk.Context, lpIncentive types.IncentiveInfo) error { + entry, found := k.apKeeper.GetEntry(ctx, ptypes.BaseCurrency) + if !found { + return sdkerrors.Wrapf(assetprofiletypes.ErrAssetProfileNotFound, "asset %s not found", ptypes.BaseCurrency) + } + baseCurrency := entry.Denom + + // Recalculate total committed info + k.UpdateTotalCommitmentInfo(ctx, baseCurrency) + + // Collect DEX revenue while tracking 65% of it for LPs reward calculation + // Assume these are collected in USDC + dexRevenue, dexRevenueForLps := k.CollectDEXRevenue(ctx) + + // Calculate each portion of DEX revenue - stakers, LPs + dexRevenueDec := sdk.NewDecCoinsFromCoins(dexRevenue...) + dexRevenueForStakers := dexRevenueDec.Sub(dexRevenueForLps) + + // Calculate each portion of Gas fees collected - stakers, LPs + gasFeeCollectedDec := sdk.NewDecCoinsFromCoins(k.tci.TotalFeesCollected...) + rewardPortionForLps := k.GetDEXRewardPortionForLPs(ctx) + gasFeesForLps := gasFeeCollectedDec.MulDecTruncate(rewardPortionForLps) + gasFeesForStakers := gasFeeCollectedDec.Sub(gasFeesForLps) + + // Sum Dex revenue for stakers + Gas fees for stakers and name it dex Revenus for stakers + // But won't sum dex revenue for LPs and gas fees for LPs as the LP revenue will be rewared by pool. + dexRevenueForStakers = dexRevenueForStakers.Add(gasFeesForStakers...) + + // Fund community pool based on the communtiy tax + dexRevenueRemainedForStakers := k.UpdateCommunityPool(ctx, dexRevenueForStakers) + + // USDC amount in sdk.Dec type + dexRevenueLPsAmt := dexRevenueForLps.AmountOf(baseCurrency) + dexRevenueStakersAmt := dexRevenueRemainedForStakers.AmountOf(baseCurrency) + gasFeesLPsAmt := gasFeesForLps.AmountOf(baseCurrency) + + // Calculate eden amount per epoch + edenAmountPerEpochLPs := lpIncentive.EdenAmountPerYear.Quo(lpIncentive.TotalBlocksPerYear).Mul(lpIncentive.DistributionEpochInBlocks) + + // Track the DEX rewards distribution for stakers + params := k.GetParams(ctx) + // Add dexRevenue amount that was tracked by Lp tracker + dexRevenueLPsAmt = dexRevenueLPsAmt.Add(params.DexRewardsLps.AmountCollectedByOtherTracker) + // Increase block number + params.DexRewardsLps.NumBlocks = params.DexRewardsLps.NumBlocks.Add(lpIncentive.DistributionEpochInBlocks) + // Incrase total dex rewards given + params.DexRewardsLps.Amount = params.DexRewardsLps.Amount.Add(dexRevenueLPsAmt).Add(gasFeesLPsAmt) + // Reset amount from other tracker + params.DexRewardsLps.AmountCollectedByOtherTracker = sdk.ZeroDec() + // Don't increase Lps rewards blocks, it will be increased whenever LP distribution epoch happens. + params.DexRewardsStakers.AmountCollectedByOtherTracker = params.DexRewardsStakers.AmountCollectedByOtherTracker.Add(dexRevenueStakersAmt) + k.SetParams(ctx, params) + + // Proxy TVL + // Multiplier on each liquidity pool + // We have 3 pools of 20, 30, 40 TVL + // We have mulitplier of 0.3, 0.5, 1.0 + // Proxy TVL = 20*0.3+30*0.5+40*1.0 + totalProxyTVL := k.CalculateProxyTVL(ctx, baseCurrency) + + totalEdenGivenLP := sdk.ZeroInt() + totalRewardsGivenLP := sdk.ZeroInt() + // Process to increase uncomitted token amount of Eden & Eden boost + k.cmk.IterateCommitments( + ctx, func(commitments ctypes.Commitments) bool { + // Commitment owner + creator := commitments.Creator + _, err := sdk.AccAddressFromBech32(creator) + if err != nil { + // This could be validator address + return false + } + + rewardsByElysStaking := sdk.NewCoins() + rewardsByEdenCommitted := sdk.NewCoins() + rewardsByEdenBCommitted := sdk.NewCoins() + rewardsByUSDCDeposit := sdk.NewCoins() + + newSumEdenRewardsUnClaimed := sdk.ZeroInt() + newSumEdenBRewardsUnClaimed := sdk.ZeroInt() + newSumDexRewardsUnClaimed := sdk.ZeroInt() + + // Calculate new unclaimed Eden tokens from LpTokens committed, Dex rewards distribution + // Distribute gas fees to LPs + // ---------------------------------------------------------- + // ---------------------------------------------------------- + newUnclaimedEdenTokensLp, dexRewardsLp := k.CalculateRewardsForLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLPs, gasFeesLPsAmt) + // Total + totalEdenGivenLP = totalEdenGivenLP.Add(newUnclaimedEdenTokensLp) + totalRewardsGivenLP = totalRewardsGivenLP.Add(dexRewardsLp) + + // Sum for each loop + newSumEdenRewardsUnClaimed = newSumEdenRewardsUnClaimed.Add(newUnclaimedEdenTokensLp) + newSumDexRewardsUnClaimed = newSumDexRewardsUnClaimed.Add(dexRewardsLp) + // ---------------------------------------------------------- + // ---------------------------------------------------------- + + // Calculate new unclaimed Eden tokens from stable stake LpTokens committed, Dex rewards distribution + // Distribute gas fees to LPs + // ---------------------------------------------------------- + // ---------------------------------------------------------- + newUnclaimedEdenTokensStableLp, dexRewardsStableLp := k.CalculateRewardsForStableStakeLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLPs, gasFeesLPsAmt, baseCurrency) + + // Total + totalEdenGivenLP = totalEdenGivenLP.Add(newUnclaimedEdenTokensStableLp) + totalRewardsGivenLP = totalRewardsGivenLP.Add(dexRewardsStableLp) + + // Sum for each loop + newSumEdenRewardsUnClaimed = newSumEdenRewardsUnClaimed.Add(newUnclaimedEdenTokensStableLp) + newSumDexRewardsUnClaimed = newSumDexRewardsUnClaimed.Add(dexRewardsStableLp) + + // Sub bucket + rewardsByUSDCDeposit = rewardsByUSDCDeposit.Add(sdk.NewCoin(ptypes.Eden, newUnclaimedEdenTokensStableLp)) + rewardsByUSDCDeposit = rewardsByUSDCDeposit.Add(sdk.NewCoin(baseCurrency, dexRewardsStableLp)) + // ---------------------------------------------------------- + // ---------------------------------------------------------- + + // Update Commitments with new unclaimed token amounts + k.UpdateCommitments(ctx, creator, &commitments, newSumEdenRewardsUnClaimed, newSumEdenBRewardsUnClaimed, newSumDexRewardsUnClaimed, baseCurrency) + + // Update sub buckets commitment with new unclaimed token amounts + k.UpdateCommitmentsSubBuckets(ctx, creator, &commitments, rewardsByElysStaking, rewardsByEdenCommitted, rewardsByEdenBCommitted, rewardsByUSDCDeposit) + return false + }, + ) + + // Calcualte the remainings + edenRemainedLP := edenAmountPerEpochLPs.Sub(totalEdenGivenLP) dexRewardsRemainedLP := dexRevenueLPsAmt.Add(gasFeesLPsAmt).Sub(sdk.NewDecFromInt(totalRewardsGivenLP)) // Fund community the remain coins // ---------------------------------- - edenRemainedCoin := sdk.NewDecCoin(ptypes.Eden, edenRemained.Add(edenRemainedLP)) - dexRewardsRemainedCoin := sdk.NewDecCoinFromDec(baseCurrency, dexRewardsRemained.Add(dexRewardsRemainedLP)) + edenRemainedCoin := sdk.NewDecCoin(ptypes.Eden, edenRemainedLP) + dexRewardsRemainedCoin := sdk.NewDecCoinFromDec(baseCurrency, dexRewardsRemainedLP) feePool := k.GetFeePool(ctx) feePool.CommunityPool = feePool.CommunityPool.Add(edenRemainedCoin) diff --git a/x/incentive/keeper/keeper_stakers.go b/x/incentive/keeper/keeper_stakers.go index d76731438..47fb9c23e 100644 --- a/x/incentive/keeper/keeper_stakers.go +++ b/x/incentive/keeper/keeper_stakers.go @@ -3,6 +3,7 @@ package keeper import ( 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" ) @@ -61,7 +62,7 @@ func (k Keeper) CalculateRewardsForStakersByCommitted(ctx sdk.Context, amt sdk.I } // Calculate new Eden-Boost token amounts based on the given conditions and user's current unclaimed token balance -func (k Keeper) CalculateEdenBoostRewards(ctx sdk.Context, delegatedAmt sdk.Int, commitments ctypes.Commitments, epochIdentifier string, edenBoostAPR int64) (sdk.Int, sdk.Int, sdk.Int) { +func (k Keeper) CalculateEdenBoostRewards(ctx sdk.Context, delegatedAmt sdk.Int, commitments ctypes.Commitments, incentiveInfo types.IncentiveInfo, edenBoostAPR sdk.Dec) (sdk.Int, sdk.Int, sdk.Int) { // Get eden commitments edenCommitted := commitments.GetCommittedAmountForDenom(ptypes.Eden) @@ -69,12 +70,13 @@ func (k Keeper) CalculateEdenBoostRewards(ctx sdk.Context, delegatedAmt sdk.Int, totalEden := delegatedAmt.Add(edenCommitted) // Calculate edenBoostAPR % APR for eden boost - epochNumsPerYear := k.CalculateEpochCountsPerYear(ctx, epochIdentifier) - if epochNumsPerYear == int64(0) { + epochNumsPerYear := incentiveInfo.TotalBlocksPerYear.Quo(incentiveInfo.DistributionEpochInBlocks) + if epochNumsPerYear.IsZero() { return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt() } - newEdenBoost := totalEden.Quo(sdk.NewInt(epochNumsPerYear)).Quo(sdk.NewInt(100)).Mul(sdk.NewInt(edenBoostAPR)) + apr := edenBoostAPR.TruncateInt() + newEdenBoost := totalEden.Quo(epochNumsPerYear).Mul(apr) // Calculate the portion of each program contribution newEdenBoostByElysStaked := sdk.ZeroInt() diff --git a/x/incentive/keeper/params.go b/x/incentive/keeper/params.go index 47b87b676..a32ed3b9a 100644 --- a/x/incentive/keeper/params.go +++ b/x/incentive/keeper/params.go @@ -138,58 +138,6 @@ func (k Keeper) UpdatePoolMultipliers(ctx sdk.Context, poolMultipliers []types.P return true } -// Find out active incentive params -func (k Keeper) GetProperIncentiveParam(ctx sdk.Context, epochIdentifier string) (bool, types.IncentiveInfo, types.IncentiveInfo) { - // Fetch incentive params - params := k.GetParams(ctx) - - // Update params - defer k.SetParams(ctx, params) - - // If we don't have enough params - if len(params.StakeIncentives) < 1 || len(params.LpIncentives) < 1 { - return false, types.IncentiveInfo{}, types.IncentiveInfo{} - } - - // Current block timestamp - timestamp := ctx.BlockTime().Unix() - - // Incentive params initialize - stakeIncentive := params.StakeIncentives[0] - lpIncentive := params.LpIncentives[0] - - // TODO: - // In V2 refactoring, have to make it available to calculate rewards for stakers and Lps at different epoch. - // Now rewards calculation is taking in one place (in a single loop) so it is now being triggered by any of the matching epoch (LPs, stakers), - // so should update this later. - if stakeIncentive.EpochIdentifier != lpIncentive.EpochIdentifier || stakeIncentive.EpochIdentifier != epochIdentifier || timestamp < stakeIncentive.StartTime.Unix() { - return false, types.IncentiveInfo{}, types.IncentiveInfo{} - } - - // Increase current epoch of Stake incentive param - stakeIncentive.CurrentEpoch = stakeIncentive.CurrentEpoch + 1 - if stakeIncentive.CurrentEpoch == stakeIncentive.NumEpochs { - if len(params.StakeIncentives) > 1 { - params.StakeIncentives = params.StakeIncentives[1:] - } else { - return false, types.IncentiveInfo{}, types.IncentiveInfo{} - } - } - - // Increase current epoch of Lp incentive param - lpIncentive.CurrentEpoch = lpIncentive.CurrentEpoch + 1 - if lpIncentive.CurrentEpoch == lpIncentive.NumEpochs { - if len(params.LpIncentives) > 1 { - params.LpIncentives = params.LpIncentives[1:] - } else { - return false, types.IncentiveInfo{}, types.IncentiveInfo{} - } - } - - // return found, stake, lp incentive params - return true, stakeIncentive, lpIncentive -} - // Calculate epoch counts per year to be used in APR calculation func (k Keeper) CalculateEpochCountsPerYear(ctx sdk.Context, epochIdentifier string) int64 { epochsInfo, found := k.epochsKeeper.GetEpochInfo(ctx, epochIdentifier) diff --git a/x/incentive/types/dex_rewards_stakers.pb.go b/x/incentive/types/dex_rewards_stakers.pb.go index 607e76b42..f63144710 100644 --- a/x/incentive/types/dex_rewards_stakers.pb.go +++ b/x/incentive/types/dex_rewards_stakers.pb.go @@ -24,24 +24,25 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// Track DexRewardsStakers -type DexRewardsStakers struct { - EpochIdentifier string `protobuf:"bytes,1,opt,name=epoch_identifier,json=epochIdentifier,proto3" json:"epoch_identifier,omitempty"` - Amount github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"amount"` +// DexRewardsTracker +type DexRewardsTracker struct { + NumBlocks github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=num_blocks,json=numBlocks,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"num_blocks"` + Amount github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"amount"` + AmountCollectedByOtherTracker github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=amount_collected_by_other_tracker,json=amountCollectedByOtherTracker,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"amount_collected_by_other_tracker"` } -func (m *DexRewardsStakers) Reset() { *m = DexRewardsStakers{} } -func (m *DexRewardsStakers) String() string { return proto.CompactTextString(m) } -func (*DexRewardsStakers) ProtoMessage() {} -func (*DexRewardsStakers) Descriptor() ([]byte, []int) { +func (m *DexRewardsTracker) Reset() { *m = DexRewardsTracker{} } +func (m *DexRewardsTracker) String() string { return proto.CompactTextString(m) } +func (*DexRewardsTracker) ProtoMessage() {} +func (*DexRewardsTracker) Descriptor() ([]byte, []int) { return fileDescriptor_aa61911f53a3bf12, []int{0} } -func (m *DexRewardsStakers) XXX_Unmarshal(b []byte) error { +func (m *DexRewardsTracker) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *DexRewardsStakers) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *DexRewardsTracker) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_DexRewardsStakers.Marshal(b, m, deterministic) + return xxx_messageInfo_DexRewardsTracker.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -51,27 +52,20 @@ func (m *DexRewardsStakers) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *DexRewardsStakers) XXX_Merge(src proto.Message) { - xxx_messageInfo_DexRewardsStakers.Merge(m, src) +func (m *DexRewardsTracker) XXX_Merge(src proto.Message) { + xxx_messageInfo_DexRewardsTracker.Merge(m, src) } -func (m *DexRewardsStakers) XXX_Size() int { +func (m *DexRewardsTracker) XXX_Size() int { return m.Size() } -func (m *DexRewardsStakers) XXX_DiscardUnknown() { - xxx_messageInfo_DexRewardsStakers.DiscardUnknown(m) +func (m *DexRewardsTracker) XXX_DiscardUnknown() { + xxx_messageInfo_DexRewardsTracker.DiscardUnknown(m) } -var xxx_messageInfo_DexRewardsStakers proto.InternalMessageInfo - -func (m *DexRewardsStakers) GetEpochIdentifier() string { - if m != nil { - return m.EpochIdentifier - } - return "" -} +var xxx_messageInfo_DexRewardsTracker proto.InternalMessageInfo func init() { - proto.RegisterType((*DexRewardsStakers)(nil), "elys.incentive.DexRewardsStakers") + proto.RegisterType((*DexRewardsTracker)(nil), "elys.incentive.DexRewardsTracker") } func init() { @@ -79,33 +73,36 @@ func init() { } var fileDescriptor_aa61911f53a3bf12 = []byte{ - // 251 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x48, 0xcd, 0xa9, 0x2c, - 0xd6, 0xcf, 0xcc, 0x4b, 0x4e, 0xcd, 0x2b, 0xc9, 0x2c, 0x4b, 0xd5, 0x4f, 0x49, 0xad, 0x88, 0x2f, - 0x4a, 0x2d, 0x4f, 0x2c, 0x4a, 0x29, 0x8e, 0x2f, 0x2e, 0x49, 0xcc, 0x4e, 0x2d, 0x2a, 0xd6, 0x2b, - 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x03, 0xa9, 0xd4, 0x83, 0xab, 0x94, 0x12, 0x49, 0xcf, 0x4f, - 0xcf, 0x07, 0x4b, 0xe9, 0x83, 0x58, 0x10, 0x55, 0x4a, 0x6d, 0x8c, 0x5c, 0x82, 0x2e, 0xa9, 0x15, - 0x41, 0x10, 0x23, 0x82, 0x21, 0x26, 0x08, 0x69, 0x72, 0x09, 0xa4, 0x16, 0xe4, 0x27, 0x67, 0xc4, - 0x67, 0xa6, 0x80, 0x74, 0xa7, 0x65, 0xa6, 0x16, 0x49, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xf1, - 0x83, 0xc5, 0x3d, 0xe1, 0xc2, 0x42, 0x6e, 0x5c, 0x6c, 0x89, 0xb9, 0xf9, 0xa5, 0x79, 0x25, 0x12, - 0x4c, 0x20, 0x05, 0x4e, 0x7a, 0x27, 0xee, 0xc9, 0x33, 0xdc, 0xba, 0x27, 0xaf, 0x96, 0x9e, 0x59, - 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x0c, 0xa5, - 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0xf5, 0x5c, 0x52, 0x93, 0x83, 0xa0, - 0xba, 0x9d, 0x7c, 0x56, 0x3c, 0x92, 0x63, 0x3c, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, - 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, - 0x86, 0x28, 0x3d, 0x24, 0xd3, 0x40, 0xfe, 0xd2, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0x06, - 0x73, 0xf4, 0x2b, 0x90, 0x02, 0x04, 0x6c, 0x72, 0x12, 0x1b, 0xd8, 0x77, 0xc6, 0x80, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xf5, 0xdb, 0xf0, 0x57, 0x2f, 0x01, 0x00, 0x00, + // 302 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xcf, 0x4a, 0x33, 0x31, + 0x14, 0xc5, 0x27, 0xfd, 0xa0, 0xd0, 0x2c, 0x3e, 0x70, 0x70, 0x51, 0x04, 0x53, 0x75, 0x21, 0xdd, + 0x34, 0x59, 0xf8, 0x06, 0x63, 0x11, 0x04, 0x45, 0x28, 0xae, 0xdc, 0x84, 0x99, 0xcc, 0xa5, 0x2d, + 0x33, 0x93, 0x5b, 0x92,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0xfe, 0xe6, 0x06, 0xe5, 0x43, 0x4d, + 0xed, 0x0a, 0x09, 0xee, 0xde, 0x2a, 0x46, 0x36, 0x15, 0x23, 0xdb, 0x8a, 0x91, 0xcf, 0x8a, 0x91, + 0x97, 0x3d, 0xf3, 0xb6, 0x7b, 0xe6, 0xbd, 0xef, 0x99, 0xf7, 0xc4, 0x0f, 0x42, 0xea, 0xd6, 0x27, + 0x1a, 0xdc, 0x1a, 0x4d, 0xd2, 0x5c, 0x44, 0x71, 0xb0, 0xae, 0x26, 0x30, 0xea, 0x37, 0xdd, 0x5f, + 0x7d, 0x05, 0x00, 0x00, 0xff, 0xff, 0x81, 0x07, 0xd5, 0x3f, 0xcd, 0x01, 0x00, 0x00, } -func (this *DexRewardsStakers) Equal(that interface{}) bool { +func (this *DexRewardsTracker) Equal(that interface{}) bool { if that == nil { return this == nil } - that1, ok := that.(*DexRewardsStakers) + that1, ok := that.(*DexRewardsTracker) if !ok { - that2, ok := that.(DexRewardsStakers) + that2, ok := that.(DexRewardsTracker) if ok { that1 = &that2 } else { @@ -117,15 +114,18 @@ func (this *DexRewardsStakers) Equal(that interface{}) bool { } else if this == nil { return false } - if this.EpochIdentifier != that1.EpochIdentifier { + if !this.NumBlocks.Equal(that1.NumBlocks) { return false } if !this.Amount.Equal(that1.Amount) { return false } + if !this.AmountCollectedByOtherTracker.Equal(that1.AmountCollectedByOtherTracker) { + return false + } return true } -func (m *DexRewardsStakers) Marshal() (dAtA []byte, err error) { +func (m *DexRewardsTracker) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -135,16 +135,26 @@ func (m *DexRewardsStakers) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *DexRewardsStakers) MarshalTo(dAtA []byte) (int, error) { +func (m *DexRewardsTracker) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *DexRewardsStakers) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *DexRewardsTracker) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + { + size := m.AmountCollectedByOtherTracker.Size() + i -= size + if _, err := m.AmountCollectedByOtherTracker.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDexRewardsStakers(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a { size := m.Amount.Size() i -= size @@ -155,13 +165,16 @@ func (m *DexRewardsStakers) MarshalToSizedBuffer(dAtA []byte) (int, error) { } i-- dAtA[i] = 0x12 - if len(m.EpochIdentifier) > 0 { - i -= len(m.EpochIdentifier) - copy(dAtA[i:], m.EpochIdentifier) - i = encodeVarintDexRewardsStakers(dAtA, i, uint64(len(m.EpochIdentifier))) - i-- - dAtA[i] = 0xa + { + size := m.NumBlocks.Size() + i -= size + if _, err := m.NumBlocks.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintDexRewardsStakers(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -176,18 +189,18 @@ func encodeVarintDexRewardsStakers(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *DexRewardsStakers) Size() (n int) { +func (m *DexRewardsTracker) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.EpochIdentifier) - if l > 0 { - n += 1 + l + sovDexRewardsStakers(uint64(l)) - } + l = m.NumBlocks.Size() + n += 1 + l + sovDexRewardsStakers(uint64(l)) l = m.Amount.Size() n += 1 + l + sovDexRewardsStakers(uint64(l)) + l = m.AmountCollectedByOtherTracker.Size() + n += 1 + l + sovDexRewardsStakers(uint64(l)) return n } @@ -197,7 +210,7 @@ func sovDexRewardsStakers(x uint64) (n int) { func sozDexRewardsStakers(x uint64) (n int) { return sovDexRewardsStakers(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *DexRewardsStakers) Unmarshal(dAtA []byte) error { +func (m *DexRewardsTracker) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -220,15 +233,15 @@ func (m *DexRewardsStakers) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: DexRewardsStakers: wiretype end group for non-group") + return fmt.Errorf("proto: DexRewardsTracker: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: DexRewardsStakers: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: DexRewardsTracker: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EpochIdentifier", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NumBlocks", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -256,7 +269,9 @@ func (m *DexRewardsStakers) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.EpochIdentifier = string(dAtA[iNdEx:postIndex]) + if err := m.NumBlocks.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { @@ -292,6 +307,40 @@ func (m *DexRewardsStakers) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AmountCollectedByOtherTracker", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDexRewardsStakers + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDexRewardsStakers + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDexRewardsStakers + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AmountCollectedByOtherTracker.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipDexRewardsStakers(dAtA[iNdEx:]) diff --git a/x/incentive/types/incentive.pb.go b/x/incentive/types/incentive.pb.go index c2333779b..94416994c 100644 --- a/x/incentive/types/incentive.pb.go +++ b/x/incentive/types/incentive.pb.go @@ -8,19 +8,16 @@ import ( github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" - github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" - time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -30,16 +27,22 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Incentive Info type IncentiveInfo struct { - // reward amount - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` - // epoch identifier - EpochIdentifier string `protobuf:"bytes,2,opt,name=epoch_identifier,json=epochIdentifier,proto3" json:"epoch_identifier,omitempty"` - // start_time of the distribution - StartTime time.Time `protobuf:"bytes,3,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time"` - // distribution duration - NumEpochs int64 `protobuf:"varint,4,opt,name=num_epochs,json=numEpochs,proto3" json:"num_epochs,omitempty"` - CurrentEpoch int64 `protobuf:"varint,5,opt,name=current_epoch,json=currentEpoch,proto3" json:"current_epoch,omitempty"` - EdenBoostApr int64 `protobuf:"varint,6,opt,name=eden_boost_apr,json=edenBoostApr,proto3" json:"eden_boost_apr,omitempty"` + // reward amount in eden for 1 year + EdenAmountPerYear github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=eden_amount_per_year,json=edenAmountPerYear,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"eden_amount_per_year"` + // starting block height of the distribution + DistributionStartBlock github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=distribution_start_block,json=distributionStartBlock,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"distribution_start_block"` + // distribution duration - block number per year + TotalBlocksPerYear github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=total_blocks_per_year,json=totalBlocksPerYear,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"total_blocks_per_year"` + // we set block numbers in 24 hrs + AllocationEpochInBlocks github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=allocation_epoch_in_blocks,json=allocationEpochInBlocks,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"allocation_epoch_in_blocks"` + // maximum eden allocation per day that won't exceed 30% apr + MaxEdenPerAllocation github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=max_eden_per_allocation,json=maxEdenPerAllocation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_eden_per_allocation"` + // number of block intervals that distribute rewards. + DistributionEpochInBlocks github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=distribution_epoch_in_blocks,json=distributionEpochInBlocks,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"distribution_epoch_in_blocks"` + // current epoch in block number + CurrentEpochInBlocks github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,opt,name=current_epoch_in_blocks,json=currentEpochInBlocks,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"current_epoch_in_blocks"` + // eden boost apr (0-1) range + EdenBoostApr github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=eden_boost_apr,json=edenBoostApr,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"eden_boost_apr"` } func (m *IncentiveInfo) Reset() { *m = IncentiveInfo{} } @@ -75,41 +78,6 @@ func (m *IncentiveInfo) XXX_DiscardUnknown() { var xxx_messageInfo_IncentiveInfo proto.InternalMessageInfo -func (m *IncentiveInfo) GetEpochIdentifier() string { - if m != nil { - return m.EpochIdentifier - } - return "" -} - -func (m *IncentiveInfo) GetStartTime() time.Time { - if m != nil { - return m.StartTime - } - return time.Time{} -} - -func (m *IncentiveInfo) GetNumEpochs() int64 { - if m != nil { - return m.NumEpochs - } - return 0 -} - -func (m *IncentiveInfo) GetCurrentEpoch() int64 { - if m != nil { - return m.CurrentEpoch - } - return 0 -} - -func (m *IncentiveInfo) GetEdenBoostApr() int64 { - if m != nil { - return m.EdenBoostApr - } - return 0 -} - func init() { proto.RegisterType((*IncentiveInfo)(nil), "elys.incentive.IncentiveInfo") } @@ -117,30 +85,34 @@ func init() { func init() { proto.RegisterFile("elys/incentive/incentive.proto", fileDescriptor_ed0e67c7f36f3313) } var fileDescriptor_ed0e67c7f36f3313 = []byte{ - // 358 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xc1, 0x4e, 0xfa, 0x40, - 0x10, 0xc6, 0xbb, 0xf0, 0xff, 0x13, 0x59, 0x05, 0x4d, 0xe3, 0xa1, 0x21, 0xb1, 0x25, 0x6a, 0x0c, - 0x1e, 0xd8, 0x26, 0xfa, 0x04, 0xd6, 0x68, 0xec, 0xb5, 0xf1, 0xe4, 0xa5, 0x69, 0xcb, 0x52, 0x1a, - 0xe8, 0x4e, 0xb3, 0xbb, 0x55, 0x79, 0x0b, 0x5e, 0xc5, 0xb7, 0xe0, 0xc8, 0xd1, 0x78, 0x40, 0x03, - 0x2f, 0x62, 0x76, 0x0b, 0xc8, 0xa9, 0x3b, 0xbf, 0xf9, 0xe6, 0xcb, 0xd7, 0x19, 0x6c, 0xd3, 0xc9, - 0x54, 0xb8, 0x19, 0x4b, 0x28, 0x93, 0xd9, 0x2b, 0xfd, 0x7b, 0x91, 0x82, 0x83, 0x04, 0xb3, 0xad, - 0xfa, 0x64, 0x47, 0x3b, 0xa7, 0x29, 0xa4, 0xa0, 0x5b, 0xae, 0x7a, 0x55, 0xaa, 0x8e, 0x93, 0x02, - 0xa4, 0x13, 0xea, 0xea, 0x2a, 0x2e, 0x87, 0xae, 0xcc, 0x72, 0x2a, 0x64, 0x94, 0x17, 0x95, 0xe0, - 0xfc, 0xa3, 0x86, 0x5b, 0xfe, 0xd6, 0xc4, 0x67, 0x43, 0x30, 0x1f, 0x71, 0x23, 0xca, 0xa1, 0x64, - 0xd2, 0x42, 0x5d, 0xd4, 0x6b, 0x7a, 0x64, 0xbe, 0x74, 0x8c, 0xaf, 0xa5, 0x73, 0x95, 0x66, 0x72, - 0x54, 0xc6, 0x24, 0x81, 0xdc, 0x4d, 0x40, 0xe4, 0x20, 0x36, 0x9f, 0xbe, 0x18, 0x8c, 0x5d, 0x39, - 0x2d, 0xa8, 0x20, 0x3e, 0x93, 0xc1, 0x66, 0xda, 0xbc, 0xc6, 0x27, 0xb4, 0x80, 0x64, 0x14, 0x66, - 0x03, 0xe5, 0x3e, 0xcc, 0x28, 0xb7, 0x6a, 0xca, 0x31, 0x38, 0xd6, 0xdc, 0xdf, 0x61, 0xf3, 0x1e, - 0x63, 0x21, 0x23, 0x2e, 0x43, 0x95, 0xce, 0xaa, 0x77, 0x51, 0xef, 0xf0, 0xa6, 0x43, 0xaa, 0xe8, - 0x64, 0x1b, 0x9d, 0x3c, 0x6f, 0xa3, 0x7b, 0x07, 0x2a, 0xd2, 0xec, 0xdb, 0x41, 0x41, 0x53, 0xcf, - 0xa9, 0x8e, 0x79, 0x86, 0x31, 0x2b, 0xf3, 0x50, 0x7b, 0x0b, 0xeb, 0x5f, 0x17, 0xf5, 0xea, 0x41, - 0x93, 0x95, 0xf9, 0x83, 0x06, 0xe6, 0x05, 0x6e, 0x25, 0x25, 0xe7, 0x94, 0xc9, 0x4a, 0x62, 0xfd, - 0xd7, 0x8a, 0xa3, 0x0d, 0xd4, 0x2a, 0xf3, 0x12, 0xb7, 0xe9, 0x80, 0xb2, 0x30, 0x06, 0x10, 0x32, - 0x8c, 0x0a, 0x6e, 0x35, 0x2a, 0x95, 0xa2, 0x9e, 0x82, 0x77, 0x05, 0xf7, 0x9e, 0xe6, 0x2b, 0x1b, - 0x2d, 0x56, 0x36, 0xfa, 0x59, 0xd9, 0x68, 0xb6, 0xb6, 0x8d, 0xc5, 0xda, 0x36, 0x3e, 0xd7, 0xb6, - 0xf1, 0x42, 0xf6, 0x76, 0xa4, 0xee, 0xd3, 0x67, 0x54, 0xbe, 0x01, 0x1f, 0xeb, 0xc2, 0x7d, 0xdf, - 0x3b, 0xa7, 0xde, 0x57, 0xdc, 0xd0, 0x3f, 0x77, 0xfb, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x38, 0x7a, - 0xa7, 0xd2, 0xed, 0x01, 0x00, 0x00, + // 426 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0xd3, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0x06, 0xf0, 0x86, 0x3f, 0x05, 0x2c, 0x98, 0x44, 0x54, 0x58, 0xa8, 0x50, 0x8a, 0x38, 0x20, + 0x2e, 0x4b, 0x0e, 0x7c, 0x82, 0x56, 0x4c, 0xa2, 0xb7, 0x69, 0x70, 0x81, 0x8b, 0xe5, 0xb8, 0xef, + 0x52, 0xab, 0x89, 0xdf, 0xc8, 0x7e, 0x03, 0xed, 0xb7, 0xe0, 0x1b, 0x71, 0xdd, 0x71, 0x47, 0xc4, + 0x61, 0x42, 0xed, 0x17, 0x41, 0x76, 0xba, 0x25, 0x63, 0xa7, 0xe5, 0x54, 0xbb, 0xb6, 0x7e, 0x8f, + 0x9e, 0x58, 0x2f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, 0xa8, 0x50, 0x2e, 0xb9, 0xd2, 0xfb, + 0xc0, 0xe8, 0x41, 0xaf, 0x9c, 0xc3, 0x56, 0x3c, 0x76, 0xe0, 0x5c, 0x37, 0x99, 0x21, 0xb0, 0xc3, + 0x52, 0xac, 0xb9, 0x7f, 0x1e, 0xd7, 0xa5, 0xbd, 0x17, 0x3d, 0xec, 0x95, 0x34, 0x2a, 0xc5, 0xfa, + 0x78, 0x01, 0xfa, 0x04, 0xcc, 0xf4, 0xda, 0x0a, 0x91, 0xbd, 0xbe, 0xf1, 0x40, 0xff, 0xb7, 0x1a, + 0xf6, 0xca, 0x7a, 0xd5, 0x35, 0x6f, 0xf5, 0x92, 0xb5, 0x31, 0xa0, 0xe9, 0x56, 0xd6, 0xa3, 0x7e, + 0xbd, 0xf6, 0xdc, 0xcd, 0x98, 0x2f, 0xec, 0xc0, 0x7f, 0xba, 0x0c, 0xd1, 0x12, 0x17, 0x95, 0x89, + 0x1e, 0xdf, 0x59, 0xff, 0x08, 0xf2, 0xf4, 0xa9, 0x53, 0x66, 0x0e, 0x99, 0x56, 0x66, 0xf6, 0xe9, + 0x7c, 0x1b, 0x07, 0x17, 0xdb, 0x38, 0xf8, 0xbb, 0x8d, 0x83, 0x9f, 0xbb, 0x78, 0x70, 0xb1, 0x8b, + 0x07, 0xbf, 0x77, 0xf1, 0xe0, 0x5b, 0xd2, 0xf1, 0xdc, 0xb4, 0x1e, 0x69, 0xa0, 0x1f, 0x68, 0x56, + 0x7e, 0x93, 0xae, 0x3b, 0xc3, 0xed, 0xed, 0x6c, 0xe8, 0x47, 0xf2, 0xc3, 0xbf, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x62, 0xa6, 0xae, 0x62, 0xfb, 0x03, 0x00, 0x00, } func (m *IncentiveInfo) Marshal() (dAtA []byte, err error) { @@ -163,40 +135,80 @@ func (m *IncentiveInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.EdenBoostApr != 0 { - i = encodeVarintIncentive(dAtA, i, uint64(m.EdenBoostApr)) - i-- - dAtA[i] = 0x30 + { + size := m.EdenBoostApr.Size() + i -= size + if _, err := m.EdenBoostApr.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) } - if m.CurrentEpoch != 0 { - i = encodeVarintIncentive(dAtA, i, uint64(m.CurrentEpoch)) - i-- - dAtA[i] = 0x28 + i-- + dAtA[i] = 0x42 + { + size := m.CurrentEpochInBlocks.Size() + i -= size + if _, err := m.CurrentEpochInBlocks.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) } - if m.NumEpochs != 0 { - i = encodeVarintIncentive(dAtA, i, uint64(m.NumEpochs)) - i-- - dAtA[i] = 0x20 + i-- + dAtA[i] = 0x3a + { + size := m.DistributionEpochInBlocks.Size() + i -= size + if _, err := m.DistributionEpochInBlocks.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) } - n1, err1 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StartTime):]) - if err1 != nil { - return 0, err1 + i-- + dAtA[i] = 0x32 + { + size := m.MaxEdenPerAllocation.Size() + i -= size + if _, err := m.MaxEdenPerAllocation.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size := m.AllocationEpochInBlocks.Size() + i -= size + if _, err := m.AllocationEpochInBlocks.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.TotalBlocksPerYear.Size() + i -= size + if _, err := m.TotalBlocksPerYear.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) } - i -= n1 - i = encodeVarintIncentive(dAtA, i, uint64(n1)) i-- dAtA[i] = 0x1a - if len(m.EpochIdentifier) > 0 { - i -= len(m.EpochIdentifier) - copy(dAtA[i:], m.EpochIdentifier) - i = encodeVarintIncentive(dAtA, i, uint64(len(m.EpochIdentifier))) - i-- - dAtA[i] = 0x12 + { + size := m.DistributionStartBlock.Size() + i -= size + if _, err := m.DistributionStartBlock.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 { - size := m.Amount.Size() + size := m.EdenAmountPerYear.Size() i -= size - if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.EdenAmountPerYear.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintIncentive(dAtA, i, uint64(size)) @@ -223,23 +235,22 @@ func (m *IncentiveInfo) Size() (n int) { } var l int _ = l - l = m.Amount.Size() + l = m.EdenAmountPerYear.Size() n += 1 + l + sovIncentive(uint64(l)) - l = len(m.EpochIdentifier) - if l > 0 { - n += 1 + l + sovIncentive(uint64(l)) - } - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StartTime) + l = m.DistributionStartBlock.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.TotalBlocksPerYear.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.AllocationEpochInBlocks.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.MaxEdenPerAllocation.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.DistributionEpochInBlocks.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.CurrentEpochInBlocks.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.EdenBoostApr.Size() n += 1 + l + sovIncentive(uint64(l)) - if m.NumEpochs != 0 { - n += 1 + sovIncentive(uint64(m.NumEpochs)) - } - if m.CurrentEpoch != 0 { - n += 1 + sovIncentive(uint64(m.CurrentEpoch)) - } - if m.EdenBoostApr != 0 { - n += 1 + sovIncentive(uint64(m.EdenBoostApr)) - } return n } @@ -280,7 +291,7 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field EdenAmountPerYear", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -308,13 +319,13 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.EdenAmountPerYear.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EpochIdentifier", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field DistributionStartBlock", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -342,13 +353,15 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.EpochIdentifier = string(dAtA[iNdEx:postIndex]) + if err := m.DistributionStartBlock.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TotalBlocksPerYear", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowIncentive @@ -358,30 +371,31 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthIncentive } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthIncentive } if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + if err := m.TotalBlocksPerYear.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NumEpochs", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllocationEpochInBlocks", wireType) } - m.NumEpochs = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowIncentive @@ -391,16 +405,31 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.NumEpochs |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIncentive + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIncentive + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AllocationEpochInBlocks.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentEpoch", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxEdenPerAllocation", wireType) } - m.CurrentEpoch = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowIncentive @@ -410,16 +439,99 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CurrentEpoch |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIncentive + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIncentive + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MaxEdenPerAllocation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 6: - if wireType != 0 { + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DistributionEpochInBlocks", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIncentive + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIncentive + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIncentive + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DistributionEpochInBlocks.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentEpochInBlocks", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIncentive + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIncentive + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIncentive + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CurrentEpochInBlocks.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EdenBoostApr", wireType) } - m.EdenBoostApr = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowIncentive @@ -429,11 +541,26 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.EdenBoostApr |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIncentive + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIncentive + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.EdenBoostApr.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipIncentive(dAtA[iNdEx:]) diff --git a/x/incentive/types/params.go b/x/incentive/types/params.go index 952ccd346..b6d71a6fb 100644 --- a/x/incentive/types/params.go +++ b/x/incentive/types/params.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - etypes "github.com/elys-network/elys/x/epochs/types" "gopkg.in/yaml.v2" ) @@ -21,6 +20,7 @@ var ( ParamStoreKeyPoolInfos = []byte("poolinfos") ParamStoreKeyElysStakeTrackingRate = []byte("elysstaketrackingrate") ParamStoreKeyDexRewardsStakers = []byte("dexrewardsstakers") + ParamStoreKeyDexRewardsLps = []byte("dexrewardslps") ) // ParamKeyTable the param key table for launch module @@ -38,9 +38,13 @@ func NewParams() Params { RewardPortionForLps: sdk.NewDecWithPrec(65, 2), PoolInfos: []PoolInfo(nil), ElysStakeTrackingRate: 10, - DexRewardsStakers: DexRewardsStakers{ - EpochIdentifier: etypes.DayEpochID, - Amount: sdk.ZeroDec(), + DexRewardsStakers: DexRewardsTracker{ + NumBlocks: sdk.ZeroInt(), + Amount: sdk.ZeroDec(), + }, + DexRewardsLps: DexRewardsTracker{ + NumBlocks: sdk.ZeroInt(), + Amount: sdk.ZeroDec(), }, } } @@ -61,6 +65,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(ParamStoreKeyPoolInfos, &p.PoolInfos, validatePoolInfos), paramtypes.NewParamSetPair(ParamStoreKeyElysStakeTrackingRate, &p.ElysStakeTrackingRate, validateElysStakeTrakcingRate), paramtypes.NewParamSetPair(ParamStoreKeyDexRewardsStakers, &p.DexRewardsStakers, validateDexRewardsStakers), + paramtypes.NewParamSetPair(ParamStoreKeyDexRewardsLps, &p.DexRewardsLps, validateDexRewardsLps), } } @@ -102,6 +107,10 @@ func (p Params) Validate() error { return err } + if err := validateDexRewardsLps(p.DexRewardsLps); err != nil { + return err + } + return nil } @@ -179,27 +188,31 @@ func validateLPIncentives(i interface{}) error { } for _, vv := range v { - if vv.Amount.LTE(sdk.ZeroInt()) { - return fmt.Errorf("invalid amount: %v", vv) + if vv.EdenAmountPerYear.LTE(sdk.ZeroInt()) { + return fmt.Errorf("invalid eden amount per year: %v", vv) + } + + if vv.TotalBlocksPerYear.LT(sdk.NewInt(1)) { + return fmt.Errorf("invalid total blocks per year: %v", vv) } - if vv.EpochIdentifier != etypes.WeekEpochID && - vv.EpochIdentifier != etypes.DayEpochID && - vv.EpochIdentifier != etypes.HourEpochID && - vv.EpochIdentifier != etypes.BandEpochID && - vv.EpochIdentifier != etypes.TenSecondsEpochID { - return fmt.Errorf("invalid epoch: %v", vv) + if vv.AllocationEpochInBlocks.LT(sdk.NewInt(0)) { + return fmt.Errorf("invalid allocation epoch in blocks: %v", vv) } - if vv.NumEpochs < 1 { - return fmt.Errorf("invalid num epoch: %v", vv) + if vv.DistributionEpochInBlocks.LT(sdk.NewInt(0)) { + return fmt.Errorf("invalid distribution epoch in blocks: %v", vv) } - if vv.CurrentEpoch < 0 { + if vv.CurrentEpochInBlocks.LT(sdk.NewInt(0)) { return fmt.Errorf("invalid current epoch: %v", vv) } - if vv.EdenBoostApr < 1 { + if vv.DistributionStartBlock.LT(sdk.NewInt(0)) { + return fmt.Errorf("invalid distribution epoch: %v", vv) + } + + if vv.EdenBoostApr.GT(sdk.NewDec(1)) || vv.EdenBoostApr.LT(sdk.ZeroDec()) { return fmt.Errorf("invalid eden boot apr: %v", vv) } } @@ -217,27 +230,31 @@ func validateStakeIncentives(i interface{}) error { } for _, vv := range v { - if vv.Amount.LTE(sdk.ZeroInt()) { - return fmt.Errorf("invalid amount: %v", vv) + if vv.EdenAmountPerYear.LTE(sdk.ZeroInt()) { + return fmt.Errorf("invalid eden amount per year: %v", vv) + } + + if vv.TotalBlocksPerYear.LT(sdk.NewInt(1)) { + return fmt.Errorf("invalid total blocks per year: %v", vv) } - if vv.EpochIdentifier != etypes.WeekEpochID && - vv.EpochIdentifier != etypes.DayEpochID && - vv.EpochIdentifier != etypes.HourEpochID && - vv.EpochIdentifier != etypes.BandEpochID && - vv.EpochIdentifier != etypes.TenSecondsEpochID { - return fmt.Errorf("invalid epoch: %v", vv) + if vv.AllocationEpochInBlocks.LT(sdk.NewInt(0)) { + return fmt.Errorf("invalid allocation epoch in blocks: %v", vv) } - if vv.NumEpochs < 1 { - return fmt.Errorf("invalid num epoch: %v", vv) + if vv.DistributionEpochInBlocks.LT(sdk.NewInt(0)) { + return fmt.Errorf("invalid distribution epoch in blocks: %v", vv) } - if vv.CurrentEpoch < 0 { + if vv.CurrentEpochInBlocks.LT(sdk.NewInt(0)) { return fmt.Errorf("invalid current epoch: %v", vv) } - if vv.EdenBoostApr < 1 { + if vv.DistributionStartBlock.LT(sdk.NewInt(0)) { + return fmt.Errorf("invalid distribution epoch: %v", vv) + } + + if vv.EdenBoostApr.GT(sdk.NewDec(1)) || vv.EdenBoostApr.LT(sdk.ZeroDec()) { return fmt.Errorf("invalid eden boot apr: %v", vv) } } @@ -264,7 +281,16 @@ func validateElysStakeTrakcingRate(i interface{}) error { } func validateDexRewardsStakers(i interface{}) error { - _, ok := i.(DexRewardsStakers) + _, ok := i.(DexRewardsTracker) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} + +func validateDexRewardsLps(i interface{}) error { + _, ok := i.(DexRewardsTracker) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } diff --git a/x/incentive/types/params.pb.go b/x/incentive/types/params.pb.go index 119198ed9..1bb8a6b4f 100644 --- a/x/incentive/types/params.pb.go +++ b/x/incentive/types/params.pb.go @@ -37,7 +37,9 @@ type Params struct { PoolInfos []PoolInfo `protobuf:"bytes,6,rep,name=pool_infos,json=poolInfos,proto3" json:"pool_infos"` ElysStakeTrackingRate int64 `protobuf:"varint,7,opt,name=elys_stake_tracking_rate,json=elysStakeTrackingRate,proto3" json:"elys_stake_tracking_rate,omitempty"` // Tracking dex rewards given to stakers - DexRewardsStakers DexRewardsStakers `protobuf:"bytes,8,opt,name=dex_rewards_stakers,json=dexRewardsStakers,proto3" json:"dex_rewards_stakers"` + DexRewardsStakers DexRewardsTracker `protobuf:"bytes,8,opt,name=dex_rewards_stakers,json=dexRewardsStakers,proto3" json:"dex_rewards_stakers"` + // Tracking dex rewards given to LPs + DexRewardsLps DexRewardsTracker `protobuf:"bytes,9,opt,name=dex_rewards_lps,json=dexRewardsLps,proto3" json:"dex_rewards_lps"` } func (m *Params) Reset() { *m = Params{} } @@ -107,11 +109,18 @@ func (m *Params) GetElysStakeTrackingRate() int64 { return 0 } -func (m *Params) GetDexRewardsStakers() DexRewardsStakers { +func (m *Params) GetDexRewardsStakers() DexRewardsTracker { if m != nil { return m.DexRewardsStakers } - return DexRewardsStakers{} + return DexRewardsTracker{} +} + +func (m *Params) GetDexRewardsLps() DexRewardsTracker { + if m != nil { + return m.DexRewardsLps + } + return DexRewardsTracker{} } func init() { @@ -121,37 +130,39 @@ func init() { func init() { proto.RegisterFile("elys/incentive/params.proto", fileDescriptor_3bca0267cb466fec) } var fileDescriptor_3bca0267cb466fec = []byte{ - // 480 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x4f, 0x6b, 0xd4, 0x40, - 0x18, 0xc6, 0x13, 0x77, 0x5d, 0xdb, 0x69, 0xeb, 0x9f, 0xac, 0x95, 0x58, 0x31, 0x1b, 0x3d, 0x48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3, 0xdb, 0x19, 0x3e, 0x6b, 0x1b, - 0x38, 0x62, 0x59, 0x58, 0x76, 0x4e, 0xca, 0xc6, 0xca, 0xc9, 0x03, 0xda, 0x06, 0xaf, 0xbb, 0xdf, - 0xbe, 0x0f, 0x8c, 0xd1, 0xf1, 0xc5, 0xda, 0x31, 0x2f, 0xd7, 0x8e, 0xf9, 0x6b, 0xed, 0x98, 0x5f, - 0x37, 0x8e, 0x71, 0xb9, 0x71, 0x8c, 0x1f, 0x1b, 0xc7, 0xf8, 0xec, 0x37, 0xd2, 0xca, 0xa7, 0x1c, - 0x72, 0xa6, 0x97, 0x20, 0x17, 0xc5, 0x21, 0xc8, 0x1a, 0x7b, 0x5c, 0x24, 0x37, 0xed, 0x15, 0xab, - 0xfb, 0xf2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x20, 0xb3, 0xab, 0x88, 0x64, 0x03, 0x00, 0x00, + // 501 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x4f, 0x6f, 0xd3, 0x3e, + 0x18, 0xc7, 0x93, 0x5f, 0xbb, 0xfe, 0x56, 0x6f, 0x65, 0x90, 0x32, 0x14, 0x86, 0x48, 0x03, 0x07, + 0x94, 0xcb, 0x12, 0xa9, 0x1c, 0x90, 0x90, 0x38, 0x50, 0x0d, 0xb4, 0x49, 0x13, 0x54, 0xe9, 0x24, + 0x24, 0x2e, 0x96, 0x1b, 0xbb, 0x5d, 0xd4, 0x24, 0x8f, 0x65, 0x7b, 0x34, 0x7d, 0x17, 0x1c, 0x39, + 0xf2, 0x32, 0x78, 0x09, 0x3b, 0xee, 0x88, 0x38, 0x4c, 0xa8, 0x7d, 0x23, 0x28, 0x7f, 0x16, 0x42, + 0xc4, 0x01, 0x38, 0xd5, 0xee, 0xe7, 0xf1, 0xc7, 0x8f, 0xbe, 0x4f, 0x8c, 0x1e, 0xb0, 0x68, 0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 0x96, 0xf6, 0xde, + 0xad, 0xc5, 0x9f, 0xdd, 0x70, 0x98, 0x30, 0xb5, 0x04, 0xb1, 0xc8, 0x37, 0x5e, 0x5a, 0x7b, 0x18, + 0xf9, 0x28, 0xa6, 0x9d, 0xfc, 0x2d, 0x3c, 0xfd, 0x11, 0x00, 0x00, 0xff, 0xff, 0xca, 0xd3, 0x44, + 0x49, 0xb5, 0x03, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -174,6 +185,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.DexRewardsLps.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a { size, err := m.DexRewardsStakers.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -311,6 +332,8 @@ func (m *Params) Size() (n int) { } l = m.DexRewardsStakers.Size() n += 1 + l + sovParams(uint64(l)) + l = m.DexRewardsLps.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -591,6 +614,39 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DexRewardsLps", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DexRewardsLps.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/incentive/types/params_test.go b/x/incentive/types/params_test.go index 46c30dc63..e32133d2c 100644 --- a/x/incentive/types/params_test.go +++ b/x/incentive/types/params_test.go @@ -2,12 +2,10 @@ package types_test import ( "testing" - "time" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - etypes "github.com/elys-network/elys/x/epochs/types" "github.com/elys-network/elys/x/incentive/types" ) @@ -25,16 +23,22 @@ func Test_validateParams(t *testing.T) { require.Error(t, params.Validate()) lpIncentive := types.IncentiveInfo{ - // reward amount - Amount: sdk.NewInt(10000), - // epoch identifier - EpochIdentifier: etypes.WeekEpochID, - // start_time of the distribution - StartTime: time.Now(), - // distribution duration - NumEpochs: 0, - CurrentEpoch: 0, - EdenBoostApr: 100, + // reward amount in eden for 1 year + EdenAmountPerYear: sdk.NewInt(10000000000000), + // starting block height of the distribution + DistributionStartBlock: sdk.ZeroInt(), + // distribution duration - block number per year + TotalBlocksPerYear: sdk.NewInt(10512000), + // we set block numbers in 24 hrs + AllocationEpochInBlocks: sdk.NewInt(28800), + // maximum eden allocation per day that won't exceed 30% apr + MaxEdenPerAllocation: sdk.NewInt(27397238400), + // number of block intervals that distribute rewards. + DistributionEpochInBlocks: sdk.NewInt(10), + // current epoch in block number + CurrentEpochInBlocks: sdk.NewInt(0), + // eden boost apr (0-1) range + EdenBoostApr: sdk.NewDec(1), } params.LpIncentives = append(params.LpIncentives, lpIncentive) From ad52fca35a4b21304e205566773c687fcd79ebfa Mon Sep 17 00:00:00 2001 From: kenta-elys Date: Thu, 23 Nov 2023 13:18:37 +0000 Subject: [PATCH 2/5] chore: refactor incentive --- docs/static/openapi.yml | 9 +++ proto/elys/incentive/params.proto | 6 ++ x/incentive/keeper/abci.go | 6 +- x/incentive/keeper/apr.go | 3 + x/incentive/keeper/keeper.go | 13 +++- x/incentive/types/params.go | 20 ++++++ x/incentive/types/params.pb.go | 115 +++++++++++++++++++++--------- 7 files changed, 134 insertions(+), 38 deletions(-) diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 5218a0033..14dcf472b 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -39620,6 +39620,9 @@ paths: type: string amount_collected_by_other_tracker: type: string + max_eden_reward_apr: + type: string + title: Maximum eden reward apr description: >- QueryParamsResponse is response type for the Query/Params RPC method. @@ -84480,6 +84483,9 @@ definitions: type: string amount_collected_by_other_tracker: type: string + max_eden_reward_apr: + type: string + title: Maximum eden reward apr description: Params defines the parameters for the module. elys.incentive.PoolInfo: type: object @@ -84631,6 +84637,9 @@ definitions: type: string amount_collected_by_other_tracker: type: string + max_eden_reward_apr: + type: string + title: Maximum eden reward apr description: QueryParamsResponse is response type for the Query/Params RPC method. elys.leveragelp.IsWhitelistedResponse: type: object diff --git a/proto/elys/incentive/params.proto b/proto/elys/incentive/params.proto index c4392c3e6..1fec5e2f0 100644 --- a/proto/elys/incentive/params.proto +++ b/proto/elys/incentive/params.proto @@ -37,4 +37,10 @@ message Params { // Tracking dex rewards given to LPs DexRewardsTracker dex_rewards_lps = 9 [(gogoproto.nullable) = false]; + + // Maximum eden reward apr + string max_eden_reward_apr = 10 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; } diff --git a/x/incentive/keeper/abci.go b/x/incentive/keeper/abci.go index ad49e3c61..75e6ecb9d 100644 --- a/x/incentive/keeper/abci.go +++ b/x/incentive/keeper/abci.go @@ -82,7 +82,7 @@ func (k Keeper) ProcessRewardsDistribution(ctx sdk.Context) { } } - lpsEpoch, lpIncentive := k.IsStakerRewardsDistributionEpoch(ctx) + lpsEpoch, lpIncentive := k.IsLPRewardsDistributionEpoch(ctx) if lpsEpoch { err := k.UpdateLPRewardsUnclaimed(ctx, lpIncentive) if err != nil { @@ -128,7 +128,7 @@ func (k Keeper) IsStakerRewardsDistributionEpoch(ctx sdk.Context) (bool, types.I } } - // return found, stake, lp incentive params + // return found, stake incentive params return true, stakeIncentive } @@ -168,6 +168,6 @@ func (k Keeper) IsLPRewardsDistributionEpoch(ctx sdk.Context) (bool, types.Incen } } - // return found, stake, lp incentive params + // return found, lp incentive params return true, lpIncentive } diff --git a/x/incentive/keeper/apr.go b/x/incentive/keeper/apr.go index a6059ff93..61dffe2d7 100644 --- a/x/incentive/keeper/apr.go +++ b/x/incentive/keeper/apr.go @@ -71,6 +71,9 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk // 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 := stkIncentive.EdenAmountPerYear.Mul(sdk.NewInt(100)).Quo(totalStakedSnapshot) + params := k.GetParams(ctx) + apr = sdk.MinInt(apr, params.MaxEdenRewardApr) + return apr, nil } } else if query.Denom == ptypes.BaseCurrency { diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index d170d67cc..e87ea4952 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -123,13 +123,22 @@ func (k Keeper) UpdateStakersRewardsUnclaimed(ctx sdk.Context, stakeIncentive ty dexRevenueLPsAmt := dexRevenueForLps.AmountOf(baseCurrency) dexRevenueStakersAmt := dexRevenueRemainedForStakers.AmountOf(baseCurrency) gasFeesLPsAmt := gasFeesForLps.AmountOf(baseCurrency) + edenBoostAPR := stakeIncentive.EdenBoostApr // Calculate eden amount per epoch + params := k.GetParams(ctx) + + // Calculate edenAmountPerEpochStakers := stakeIncentive.EdenAmountPerYear.Quo(stakeIncentive.TotalBlocksPerYear).Mul(stakeIncentive.DistributionEpochInBlocks) - edenBoostAPR := stakeIncentive.EdenBoostApr + + // 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) + maxEdenAmountPerStakers := params.MaxEdenRewardApr.Quo(sdk.NewInt(100)).Mul(k.tci.TotalElysBonded.Add(k.tci.TotalEdenEdenBoostCommitted)).Quo(stakeIncentive.TotalBlocksPerYear).Mul(stakeIncentive.DistributionEpochInBlocks) + + // Use min amount (eden allocation from tokenomics and max apr based eden amount) + edenAmountPerEpochStakers = sdk.MinInt(edenAmountPerEpochStakers, maxEdenAmountPerStakers) // Track the DEX rewards distribution for stakers - params := k.GetParams(ctx) // Add dexRevenue amount that was tracked by Lp tracker dexRevenueStakersAmt = dexRevenueStakersAmt.Add(params.DexRewardsStakers.AmountCollectedByOtherTracker) // Increase block number diff --git a/x/incentive/types/params.go b/x/incentive/types/params.go index b6d71a6fb..263cbe30e 100644 --- a/x/incentive/types/params.go +++ b/x/incentive/types/params.go @@ -21,6 +21,7 @@ var ( ParamStoreKeyElysStakeTrackingRate = []byte("elysstaketrackingrate") ParamStoreKeyDexRewardsStakers = []byte("dexrewardsstakers") ParamStoreKeyDexRewardsLps = []byte("dexrewardslps") + ParamStoreKeyMaxEdenRewardApr = []byte("maxedenrewardapr") ) // ParamKeyTable the param key table for launch module @@ -46,6 +47,7 @@ func NewParams() Params { NumBlocks: sdk.ZeroInt(), Amount: sdk.ZeroDec(), }, + MaxEdenRewardApr: sdk.NewInt(30), } } @@ -66,6 +68,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(ParamStoreKeyElysStakeTrackingRate, &p.ElysStakeTrackingRate, validateElysStakeTrakcingRate), paramtypes.NewParamSetPair(ParamStoreKeyDexRewardsStakers, &p.DexRewardsStakers, validateDexRewardsStakers), paramtypes.NewParamSetPair(ParamStoreKeyDexRewardsLps, &p.DexRewardsLps, validateDexRewardsLps), + paramtypes.NewParamSetPair(ParamStoreKeyMaxEdenRewardApr, &p.MaxEdenRewardApr, validateEdenRewardApr), } } @@ -297,3 +300,20 @@ func validateDexRewardsLps(i interface{}) error { return nil } + +func validateEdenRewardApr(i interface{}) error { + v, ok := i.(sdk.Int) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNegative() { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.LT(sdk.ZeroInt()) { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} diff --git a/x/incentive/types/params.pb.go b/x/incentive/types/params.pb.go index 1bb8a6b4f..d81a541ec 100644 --- a/x/incentive/types/params.pb.go +++ b/x/incentive/types/params.pb.go @@ -40,6 +40,8 @@ type Params struct { DexRewardsStakers DexRewardsTracker `protobuf:"bytes,8,opt,name=dex_rewards_stakers,json=dexRewardsStakers,proto3" json:"dex_rewards_stakers"` // Tracking dex rewards given to LPs DexRewardsLps DexRewardsTracker `protobuf:"bytes,9,opt,name=dex_rewards_lps,json=dexRewardsLps,proto3" json:"dex_rewards_lps"` + // Maximum eden reward apr + MaxEdenRewardApr github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,10,opt,name=max_eden_reward_apr,json=maxEdenRewardApr,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_eden_reward_apr"` } func (m *Params) Reset() { *m = Params{} } @@ -130,39 +132,40 @@ func init() { func init() { proto.RegisterFile("elys/incentive/params.proto", fileDescriptor_3bca0267cb466fec) } var fileDescriptor_3bca0267cb466fec = []byte{ - // 501 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x4f, 0x6f, 0xd3, 0x3e, - 0x18, 0xc7, 0x93, 0x5f, 0xbb, 0xfe, 0x56, 0x6f, 0x65, 0x90, 0x32, 0x14, 0x86, 0x48, 0x03, 0x07, - 0x94, 0xcb, 0x12, 0xa9, 0x1c, 0x90, 0x90, 0x38, 0x50, 0x0d, 0xb4, 0x49, 0x13, 0x54, 0xe9, 0x24, - 0x24, 0x2e, 0x96, 0x1b, 0xbb, 0x5d, 0xd4, 0x24, 0x8f, 0x65, 0x7b, 0x34, 0x7d, 0x17, 0x1c, 0x39, - 0xf2, 0x32, 0x78, 0x09, 0x3b, 0xee, 0x88, 0x38, 0x4c, 0xa8, 0x7d, 0x23, 0x28, 0x7f, 0x16,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x93, 0xee, 0x11, 0x0b, 0xfc, 0xdd, 0x4a, 0x72, 0x46, 0x52, 0x63, 0x88, - 0xf6, 0x97, 0xa1, 0x3a, 0xa7, 0x82, 0x2c, 0x31, 0xa1, 0x54, 0x60, 0x96, 0x90, 0x69, 0xc4, 0xa8, - 0xd9, 0xb6, 0x75, 0x67, 0xdb, 0xef, 0xdf, 0xc0, 0x97, 0x94, 0x8a, 0x57, 0x05, 0x32, 0x02, 0x74, - 0xaf, 0x88, 0x11, 0x73, 0x10, 0x2a, 0x84, 0x04, 0xcf, 0x40, 0xe0, 0x88, 0x4b, 0x73, 0xeb, 0x9f, - 0x3a, 0xea, 0x17, 0xb6, 0x71, 0x21, 0x7b, 0x0d, 0xe2, 0x94, 0x4b, 0xe3, 0x05, 0x42, 0xd9, 0x28, - 0x71, 0x98, 0xcc, 0x40, 0x9a, 0x9d, 0x3c, 0x37, 0xb3, 0x99, 0xdb, 0x18, 0x20, 0xaa, 0x45, 0xd6, - 0xe5, 0xe5, 0x5e, 0x1a, 0xcf, 0x90, 0x99, 0xd5, 0x16, 0x73, 0xc6, 0x4a, 0x90, 0x60, 0x11, 0x26, - 0x73, 0x2c, 0x88, 0x62, 0xe6, 0xff, 0xb6, 0xee, 0xb4, 0xfc, 0xfd, 0x8c, 0x4f, 0x32, 0x7c, 0x56, - 0x52, 0x9f, 0x28, 0x66, 0xbc, 0x43, 0xfd, 0xdf, 0x7c, 0x27, 0xe6, 0xb6, 0xad, 0x3b, 0x3b, 0xc3, - 0x47, 0xcd, 0x06, 0x8e, 0x58, 0xea, 0x17, 0x95, 0xb9, 0x84, 0x89, 0xb2, 0x93, 0x3b, 0xb4, 0x02, - 0x93, 0xc2, 0x60, 0xbc, 0x45, 0x7b, 0x75, 0x71, 0x16, 0x57, 0xf7, 0xef, 0xa4, 0xbd, 0x9f, 0xd2, - 0x53, 0x2e, 0x9f, 0xb7, 0x3f, 0x7d, 0x1e, 0x68, 0xa3, 0xe3, 0xcb, 0xb5, 0xa5, 0x5f, 0xad, 0x2d, - 0xfd, 0xfb, 0xda, 0xd2, 0x3f, 0x6e, 0x2c, 0xed, 0x6a, 0x63, 0x69, 0x5f, 0x37, 0x96, 0xf6, 0xde, - 0xad, 0xc5, 0x9f, 0xdd, 0x70, 0x98, 0x30, 0xb5, 0x04, 0xb1, 0xc8, 0x37, 0x5e, 0x5a, 0x7b, 0x18, - 0xf9, 0x28, 0xa6, 0x9d, 0xfc, 0x2d, 0x3c, 0xfd, 0x11, 0x00, 0x00, 0xff, 0xff, 0xca, 0xd3, 0x44, - 0x49, 0xb5, 0x03, 0x00, 0x00, + // 527 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0xc7, 0x1b, 0x56, 0xca, 0xea, 0xad, 0x6c, 0xa4, 0x0c, 0x99, 0x21, 0xd2, 0xc2, 0x01, 0xe5, + 0xb2, 0x44, 0x2a, 0x07, 0x24, 0x24, 0x0e, 0xab, 0x36, 0xb4, 0x4a, 0x08, 0xaa, 0x74, 0x12, 0x12, + 0x12, 0xb2, 0xdc, 0xd8, 0xed, 0xa2, 0x26, 0xb6, 0x65, 0x7b, 0x34, 0x7d, 0x0b, 0x6e, 0x70, 0xe4, + 0x71, 0x76, 0xdc, 0x11, 0x71, 0x98, 0x50, 0xfb, 0x22, 0xc8, 0x49, 0x16, 0x42, 0xc5, 0x81, 0x71, + 0x8a, 0x9d, 0xdf, 0xe7, 0x9f, 0xbf, 0xfc, 0x1d, 0x83, 0x47, 0x34, 0x5e, 0x28, 0x3f, 0x62, 0x21, + 0x65, 0x3a, 0xfa, 0x44, 0x7d, 0x81, 0x25, 0x4e, 0x94, 0x27, 0x24, 0xd7, 0xdc, 0xbe, 0x6b, 0xa0, + 0x57, 0xc2, 0xfd, 0xfb, 0x53, 0x3e, 0xe5, 0x19, 0xf2, 0xcd, 0x28, 0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7d, 0xf0, 0x2a, 0x66, 0xf3, 0x01, 0x07, 0x8c, + 0xea, 0x39, 0x97, 0xb3, 0x6c, 0xe2, 0xa7, 0x95, 0x7b, 0x97, 0xed, 0x32, 0x6e, 0x64, 0x57, 0xed, + 0xf9, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x96, 0x83, 0x00, 0xbe, 0x14, 0x04, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -185,6 +188,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.MaxEdenRewardApr.Size() + i -= size + if _, err := m.MaxEdenRewardApr.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 { size, err := m.DexRewardsLps.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -334,6 +347,8 @@ func (m *Params) Size() (n int) { n += 1 + l + sovParams(uint64(l)) l = m.DexRewardsLps.Size() n += 1 + l + sovParams(uint64(l)) + l = m.MaxEdenRewardApr.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -647,6 +662,40 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxEdenRewardApr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MaxEdenRewardApr.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) From 06153efa5a4b87ea02f8387d927c2fc662da1c24 Mon Sep 17 00:00:00 2001 From: kenta-elys Date: Thu, 23 Nov 2023 13:48:17 +0000 Subject: [PATCH 3/5] chore: fix start block time comparison issue --- config.yml | 33 +++++++++++------ proto/elys/incentive/params.proto | 2 +- x/incentive/keeper/abci.go | 4 +-- x/incentive/keeper/apr.go | 8 ++++- x/incentive/keeper/keeper.go | 4 +-- x/incentive/types/params.go | 8 ++--- x/incentive/types/params.pb.go | 60 +++++++++++++++---------------- 7 files changed, 67 insertions(+), 52 deletions(-) diff --git a/config.yml b/config.yml index 15d81d106..dbd473a71 100644 --- a/config.yml +++ b/config.yml @@ -284,24 +284,37 @@ genesis: incentive: params: lp_incentives: - - amount: "100000000000" - epoch_identifier: tenseconds - start_time: "2023-04-20T12:34:56.789Z" - num_epochs: "3154000" - current_epoch: "0" + - 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: - - amount: "100000000000" - epoch_identifier: tenseconds - start_time: "2023-04-20T12:34:56.789Z" - num_epochs: "3154000" - current_epoch: "0" + - 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" community_tax: "0.00" withdraw_addr_enabled: true reward_portion_for_lps: "0.65" pool_infos: [] elys_stake_tracking_rate: "10" + dex_rewards_stakers: + num_blocks: "0" + amount: "0" + amount_collected_by_other_tracker: "0" + dex_rewards_lps: + num_blocks: "0" + amount: "0" + amount_collected_by_other_tracker: "0" + max_eden_reward_apr: "0.30" fee_pool: community_pool: - amount: "0" diff --git a/proto/elys/incentive/params.proto b/proto/elys/incentive/params.proto index 1fec5e2f0..17fa3c0dd 100644 --- a/proto/elys/incentive/params.proto +++ b/proto/elys/incentive/params.proto @@ -40,7 +40,7 @@ message Params { // Maximum eden reward apr string max_eden_reward_apr = 10 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; } diff --git a/x/incentive/keeper/abci.go b/x/incentive/keeper/abci.go index 75e6ecb9d..5999c824f 100644 --- a/x/incentive/keeper/abci.go +++ b/x/incentive/keeper/abci.go @@ -114,7 +114,7 @@ func (k Keeper) IsStakerRewardsDistributionEpoch(ctx sdk.Context) (bool, types.I } curBlockHeight := sdk.NewInt(ctx.BlockHeight()) - if stakeIncentive.DistributionStartBlock.LT(curBlockHeight) { + if stakeIncentive.DistributionStartBlock.GT(curBlockHeight) { return false, types.IncentiveInfo{} } @@ -154,7 +154,7 @@ func (k Keeper) IsLPRewardsDistributionEpoch(ctx sdk.Context) (bool, types.Incen } curBlockHeight := sdk.NewInt(ctx.BlockHeight()) - if lpIncentive.DistributionStartBlock.LT(curBlockHeight) { + if lpIncentive.DistributionStartBlock.GT(curBlockHeight) { return false, types.IncentiveInfo{} } diff --git a/x/incentive/keeper/apr.go b/x/incentive/keeper/apr.go index 61dffe2d7..fd5fb1073 100644 --- a/x/incentive/keeper/apr.go +++ b/x/incentive/keeper/apr.go @@ -72,7 +72,8 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk // 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 := stkIncentive.EdenAmountPerYear.Mul(sdk.NewInt(100)).Quo(totalStakedSnapshot) params := k.GetParams(ctx) - apr = sdk.MinInt(apr, params.MaxEdenRewardApr) + maxApr := params.MaxEdenRewardApr.MulInt(sdk.NewInt(100)).TruncateInt() + apr = sdk.MinInt(apr, maxApr) return apr, nil } @@ -89,6 +90,11 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk return sdk.ZeroInt(), nil } + // If no rewards were given. + if params.DexRewardsStakers.NumBlocks.IsZero() { + 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) diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index e87ea4952..6740eef96 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -133,10 +133,10 @@ func (k Keeper) UpdateStakersRewardsUnclaimed(ctx sdk.Context, stakeIncentive ty // 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) - maxEdenAmountPerStakers := params.MaxEdenRewardApr.Quo(sdk.NewInt(100)).Mul(k.tci.TotalElysBonded.Add(k.tci.TotalEdenEdenBoostCommitted)).Quo(stakeIncentive.TotalBlocksPerYear).Mul(stakeIncentive.DistributionEpochInBlocks) + maxEdenAmountPerStakers := params.MaxEdenRewardApr.MulInt(k.tci.TotalElysBonded.Add(k.tci.TotalEdenEdenBoostCommitted)).MulInt(stakeIncentive.DistributionEpochInBlocks).QuoInt(stakeIncentive.TotalBlocksPerYear) // Use min amount (eden allocation from tokenomics and max apr based eden amount) - edenAmountPerEpochStakers = sdk.MinInt(edenAmountPerEpochStakers, maxEdenAmountPerStakers) + edenAmountPerEpochStakers = sdk.MinInt(edenAmountPerEpochStakers, maxEdenAmountPerStakers.TruncateInt()) // Track the DEX rewards distribution for stakers // Add dexRevenue amount that was tracked by Lp tracker diff --git a/x/incentive/types/params.go b/x/incentive/types/params.go index 263cbe30e..1dc873009 100644 --- a/x/incentive/types/params.go +++ b/x/incentive/types/params.go @@ -47,7 +47,7 @@ func NewParams() Params { NumBlocks: sdk.ZeroInt(), Amount: sdk.ZeroDec(), }, - MaxEdenRewardApr: sdk.NewInt(30), + MaxEdenRewardApr: sdk.NewDecWithPrec(3, 1), } } @@ -302,7 +302,7 @@ func validateDexRewardsLps(i interface{}) error { } func validateEdenRewardApr(i interface{}) error { - v, ok := i.(sdk.Int) + v, ok := i.(sdk.Dec) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } @@ -311,9 +311,5 @@ func validateEdenRewardApr(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } - if v.LT(sdk.ZeroInt()) { - return fmt.Errorf("invalid parameter type: %T", i) - } - return nil } diff --git a/x/incentive/types/params.pb.go b/x/incentive/types/params.pb.go index d81a541ec..3782999c2 100644 --- a/x/incentive/types/params.pb.go +++ b/x/incentive/types/params.pb.go @@ -41,7 +41,7 @@ type Params struct { // Tracking dex rewards given to LPs DexRewardsLps DexRewardsTracker `protobuf:"bytes,9,opt,name=dex_rewards_lps,json=dexRewardsLps,proto3" json:"dex_rewards_lps"` // Maximum eden reward apr - MaxEdenRewardApr github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,10,opt,name=max_eden_reward_apr,json=maxEdenRewardApr,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_eden_reward_apr"` + MaxEdenRewardApr github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,10,opt,name=max_eden_reward_apr,json=maxEdenRewardApr,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_eden_reward_apr"` } func (m *Params) Reset() { *m = Params{} } @@ -132,40 +132,40 @@ func init() { func init() { proto.RegisterFile("elys/incentive/params.proto", fileDescriptor_3bca0267cb466fec) } var fileDescriptor_3bca0267cb466fec = []byte{ - // 527 bytes of a gzipped FileDescriptorProto + // 524 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x6e, 0xd3, 0x30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 0x7d, 0xf0, 0x2a, 0x66, 0xf3, 0x01, 0xfb, 0x8c, 0xea, 0x39, 0x97, + 0xb3, 0x6c, 0xe2, 0xa7, 0x95, 0x7b, 0x97, 0xed, 0x32, 0x6e, 0x66, 0x57, 0xed, 0xf9, 0xaf, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xea, 0x74, 0xfc, 0xe3, 0x14, 0x04, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { From 3bd1cb10f799499907a2cc07e95a976e88d4f690 Mon Sep 17 00:00:00 2001 From: kenta-elys Date: Thu, 23 Nov 2023 16:22:36 +0000 Subject: [PATCH 4/5] chore: add v6 migrator in incnetive --- x/incentive/migrations/v6_migration.go | 11 +++++++++++ x/incentive/module.go | 2 +- x/incentive/types/params.go | 10 ++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 x/incentive/migrations/v6_migration.go diff --git a/x/incentive/migrations/v6_migration.go b/x/incentive/migrations/v6_migration.go new file mode 100644 index 000000000..e76716958 --- /dev/null +++ b/x/incentive/migrations/v6_migration.go @@ -0,0 +1,11 @@ +package migrations + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/incentive/types" +) + +func (m Migrator) V6Migration(ctx sdk.Context) error { + m.keeper.SetParams(ctx, types.NewParams()) + return nil +} diff --git a/x/incentive/module.go b/x/incentive/module.go index a5ca53b86..597b4627f 100644 --- a/x/incentive/module.go +++ b/x/incentive/module.go @@ -111,7 +111,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) m := migrations.NewMigrator(am.keeper) - err := cfg.RegisterMigration(types.ModuleName, 4, m.V5Migration) + err := cfg.RegisterMigration(types.ModuleName, 5, m.V6Migration) if err != nil { panic(err) } diff --git a/x/incentive/types/params.go b/x/incentive/types/params.go index 1dc873009..64937c0a0 100644 --- a/x/incentive/types/params.go +++ b/x/incentive/types/params.go @@ -40,12 +40,14 @@ func NewParams() Params { PoolInfos: []PoolInfo(nil), ElysStakeTrackingRate: 10, DexRewardsStakers: DexRewardsTracker{ - NumBlocks: sdk.ZeroInt(), - Amount: sdk.ZeroDec(), + NumBlocks: sdk.ZeroInt(), + Amount: sdk.ZeroDec(), + AmountCollectedByOtherTracker: sdk.ZeroDec(), }, DexRewardsLps: DexRewardsTracker{ - NumBlocks: sdk.ZeroInt(), - Amount: sdk.ZeroDec(), + NumBlocks: sdk.ZeroInt(), + Amount: sdk.ZeroDec(), + AmountCollectedByOtherTracker: sdk.ZeroDec(), }, MaxEdenRewardApr: sdk.NewDecWithPrec(3, 1), } From c2cb3b4741d8f594d85776c83fa882718eaf84b2 Mon Sep 17 00:00:00 2001 From: kenta-elys Date: Fri, 24 Nov 2023 07:47:57 +0000 Subject: [PATCH 5/5] chore: fix issue with update price feeder --- config.yml | 2 ++ x/amm/client/wasm/query_amm_price_by_denom.go | 9 +++++++++ x/oracle/client/cli/tx_price_feeder.go | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.yml b/config.yml index dbd473a71..d45b68926 100644 --- a/config.yml +++ b/config.yml @@ -419,6 +419,8 @@ genesis: priceFeeders: - feeder: "elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w" is_active: true + - feeder: "elys1v30pe777dj9mgsnlv0j2c5wh05m0ya0nlhuv7t" + is_active: true prices: - asset: USDT price: "1.00" diff --git a/x/amm/client/wasm/query_amm_price_by_denom.go b/x/amm/client/wasm/query_amm_price_by_denom.go index e20c2c206..08bd0c465 100644 --- a/x/amm/client/wasm/query_amm_price_by_denom.go +++ b/x/amm/client/wasm/query_amm_price_by_denom.go @@ -17,6 +17,15 @@ func (oq *Querier) queryAmmPriceByDenom(ctx sdk.Context, query *ammtypes.QueryAM return nil, errorsmod.Wrapf(aptypes.ErrAssetProfileNotFound, "denom: %s", denom) } + // If amount is zero + if query.TokenIn.Amount.IsZero() { + responseBytes, err := json.Marshal(sdk.ZeroDec()) + if err != nil { + return nil, errorsmod.Wrap(err, "failed to serialize in route by denom response") + } + return responseBytes, nil + } + // uses asset profile denom usdcDenom := assetProfile.Denom diff --git a/x/oracle/client/cli/tx_price_feeder.go b/x/oracle/client/cli/tx_price_feeder.go index 4f027b724..8d95e58b5 100644 --- a/x/oracle/client/cli/tx_price_feeder.go +++ b/x/oracle/client/cli/tx_price_feeder.go @@ -21,7 +21,7 @@ func CmdSetPriceFeeder() *cobra.Command { return err } - isActive, err := strconv.ParseBool(args[1]) + isActive, err := strconv.ParseBool(args[0]) if err != nil { return err }