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: Move c value bounds to per-chain params #732

Merged
merged 17 commits into from
Jan 22, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- [732](https://github.com/persistenceOne/pstake-native/pull/732) Move c value bounds to per-chain params.
- [729](https://github.com/persistenceOne/pstake-native/pull/729) Add rewards account query (hence autocompound) OnChanOpenAck.
- [727](https://github.com/persistenceOne/pstake-native/pull/727) Send LSM redeem messages in chunks.
- [721](https://github.com/persistenceOne/pstake-native/pull/721) Add Query host chain user unbondings.
Expand Down
67 changes: 45 additions & 22 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,28 +1019,51 @@
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// stuck unbonding epoch numbers
RemovableUnbondings := map[string]map[int64]any{"cosmoshub-4": {312: nil}, "osmosis-1": {429: nil, 432: nil}}

// get the stuck unbondings from the store
unbondings := app.LiquidStakeIBCKeeper.FilterUnbondings(
ctx,
func(u liquidstakeibctypes.Unbonding) bool {
_, chain := RemovableUnbondings[u.ChainId]
if chain {
_, epoch := RemovableUnbondings[u.ChainId][u.EpochNumber]
if epoch {
return true
}
}
return false
},
)

// mark the stuck unbondings as failed, so they can be processed
for _, unbonding := range unbondings {
unbonding.State = liquidstakeibctypes.Unbonding_UNBONDING_FAILED
app.LiquidStakeIBCKeeper.SetUnbonding(ctx, unbonding)
for _, hc := range app.LiquidStakeIBCKeeper.GetAllHostChains(ctx) {
switch hc.ChainId {
case "cosmoshub-4":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.85")
kruspy marked this conversation as resolved.
Show resolved Hide resolved
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)
break

Check failure on line 1030 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

S1023: redundant break statement (gosimple)
kruspy marked this conversation as resolved.
Show resolved Hide resolved
kruspy marked this conversation as resolved.
Show resolved Hide resolved
case "osmosis-1":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.97")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)
break

Check failure on line 1037 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

S1023: redundant break statement (gosimple)
kruspy marked this conversation as resolved.
Show resolved Hide resolved
case "theta-testnet-001":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.9")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)
break

Check failure on line 1044 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

S1023: redundant break statement (gosimple)
kruspy marked this conversation as resolved.
Show resolved Hide resolved
case "osmo-test-5":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.95")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)
break

Check failure on line 1051 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

S1023: redundant break statement (gosimple)
kruspy marked this conversation as resolved.
Show resolved Hide resolved
case "dydx-test-4":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.95")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)
break

Check failure on line 1058 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

S1023: redundant break statement (gosimple)
kruspy marked this conversation as resolved.
Show resolved Hide resolved
case "gaia-1":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.95")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)
break

Check failure on line 1065 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

S1023: redundant break statement (gosimple)
kruspy marked this conversation as resolved.
Show resolved Hide resolved
}
}

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
Expand Down
2 changes: 1 addition & 1 deletion app/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package app

const (
appName = "pStake"
UpgradeName = "v2.8.2"
UpgradeName = "v2.9.0"
)
11 changes: 11 additions & 0 deletions proto/pstake/liquidstakeibc/v1beta1/liquidstakeibc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,25 @@
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string upper_c_value_limit = 10 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // upper limit for the c value of the host chain

string lower_c_value_limit = 11 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // lower limit for the c value of the host chain
}

message ICAAccount {
enum ChannelState {
// ICA channel is being created
ICA_CHANNEL_CREATING = 0;

Check failure on line 135 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 135 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 137 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 +184,7 @@
message Deposit {
enum DepositState {
// no action has been initiated on the deposit
DEPOSIT_PENDING = 0;

Check failure on line 187 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
15 changes: 4 additions & 11 deletions proto/pstake/liquidstakeibc/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
option go_package = "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types";

// Params defines the parameters for the module.
message Params {

Check failure on line 11 in proto/pstake/liquidstakeibc/v1beta1/params.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "3" with name "upper_c_value_limit" on message "Params" was deleted.

Check failure on line 11 in proto/pstake/liquidstakeibc/v1beta1/params.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "4" with name "lower_c_value_limit" on message "Params" was deleted.
option (amino.name) = "pstake/x/liquidstakeibc/Params";

string admin_address = 1
Expand All @@ -18,15 +18,8 @@
string fee_address = 2 [ (cosmos_proto.scalar) =
"cosmos.AddressString" ]; // protocol fee address

string upper_c_value_limit = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // upper limit for the c value of a host chain

string lower_c_value_limit = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // lower limit for the c value of a host chain
// fields 3 and 4 were migrated to on-chain params.
// check https://github.com/persistenceOne/pstake-native/pull/732.
reserved 3; // upper_c_value_limit
reserved 4; // lower_c_value_limit
}
17 changes: 11 additions & 6 deletions x/liquidstakeibc/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ import (
)

func TestGenesis(t *testing.T) {
upperCValueLimit, _ := sdk.NewDecFromStr("1.05")
lowerCValueLimit, _ := sdk.NewDecFromStr("0.95")

genesisState := &types.GenesisState{
Params: types.DefaultParams(),
HostChains: []*types.HostChain{{
ChainId: "chainA-1",
ConnectionId: "connection-1",
Params: &types.HostChainLSParams{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
UpperCValueLimit: upperCValueLimit,
LowerCValueLimit: lowerCValueLimit,
},
HostDenom: "uatom",
ChannelId: "channel-1",
Expand Down
6 changes: 2 additions & 4 deletions x/liquidstakeibc/keeper/grpc_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ func (suite *IntegrationTestSuite) TestQueryParams() {
req: &types.QueryParamsRequest{},
resp: &types.QueryParamsResponse{
Params: types.Params{
AdminAddress: "persistence1gztc3y3k52hjds5nqvl7h9jvfnc33spz47zcjy",
FeeAddress: "persistence1gztc3y3k52hjds5nqvl7h9jvfnc33spz47zcjy",
UpperCValueLimit: decFromStr("1.1"),
LowerCValueLimit: decFromStr("0.85"),
AdminAddress: "persistence1gztc3y3k52hjds5nqvl7h9jvfnc33spz47zcjy",
FeeAddress: "persistence1gztc3y3k52hjds5nqvl7h9jvfnc33spz47zcjy",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion x/liquidstakeibc/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func CValueLimits(k Keeper) sdk.Invariant {
str := ""
broken := false
for _, hc := range hostChains {
if !k.CValueWithinLimits(ctx, hc) {
if !k.CValueWithinLimits(hc) {
str = fmt.Sprintf("chainID: %s, cValue: %s \n", hc.ChainId, hc.CValue)
}
}
Expand Down
6 changes: 3 additions & 3 deletions x/liquidstakeibc/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (k *Keeper) UpdateCValues(ctx sdk.Context) {
}()

// if the c value is out of bounds, disable the chain
if !k.CValueWithinLimits(ctx, hc) {
if !k.CValueWithinLimits(hc) {
hc.Active = false
k.SetHostChain(ctx, hc)

Expand All @@ -350,8 +350,8 @@ func (k *Keeper) UpdateCValues(ctx sdk.Context) {
}
}

func (k *Keeper) CValueWithinLimits(ctx sdk.Context, hc *types.HostChain) bool {
return hc.CValue.LT(k.GetParams(ctx).UpperCValueLimit) && hc.CValue.GT(k.GetParams(ctx).LowerCValueLimit)
func (k *Keeper) CValueWithinLimits(hc *types.HostChain) bool {
return hc.CValue.LT(hc.Params.UpperCValueLimit) && hc.CValue.GT(hc.Params.LowerCValueLimit)
}

func (k *Keeper) CalculateAutocompoundLimit(autocompoundFactor sdk.Dec) sdk.Dec {
Expand Down
17 changes: 6 additions & 11 deletions x/liquidstakeibc/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ func (suite *IntegrationTestSuite) TestGetSetParams() {
{
name: "normal params",
params: types.Params{
AdminAddress: "persistence10khgeppewe4rgfrcy809r9h00aquwxxxrk6glr",
FeeAddress: "persistence1xruvjju28j0a5ud5325rfdak8f5a04h0s30mld",
UpperCValueLimit: decFromStr("1.1"),
LowerCValueLimit: decFromStr("0.9"),
AdminAddress: "persistence10khgeppewe4rgfrcy809r9h00aquwxxxrk6glr",
FeeAddress: "persistence1xruvjju28j0a5ud5325rfdak8f5a04h0s30mld",
},
expected: types.Params{
AdminAddress: "persistence10khgeppewe4rgfrcy809r9h00aquwxxxrk6glr",
FeeAddress: "persistence1xruvjju28j0a5ud5325rfdak8f5a04h0s30mld",
UpperCValueLimit: decFromStr("1.1"),
LowerCValueLimit: decFromStr("0.9"),
AdminAddress: "persistence10khgeppewe4rgfrcy809r9h00aquwxxxrk6glr",
FeeAddress: "persistence1xruvjju28j0a5ud5325rfdak8f5a04h0s30mld",
},
},
}
Expand Down Expand Up @@ -274,9 +270,8 @@ func (suite *IntegrationTestSuite) TestUpdateCValues() {
suite.Require().NotPanics(func() { pstakeApp.LiquidStakeIBCKeeper.UpdateCValues(ctx) })

// lower limits so that chain goes out of limits
params := pstakeApp.LiquidStakeIBCKeeper.GetParams(ctx)
params.UpperCValueLimit = sdk.MustNewDecFromStr("0.5")
pstakeApp.LiquidStakeIBCKeeper.SetParams(ctx, params)
hc.Params.UpperCValueLimit = sdk.MustNewDecFromStr("0.5")
pstakeApp.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)
suite.Require().NotPanics(func() { pstakeApp.LiquidStakeIBCKeeper.UpdateCValues(ctx) })
hc, _ = pstakeApp.LiquidStakeIBCKeeper.GetHostChain(ctx, suite.chainB.ChainID)
suite.Require().Equal(false, hc.Active)
Expand Down
14 changes: 14 additions & 0 deletions x/liquidstakeibc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ func (k msgServer) UpdateHostChain(
return nil, err
}
hc.Params.MaxEntries = uint32(entries)
case types.KeyUpperCValueLimit:
limit, err := sdktypes.NewDecFromStr(update.Value)
if err != nil {
return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err)
}
// limit validated in msg.ValidateBasic()
hc.Params.UpperCValueLimit = limit
case types.KeyLowerCValueLimit:
limit, err := sdktypes.NewDecFromStr(update.Value)
if err != nil {
return nil, fmt.Errorf("unable to parse string to sdk.Dec: %w", err)
}
// limit validated in msg.ValidateBasic()
hc.Params.LowerCValueLimit = limit
case types.KeyRedelegationAcceptableDelta:
redelegationAcceptableDelta, ok := sdktypes.NewIntFromString(update.Value)
if !ok {
Expand Down
6 changes: 2 additions & 4 deletions x/liquidstakeibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,8 @@ func (suite *IntegrationTestSuite) Test_msgServer_UpdateParams() {
msg: &types.MsgUpdateParams{
Authority: suite.chainA.SenderAccount.GetAddress().String(),
Params: types.Params{
AdminAddress: suite.chainA.SenderAccount.GetAddress().String(),
FeeAddress: suite.chainA.SenderAccount.GetAddress().String(),
UpperCValueLimit: sdk.OneDec(),
LowerCValueLimit: sdk.ZeroDec(),
AdminAddress: suite.chainA.SenderAccount.GetAddress().String(),
FeeAddress: suite.chainA.SenderAccount.GetAddress().String(),
},
},
},
Expand Down
20 changes: 14 additions & 6 deletions x/liquidstakeibc/keeper/setup_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,21 @@ func (suite *IntegrationTestSuite) SetupHostChainAB() {
lsmBondFactor, err := sdk.NewDecFromStr("50")
suite.NoError(err)

upperCValueLimit, err := sdk.NewDecFromStr("1.05")
suite.NoError(err)

lowerCValueLimit, err := sdk.NewDecFromStr("0.95")
suite.NoError(err)

hostChainLSParams := &types.HostChainLSParams{
DepositFee: depositFee,
RestakeFee: restakeFee,
UnstakeFee: unstakeFee,
RedemptionFee: redemptionFee,
LsmValidatorCap: lsmValidatorCap,
LsmBondFactor: lsmBondFactor,
DepositFee: depositFee,
RestakeFee: restakeFee,
UnstakeFee: unstakeFee,
RedemptionFee: redemptionFee,
LsmValidatorCap: lsmValidatorCap,
LsmBondFactor: lsmBondFactor,
UpperCValueLimit: upperCValueLimit,
LowerCValueLimit: lowerCValueLimit,
}

validators := make([]*types.Validator, 0)
Expand Down
17 changes: 11 additions & 6 deletions x/liquidstakeibc/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,23 @@ func TestGenesisState_Validate(t *testing.T) {
}

func ValidGenesis() *types.GenesisState {
upperCValueLimit, _ := sdk.NewDecFromStr("1.05")
lowerCValueLimit, _ := sdk.NewDecFromStr("0.95")

return &types.GenesisState{
Params: types.DefaultParams(),
HostChains: []*types.HostChain{{
ChainId: "chainA-1",
ConnectionId: "connection-1",
Params: &types.HostChainLSParams{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
UpperCValueLimit: upperCValueLimit,
LowerCValueLimit: lowerCValueLimit,
},
HostDenom: "uatom",
ChannelId: "channel-1",
Expand Down
2 changes: 2 additions & 0 deletions x/liquidstakeibc/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const (
KeyLSMValidatorCap string = "lsm_validator_cap"
KeyLSMBondFactor string = "lsm_bond_factor"
KeyMaxEntries string = "max_entries"
KeyUpperCValueLimit string = "upper_c_value_limit"
KeyLowerCValueLimit string = "lower_c_value_limit"
KeyRedelegationAcceptableDelta string = "redelegation_acceptable_delta"
KeyMinimumDeposit string = "min_deposit"
KeyActive string = "active"
Expand Down
Loading
Loading