Skip to content

Commit

Permalink
add code to force unbond and withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 committed Dec 7, 2024
1 parent 163d163 commit dd87095
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
10 changes: 4 additions & 6 deletions x/liquidstakeibc/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ import (
func (k *Keeper) BeginBlock(ctx sdk.Context) {
// perform BeginBlocker tasks for each chain
for _, hc := range k.GetAllHostChains(ctx) {
if !hc.Active {
// don't do anything on inactive chains
continue
if hc.Active {
// attempt to delegate
k.DoDelegate(ctx, hc)

}

// attempt to recreate closed ICA channels
k.DoRecreateICA(ctx, hc)

// attempt to delegate
k.DoDelegate(ctx, hc)

// attempt to automatically claim matured undelegations
k.DoClaim(ctx, hc)

Expand Down
5 changes: 3 additions & 2 deletions x/liquidstakeibc/keeper/icq.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ func DelegationCallback(k Keeper, ctx sdk.Context, data []byte, query icqtypes.Q
k.SetHostChainValidator(ctx, hc, validator)

// update the c value for the slashed chain
k.UpdateCValue(ctx, hc)

if hc.Active {
k.UpdateCValue(ctx, hc)
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlashing,
Expand Down
4 changes: 3 additions & 1 deletion x/liquidstakeibc/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ func (k *Keeper) UpdateCValues(ctx sdk.Context) {
hostChains := k.GetAllHostChains(ctx)

for _, hc := range hostChains {
k.UpdateCValue(ctx, hc)
if hc.Active {
k.UpdateCValue(ctx, hc)
}
}
}

Expand Down
44 changes: 44 additions & 0 deletions x/liquidstakeibc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/cosmos/gogoproto/proto"
"strconv"
"strings"

Expand Down Expand Up @@ -331,7 +332,50 @@ func (k msgServer) UpdateHostChain(
if err := k.QueryValidatorDelegationUpdate(ctx, hc, val); err != nil {
return nil, fmt.Errorf("unable to send ICQ query for validator delegation update")
}
case types.KeyForceUnbond:
if hc.Active {
return nil, fmt.Errorf("cannot force unbond to active host chain")
}
validator, coin, valid := strings.Cut(update.Value, ",")
if !valid {
return nil, fmt.Errorf("invalid force unbond value, expected form \"cosmovaloperxx,123denom\" ")
}
val, found := hc.GetValidator(validator)
if !found {
return nil, types.ErrValidatorNotFound
}
amount, err := sdktypes.ParseCoinNormalized(coin)
if err != nil {
return nil, err
}
msgUnbond := &stakingtypes.MsgUndelegate{
DelegatorAddress: hc.DelegationAccount.Address,
ValidatorAddress: val.OperatorAddress,
Amount: amount,
}
_, err = k.GenerateAndExecuteICATx(ctx, hc.ConnectionId, hc.DelegationAccount.Owner, []proto.Message{msgUnbond})
if err != nil {
return nil, err
}

case types.KeyForceICATransfer:
amount, err := sdktypes.ParseCoinNormalized(update.Value)
if err != nil {
return nil, err
}
_, err = k.SendICATransfer(ctx, hc, amount, hc.DelegationAccount.Address, k.GetUndelegationModuleAccount(ctx).GetAddress().String(), hc.DelegationAccount.Owner)
if err != nil {
return nil, err
}
case types.KeyForceICATransferRewards:
amount, err := sdktypes.ParseCoinNormalized(update.Value)
if err != nil {
return nil, err
}
_, err = k.SendICATransfer(ctx, hc, amount, hc.RewardsAccount.Address, k.GetUndelegationModuleAccount(ctx).GetAddress().String(), hc.RewardsAccount.Owner)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("invalid or unexpected update key: %s", update.Key)
}
Expand Down
3 changes: 3 additions & 0 deletions x/liquidstakeibc/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ const (
KeyFlags string = "flags"
KeyRewardParams string = "reward_params"
KeyForceUpdateValidator string = "force_update_validator"
KeyForceUnbond string = "force_unbond"
KeyForceICATransfer string = "force_ica_transfer"
KeyForceICATransferRewards string = "force_ica_transfer_rewards"
)

var (
Expand Down
26 changes: 26 additions & 0 deletions x/liquidstakeibc/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,32 @@ func (m *MsgUpdateHostChain) ValidateBasic() error {
if err != nil {
return err
}
case KeyForceUnbond:
// expected "chainvaloper1xxx,1234denom"
validator, coin, valid := strings.Cut(update.Value, ",")
if !valid {
return fmt.Errorf("invalid force unbond value, expected form \"cosmovaloperxx,123denom\" ")
}
_, _, err := bech32.DecodeAndConvert(validator)
if err != nil {
return err
}
_, err = sdk.ParseCoinNormalized(coin)
if err != nil {
return err
}
case KeyForceICATransfer:
// expected "1234denom"
_, err := sdk.ParseCoinNormalized(update.Value)
if err != nil {
return err
}
case KeyForceICATransferRewards:
// expected "1234denom"
_, err := sdk.ParseCoinNormalized(update.Value)
if err != nil {
return err
}
default:
return fmt.Errorf("invalid or unexpected update key: %s", update.Key)
}
Expand Down

0 comments on commit dd87095

Please sign in to comment.