Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 committed Dec 18, 2023
2 parents e2393f3 + ceddb78 commit 99d78af
Show file tree
Hide file tree
Showing 37 changed files with 3,259 additions and 196 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.x
- name: Set up Go 1.21.x
uses: actions/setup-go@v5
with:
go-version: ^1.21
go-version: "1.21.5"
id: go

- name: Check out code into the Go module directory
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: "1.21.5"

- uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: "v1.52.2"
args: --timeout=5m
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: "1.21.5"

- uses: actions/checkout@v4

Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
- name: Setup Go with cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: 1.21.0
go-version: "1.21.5"
id: go

- name: Checkout repository
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
- name: Setup Go with cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: 1.21.0
go-version: "1.21.5"
id: go

- name: Checkout repository
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ linters:
- gosimple
- govet
- ineffassign
- interfacer
- maligned
- misspell
- nakedret
Expand Down
33 changes: 28 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ import (

pstakeante "github.com/persistenceOne/pstake-native/v2/ante"
pstakeappparams "github.com/persistenceOne/pstake-native/v2/app/params"
"github.com/persistenceOne/pstake-native/v2/x/liquidstake"
liquidstakekeeper "github.com/persistenceOne/pstake-native/v2/x/liquidstake/keeper"
liquidstaketypes "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types"
"github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc"
liquidstakeibckeeper "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/keeper"
liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
Expand Down Expand Up @@ -175,6 +178,7 @@ var (
interchainquery.AppModuleBasic{},
lscosmos.AppModuleBasic{},
liquidstakeibc.AppModuleBasic{},
liquidstake.AppModuleBasic{},
ratesync.AppModuleBasic{},
consensus.AppModuleBasic{},
)
Expand All @@ -191,6 +195,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
liquidstakeibctypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquidstaketypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquidstakeibctypes.DepositModuleAccount: nil,
liquidstakeibctypes.UndelegationModuleAccount: {authtypes.Burner},
}
Expand Down Expand Up @@ -249,6 +254,7 @@ type PstakeApp struct {
EpochsKeeper *epochskeeper.Keeper
InterchainQueryKeeper interchainquerykeeper.Keeper
LiquidStakeIBCKeeper liquidstakeibckeeper.Keeper
LiquidStakeKeeper liquidstakekeeper.Keeper
RatesyncKeeper *ratesynckeeper.Keeper

// make scoped keepers public for test purposes
Expand Down Expand Up @@ -302,7 +308,8 @@ func NewpStakeApp(
evidencetypes.StoreKey, ibctransfertypes.StoreKey,
capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, epochstypes.StoreKey, interchainquerytypes.StoreKey,
ibcfeetypes.StoreKey, liquidstakeibctypes.StoreKey, consensusparamtypes.StoreKey, ratesynctypes.StoreKey,
ibcfeetypes.StoreKey, liquidstakeibctypes.StoreKey, liquidstaketypes.StoreKey, consensusparamtypes.StoreKey,
ratesynctypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -418,6 +425,17 @@ func NewpStakeApp(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

app.LiquidStakeKeeper = liquidstakekeeper.NewKeeper(
appCodec,
keys[liquidstaketypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
app.SlashingKeeper,
app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibcexported.StoreKey],
Expand Down Expand Up @@ -495,6 +513,7 @@ func NewpStakeApp(
app.RatesyncKeeper.LiquidStakeIBCHooks()))

_ = app.InterchainQueryKeeper.SetCallbackHandler(liquidstakeibctypes.ModuleName, app.LiquidStakeIBCKeeper.CallbackHandler())

liquidStakeIBCModule := liquidstakeibc.NewIBCModule(app.LiquidStakeIBCKeeper)

ibcTransferHooksKeeper := ibchookerkeeper.NewKeeper()
Expand All @@ -519,9 +538,9 @@ func NewpStakeApp(
ibcRouter.
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack)
//AddRoute(liquidstakeibctypes.ModuleName, icaControllerStack).
//AddRoute(ratesynctypes.ModuleName, icaControllerStack)
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(liquidstakeibctypes.ModuleName, icaControllerStack).
AddRoute(ratesynctypes.ModuleName, icaControllerStack)

app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -605,6 +624,7 @@ func NewpStakeApp(
//ibchooker.NewAppModule(),
interchainQueryModule,
liquidstakeibc.NewAppModule(app.LiquidStakeIBCKeeper),
liquidstake.NewAppModule(app.LiquidStakeKeeper),
ratesync.NewAppModule(appCodec, *app.RatesyncKeeper, app.AccountKeeper, app.BankKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
)
Expand Down Expand Up @@ -640,6 +660,7 @@ func NewpStakeApp(
ibchookertypes.ModuleName, //Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
ratesynctypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand Down Expand Up @@ -668,6 +689,7 @@ func NewpStakeApp(
ibchookertypes.ModuleName, //Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
ratesynctypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand Down Expand Up @@ -703,6 +725,7 @@ func NewpStakeApp(
ibchookertypes.ModuleName, //Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
ratesynctypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand Down Expand Up @@ -1004,7 +1027,7 @@ func (app *PstakeApp) RegisterUpgradeHandler() {

if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{
Added: []string{ratesynctypes.StoreKey},
Added: []string{ratesynctypes.StoreKey, liquidstaketypes.StoreKey},
Deleted: []string{},
}

Expand Down
5 changes: 5 additions & 0 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,8 @@ func PP(data interface{}) {
}
fmt.Printf("%s \n", p)
}

// NoInflationCalculationFn is the function with disabled inflation.
func NoInflationCalculationFn(_ sdk.Context, minter minttypes.Minter, params minttypes.Params, bondedRatio math.LegacyDec) math.LegacyDec {
return math.LegacyNewDec(1)
}
15 changes: 14 additions & 1 deletion proto/pstake/liquidstake/v1beta1/liquidstake.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@ message Params {
(gogoproto.nullable) = false
];

// cw_locked_pool_address defines the bech32-encoded address of
// CwLockedPoolAddress defines the bech32-encoded address of
// a CW smart-contract representing a time locked LP (e.g. Superfluid LP).
string cw_locked_pool_address = 6
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// FeeAccountAddress defines the bech32-encoded address of
// a an account responsible for accumulating protocol fees.
string fee_account_address = 7
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// AutocompoundFeeRate specifies the fee rate for auto redelegating the stake
// rewards. The fee is taken in favour of the fee account (see
// FeeAccountAddress).
string autocompound_fee_rate = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// ValidatorStatus enumerates the status of a liquid validator.
Expand Down
2 changes: 1 addition & 1 deletion proto/pstake/liquidstakeibc/v1beta1/liquidstakeibc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ message RewardParams {
// rewards denom on the host chain
string denom = 1;
// entity which will convert rewards to the host denom
string destination = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string destination = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

message HostChainLSParams {
Expand Down
6 changes: 2 additions & 4 deletions x/liquidstake/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

k.UpdateLiquidValidatorSet(ctx)

whitelistedValsMap := types.GetWhitelistedValsMap(k.GetParams(ctx).WhitelistedValidators)
k.AutocompoundStakingRewards(ctx, whitelistedValsMap)
// return value of UpdateLiquidValidatorSet is useful only in testing
_ = k.UpdateLiquidValidatorSet(ctx)
}
3 changes: 2 additions & 1 deletion x/liquidstake/handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package liquidstake

import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -29,7 +30,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
return sdk.WrapServiceResult(ctx, res, err)

default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
return nil, errors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
}
}
}
7 changes: 6 additions & 1 deletion x/liquidstake/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
if err := types.ValidateGenesis(genState); err != nil {
panic(err)
}

// init to prevent nil slice, []types.WhitelistedValidator(nil)
if genState.Params.WhitelistedValidators == nil || len(genState.Params.WhitelistedValidators) == 0 {
genState.Params.WhitelistedValidators = []types.WhitelistedValidator{}
}
k.SetParams(ctx, genState.Params)

if err := k.SetParams(ctx, genState.Params); err != nil {
panic(err)
}

for _, lv := range genState.LiquidValidators {
k.SetLiquidValidator(ctx, lv)
Expand All @@ -32,6 +36,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
// ExportGenesis returns the liquidstake module's genesis state.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params := k.GetParams(ctx)

// init to prevent nil slice, []types.WhitelistedValidator(nil)
if params.WhitelistedValidators == nil || len(params.WhitelistedValidators) == 0 {
params.WhitelistedValidators = []types.WhitelistedValidator{}
Expand Down
68 changes: 68 additions & 0 deletions x/liquidstake/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package keeper_test

import (
"cosmossdk.io/math"
_ "github.com/stretchr/testify/suite"

"github.com/persistenceOne/pstake-native/v2/x/liquidstake/types"
)

func (s *KeeperTestSuite) TestInitGenesis() {
genState := *types.DefaultGenesisState()
s.keeper.InitGenesis(s.ctx, genState)
got := s.keeper.ExportGenesis(s.ctx)
s.Require().Equal(genState, *got)
}

func (s *KeeperTestSuite) TestImportExportGenesis() {
k, ctx := s.keeper, s.ctx
_, valOpers, _ := s.CreateValidators([]int64{1000000, 1000000, 1000000})
params := k.GetParams(ctx)

params.WhitelistedValidators = []types.WhitelistedValidator{
{ValidatorAddress: valOpers[0].String(), TargetWeight: math.NewInt(10)},
{ValidatorAddress: valOpers[1].String(), TargetWeight: math.NewInt(10)},
}
k.SetParams(ctx, params)
k.UpdateLiquidValidatorSet(ctx)

stakingAmt := math.NewInt(100000000)
s.Require().NoError(s.liquidStaking(s.delAddrs[0], stakingAmt))
lvs := k.GetAllLiquidValidators(ctx)
s.Require().Len(lvs, 2)

lvStates := k.GetAllLiquidValidatorStates(ctx)
genState := k.ExportGenesis(ctx)

bz := s.app.AppCodec().MustMarshalJSON(genState)

var genState2 types.GenesisState
s.app.AppCodec().MustUnmarshalJSON(bz, &genState2)
k.InitGenesis(ctx, genState2)
genState3 := k.ExportGenesis(ctx)

s.Require().Equal(*genState, genState2)
s.Require().Equal(genState2, *genState3)

lvs = k.GetAllLiquidValidators(ctx)
s.Require().Len(lvs, 2)

lvStates3 := k.GetAllLiquidValidatorStates(ctx)
s.Require().EqualValues(lvStates, lvStates3)
}

func (s *KeeperTestSuite) TestImportExportGenesisEmpty() {
k, ctx := s.keeper, s.ctx
k.SetParams(ctx, types.DefaultParams())
k.UpdateLiquidValidatorSet(ctx)
genState := k.ExportGenesis(ctx)

var genState2 types.GenesisState
bz := s.app.AppCodec().MustMarshalJSON(genState)
s.app.AppCodec().MustUnmarshalJSON(bz, &genState2)
k.InitGenesis(ctx, genState2)

genState3 := k.ExportGenesis(ctx)
s.Require().Equal(*genState, genState2)
s.Require().Equal(genState2, *genState3)
}
2 changes: 1 addition & 1 deletion x/liquidstake/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k Querier) LiquidValidators(c context.Context, req *types.QueryLiquidValid
return &types.QueryLiquidValidatorsResponse{LiquidValidators: k.GetAllLiquidValidatorStates(ctx)}, nil
}

// States queries states of liquid staking module.
// States queries states of liquid stake module.
func (k Querier) States(c context.Context, req *types.QueryStatesRequest) (*types.QueryStatesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
Expand Down
Loading

0 comments on commit 99d78af

Please sign in to comment.