Skip to content

Commit

Permalink
add basic upgrade handler for commitment, incentive, masterchef, dist…
Browse files Browse the repository at this point in the history
…ribution
  • Loading branch information
jelysn committed Apr 18, 2024
1 parent a9863e6 commit 61f4962
Show file tree
Hide file tree
Showing 25 changed files with 1,518 additions and 241 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 1 addition & 46 deletions proto/elys/commitment/commitments.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}
29 changes: 29 additions & 0 deletions proto/elys/incentive/dex_rewards_traker.proto
Original file line number Diff line number Diff line change
@@ -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
];
}
45 changes: 45 additions & 0 deletions proto/elys/incentive/incentive.proto
Original file line number Diff line number Diff line change
@@ -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
];
}
46 changes: 46 additions & 0 deletions proto/elys/incentive/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
50 changes: 0 additions & 50 deletions x/commitment/migrations/v3_migration.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 4 additions & 6 deletions x/commitment/types/commitments.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions x/estaking/genesis.go → x/estaking/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 3 additions & 7 deletions x/estaking/genesis_test.go → x/estaking/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package estaking_test
package keeper_test

import (
"testing"

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"
)
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions x/estaking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading

0 comments on commit 61f4962

Please sign in to comment.