From 61f49629f574a6ab0517c57a330b85b18fd9d806 Mon Sep 17 00:00:00 2001 From: jelysn Date: Thu, 18 Apr 2024 20:12:01 +0800 Subject: [PATCH] add basic upgrade handler for commitment, incentive, masterchef, distribution --- app/app.go | 2 +- proto/elys/commitment/commitments.proto | 47 +- proto/elys/incentive/dex_rewards_traker.proto | 29 + proto/elys/incentive/incentive.proto | 45 ++ proto/elys/incentive/params.proto | 46 ++ x/commitment/migrations/v3_migration.go | 50 -- x/commitment/types/commitments.pb.go | 10 +- x/estaking/{ => keeper}/genesis.go | 7 +- x/estaking/{ => keeper}/genesis_test.go | 10 +- x/estaking/module.go | 4 +- x/incentive/migrations/new_migrator.go | 28 +- x/incentive/migrations/v10_migration.go | 11 - x/incentive/migrations/v11_migration.go | 124 ++++ x/incentive/migrations/v2_migration.go | 11 - x/incentive/migrations/v3_migration.go | 11 - x/incentive/migrations/v4_migration.go | 11 - x/incentive/migrations/v5_migration.go | 11 - x/incentive/migrations/v6_migration.go | 11 - x/incentive/migrations/v7_migration.go | 11 - x/incentive/migrations/v8_migration.go | 11 - x/incentive/migrations/v9_migration.go | 11 - x/incentive/module.go | 28 +- x/incentive/types/incentive.pb.go | 619 ++++++++++++++++++ x/incentive/types/params.pb.go | 602 ++++++++++++++++- x/masterchef/keeper/hooks_masterchef.go | 9 +- 25 files changed, 1518 insertions(+), 241 deletions(-) create mode 100644 proto/elys/incentive/dex_rewards_traker.proto create mode 100644 proto/elys/incentive/incentive.proto rename x/estaking/{ => keeper}/genesis.go (86%) rename x/estaking/{ => keeper}/genesis_test.go (66%) delete mode 100644 x/incentive/migrations/v10_migration.go create mode 100644 x/incentive/migrations/v11_migration.go delete mode 100644 x/incentive/migrations/v2_migration.go delete mode 100644 x/incentive/migrations/v3_migration.go delete mode 100644 x/incentive/migrations/v4_migration.go delete mode 100644 x/incentive/migrations/v5_migration.go delete mode 100644 x/incentive/migrations/v6_migration.go delete mode 100644 x/incentive/migrations/v7_migration.go delete mode 100644 x/incentive/migrations/v8_migration.go delete mode 100644 x/incentive/migrations/v9_migration.go create mode 100644 x/incentive/types/incentive.pb.go diff --git a/app/app.go b/app/app.go index a95441c99..661db9c67 100644 --- a/app/app.go +++ b/app/app.go @@ -865,7 +865,7 @@ func NewElysApp( authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - incentiveModule := incentivemodule.NewAppModule(appCodec, app.IncentiveKeeper) + incentiveModule := incentivemodule.NewAppModule(appCodec, app.IncentiveKeeper, app.EstakingKeeper, app.MasterchefKeeper, app.DistrKeeper, app.CommitmentKeeper) app.BurnerKeeper = *burnermodulekeeper.NewKeeper( appCodec, diff --git a/proto/elys/commitment/commitments.proto b/proto/elys/commitment/commitments.proto index f7d6a8968..3bb7024b7 100644 --- a/proto/elys/commitment/commitments.proto +++ b/proto/elys/commitment/commitments.proto @@ -39,14 +39,6 @@ message CommittedTokens { repeated Lockup lockups = 3 [ (gogoproto.nullable) = false ]; } -message RewardsUnclaimed { - string denom = 1; - string amount = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; -} - message VestingTokens { string denom = 1; string total_amount = 2 [ @@ -62,8 +54,6 @@ message VestingTokens { int64 vest_started_timestamp = 7; } - -// GenesisState defines the commitment module's genesis state. message LegacyCommitments { string creator = 1; repeated CommittedTokens committed_tokens = 2; @@ -75,7 +65,7 @@ message LegacyCommitments { (gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" ]; - repeated LegacyVestingTokens vesting_tokens = 5; + repeated VestingTokens vesting_tokens = 5; repeated cosmos.base.v1beta1.Coin rewards_by_elys_unclaimed = 6 [ (gogoproto.nullable) = false, @@ -97,38 +87,3 @@ message LegacyCommitments { (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" ]; } - -message LegacyVestingTokens { - string denom = 1; - string total_amount = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; - string unvested_amount = 3 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; - string epoch_identifier = 4; - int64 num_epochs = 5; - int64 current_epoch = 6; - int64 vest_started_timestamp = 7; -} - -message LegacyVestingInfo { - string base_denom = 1; - string vesting_denom = 2; - string epoch_identifier = 3; - int64 num_epochs = 4; - string vest_now_factor = 5 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; - int64 num_max_vestings = 6; -} - -// Params defines the parameters for the module. -message LegacyParams { - option (gogoproto.goproto_stringer) = false; - - repeated LegacyVestingInfo vesting_infos = 1; -} \ No newline at end of file diff --git a/proto/elys/incentive/dex_rewards_traker.proto b/proto/elys/incentive/dex_rewards_traker.proto new file mode 100644 index 000000000..99949591b --- /dev/null +++ b/proto/elys/incentive/dex_rewards_traker.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; +package elys.incentive; + +option go_package = "github.com/elys-network/elys/x/incentive/types"; +option (gogoproto.equal_all) = true; + +import "gogoproto/gogo.proto"; + +// DexRewardsTracker is used for tracking rewards for stakers and LPs, all +// amount here is in USDC +message DexRewardsTracker { + // Number of blocks since start of epoch (distribution epoch) + string num_blocks = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + // Accumulated amount at distribution epoch - recalculated at every + // distribution epoch + string amount = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + // Accumulated rewards tracked by other (when it's for staking, from lp, if + // it's for lp, from staking) + string amount_collected_by_other_tracker = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/elys/incentive/incentive.proto b/proto/elys/incentive/incentive.proto new file mode 100644 index 000000000..3a2784c48 --- /dev/null +++ b/proto/elys/incentive/incentive.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; +package elys.incentive; +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/elys-network/elys/x/incentive/types"; + +// Incentive Info +message IncentiveInfo { + // 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 + ]; + // 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 + ]; + // unused + string epoch_num_blocks = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + // unused + string max_eden_per_allocation = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + // unused + 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 + ]; +} \ No newline at end of file diff --git a/proto/elys/incentive/params.proto b/proto/elys/incentive/params.proto index 937cc3f8d..462ac9246 100644 --- a/proto/elys/incentive/params.proto +++ b/proto/elys/incentive/params.proto @@ -2,11 +2,57 @@ syntax = "proto3"; package elys.incentive; import "gogoproto/gogo.proto"; +import "elys/incentive/incentive.proto"; +import "elys/incentive/pool.proto"; +import "elys/incentive/dex_rewards_traker.proto"; option go_package = "github.com/elys-network/elys/x/incentive/types"; // Params defines the parameters for the module. message Params { option (gogoproto.goproto_stringer) = false; + IncentiveInfo lp_incentives = 1; + IncentiveInfo stake_incentives = 2; + // Dex revenue percent for lps, `100 - reward_portion_for_lps - + // reward_portion_for_stakers = revenue percent for protocol`. + string reward_portion_for_lps = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // Dex revenue percent for lps, `100 - reward_portion_for_lps - + // reward_portion_for_stakers = revenue percent for protocol`. + string reward_portion_for_stakers = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // Pool information + // poolId, reward wallet, **multiplier**, dex rewards given + repeated PoolInfo pool_infos = 5 [ (gogoproto.nullable) = false ]; + + // Number of blocks to update elys staked amount for delegators + int64 elys_stake_snap_interval = 6; + + // Tracking dex rewards given to stakers + DexRewardsTracker dex_rewards_stakers = 7 [ (gogoproto.nullable) = false ]; + + // Tracking dex rewards given to LPs + DexRewardsTracker dex_rewards_lps = 8 [ (gogoproto.nullable) = false ]; + + // Maximum eden reward apr for stakers - [0 - 0.3] + string max_eden_reward_apr_stakers = 9 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // Maximum eden reward apr for lps - [0 - 0.3] + string max_eden_reward_apr_lps = 10 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // Distribution interval in blocks - number of blocks on distribution epoch + int64 distribution_interval = 11; } diff --git a/x/commitment/migrations/v3_migration.go b/x/commitment/migrations/v3_migration.go index 3bd4ea898..ffd4806d4 100644 --- a/x/commitment/migrations/v3_migration.go +++ b/x/commitment/migrations/v3_migration.go @@ -1,60 +1,10 @@ package migrations import ( - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/commitment/types" ) func (m Migrator) V3Migration(ctx sdk.Context) error { - legacyParams := m.keeper.GetLegacyParams(ctx) - totalCommitted := sdk.Coins{} - legacyCommitments := m.keeper.GetAllLegacyCommitments(ctx) - for _, legacy := range legacyCommitments { - - vestingTokens := []*types.VestingTokens{} - for _, vt := range legacy.VestingTokens { - blockMultiplier := int64(17280) // "day" - if vt.EpochIdentifier == "tenseconds" { - blockMultiplier = int64(2) - } else { - blockMultiplier = int64(720) // "hour" - } - vestingTokens = append(vestingTokens, &types.VestingTokens{ - Denom: vt.Denom, - TotalAmount: vt.UnvestedAmount, - ClaimedAmount: math.ZeroInt(), - NumBlocks: vt.NumEpochs * blockMultiplier, - StartBlock: ctx.BlockHeight(), - VestStartedTimestamp: vt.VestStartedTimestamp, - }) - } - m.keeper.SetCommitments(ctx, types.Commitments{ - Creator: legacy.Creator, - CommittedTokens: legacy.CommittedTokens, - Claimed: legacy.Claimed, - VestingTokens: vestingTokens, - }) - for _, token := range legacy.CommittedTokens { - totalCommitted = totalCommitted.Add(sdk.NewCoin(token.Denom, token.Amount)) - } - } - - vestingInfos := []*types.VestingInfo{} - for _, legacy := range legacyParams.VestingInfos { - vestingInfos = append(vestingInfos, &types.VestingInfo{ - BaseDenom: legacy.BaseDenom, - VestingDenom: legacy.VestingDenom, - NumBlocks: legacy.NumEpochs * 17280, - VestNowFactor: legacy.VestNowFactor, - NumMaxVestings: legacy.NumMaxVestings, - }) - } - - m.keeper.SetParams(ctx, types.Params{ - VestingInfos: vestingInfos, - TotalCommitted: totalCommitted, - }) return nil } diff --git a/x/commitment/types/commitments.pb.go b/x/commitment/types/commitments.pb.go index abb20d564..d4240de70 100644 --- a/x/commitment/types/commitments.pb.go +++ b/x/commitment/types/commitments.pb.go @@ -310,14 +310,12 @@ func (m *VestingTokens) GetVestStartedTimestamp() int64 { } return 0 } - -// GenesisState defines the commitment module's genesis state. type LegacyCommitments struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` CommittedTokens []*CommittedTokens `protobuf:"bytes,2,rep,name=committed_tokens,json=committedTokens,proto3" json:"committed_tokens,omitempty"` RewardsUnclaimed github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=rewards_unclaimed,json=rewardsUnclaimed,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"rewards_unclaimed"` Claimed github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=claimed,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"claimed"` - VestingTokens []*LegacyVestingTokens `protobuf:"bytes,5,rep,name=vesting_tokens,json=vestingTokens,proto3" json:"vesting_tokens,omitempty"` + VestingTokens []*VestingTokens `protobuf:"bytes,5,rep,name=vesting_tokens,json=vestingTokens,proto3" json:"vesting_tokens,omitempty"` RewardsByElysUnclaimed github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=rewards_by_elys_unclaimed,json=rewardsByElysUnclaimed,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"rewards_by_elys_unclaimed"` RewardsByEdenUnclaimed github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,7,rep,name=rewards_by_eden_unclaimed,json=rewardsByEdenUnclaimed,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"rewards_by_eden_unclaimed"` RewardsByEdenbUnclaimed github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,8,rep,name=rewards_by_edenb_unclaimed,json=rewardsByEdenbUnclaimed,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"rewards_by_edenb_unclaimed"` @@ -328,7 +326,7 @@ func (m *LegacyCommitments) Reset() { *m = LegacyCommitments{} } func (m *LegacyCommitments) String() string { return proto.CompactTextString(m) } func (*LegacyCommitments) ProtoMessage() {} func (*LegacyCommitments) Descriptor() ([]byte, []int) { - return fileDescriptor_47379c930fe66ed6, []int{5} + return fileDescriptor_47379c930fe66ed6, []int{0} } func (m *LegacyCommitments) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -385,7 +383,7 @@ func (m *LegacyCommitments) GetClaimed() github_com_cosmos_cosmos_sdk_types.Coin return nil } -func (m *LegacyCommitments) GetVestingTokens() []*LegacyVestingTokens { +func (m *LegacyCommitments) GetVestingTokens() []*VestingTokens { if m != nil { return m.VestingTokens } @@ -2491,7 +2489,7 @@ func (m *LegacyCommitments) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.VestingTokens = append(m.VestingTokens, &LegacyVestingTokens{}) + m.VestingTokens = append(m.VestingTokens, &VestingTokens{}) if err := m.VestingTokens[len(m.VestingTokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/x/estaking/genesis.go b/x/estaking/keeper/genesis.go similarity index 86% rename from x/estaking/genesis.go rename to x/estaking/keeper/genesis.go index f4544c7b9..71eaee0e4 100644 --- a/x/estaking/genesis.go +++ b/x/estaking/keeper/genesis.go @@ -1,15 +1,14 @@ -package estaking +package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/elys-network/elys/x/estaking/keeper" "github.com/elys-network/elys/x/estaking/types" ptypes "github.com/elys-network/elys/x/parameter/types" ) // InitGenesis initializes the module's state from a provided genesis state. -func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { +func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { var shouldRunEdenValHook = false var shouldRunEdenBValHook = false edenValAddr := sdk.ValAddress(authtypes.NewModuleAddress(ptypes.Eden)) @@ -46,7 +45,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) } // ExportGenesis returns the module's exported genesis -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { genesis := types.DefaultGenesis() genesis.Params = k.GetParams(ctx) diff --git a/x/estaking/genesis_test.go b/x/estaking/keeper/genesis_test.go similarity index 66% rename from x/estaking/genesis_test.go rename to x/estaking/keeper/genesis_test.go index f81ef74e0..a19e54fc2 100644 --- a/x/estaking/genesis_test.go +++ b/x/estaking/keeper/genesis_test.go @@ -1,4 +1,4 @@ -package estaking_test +package keeper_test import ( "testing" @@ -6,7 +6,6 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" simapp "github.com/elys-network/elys/app" "github.com/elys-network/elys/testutil/nullify" - "github.com/elys-network/elys/x/estaking" "github.com/elys-network/elys/x/estaking/types" "github.com/stretchr/testify/require" ) @@ -16,16 +15,13 @@ func TestGenesis(t *testing.T) { ctx := app.BaseApp.NewContext(true, tmproto.Header{}) genesisState := types.GenesisState{ Params: types.DefaultParams(), - // this line is used by starport scaffolding # genesis/test/state } k := app.EstakingKeeper - estaking.InitGenesis(ctx, k, genesisState) - got := estaking.ExportGenesis(ctx, k) + k.InitGenesis(ctx, genesisState) + got := k.ExportGenesis(ctx) require.NotNil(t, got) nullify.Fill(&genesisState) nullify.Fill(got) - - // this line is used by starport scaffolding # genesis/test/assert } diff --git a/x/estaking/module.go b/x/estaking/module.go index 467b5dd05..05fa55381 100644 --- a/x/estaking/module.go +++ b/x/estaking/module.go @@ -126,14 +126,14 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) - InitGenesis(ctx, am.keeper, genState) + am.keeper.InitGenesis(ctx, genState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the module's exported genesis state as raw JSON bytes. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := ExportGenesis(ctx, am.keeper) + genState := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(genState) } diff --git a/x/incentive/migrations/new_migrator.go b/x/incentive/migrations/new_migrator.go index efb434c4a..ee482abfb 100644 --- a/x/incentive/migrations/new_migrator.go +++ b/x/incentive/migrations/new_migrator.go @@ -1,13 +1,33 @@ package migrations import ( - "github.com/elys-network/elys/x/incentive/keeper" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + commitmentkeeper "github.com/elys-network/elys/x/commitment/keeper" + estakingkeeper "github.com/elys-network/elys/x/estaking/keeper" + incentivekeeper "github.com/elys-network/elys/x/incentive/keeper" + masterchefkeeper "github.com/elys-network/elys/x/masterchef/keeper" ) type Migrator struct { - keeper keeper.Keeper + incentiveKeeper incentivekeeper.Keeper + estakingKeeper estakingkeeper.Keeper + masterchefKeeper masterchefkeeper.Keeper + distrKeeper distrkeeper.Keeper + commitmentKeeper commitmentkeeper.Keeper } -func NewMigrator(keeper keeper.Keeper) Migrator { - return Migrator{keeper: keeper} +func NewMigrator( + incentiveKeeper incentivekeeper.Keeper, + estakingKeeper estakingkeeper.Keeper, + masterchefKeeper masterchefkeeper.Keeper, + distrKeeper distrkeeper.Keeper, + commitmentKeeper commitmentkeeper.Keeper, +) Migrator { + return Migrator{ + incentiveKeeper: incentiveKeeper, + estakingKeeper: estakingKeeper, + masterchefKeeper: masterchefKeeper, + distrKeeper: distrKeeper, + commitmentKeeper: commitmentKeeper, + } } diff --git a/x/incentive/migrations/v10_migration.go b/x/incentive/migrations/v10_migration.go deleted file mode 100644 index 232ad4069..000000000 --- a/x/incentive/migrations/v10_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func (m Migrator) V10Migration(ctx sdk.Context) error { - params := m.keeper.GetParams(ctx) - m.keeper.SetParams(ctx, params) - return nil -} diff --git a/x/incentive/migrations/v11_migration.go b/x/incentive/migrations/v11_migration.go new file mode 100644 index 000000000..5f6847692 --- /dev/null +++ b/x/incentive/migrations/v11_migration.go @@ -0,0 +1,124 @@ +package migrations + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + commitmenttypes "github.com/elys-network/elys/x/commitment/types" + estakingtypes "github.com/elys-network/elys/x/estaking/types" + mastercheftypes "github.com/elys-network/elys/x/masterchef/types" + ptypes "github.com/elys-network/elys/x/parameter/types" +) + +func (m Migrator) V11Migration(ctx sdk.Context) error { + // initialize pool infos from incentive module + incentiveParams := m.incentiveKeeper.GetParams(ctx) + for _, poolInfo := range incentiveParams.PoolInfos { + m.masterchefKeeper.SetPool(ctx, mastercheftypes.PoolInfo{ + PoolId: poolInfo.PoolId, + RewardWallet: poolInfo.RewardWallet, + Multiplier: poolInfo.Multiplier, + NumBlocks: poolInfo.NumBlocks, + DexRewardAmountGiven: poolInfo.DexRewardAmountGiven, + EdenRewardAmountGiven: poolInfo.EdenRewardAmountGiven, + EdenApr: poolInfo.EdenApr, + DexApr: poolInfo.DexApr, + ExternalIncentiveApr: sdk.ZeroDec(), + ExternalRewardDenoms: []string{}, + }) + } + + // initiate masterchef params + m.masterchefKeeper.SetParams(ctx, mastercheftypes.NewParams( + nil, // TODO: + sdk.NewDecWithPrec(60, 2), + sdk.NewDecWithPrec(25, 2), + mastercheftypes.DexRewardsTracker{ + NumBlocks: sdk.NewInt(1), + Amount: sdk.ZeroDec(), + }, + sdk.NewDecWithPrec(5, 1), + "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", + )) + + // initiate estaking module data + m.estakingKeeper.InitGenesis(ctx, estakingtypes.GenesisState{ + Params: estakingtypes.Params{ + StakeIncentives: nil, // TODO: + EdenCommitVal: "", + EdenbCommitVal: "", + MaxEdenRewardAprStakers: sdk.NewDecWithPrec(3, 1), // 30% + EdenBoostApr: sdk.OneDec(), + DexRewardsStakers: estakingtypes.DexRewardsTracker{ + NumBlocks: sdk.OneInt(), + Amount: sdk.ZeroDec(), + }, + }, + }) + + // initiate missing distribution module data + m.distrKeeper.InitGenesis(ctx, *distrtypes.DefaultGenesisState()) + + // execute missing validator creation hooks + validators := m.estakingKeeper.Keeper.GetAllValidators(ctx) + for _, val := range validators { + err := m.estakingKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) + if err != nil { + panic(err) + } + } + + // execute missing delegation creation hooks + allDelegations := m.estakingKeeper.Keeper.GetAllDelegations(ctx) + for _, delegation := range allDelegations { + delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) + valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) + if err != nil { + panic(err) + } + err = m.estakingKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr) + if err != nil { + panic(err) + } + } + + // Update all commitments (move all unclaimed into claimed) + // and execute missing eden/edenb commitment hooks + edenValAddr := sdk.ValAddress(authtypes.NewModuleAddress(ptypes.Eden)) + edenBValAddr := sdk.ValAddress(authtypes.NewModuleAddress(ptypes.EdenB)) + legacyCommitments := m.commitmentKeeper.GetAllLegacyCommitments(ctx) + for _, legacy := range legacyCommitments { + creator := legacy.Creator + addr, err := sdk.AccAddressFromBech32(creator) + if err != nil { + // This is validator address + m.commitmentKeeper.RemoveCommitments(ctx, creator) + continue + } + + commitments := commitmenttypes.Commitments{ + Creator: legacy.Creator, + CommittedTokens: legacy.CommittedTokens, + Claimed: legacy.Claimed.Add(legacy.RewardsUnclaimed...), + VestingTokens: legacy.VestingTokens, + } + m.commitmentKeeper.SetCommitments(ctx, commitments) + for _, committed := range commitments.CommittedTokens { + if committed.Denom == ptypes.Eden { + err = m.estakingKeeper.Hooks().AfterDelegationModified(ctx, addr, edenValAddr) + if err != nil { + panic(err) + } + } + if committed.Denom == ptypes.EdenB { + err = m.estakingKeeper.Hooks().AfterDelegationModified(ctx, addr, edenBValAddr) + if err != nil { + panic(err) + } + } + } + + } + + return nil +} diff --git a/x/incentive/migrations/v2_migration.go b/x/incentive/migrations/v2_migration.go deleted file mode 100644 index 24badeb86..000000000 --- a/x/incentive/migrations/v2_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/incentive/types" -) - -func (m Migrator) V2Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.DefaultParams()) - return nil -} diff --git a/x/incentive/migrations/v3_migration.go b/x/incentive/migrations/v3_migration.go deleted file mode 100644 index 10b5c8de5..000000000 --- a/x/incentive/migrations/v3_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/incentive/types" -) - -func (m Migrator) V3Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.DefaultParams()) - return nil -} diff --git a/x/incentive/migrations/v4_migration.go b/x/incentive/migrations/v4_migration.go deleted file mode 100644 index d6bc38a81..000000000 --- a/x/incentive/migrations/v4_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/incentive/types" -) - -func (m Migrator) V4Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.DefaultParams()) - return nil -} diff --git a/x/incentive/migrations/v5_migration.go b/x/incentive/migrations/v5_migration.go deleted file mode 100644 index 6f19fcf42..000000000 --- a/x/incentive/migrations/v5_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/incentive/types" -) - -func (m Migrator) V5Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.DefaultParams()) - return nil -} diff --git a/x/incentive/migrations/v6_migration.go b/x/incentive/migrations/v6_migration.go deleted file mode 100644 index 05db6514a..000000000 --- a/x/incentive/migrations/v6_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -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.DefaultParams()) - return nil -} diff --git a/x/incentive/migrations/v7_migration.go b/x/incentive/migrations/v7_migration.go deleted file mode 100644 index 24043633f..000000000 --- a/x/incentive/migrations/v7_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/incentive/types" -) - -func (m Migrator) V7Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.DefaultParams()) - return nil -} diff --git a/x/incentive/migrations/v8_migration.go b/x/incentive/migrations/v8_migration.go deleted file mode 100644 index 01b18e400..000000000 --- a/x/incentive/migrations/v8_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/incentive/types" -) - -func (m Migrator) V8Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.DefaultParams()) - return nil -} diff --git a/x/incentive/migrations/v9_migration.go b/x/incentive/migrations/v9_migration.go deleted file mode 100644 index 1892b7876..000000000 --- a/x/incentive/migrations/v9_migration.go +++ /dev/null @@ -1,11 +0,0 @@ -package migrations - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/elys-network/elys/x/incentive/types" -) - -func (m Migrator) V9Migration(ctx sdk.Context) error { - m.keeper.SetParams(ctx, types.Params{}) - return nil -} diff --git a/x/incentive/module.go b/x/incentive/module.go index 79e263ce8..3894636f4 100644 --- a/x/incentive/module.go +++ b/x/incentive/module.go @@ -17,10 +17,14 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + commitmentkeeper "github.com/elys-network/elys/x/commitment/keeper" + estakingkeeper "github.com/elys-network/elys/x/estaking/keeper" "github.com/elys-network/elys/x/incentive/client/cli" "github.com/elys-network/elys/x/incentive/keeper" "github.com/elys-network/elys/x/incentive/migrations" "github.com/elys-network/elys/x/incentive/types" + masterchefkeeper "github.com/elys-network/elys/x/masterchef/keeper" ) var ( @@ -93,16 +97,28 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic - keeper keeper.Keeper + keeper keeper.Keeper + estakingKeeper estakingkeeper.Keeper + masterchefKeeper masterchefkeeper.Keeper + distrKeeper distrkeeper.Keeper + commitmentKeeper commitmentkeeper.Keeper } func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, + estakingKeeper estakingkeeper.Keeper, + masterchefKeeper masterchefkeeper.Keeper, + distrKeeper distrkeeper.Keeper, + commitmentKeeper commitmentkeeper.Keeper, ) AppModule { return AppModule{ - AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + estakingKeeper: estakingKeeper, + masterchefKeeper: masterchefKeeper, + distrKeeper: distrKeeper, + commitmentKeeper: commitmentKeeper, } } @@ -110,8 +126,8 @@ func NewAppModule( 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, 9, m.V10Migration) + m := migrations.NewMigrator(am.keeper, am.estakingKeeper, am.masterchefKeeper, am.distrKeeper, am.commitmentKeeper) + err := cfg.RegisterMigration(types.ModuleName, 10, m.V11Migration) if err != nil { panic(err) } @@ -137,7 +153,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 -func (AppModule) ConsensusVersion() uint64 { return 10 } +func (AppModule) ConsensusVersion() uint64 { return 11 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} diff --git a/x/incentive/types/incentive.pb.go b/x/incentive/types/incentive.pb.go new file mode 100644 index 000000000..eb0c3a1ad --- /dev/null +++ b/x/incentive/types/incentive.pb.go @@ -0,0 +1,619 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: elys/incentive/incentive.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Incentive Info +type IncentiveInfo struct { + // 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"` + // unused + EpochNumBlocks github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=epoch_num_blocks,json=epochNumBlocks,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"epoch_num_blocks"` + // unused + 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"` + // unused + 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"` +} + +func (m *IncentiveInfo) Reset() { *m = IncentiveInfo{} } +func (m *IncentiveInfo) String() string { return proto.CompactTextString(m) } +func (*IncentiveInfo) ProtoMessage() {} +func (*IncentiveInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_ed0e67c7f36f3313, []int{0} +} +func (m *IncentiveInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IncentiveInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IncentiveInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IncentiveInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_IncentiveInfo.Merge(m, src) +} +func (m *IncentiveInfo) XXX_Size() int { + return m.Size() +} +func (m *IncentiveInfo) XXX_DiscardUnknown() { + xxx_messageInfo_IncentiveInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_IncentiveInfo proto.InternalMessageInfo + +func init() { + proto.RegisterType((*IncentiveInfo)(nil), "elys.incentive.IncentiveInfo") +} + +func init() { proto.RegisterFile("elys/incentive/incentive.proto", fileDescriptor_ed0e67c7f36f3313) } + +var fileDescriptor_ed0e67c7f36f3313 = []byte{ + // 404 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x8a, 0xd4, 0x40, + 0x10, 0x86, 0x13, 0x75, 0x57, 0x6c, 0x70, 0xd1, 0x30, 0x6a, 0x5c, 0x24, 0x23, 0x1e, 0xc4, 0xcb, + 0x26, 0x07, 0x9f, 0x60, 0x07, 0x16, 0xcc, 0x45, 0x16, 0xbd, 0xa8, 0x97, 0xa6, 0x93, 0xd4, 0x66, + 0x9a, 0x49, 0x77, 0x85, 0xee, 0x8a, 0xce, 0xbc, 0x85, 0x8f, 0xb5, 0xc7, 0x3d, 0x89, 0x78, 0x58, + 0x64, 0xe6, 0x45, 0xa4, 0x3b, 0x33, 0x3b, 0x19, 0xbc, 0xe5, 0x94, 0xee, 0x54, 0xf1, 0x7d, 0xfd, + 0x53, 0x14, 0x4b, 0xa0, 0x59, 0xd9, 0x4c, 0xea, 0x12, 0x34, 0xc9, 0xef, 0xb0, 0x3f, 0xa5, 0xad, + 0x41, 0xc2, 0xe8, 0xc4, 0xd5, 0xd3, 0xbb, 0xbf, 0xa7, 0x93, 0x1a, 0x6b, 0xf4, 0xa5, 0xcc, 0x9d, + 0xfa, 0xae, 0xd3, 0x69, 0x8d, 0x58, 0x37, 0x90, 0xf9, 0x5b, 0xd1, 0x5d, 0x65, 0x24, 0x15, 0x58, + 0x12, 0xaa, 0xed, 0x1b, 0xde, 0xfc, 0x3a, 0x62, 0x8f, 0xf3, 0x1d, 0x24, 0xd7, 0x57, 0x18, 0x71, + 0x36, 0x81, 0x0a, 0x34, 0x17, 0x0a, 0x3b, 0x4d, 0xbc, 0x05, 0xc3, 0x57, 0x20, 0x4c, 0x1c, 0xbe, + 0x0e, 0xdf, 0x3d, 0x9a, 0xa5, 0xd7, 0xb7, 0xd3, 0xe0, 0xcf, 0xed, 0xf4, 0x6d, 0x2d, 0x69, 0xde, + 0x15, 0x69, 0x89, 0x2a, 0x2b, 0xd1, 0x2a, 0xb4, 0xdb, 0xcf, 0x99, 0xad, 0x16, 0x19, 0xad, 0x5a, + 0xb0, 0x69, 0xae, 0xe9, 0xd3, 0x53, 0xc7, 0x3a, 0xf7, 0xa8, 0x4b, 0x30, 0x5f, 0x41, 0x98, 0x68, + 0xce, 0xe2, 0x4a, 0x5a, 0x32, 0xb2, 0xe8, 0x48, 0xa2, 0xe6, 0x96, 0x84, 0x21, 0x5e, 0x34, 0x58, + 0x2e, 0xe2, 0x7b, 0xa3, 0x24, 0xcf, 0x87, 0xbc, 0xcf, 0x0e, 0x37, 0x73, 0xb4, 0x48, 0xb0, 0x67, + 0x84, 0x24, 0x9a, 0x1e, 0x6e, 0xf7, 0x59, 0xee, 0x8f, 0xd2, 0x44, 0x1e, 0xe6, 0xd1, 0x76, 0x17, + 0xe6, 0x0b, 0x7b, 0x02, 0x2d, 0x96, 0x73, 0xae, 0x3b, 0xb5, 0xd5, 0xc4, 0x0f, 0x46, 0xd1, 0x4f, + 0x3c, 0xe7, 0x63, 0xa7, 0x7a, 0x41, 0x04, 0xec, 0x85, 0x12, 0x4b, 0xee, 0x67, 0xe1, 0x1e, 0x2e, + 0x9a, 0x06, 0x4b, 0xe1, 0x12, 0xc6, 0x47, 0xa3, 0x04, 0x13, 0x25, 0x96, 0x17, 0x15, 0xe8, 0x4b, + 0x30, 0xe7, 0x77, 0xac, 0x08, 0xd9, 0xab, 0x83, 0x69, 0xf4, 0x69, 0xa4, 0xde, 0x85, 0x39, 0x1e, + 0xe5, 0x7a, 0x39, 0x64, 0x5e, 0x38, 0x64, 0xae, 0xf7, 0xb9, 0xca, 0xce, 0x18, 0xd0, 0xf4, 0x9f, + 0xeb, 0xe1, 0xb8, 0x5c, 0x5b, 0xdc, 0x81, 0x66, 0xf6, 0xe1, 0x7a, 0x9d, 0x84, 0x37, 0xeb, 0x24, + 0xfc, 0xbb, 0x4e, 0xc2, 0x9f, 0x9b, 0x24, 0xb8, 0xd9, 0x24, 0xc1, 0xef, 0x4d, 0x12, 0x7c, 0x4b, + 0x07, 0x5c, 0xb7, 0x44, 0x67, 0x1a, 0xe8, 0x07, 0x9a, 0x85, 0xbf, 0x64, 0xcb, 0xc1, 0xce, 0x79, + 0x47, 0x71, 0xec, 0x37, 0xe5, 0xfd, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf, 0x65, 0x62, 0xc6, + 0x92, 0x03, 0x00, 0x00, +} + +func (m *IncentiveInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IncentiveInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IncentiveInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.CurrentEpochInBlocks.Size() + i -= size + if _, err := m.CurrentEpochInBlocks.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) + } + 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)) + } + 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.EpochNumBlocks.Size() + i -= size + if _, err := m.EpochNumBlocks.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-- + dAtA[i] = 0x1a + { + 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.EdenAmountPerYear.Size() + i -= size + if _, err := m.EdenAmountPerYear.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIncentive(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintIncentive(dAtA []byte, offset int, v uint64) int { + offset -= sovIncentive(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *IncentiveInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.EdenAmountPerYear.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.DistributionStartBlock.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.TotalBlocksPerYear.Size() + n += 1 + l + sovIncentive(uint64(l)) + l = m.EpochNumBlocks.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)) + return n +} + +func sovIncentive(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozIncentive(x uint64) (n int) { + return sovIncentive(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIncentive + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IncentiveInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IncentiveInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EdenAmountPerYear", 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.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 DistributionStartBlock", 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.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 TotalBlocksPerYear", 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.TotalBlocksPerYear.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochNumBlocks", 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.EpochNumBlocks.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxEdenPerAllocation", 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.MaxEdenPerAllocation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + 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 + default: + iNdEx = preIndex + skippy, err := skipIncentive(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthIncentive + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipIncentive(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIncentive + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIncentive + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIncentive + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthIncentive + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupIncentive + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthIncentive + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthIncentive = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowIncentive = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupIncentive = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/incentive/types/params.pb.go b/x/incentive/types/params.pb.go index ec749f320..e6d6a4e31 100644 --- a/x/incentive/types/params.pb.go +++ b/x/incentive/types/params.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -25,6 +26,27 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { + LpIncentives *IncentiveInfo `protobuf:"bytes,1,opt,name=lp_incentives,json=lpIncentives,proto3" json:"lp_incentives,omitempty"` + StakeIncentives *IncentiveInfo `protobuf:"bytes,2,opt,name=stake_incentives,json=stakeIncentives,proto3" json:"stake_incentives,omitempty"` + // Dex revenue percent for lps, `100 - reward_portion_for_lps - reward_portion_for_stakers = revenue percent for protocol`. + RewardPortionForLps github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=reward_portion_for_lps,json=rewardPortionForLps,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_portion_for_lps"` + // Dex revenue percent for lps, `100 - reward_portion_for_lps - reward_portion_for_stakers = revenue percent for protocol`. + RewardPortionForStakers github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=reward_portion_for_stakers,json=rewardPortionForStakers,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_portion_for_stakers"` + // Pool information + // poolId, reward wallet, **multiplier**, dex rewards given + PoolInfos []PoolInfo `protobuf:"bytes,5,rep,name=pool_infos,json=poolInfos,proto3" json:"pool_infos"` + // Number of blocks to update elys staked amount for delegators + ElysStakeSnapInterval int64 `protobuf:"varint,6,opt,name=elys_stake_snap_interval,json=elysStakeSnapInterval,proto3" json:"elys_stake_snap_interval,omitempty"` + // Tracking dex rewards given to stakers + DexRewardsStakers DexRewardsTracker `protobuf:"bytes,7,opt,name=dex_rewards_stakers,json=dexRewardsStakers,proto3" json:"dex_rewards_stakers"` + // Tracking dex rewards given to LPs + DexRewardsLps DexRewardsTracker `protobuf:"bytes,8,opt,name=dex_rewards_lps,json=dexRewardsLps,proto3" json:"dex_rewards_lps"` + // Maximum eden reward apr for stakers - [0 - 0.3] + MaxEdenRewardAprStakers github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=max_eden_reward_apr_stakers,json=maxEdenRewardAprStakers,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_eden_reward_apr_stakers"` + // Maximum eden reward apr for lps - [0 - 0.3] + MaxEdenRewardAprLps github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,10,opt,name=max_eden_reward_apr_lps,json=maxEdenRewardAprLps,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_eden_reward_apr_lps"` + // Distribution interval in blocks - number of blocks on distribution epoch + DistributionInterval int64 `protobuf:"varint,11,opt,name=distribution_interval,json=distributionInterval,proto3" json:"distribution_interval,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -59,6 +81,55 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo +func (m *Params) GetLpIncentives() *IncentiveInfo { + if m != nil { + return m.LpIncentives + } + return nil +} + +func (m *Params) GetStakeIncentives() *IncentiveInfo { + if m != nil { + return m.StakeIncentives + } + return nil +} + +func (m *Params) GetPoolInfos() []PoolInfo { + if m != nil { + return m.PoolInfos + } + return nil +} + +func (m *Params) GetElysStakeSnapInterval() int64 { + if m != nil { + return m.ElysStakeSnapInterval + } + return 0 +} + +func (m *Params) GetDexRewardsStakers() DexRewardsTracker { + if m != nil { + return m.DexRewardsStakers + } + return DexRewardsTracker{} +} + +func (m *Params) GetDexRewardsLps() DexRewardsTracker { + if m != nil { + return m.DexRewardsLps + } + return DexRewardsTracker{} +} + +func (m *Params) GetDistributionInterval() int64 { + if m != nil { + return m.DistributionInterval + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "elys.incentive.Params") } @@ -66,17 +137,40 @@ func init() { func init() { proto.RegisterFile("elys/incentive/params.proto", fileDescriptor_3bca0267cb466fec) } var fileDescriptor_3bca0267cb466fec = []byte{ - // 153 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4e, 0xcd, 0xa9, 0x2c, - 0xd6, 0xcf, 0xcc, 0x4b, 0x4e, 0xcd, 0x2b, 0xc9, 0x2c, 0x4b, 0xd5, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, - 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x03, 0x49, 0xea, 0xc1, 0x25, 0xa5, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0x95, 0x12, 0x1f, 0x17, 0x5b, 0x00, - 0x58, 0x97, 0x15, 0xcb, 0x8c, 0x05, 0xf2, 0x0c, 0x4e, 0x1e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, - 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, - 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x97, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, - 0x0f, 0x32, 0x5a, 0x37, 0x2f, 0xb5, 0xa4, 0x3c, 0xbf, 0x28, 0x1b, 0xcc, 0xd1, 0xaf, 0x40, 0x72, - 0x46, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x02, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x60, 0x74, 0xc7, 0x45, 0xa5, 0x00, 0x00, 0x00, + // 526 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x41, 0x6f, 0xd3, 0x30, + 0x18, 0x4d, 0x68, 0xe9, 0xa8, 0xcb, 0x18, 0x64, 0x1b, 0x0b, 0x9d, 0x48, 0x0b, 0x07, 0xe8, 0x65, + 0x89, 0xb4, 0x1d, 0x90, 0x90, 0x38, 0x50, 0x0d, 0xb4, 0x4a, 0x48, 0x54, 0x19, 0x12, 0x12, 0x17, + 0xcb, 0x4d, 0xdc, 0x12, 0x25, 0xb1, 0x2d, 0xdb, 0xdb, 0xb2, 0x7f, 0xc1, 0x11, 0x6e, 0xfc, 0x9c, + 0x1d, 0x77, 0x44, 0x1c, 0x26, 0xd4, 0xfe, 0x11, 0x64, 0x27, 0xcd, 0x42, 0xb4, 0x03, 0xeb, 0x29, + 0x76, 0xde, 0xe7, 0xf7, 0xde, 0xf7, 0x3d, 0x1b, 0xec, 0xe2, 0xe4, 0x5c, 0x78, 0x11, 0x09, 0x30, + 0x91, 0xd1, 0x29, 0xf6, 0x18, 0xe2, 0x28, 0x15, 0x2e, 0xe3, 0x54, 0x52, 0xeb, 0x81, 0x02, 0xdd, + 0x12, 0xec, 0x6e, 0xcd, 0xe8, 0x8c, 0x6a, 0xc8, 0x53, 0xab, 0xbc, 0xaa, 0xeb, 0xd4, 0x28, 0xca, + 0x55, 0x81, 0x3f, 0xa9, 0x4b, 0x50, 0x9a, 0x14, 0xd0, 0xcb, 0x1a, 0x14, 0xe2, 0x0c, 0x72, 0x7c, + 0x86, 0x78, 0x28, 0xa0, 0xe4, 0x28, 0xc6, 0x3c, 0x2f, 0x7c, 0xfe, 0x63, 0x0d, 0xb4, 0xc6, 0xda, + 0x9a, 0x35, 0x04, 0xeb, 0x09, 0x83, 0xe5, 0x19, 0x61, 0x9b, 0x7d, 0x73, 0xd0, 0xd9, 0x7f, 0xea, + 0xfe, 0x6b, 0xd6, 0x1d, 0x2d, 0x57, 0x23, 0x32, 0xa5, 0xfe, 0xfd, 0x84, 0x95, 0x3f, 0x84, 0x75, + 0x04, 0x1e, 0x0a, 0x89, 0x62, 0x5c, 0xa5, 0xb9, 0xf3, 0x3f, 0x34, 0x1b, 0xfa, 0x58, 0x85, 0x29, + 0x00, 0x8f, 0x73, 0xc3, 0x90, 0x51, 0x2e, 0x23, 0x4a, 0xe0, 0x94, 0x72, 0x98, 0x30, 0x61, 0x37, + 0xfa, 0xe6, 0xa0, 0x3d, 0x74, 0x2f, 0xae, 0x7a, 0xc6, 0xef, 0xab, 0xde, 0x8b, 0x59, 0x24, 0xbf, + 0x9e, 0x4c, 0xdc, 0x80, 0xa6, 0x5e, 0x40, 0x45, 0x4a, 0x45, 0xf1, 0xd9, 0x13, 0x61, 0xec, 0xc9, + 0x73, 0x86, 0x85, 0x7b, 0x88, 0x03, 0x7f, 0x33, 0x67, 0x1b, 0xe7, 0x64, 0xef, 0x29, 0xff, 0xc0, + 0x84, 0x15, 0x83, 0xee, 0x0d, 0x22, 0xda, 0x0a, 0x17, 0x76, 0x73, 0x25, 0xa1, 0x9d, 0xba, 0xd0, + 0x71, 0x4e, 0x67, 0xbd, 0x01, 0x40, 0x25, 0x04, 0x23, 0x32, 0xa5, 0xc2, 0xbe, 0xdb, 0x6f, 0x0c, + 0x3a, 0xfb, 0x76, 0x7d, 0x2a, 0x63, 0x4a, 0x13, 0x35, 0x90, 0x61, 0x53, 0xc9, 0xfa, 0x6d, 0x56, + 0xec, 0x85, 0xf5, 0x0a, 0xd8, 0xaa, 0x36, 0x77, 0x07, 0x05, 0x41, 0x2a, 0x2b, 0x89, 0xf9, 0x29, + 0x4a, 0xec, 0x56, 0xdf, 0x1c, 0x34, 0xfc, 0x6d, 0x85, 0x6b, 0xb5, 0x63, 0x82, 0xd8, 0xa8, 0x00, + 0xad, 0xcf, 0x60, 0xb3, 0x1a, 0xff, 0xb2, 0xbb, 0x35, 0x1d, 0xcb, 0xb3, 0xba, 0x81, 0x43, 0x9c, + 0xf9, 0x79, 0xe5, 0x27, 0x8e, 0x82, 0x18, 0xf3, 0xc2, 0xc9, 0xa3, 0xb0, 0x04, 0x96, 0x0d, 0x7d, + 0x04, 0x1b, 0x55, 0x62, 0x95, 0xcd, 0xbd, 0xdb, 0x91, 0xae, 0x5f, 0x93, 0xaa, 0x38, 0x12, 0xb0, + 0x9b, 0xa2, 0x0c, 0xe2, 0x10, 0x93, 0x82, 0x15, 0x22, 0x76, 0x9d, 0x47, 0x7b, 0xb5, 0x3c, 0x52, + 0x94, 0xbd, 0x0b, 0x31, 0xc9, 0x75, 0xde, 0xb2, 0x32, 0x8f, 0x10, 0xec, 0xdc, 0xa4, 0xa6, 0xda, + 0x00, 0xab, 0x5d, 0xb1, 0xba, 0x92, 0xea, 0xe9, 0x00, 0x6c, 0x87, 0x91, 0x90, 0x3c, 0x9a, 0x9c, + 0xe8, 0x0b, 0x56, 0x66, 0xd6, 0xd1, 0x99, 0x6d, 0x55, 0xc1, 0x65, 0x64, 0xaf, 0x9b, 0xdf, 0x7f, + 0xf6, 0x8c, 0xe1, 0xd1, 0xc5, 0xdc, 0x31, 0x2f, 0xe7, 0x8e, 0xf9, 0x67, 0xee, 0x98, 0xdf, 0x16, + 0x8e, 0x71, 0xb9, 0x70, 0x8c, 0x5f, 0x0b, 0xc7, 0xf8, 0xe2, 0x56, 0x1c, 0xa9, 0x51, 0xef, 0x11, + 0x2c, 0xcf, 0x28, 0x8f, 0xf5, 0xc6, 0xcb, 0x2a, 0x0f, 0x5f, 0xbb, 0x9b, 0xb4, 0xf4, 0x63, 0x3f, + 0xf8, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x54, 0xb8, 0x55, 0x93, 0x95, 0x04, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -99,6 +193,114 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.DistributionInterval != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.DistributionInterval)) + i-- + dAtA[i] = 0x58 + } + { + size := m.MaxEdenRewardAprLps.Size() + i -= size + if _, err := m.MaxEdenRewardAprLps.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + { + size := m.MaxEdenRewardAprStakers.Size() + i -= size + if _, err := m.MaxEdenRewardAprStakers.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + { + size, err := m.DexRewardsLps.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + { + size, err := m.DexRewardsStakers.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + if m.ElysStakeSnapInterval != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.ElysStakeSnapInterval)) + i-- + dAtA[i] = 0x30 + } + if len(m.PoolInfos) > 0 { + for iNdEx := len(m.PoolInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PoolInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + { + size := m.RewardPortionForStakers.Size() + i -= size + if _, err := m.RewardPortionForStakers.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.RewardPortionForLps.Size() + i -= size + if _, err := m.RewardPortionForLps.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.StakeIncentives != nil { + { + size, err := m.StakeIncentives.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.LpIncentives != nil { + { + size, err := m.LpIncentives.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -119,6 +321,38 @@ func (m *Params) Size() (n int) { } var l int _ = l + if m.LpIncentives != nil { + l = m.LpIncentives.Size() + n += 1 + l + sovParams(uint64(l)) + } + if m.StakeIncentives != nil { + l = m.StakeIncentives.Size() + n += 1 + l + sovParams(uint64(l)) + } + l = m.RewardPortionForLps.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.RewardPortionForStakers.Size() + n += 1 + l + sovParams(uint64(l)) + if len(m.PoolInfos) > 0 { + for _, e := range m.PoolInfos { + l = e.Size() + n += 1 + l + sovParams(uint64(l)) + } + } + if m.ElysStakeSnapInterval != 0 { + n += 1 + sovParams(uint64(m.ElysStakeSnapInterval)) + } + l = m.DexRewardsStakers.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.DexRewardsLps.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.MaxEdenRewardAprStakers.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.MaxEdenRewardAprLps.Size() + n += 1 + l + sovParams(uint64(l)) + if m.DistributionInterval != 0 { + n += 1 + sovParams(uint64(m.DistributionInterval)) + } return n } @@ -157,6 +391,352 @@ func (m *Params) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LpIncentives", 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 m.LpIncentives == nil { + m.LpIncentives = &IncentiveInfo{} + } + if err := m.LpIncentives.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakeIncentives", 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 m.StakeIncentives == nil { + m.StakeIncentives = &IncentiveInfo{} + } + if err := m.StakeIncentives.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardPortionForLps", 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.RewardPortionForLps.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardPortionForStakers", 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.RewardPortionForStakers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolInfos", 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 + } + m.PoolInfos = append(m.PoolInfos, PoolInfo{}) + if err := m.PoolInfos[len(m.PoolInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ElysStakeSnapInterval", wireType) + } + m.ElysStakeSnapInterval = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ElysStakeSnapInterval |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DexRewardsStakers", 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.DexRewardsStakers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + 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 + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxEdenRewardAprStakers", 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.MaxEdenRewardAprStakers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxEdenRewardAprLps", 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.MaxEdenRewardAprLps.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DistributionInterval", wireType) + } + m.DistributionInterval = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DistributionInterval |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/masterchef/keeper/hooks_masterchef.go b/x/masterchef/keeper/hooks_masterchef.go index 13dff9a2a..47a11c12d 100644 --- a/x/masterchef/keeper/hooks_masterchef.go +++ b/x/masterchef/keeper/hooks_masterchef.go @@ -44,7 +44,6 @@ func (k Keeper) UpdateAccPerShare(ctx sdk.Context, poolId uint64, rewardDenom st func (k Keeper) UpdateUserRewardPending(ctx sdk.Context, poolId uint64, rewardDenom string, user string, isDeposit bool, amount sdk.Int) { poolRewardInfo, found := k.GetPoolRewardInfo(ctx, poolId, rewardDenom) - if !found { poolRewardInfo = types.PoolRewardInfo{ PoolId: poolId, @@ -55,7 +54,6 @@ func (k Keeper) UpdateUserRewardPending(ctx sdk.Context, poolId uint64, rewardDe } userRewardInfo, found := k.GetUserRewardInfo(ctx, user, poolId, rewardDenom) - if !found { userRewardInfo = types.UserRewardInfo{ User: user, @@ -75,9 +73,10 @@ func (k Keeper) UpdateUserRewardPending(ctx sdk.Context, poolId uint64, rewardDe } userRewardInfo.RewardPending = userRewardInfo.RewardPending.Add( - poolRewardInfo.PoolAccRewardPerShare.Mul( - math.LegacyNewDecFromInt(userBalance), - ).Sub(userRewardInfo.RewardDebt).Quo(math.LegacyNewDecFromInt(ammtypes.OneShare)), + poolRewardInfo.PoolAccRewardPerShare. + Mul(math.LegacyNewDecFromInt(userBalance)). + Sub(userRewardInfo.RewardDebt). + Quo(math.LegacyNewDecFromInt(ammtypes.OneShare)), ) k.SetUserRewardInfo(ctx, userRewardInfo)