Skip to content

Commit

Permalink
move rebalancing to day epoch.
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 committed May 29, 2024
1 parent e4464f1 commit 0d777d2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
21 changes: 0 additions & 21 deletions x/liquidstake/abci.go

This file was deleted.

7 changes: 6 additions & 1 deletion x/liquidstake/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ func (h EpochHooks) AfterEpochEnd(_ sdk.Context, _ string, _ int64) error {
return nil
}

func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, _ int64) error {
if !k.GetParams(ctx).ModulePaused {
// Update the liquid validator set at the start of each epoch
if epochIdentifier == liquidstake.AutocompoundEpoch {
k.AutocompoundStakingRewards(ctx, liquidstake.GetWhitelistedValsMap(k.GetParams(ctx).WhitelistedValidators))
}

if epochIdentifier == liquidstake.RebalanceEpoch {
// return value of UpdateLiquidValidatorSet is useful only in testing
_ = k.UpdateLiquidValidatorSet(ctx)
}
}

return nil
Expand Down
11 changes: 3 additions & 8 deletions x/liquidstake/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

chain "github.com/persistenceOne/pstake-native/v2/app"
testhelpers "github.com/persistenceOne/pstake-native/v2/app/helpers"
"github.com/persistenceOne/pstake-native/v2/x/liquidstake"
"github.com/persistenceOne/pstake-native/v2/x/liquidstake/keeper"
"github.com/persistenceOne/pstake-native/v2/x/liquidstake/types"
)
Expand Down Expand Up @@ -83,15 +82,15 @@ func (s *KeeperTestSuite) CreateValidators(powers []int64) ([]sdk.AccAddress, []
pks := testhelpers.CreateTestPubKeys(num)
skParams := s.app.StakingKeeper.GetParams(s.ctx)
skParams.ValidatorLiquidStakingCap = sdk.OneDec()
s.app.StakingKeeper.SetParams(s.ctx, skParams)
_ = s.app.StakingKeeper.SetParams(s.ctx, skParams)
for i, power := range powers {
val, err := stakingtypes.NewValidator(valAddrs[i], pks[i], stakingtypes.Description{})
s.Require().NoError(err)
s.app.StakingKeeper.SetValidator(s.ctx, val)
err = s.app.StakingKeeper.SetValidatorByConsAddr(s.ctx, val)
s.Require().NoError(err)
s.app.StakingKeeper.SetNewValidatorByPowerIndex(s.ctx, val)
s.app.StakingKeeper.Hooks().AfterValidatorCreated(s.ctx, val.GetOperator())
_ = s.app.StakingKeeper.Hooks().AfterValidatorCreated(s.ctx, val.GetOperator())
newShares, err := s.app.StakingKeeper.Delegate(s.ctx, addrs[i], math.NewInt(power), stakingtypes.Unbonded, val, true)
s.Require().NoError(err)
s.Require().Equal(newShares.TruncateInt(), math.NewInt(power))
Expand Down Expand Up @@ -302,7 +301,7 @@ func (s *KeeperTestSuite) printRedelegationsLiquidTokens() {
}
}

func (s *KeeperTestSuite) advanceHeight(height int, withBeginBlock bool) {
func (s *KeeperTestSuite) advanceHeight(height int, _ bool) {
feeCollector := s.app.AccountKeeper.GetModuleAddress(
authtypes.FeeCollectorName,
)
Expand Down Expand Up @@ -373,10 +372,6 @@ func (s *KeeperTestSuite) advanceHeight(height int, withBeginBlock bool) {
)

s.app.DistrKeeper.SetFeePool(s.ctx, feePool)
if withBeginBlock {
// liquid validator set update and rebalancing
liquidstake.BeginBlocker(s.ctx, s.app.LiquidStakeKeeper)
}

staking.EndBlocker(s.ctx, s.app.StakingKeeper)
}
Expand Down
10 changes: 4 additions & 6 deletions x/liquidstake/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
}

// ValidateGenesis performs genesis state validation for the liquidstake module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
Expand Down Expand Up @@ -102,7 +102,7 @@ func (AppModule) Name() string {
}

// RegisterInvariants registers the liquidstake module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// QuerierRoute returns the liquidstake module's querier route name.
func (AppModule) QuerierRoute() string {
Expand Down Expand Up @@ -135,12 +135,10 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
func (AppModule) ConsensusVersion() uint64 { return 1 }

// BeginBlock returns the begin blocker for the liquidstake module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
BeginBlocker(ctx, am.keeper)
}
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}

// EndBlock returns the end blocker for the liquidstake module. It returns no validator
// updates.
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}
1 change: 1 addition & 0 deletions x/liquidstake/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (

// Epoch identifiers
AutocompoundEpoch = "hour"
RebalanceEpoch = "day"
)

var (
Expand Down

0 comments on commit 0d777d2

Please sign in to comment.