diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 863b2af8968..3d3db3a72d1 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -375,6 +375,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appKeepers.GetSubspace(valsetpreftypes.ModuleName), appKeepers.StakingKeeper, appKeepers.DistrKeeper, + appKeepers.LockupKeeper, ) appKeepers.ValidatorSetPreferenceKeeper = &validatorSetPreferenceKeeper diff --git a/proto/osmosis/valset-pref/v1beta1/tx.proto b/proto/osmosis/valset-pref/v1beta1/tx.proto index 2927a6ddf58..5de6b24daee 100644 --- a/proto/osmosis/valset-pref/v1beta1/tx.proto +++ b/proto/osmosis/valset-pref/v1beta1/tx.proto @@ -35,6 +35,11 @@ service Msg { // validator-set. rpc WithdrawDelegationRewards(MsgWithdrawDelegationRewards) returns (MsgWithdrawDelegationRewardsResponse); + + // DelegateBondedTokens allows users to break the lockup bond and delegate + // osmo tokens to a predefined validator-set. + rpc DelegateBondedTokens(MsgDelegateBondedTokens) + returns (MsgDelegateBondedTokensResponse); } // MsgCreateValidatorSetPreference is a list that holds validator-set. @@ -107,3 +112,15 @@ message MsgWithdrawDelegationRewards { } message MsgWithdrawDelegationRewardsResponse {} + +// MsgDelegateBondedTokens breaks bonded lockup (by ID) of osmo, of +// length <= 2 weeks and takes all that osmo and delegates according to +// delegator's current validator set preference. +message MsgDelegateBondedTokens { + // delegator is the user who is trying to force unbond osmo and delegate. + string delegator = 1 [ (gogoproto.moretags) = "yaml:\"delegator\"" ]; + // lockup id of osmo in the pool + uint64 lockID = 2; +} + +message MsgDelegateBondedTokensResponse {} \ No newline at end of file diff --git a/x/valset-pref/export_test.go b/x/valset-pref/export_test.go new file mode 100644 index 00000000000..493449c7d40 --- /dev/null +++ b/x/valset-pref/export_test.go @@ -0,0 +1,11 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + lockuptypes "github.com/osmosis-labs/osmosis/v14/x/lockup/types" +) + +func (k Keeper) ValidateLockForForceUnlock(ctx sdk.Context, lockID uint64, delegatorAddr string) (*lockuptypes.PeriodLock, sdk.Int, error) { + return k.validateLockForForceUnlock(ctx, lockID, delegatorAddr) +} diff --git a/x/valset-pref/keeper.go b/x/valset-pref/keeper.go index a4947f1f5a8..b740f209b2c 100644 --- a/x/valset-pref/keeper.go +++ b/x/valset-pref/keeper.go @@ -19,18 +19,21 @@ type Keeper struct { paramSpace paramtypes.Subspace stakingKeeper types.StakingInterface distirbutionKeeper types.DistributionKeeper + lockupKeeper types.LockupKeeper } func NewKeeper(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, stakingKeeper types.StakingInterface, distirbutionKeeper types.DistributionKeeper, + lockupKeeper types.LockupKeeper, ) Keeper { return Keeper{ storeKey: storeKey, paramSpace: paramSpace, stakingKeeper: stakingKeeper, distirbutionKeeper: distirbutionKeeper, + lockupKeeper: lockupKeeper, } } diff --git a/x/valset-pref/keeper_test.go b/x/valset-pref/keeper_test.go index b955d697081..75c1215d5c7 100644 --- a/x/valset-pref/keeper_test.go +++ b/x/valset-pref/keeper_test.go @@ -3,15 +3,18 @@ package keeper_test import ( "fmt" "testing" + "time" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/suite" + "github.com/osmosis-labs/osmosis/v14/app/apptesting" + appParams "github.com/osmosis-labs/osmosis/v14/app/params" + lockuptypes "github.com/osmosis-labs/osmosis/v14/x/lockup/types" "github.com/osmosis-labs/osmosis/v14/x/valset-pref/types" - "github.com/stretchr/testify/suite" - valPref "github.com/osmosis-labs/osmosis/v14/x/valset-pref" ) @@ -199,7 +202,71 @@ func (suite *KeeperTestSuite) SetupValidatorsAndDelegations() ([]string, []types amountToFund := sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 100_000_000)} // 100 osmo return valAddrs, preferences, amountToFund +} + +func (suite *KeeperTestSuite) SetupLocks(delegator sdk.AccAddress) []lockuptypes.PeriodLock { + // create a pool with uosmo + locks := []lockuptypes.PeriodLock{} + // Setup lock + coinsToLock := sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 10_000_000)} + osmoToLock := sdk.Coins{sdk.NewInt64Coin(appParams.BaseCoinUnit, 10_000_000)} + multipleCoinsToLock := sdk.Coins{coinsToLock[0], osmoToLock[0]} + suite.FundAcc(delegator, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 100_000_000), sdk.NewInt64Coin(appParams.BaseCoinUnit, 100_000_000)}) + + // lock with osmo + twoWeekDuration, err := time.ParseDuration("336h") + suite.Require().NoError(err) + workingLock, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, delegator, osmoToLock, twoWeekDuration) + suite.Require().NoError(err) + + locks = append(locks, workingLock) + + // locking with stake denom instead of osmo denom + stakeDenomLock, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, delegator, coinsToLock, twoWeekDuration) + suite.Require().NoError(err) + + locks = append(locks, stakeDenomLock) + + // lock case where lock owner != delegator + suite.FundAcc(sdk.AccAddress([]byte("addr5---------------")), osmoToLock) + lockWithDifferentOwner, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, sdk.AccAddress([]byte("addr5---------------")), osmoToLock, twoWeekDuration) + suite.Require().NoError(err) + + locks = append(locks, lockWithDifferentOwner) + + // lock case where the duration != <= 2 weeks + morethanTwoWeekDuration, err := time.ParseDuration("337h") + suite.Require().NoError(err) + maxDurationLock, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, delegator, osmoToLock, morethanTwoWeekDuration) + suite.Require().NoError(err) + + locks = append(locks, maxDurationLock) + + // unbonding locks + unbondingLocks, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, delegator, osmoToLock, twoWeekDuration) + suite.Require().NoError(err) + + err = suite.App.LockupKeeper.BeginUnlock(suite.Ctx, unbondingLocks.ID, nil) + suite.Require().NoError(err) + + locks = append(locks, unbondingLocks) + + // synthetic locks + syntheticLocks, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, delegator, osmoToLock, twoWeekDuration) + suite.Require().NoError(err) + + err = suite.App.LockupKeeper.CreateSyntheticLockup(suite.Ctx, syntheticLocks.ID, "uosmo", time.Minute, true) + suite.Require().NoError(err) + + locks = append(locks, syntheticLocks) + + // multiple asset lock + multiassetLock, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, delegator, multipleCoinsToLock, twoWeekDuration) + suite.Require().NoError(err) + + locks = append(locks, multiassetLock) + return locks } func TestKeeperTestSuite(t *testing.T) { diff --git a/x/valset-pref/msg_server.go b/x/valset-pref/msg_server.go index 703e08314f6..138d07df3a1 100644 --- a/x/valset-pref/msg_server.go +++ b/x/valset-pref/msg_server.go @@ -5,6 +5,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/v14/x/valset-pref/types" ) @@ -34,6 +35,7 @@ func (server msgServer) SetValidatorSetPreference(goCtx context.Context, msg *ty return &types.MsgSetValidatorSetPreferenceResponse{}, nil } +// DelegateToValidatorSet delegates to a delegators existing validator-set. func (server msgServer) DelegateToValidatorSet(goCtx context.Context, msg *types.MsgDelegateToValidatorSet) (*types.MsgDelegateToValidatorSetResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -45,6 +47,7 @@ func (server msgServer) DelegateToValidatorSet(goCtx context.Context, msg *types return &types.MsgDelegateToValidatorSetResponse{}, nil } +// UndelegateFromValidatorSet undelegates {coin} amount from the validator set. func (server msgServer) UndelegateFromValidatorSet(goCtx context.Context, msg *types.MsgUndelegateFromValidatorSet) (*types.MsgUndelegateFromValidatorSetResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -56,6 +59,7 @@ func (server msgServer) UndelegateFromValidatorSet(goCtx context.Context, msg *t return &types.MsgUndelegateFromValidatorSetResponse{}, nil } +// RedelegateValidatorSet allows delegators to set a new validator set and switch validators. func (server msgServer) RedelegateValidatorSet(goCtx context.Context, msg *types.MsgRedelegateValidatorSet) (*types.MsgRedelegateValidatorSetResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -87,6 +91,7 @@ func (server msgServer) RedelegateValidatorSet(goCtx context.Context, msg *types return &types.MsgRedelegateValidatorSetResponse{}, nil } +// WithdrawDelegationRewards withdraws all the delegation rewards from the validator in the val-set. func (server msgServer) WithdrawDelegationRewards(goCtx context.Context, msg *types.MsgWithdrawDelegationRewards) (*types.MsgWithdrawDelegationRewardsResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -97,3 +102,33 @@ func (server msgServer) WithdrawDelegationRewards(goCtx context.Context, msg *ty return &types.MsgWithdrawDelegationRewardsResponse{}, nil } + +// DelegateBondedTokens force unlocks bonded uosmo and stakes according to your current validator set preference. +func (server msgServer) DelegateBondedTokens(goCtx context.Context, msg *types.MsgDelegateBondedTokens) (*types.MsgDelegateBondedTokensResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // get the existingValSet if it exists, if not check existingStakingPosition and return it + _, err := server.keeper.GetDelegationPreferences(ctx, msg.Delegator) + if err != nil { + return nil, fmt.Errorf("user %s doesn't have validator set", msg.Delegator) + } + + // Message 1: force unlock bonded osmo tokens. + unlockedOsmoToken, err := server.keeper.ForceUnlockBondedOsmo(ctx, msg.LockID, msg.Delegator) + if err != nil { + return nil, err + } + + delegator, err := sdk.AccAddressFromBech32(msg.Delegator) + if err != nil { + return nil, err + } + + // Message 2: Perform osmo token delegation. + _, err = server.DelegateToValidatorSet(goCtx, types.NewMsgDelegateToValidatorSet(delegator, unlockedOsmoToken)) + if err != nil { + return nil, err + } + + return &types.MsgDelegateBondedTokensResponse{}, nil +} diff --git a/x/valset-pref/msg_server_test.go b/x/valset-pref/msg_server_test.go index 185e0961b92..6d89ede7e8d 100644 --- a/x/valset-pref/msg_server_test.go +++ b/x/valset-pref/msg_server_test.go @@ -3,6 +3,7 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" + appParams "github.com/osmosis-labs/osmosis/v14/app/params" valPref "github.com/osmosis-labs/osmosis/v14/x/valset-pref" "github.com/osmosis-labs/osmosis/v14/x/valset-pref/types" ) @@ -642,7 +643,118 @@ func (suite *KeeperTestSuite) TestWithdrawDelegationRewards() { } else { suite.Require().Error(err) + } + }) + } +} +func (suite *KeeperTestSuite) TestDelegateBondedTokens() { + suite.SetupTest() + + testLock := suite.SetupLocks(sdk.AccAddress([]byte("addr1---------------"))) + + tests := []struct { + name string + delegator sdk.AccAddress + lockId uint64 + expectedUnlockedOsmo sdk.Coin + expectedDelegations []sdk.Dec + setValSet bool + expectPass bool + }{ + { + name: "DelegateBondedTokens with existing osmo denom lockId, bonded and <= 2 weeks bond duration", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: testLock[0].ID, + expectedUnlockedOsmo: sdk.NewCoin(appParams.BaseCoinUnit, sdk.NewInt(60_000_000)), // delegator has 100osmo and creates 5 locks 10osmo each, forceUnlock only 1 lock + expectedDelegations: []sdk.Dec{sdk.NewDec(2_000_000), sdk.NewDec(3_300_000), sdk.NewDec(1_200_000), sdk.NewDec(3_500_000)}, + setValSet: true, + expectPass: true, + }, + { + name: "DelegateBondedTokens with existing stake denom lockId, bonded and <= 2 weeks bond duration", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: testLock[1].ID, + expectPass: false, + }, + { + name: "DelegateBondedTokens with non existing lockId", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: 10, + expectPass: false, + }, + { + name: "DelegateBondedTokens with lockOwner != delegatorOwner", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: testLock[2].ID, + expectPass: false, + }, + { + name: "DelegateBondedTokens with lock duration > 2 weeks", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: testLock[3].ID, + expectPass: false, + }, + { + name: "DelegateBondedTokens with non bonded lockId", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: testLock[4].ID, + expectPass: false, + }, + { + name: "DelegateBondedTokens with synthetic locks", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: testLock[5].ID, + expectPass: false, + }, + { + name: "DelegateBondedTokens with multiple asset lock", + delegator: sdk.AccAddress([]byte("addr1---------------")), + lockId: testLock[6].ID, + expectPass: false, + }, + } + + for _, test := range tests { + suite.Run(test.name, func() { + // setup message server + msgServer := valPref.NewMsgServerImpl(suite.App.ValidatorSetPreferenceKeeper) + c := sdk.WrapSDKContext(suite.Ctx) + + // creates a validator preference list to delegate to + preferences := suite.PrepareDelegateToValidatorSet() + + if test.setValSet { + // SetValidatorSetPreference sets a new list of val-set + _, err := msgServer.SetValidatorSetPreference(c, types.NewMsgSetValidatorSetPreference(test.delegator, preferences)) + suite.Require().NoError(err) + } + + _, err := msgServer.DelegateBondedTokens(c, types.NewMsgDelegateBondedTokens(test.delegator, test.lockId)) + if test.expectPass { + suite.Require().NoError(err) + + // check that the lock has been successfully unlocked + // existingLocks should not contain the current lock + existingLocks, err := suite.App.LockupKeeper.GetPeriodLocks(suite.Ctx) + + suite.Require().NoError(err) + suite.Require().Equal(len(existingLocks), len(testLock)-1) + + balance := suite.App.BankKeeper.GetBalance(suite.Ctx, test.delegator, appParams.BaseCoinUnit) + suite.Require().Equal(balance, test.expectedUnlockedOsmo) + + // check if delegation has been done by checking if expectedDelegations matches after delegation + for i, val := range preferences { + valAddr, err := sdk.ValAddressFromBech32(val.ValOperAddress) + suite.Require().NoError(err) + + // guarantees that the delegator exists because we check it in DelegateToValidatorSet + del, _ := suite.App.StakingKeeper.GetDelegation(suite.Ctx, test.delegator, valAddr) + suite.Require().Equal(del.Shares, test.expectedDelegations[i]) + } + } else { + suite.Require().Error(err) } }) } diff --git a/x/valset-pref/types/expected_interfaces.go b/x/valset-pref/types/expected_interfaces.go index eba662d69a0..a42a4f408ce 100644 --- a/x/valset-pref/types/expected_interfaces.go +++ b/x/valset-pref/types/expected_interfaces.go @@ -5,6 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + lockuptypes "github.com/osmosis-labs/osmosis/v14/x/lockup/types" ) // StakingInterface expected staking keeper. @@ -23,10 +25,16 @@ type BankKeeper interface { GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin } -// For testing only type DistributionKeeper interface { WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) IncrementValidatorPeriod(ctx sdk.Context, val stakingtypes.ValidatorI) uint64 CalculateDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins) AllocateTokensToValidator(ctx sdk.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) } +type LockupKeeper interface { + GetLockByID(ctx sdk.Context, lockID uint64) (*lockuptypes.PeriodLock, error) + GetAllSyntheticLockupsByLockup(ctx sdk.Context, lockID uint64) []lockuptypes.SyntheticLock + ForceUnlock(ctx sdk.Context, lock lockuptypes.PeriodLock) error + BeginUnlock(ctx sdk.Context, lockID uint64, coins sdk.Coins) error + GetPeriodLocks(ctx sdk.Context) ([]lockuptypes.PeriodLock, error) +} diff --git a/x/valset-pref/types/msgs.go b/x/valset-pref/types/msgs.go index 47686499ef9..e34e5951405 100644 --- a/x/valset-pref/types/msgs.go +++ b/x/valset-pref/types/msgs.go @@ -249,3 +249,37 @@ func (m MsgWithdrawDelegationRewards) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(m.Delegator) return []sdk.AccAddress{delegator} } + +// constants +const ( + TypeMsgDelegateBondedTokens = "delegate_bonded_tokens" +) + +var _ sdk.Msg = &MsgDelegateBondedTokens{} + +// NewMsgMsgStakeToValidatorSet creates a msg to stake to a validator. +func NewMsgDelegateBondedTokens(delegator sdk.AccAddress, lockId uint64) *MsgDelegateBondedTokens { + return &MsgDelegateBondedTokens{ + Delegator: delegator.String(), + LockID: lockId, + } +} + +func (m MsgDelegateBondedTokens) Type() string { return TypeMsgDelegateBondedTokens } +func (m MsgDelegateBondedTokens) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.Delegator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) + } + + return nil +} + +func (m MsgDelegateBondedTokens) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} + +func (m MsgDelegateBondedTokens) GetSigners() []sdk.AccAddress { + delegator, _ := sdk.AccAddressFromBech32(m.Delegator) + return []sdk.AccAddress{delegator} +} diff --git a/x/valset-pref/types/tx.pb.go b/x/valset-pref/types/tx.pb.go index 5f9a653cc1f..2303f971d95 100644 --- a/x/valset-pref/types/tx.pb.go +++ b/x/valset-pref/types/tx.pb.go @@ -483,6 +483,99 @@ func (m *MsgWithdrawDelegationRewardsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWithdrawDelegationRewardsResponse proto.InternalMessageInfo +// MsgDelegateBondedTokens breaks bonded lockup (by ID) of osmo, of +// length <= 2 weeks and takes all that osmo and delegates according to +// delegator's current validator set preference. +type MsgDelegateBondedTokens struct { + // delegator is the user who is trying to force unbond osmo and delegate. + Delegator string `protobuf:"bytes,1,opt,name=delegator,proto3" json:"delegator,omitempty" yaml:"delegator"` + // lockup id of osmo in the pool + LockID uint64 `protobuf:"varint,2,opt,name=lockID,proto3" json:"lockID,omitempty"` +} + +func (m *MsgDelegateBondedTokens) Reset() { *m = MsgDelegateBondedTokens{} } +func (m *MsgDelegateBondedTokens) String() string { return proto.CompactTextString(m) } +func (*MsgDelegateBondedTokens) ProtoMessage() {} +func (*MsgDelegateBondedTokens) Descriptor() ([]byte, []int) { + return fileDescriptor_daa95be02b2fc560, []int{10} +} +func (m *MsgDelegateBondedTokens) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDelegateBondedTokens) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDelegateBondedTokens.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDelegateBondedTokens) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDelegateBondedTokens.Merge(m, src) +} +func (m *MsgDelegateBondedTokens) XXX_Size() int { + return m.Size() +} +func (m *MsgDelegateBondedTokens) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDelegateBondedTokens.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDelegateBondedTokens proto.InternalMessageInfo + +func (m *MsgDelegateBondedTokens) GetDelegator() string { + if m != nil { + return m.Delegator + } + return "" +} + +func (m *MsgDelegateBondedTokens) GetLockID() uint64 { + if m != nil { + return m.LockID + } + return 0 +} + +type MsgDelegateBondedTokensResponse struct { +} + +func (m *MsgDelegateBondedTokensResponse) Reset() { *m = MsgDelegateBondedTokensResponse{} } +func (m *MsgDelegateBondedTokensResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDelegateBondedTokensResponse) ProtoMessage() {} +func (*MsgDelegateBondedTokensResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_daa95be02b2fc560, []int{11} +} +func (m *MsgDelegateBondedTokensResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDelegateBondedTokensResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDelegateBondedTokensResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgDelegateBondedTokensResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDelegateBondedTokensResponse.Merge(m, src) +} +func (m *MsgDelegateBondedTokensResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDelegateBondedTokensResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDelegateBondedTokensResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDelegateBondedTokensResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSetValidatorSetPreference)(nil), "osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreference") proto.RegisterType((*MsgSetValidatorSetPreferenceResponse)(nil), "osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreferenceResponse") @@ -494,6 +587,8 @@ func init() { proto.RegisterType((*MsgRedelegateValidatorSetResponse)(nil), "osmosis.valsetpref.v1beta1.MsgRedelegateValidatorSetResponse") proto.RegisterType((*MsgWithdrawDelegationRewards)(nil), "osmosis.valsetpref.v1beta1.MsgWithdrawDelegationRewards") proto.RegisterType((*MsgWithdrawDelegationRewardsResponse)(nil), "osmosis.valsetpref.v1beta1.MsgWithdrawDelegationRewardsResponse") + proto.RegisterType((*MsgDelegateBondedTokens)(nil), "osmosis.valsetpref.v1beta1.MsgDelegateBondedTokens") + proto.RegisterType((*MsgDelegateBondedTokensResponse)(nil), "osmosis.valsetpref.v1beta1.MsgDelegateBondedTokensResponse") } func init() { @@ -501,44 +596,48 @@ func init() { } var fileDescriptor_daa95be02b2fc560 = []byte{ - // 583 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0x4d, 0x8b, 0xd3, 0x40, - 0x18, 0xee, 0x6c, 0x55, 0xd8, 0xe9, 0x45, 0xc2, 0x22, 0x6d, 0xd0, 0xb4, 0xc6, 0xd5, 0xf6, 0xd2, - 0x0c, 0xad, 0x8a, 0x1f, 0x20, 0x68, 0x15, 0x6f, 0x05, 0xcd, 0xfa, 0x01, 0x1e, 0x84, 0x49, 0xfb, - 0x36, 0x1b, 0x4c, 0x32, 0x21, 0x33, 0xfb, 0xf5, 0x27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0xe1, 0x98, 0x97, 0xf1, 0x99, 0xee, 0x45, 0x66, 0xcc, 0x45, 0xee, - 0xfe, 0xef, 0xf3, 0xb8, 0x3a, 0xe4, 0xb6, 0xf2, 0x11, 0xe1, 0x46, 0xf6, 0x45, 0x70, 0x37, 0xaf, - 0x40, 0x79, 0xfb, 0xa7, 0x3e, 0x2c, 0xcb, 0x5c, 0x28, 0x54, 0xde, 0x23, 0x7c, 0x29, 0x63, 0x6d, - 0x6f, 0x17, 0x04, 0x5f, 0x4d, 0x53, 0x1f, 0x94, 0xa2, 0x49, 0x41, 0x9f, 0x10, 0x56, 0x73, 0x16, - 0xee, 0x5e, 0x41, 0xf4, 0x6c, 0xaa, 0xfa, 0xa8, 0x34, 0xf5, 0x54, 0xb5, 0x32, 0xd6, 0xa5, 0xa8, - 0x5a, 0xab, 0x69, 0x85, 0xd5, 0xca, 0x1f, 0xee, 0x78, 0xb0, 0xb2, 0x47, 0xbb, 0x68, 0xb0, 0x32, - 0x99, 0x85, 0x83, 0x55, 0x38, 0xfa, 0x83, 0xe7, 0x87, 0x33, 0x0d, 0x1d, 0xcd, 0x34, 0xf4, 0x6b, - 0xa6, 0xa1, 0x0f, 0x73, 0xad, 0x72, 0x34, 0xd7, 0x2a, 0x3f, 0xe6, 0x5a, 0xe5, 0xcd, 0x9d, 0xa5, - 0xeb, 0x2c, 0xcd, 0xd2, 0x75, 0xa9, 0xc5, 0x89, 0x7c, 0x59, 0x7b, 0xb7, 0xc8, 0xfe, 0xa9, 0xf7, - 0x35, 0xbe, 0xe3, 0xac, 0x0b, 0xf1, 0xc3, 0x7a, 0xf3, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xce, - 0x80, 0x70, 0xcd, 0x1c, 0x08, 0x00, 0x00, + // 643 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4d, 0x6b, 0xd4, 0x40, + 0x18, 0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, 0x1d, 0xc1, 0xcd, 0xdf, 0xec, 0x8f, 0x2c, 0x49, 0xbc, 0x57, 0x81, + 0x34, 0x91, 0xd2, 0x79, 0x76, 0x3c, 0x92, 0xd0, 0xc9, 0x48, 0x42, 0x3f, 0x47, 0x12, 0x7a, 0x3f, + 0x96, 0x6a, 0x27, 0x63, 0xa9, 0xf6, 0x7d, 0x2c, 0xd5, 0x5e, 0xdd, 0xca, 0xec, 0xf8, 0x24, 0x41, + 0xd3, 0xd1, 0x0d, 0x46, 0xd2, 0xe7, 0x46, 0xeb, 0x06, 0x39, 0x3c, 0xf7, 0xe8, 0x88, 0x16, 0xbf, + 0x31, 0x1f, 0xbd, 0x36, 0x36, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x25, 0xf3, 0x25, 0x31, + 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -569,6 +668,9 @@ type MsgClient interface { // WithdrawDelegationRewards allows users to claim rewards from the // validator-set. WithdrawDelegationRewards(ctx context.Context, in *MsgWithdrawDelegationRewards, opts ...grpc.CallOption) (*MsgWithdrawDelegationRewardsResponse, error) + // DelegateBondedTokens allows users to break the lockup bond and delegate + // osmo tokens to a predefined validator-set. + DelegateBondedTokens(ctx context.Context, in *MsgDelegateBondedTokens, opts ...grpc.CallOption) (*MsgDelegateBondedTokensResponse, error) } type msgClient struct { @@ -624,6 +726,15 @@ func (c *msgClient) WithdrawDelegationRewards(ctx context.Context, in *MsgWithdr return out, nil } +func (c *msgClient) DelegateBondedTokens(ctx context.Context, in *MsgDelegateBondedTokens, opts ...grpc.CallOption) (*MsgDelegateBondedTokensResponse, error) { + out := new(MsgDelegateBondedTokensResponse) + err := c.cc.Invoke(ctx, "/osmosis.valsetpref.v1beta1.Msg/DelegateBondedTokens", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // SetValidatorSetPreference creates a set of validator preference. @@ -642,6 +753,9 @@ type MsgServer interface { // WithdrawDelegationRewards allows users to claim rewards from the // validator-set. WithdrawDelegationRewards(context.Context, *MsgWithdrawDelegationRewards) (*MsgWithdrawDelegationRewardsResponse, error) + // DelegateBondedTokens allows users to break the lockup bond and delegate + // osmo tokens to a predefined validator-set. + DelegateBondedTokens(context.Context, *MsgDelegateBondedTokens) (*MsgDelegateBondedTokensResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -663,6 +777,9 @@ func (*UnimplementedMsgServer) RedelegateValidatorSet(ctx context.Context, req * func (*UnimplementedMsgServer) WithdrawDelegationRewards(ctx context.Context, req *MsgWithdrawDelegationRewards) (*MsgWithdrawDelegationRewardsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method WithdrawDelegationRewards not implemented") } +func (*UnimplementedMsgServer) DelegateBondedTokens(ctx context.Context, req *MsgDelegateBondedTokens) (*MsgDelegateBondedTokensResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DelegateBondedTokens not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -758,6 +875,24 @@ func _Msg_WithdrawDelegationRewards_Handler(srv interface{}, ctx context.Context return interceptor(ctx, in, info, handler) } +func _Msg_DelegateBondedTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDelegateBondedTokens) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).DelegateBondedTokens(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.valsetpref.v1beta1.Msg/DelegateBondedTokens", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).DelegateBondedTokens(ctx, req.(*MsgDelegateBondedTokens)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "osmosis.valsetpref.v1beta1.Msg", HandlerType: (*MsgServer)(nil), @@ -782,6 +917,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "WithdrawDelegationRewards", Handler: _Msg_WithdrawDelegationRewards_Handler, }, + { + MethodName: "DelegateBondedTokens", + Handler: _Msg_DelegateBondedTokens_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "osmosis/valset-pref/v1beta1/tx.proto", @@ -1100,6 +1239,64 @@ func (m *MsgWithdrawDelegationRewardsResponse) MarshalToSizedBuffer(dAtA []byte) return len(dAtA) - i, nil } +func (m *MsgDelegateBondedTokens) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDelegateBondedTokens) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDelegateBondedTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.LockID != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.LockID)) + i-- + dAtA[i] = 0x10 + } + if len(m.Delegator) > 0 { + i -= len(m.Delegator) + copy(dAtA[i:], m.Delegator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Delegator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgDelegateBondedTokensResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgDelegateBondedTokensResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDelegateBondedTokensResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1237,6 +1434,31 @@ func (m *MsgWithdrawDelegationRewardsResponse) Size() (n int) { return n } +func (m *MsgDelegateBondedTokens) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Delegator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.LockID != 0 { + n += 1 + sovTx(uint64(m.LockID)) + } + return n +} + +func (m *MsgDelegateBondedTokensResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2037,6 +2259,157 @@ func (m *MsgWithdrawDelegationRewardsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgDelegateBondedTokens) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDelegateBondedTokens: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDelegateBondedTokens: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Delegator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Delegator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LockID", wireType) + } + m.LockID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LockID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgDelegateBondedTokensResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgDelegateBondedTokensResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDelegateBondedTokensResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/valset-pref/validator_set.go b/x/valset-pref/validator_set.go index 227a78dc4ca..f7fe68c95dd 100644 --- a/x/valset-pref/validator_set.go +++ b/x/valset-pref/validator_set.go @@ -3,10 +3,14 @@ package keeper import ( "fmt" "sort" + "time" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/osmosis-labs/osmosis/osmomath" + appParams "github.com/osmosis-labs/osmosis/v14/app/params" + lockuptypes "github.com/osmosis-labs/osmosis/v14/x/lockup/types" "github.com/osmosis-labs/osmosis/v14/x/valset-pref/types" ) @@ -254,6 +258,35 @@ func (k Keeper) withdrawExistingValSetStakingPosition(ctx sdk.Context, delegator return nil } +// ForceUnlockBondedOsmo allows breaking of a bonded lockup (by ID) of osmo, of length <= 2 weeks. +// We want to later have osmo incentives get auto-staked, we want people w/ no staking positions to +// get their osmo auto-locked. This function takes all that osmo and stakes according to your +// current validator set preference. +// (Note: Noting that there is an implicit valset preference if you've already staked) +func (k Keeper) ForceUnlockBondedOsmo(ctx sdk.Context, lockID uint64, delegatorAddr string) (sdk.Coin, error) { + lock, lockedOsmoAmount, err := k.validateLockForForceUnlock(ctx, lockID, delegatorAddr) + if err != nil { + return sdk.Coin{}, err + } + + // Ensured the lock has no superfluid relation by checking that there are no synthetic locks + synthLocks := k.lockupKeeper.GetAllSyntheticLockupsByLockup(ctx, lockID) + if len(synthLocks) != 0 { + return sdk.Coin{}, fmt.Errorf("cannot use DelegateBondedTokens with synthetic locks.") + } + + // ForceUnlock ignores lockup duration and unlock tokens immediately. + err = k.lockupKeeper.ForceUnlock(ctx, *lock) + if err != nil { + return sdk.Coin{}, err + } + + // Takes unlocked osmo, and delegate according to valset pref + unlockedOsmoCoin := sdk.Coin{Denom: appParams.BaseCoinUnit, Amount: lockedOsmoAmount} + + return unlockedOsmoCoin, nil +} + // GetValAddrAndVal checks if the validator address is valid and the validator provided exists on chain. func (k Keeper) getValAddrAndVal(ctx sdk.Context, valOperAddress string) (sdk.ValAddress, stakingtypes.Validator, error) { valAddr, err := sdk.ValAddressFromBech32(valOperAddress) @@ -375,3 +408,40 @@ func (k Keeper) FindMax(valPrefs []*valSet) (max valSet, idx int) { } return max, idx } + +// check if lock owner matches the delegator, contains only uosmo and is bonded for <= 2weeks +func (k Keeper) validateLockForForceUnlock(ctx sdk.Context, lockID uint64, delegatorAddr string) (*lockuptypes.PeriodLock, sdk.Int, error) { + // Checks if sender is lock ID owner + lock, err := k.lockupKeeper.GetLockByID(ctx, lockID) + if err != nil { + return nil, sdk.Int{}, err + } + if lock.GetOwner() != delegatorAddr { + return nil, sdk.Int{}, fmt.Errorf("delegator (%s) and lock owner (%s) does not match", delegatorAddr, lock.Owner) + } + + lockedOsmoAmount := sdk.NewInt(0) + + // check that lock contains only 1 token + coin, err := lock.SingleCoin() + if err != nil { + return nil, sdk.Int{}, fmt.Errorf("lock fails to meet expected invariant, it contains multiple coins") + } + + // check that the lock denom is uosmo + if coin.Denom == appParams.BaseCoinUnit { + lockedOsmoAmount = lockedOsmoAmount.Add(coin.Amount) + } + + // check if there is enough uosmo token in the lock + if lockedOsmoAmount.LTE(sdk.NewInt(0)) { + return nil, sdk.Int{}, fmt.Errorf("lock does not contain osmo denom, or there isn't enough osmo to unbond") + } + + // Checks if lock ID is bonded and ensure that the duration is <= 2 weeks + if lock.IsUnlocking() || lock.Duration > time.Hour*24*7*2 { + return nil, sdk.Int{}, fmt.Errorf("the tokens have to bonded and the duration has to be <= 2weeks") + } + + return lock, lockedOsmoAmount, nil +} diff --git a/x/valset-pref/validator_set_test.go b/x/valset-pref/validator_set_test.go new file mode 100644 index 00000000000..8b17552b8b5 --- /dev/null +++ b/x/valset-pref/validator_set_test.go @@ -0,0 +1,66 @@ +package keeper_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (suite *KeeperTestSuite) TestValidateLockForForceUnlock() { + + locks := suite.SetupLocks(sdk.AccAddress([]byte("addr1---------------"))) + + tests := []struct { + name string + lockID uint64 + delegatorAddr string + expectPass bool + }{ + { + name: "happy case", + lockID: locks[0].ID, + delegatorAddr: sdk.AccAddress([]byte("addr1---------------")).String(), + expectPass: true, + }, + { + name: "lock Id doesnot match with delegator", + lockID: locks[0].ID, + delegatorAddr: "addr2---------------", + expectPass: false, + }, + { + name: "Invalid Lock: contains multiple coins", + lockID: locks[6].ID, + delegatorAddr: "addr1---------------", + expectPass: false, + }, + { + name: "Invalid Lock: contains non osmo denom", + lockID: locks[1].ID, + delegatorAddr: "addr1---------------", + expectPass: false, + }, + { + name: "Invalid Lock: contains lock with duration > 2 weeks", + lockID: locks[3].ID, + delegatorAddr: "addr1---------------", + expectPass: false, + }, + { + name: "Invalid lock: non bonded lockId", + lockID: locks[4].ID, + delegatorAddr: "addr1---------------", + expectPass: false, + }, + } + + for _, test := range tests { + suite.Run(test.name, func() { + _, _, err := suite.App.ValidatorSetPreferenceKeeper.ValidateLockForForceUnlock(suite.Ctx, test.lockID, test.delegatorAddr) + if test.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + }) + } + +}