Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sprint of improvements for stkxprt / liquidstake #700

Merged
merged 8 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 23 additions & 1 deletion 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 @@ -173,6 +176,7 @@ var (
interchainquery.AppModuleBasic{},
lscosmos.AppModuleBasic{},
liquidstakeibc.AppModuleBasic{},
liquidstake.AppModuleBasic{},
consensus.AppModuleBasic{},
)

Expand All @@ -188,6 +192,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 @@ -246,6 +251,7 @@ type PstakeApp struct {
EpochsKeeper *epochskeeper.Keeper
InterchainQueryKeeper interchainquerykeeper.Keeper
LiquidStakeIBCKeeper liquidstakeibckeeper.Keeper
LiquidStakeKeeper liquidstakekeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -298,7 +304,7 @@ 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,
ibcfeetypes.StoreKey, liquidstakeibctypes.StoreKey, liquidstaketypes.StoreKey, consensusparamtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -513,6 +519,18 @@ func NewpStakeApp(

app.IBCKeeper.SetRouter(ibcRouter)

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(),
)

// register the proposal types

// Register the proposal types
Expand Down Expand Up @@ -592,6 +610,7 @@ func NewpStakeApp(
//ibchooker.NewAppModule(),
interchainQueryModule,
liquidstakeibc.NewAppModule(app.LiquidStakeIBCKeeper),
liquidstake.NewAppModule(app.LiquidStakeKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
)

Expand Down Expand Up @@ -626,6 +645,7 @@ func NewpStakeApp(
ibchookertypes.ModuleName, //Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
consensusparamtypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -653,6 +673,7 @@ func NewpStakeApp(
ibchookertypes.ModuleName, //Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
consensusparamtypes.ModuleName,
)

Expand Down Expand Up @@ -687,6 +708,7 @@ func NewpStakeApp(
ibchookertypes.ModuleName, //Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
consensusparamtypes.ModuleName,
)

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)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down Expand Up @@ -171,6 +170,7 @@ require (
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
Expand Down
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 @@
// 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 Expand Up @@ -121,9 +121,9 @@
message ICAAccount {
enum ChannelState {
// ICA channel is being created
ICA_CHANNEL_CREATING = 0;

Check failure on line 124 in proto/pstake/liquidstakeibc/v1beta1/liquidstakeibc.proto

View workflow job for this annotation

GitHub Actions / lint

Enum value name "ICA_CHANNEL_CREATING" should be prefixed with "CHANNEL_STATE_".

Check failure on line 124 in proto/pstake/liquidstakeibc/v1beta1/liquidstakeibc.proto

View workflow job for this annotation

GitHub Actions / lint

Enum zero value name "ICA_CHANNEL_CREATING" should be suffixed with "_UNSPECIFIED".
// ICA is established and the account can be used
ICA_CHANNEL_CREATED = 1;

Check failure on line 126 in proto/pstake/liquidstakeibc/v1beta1/liquidstakeibc.proto

View workflow job for this annotation

GitHub Actions / lint

Enum value name "ICA_CHANNEL_CREATED" should be prefixed with "CHANNEL_STATE_".
}

// address of the ica on the controller chain
Expand Down Expand Up @@ -173,7 +173,7 @@
message Deposit {
enum DepositState {
// no action has been initiated on the deposit
DEPOSIT_PENDING = 0;

Check failure on line 176 in proto/pstake/liquidstakeibc/v1beta1/liquidstakeibc.proto

View workflow job for this annotation

GitHub Actions / lint

Enum value name "DEPOSIT_PENDING" should be prefixed with "DEPOSIT_STATE_".
// deposit sent to the host chain delegator address
DEPOSIT_SENT = 1;
// deposit received by the host chain delegator address
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
Loading