Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowman committed Aug 16, 2024
1 parent d75044d commit 806398f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
6 changes: 2 additions & 4 deletions x/interchainstaking/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func ExecuteQueuedUnbondings(k *Keeper, ctx sdk.Context, args []byte) error {
if err != nil {
return err
}
k.HandleQueuedUnbondings(ctx, params.Zone, int64(params.Epoch), params.Rate)
return nil
return k.HandleQueuedUnbondings(ctx, params.Zone, int64(params.Epoch), params.Rate)
}

func DistributeUnbondings(k *Keeper, ctx sdk.Context, args []byte) error {
Expand All @@ -120,6 +119,5 @@ func DistributeUnbondings(k *Keeper, ctx sdk.Context, args []byte) error {
if err != nil {
return err
}
k.PayoutUnbondings(ctx, params.Epoch, params.Zone)
return nil
return k.PayoutUnbondings(ctx, int64(params.Epoch), params.Zone)
}
27 changes: 0 additions & 27 deletions x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,33 +525,6 @@ func (k *Keeper) GCCompletedRedelegations(ctx sdk.Context) error {
return err
}

func (k *Keeper) HandleMaturedUnbondings(ctx sdk.Context, zone *types.Zone) error {
k.IterateZoneStatusWithdrawalRecords(ctx, zone.ChainId, types.WithdrawStatusUnbond, func(idx int64, withdrawal types.WithdrawalRecord) bool {
if ctx.BlockTime().After(withdrawal.CompletionTime) && withdrawal.Acknowledged { // completion date has passed.
k.Logger(ctx).Info("found completed unbonding")
sendMsg := &banktypes.MsgSend{FromAddress: zone.DelegationAddress.GetAddress(), ToAddress: withdrawal.Recipient, Amount: sdk.Coins{withdrawal.Amount[0]}}
err := k.SubmitTx(ctx, []sdk.Msg{sendMsg}, zone.DelegationAddress, types.TxUnbondSendMemo(withdrawal.Txhash), zone.MessagesPerTx)

if err != nil {
k.Logger(ctx).Error("error submitting transaction - requeue withdrawal", "error", err)

// do not update status and increment completion time
withdrawal.DelayCompletion(ctx, types.DefaultWithdrawalRequeueDelay)
err = k.SetWithdrawalRecord(ctx, withdrawal)
if err != nil {
k.Logger(ctx).Error("error updating withdrawal record", "error", err)
}

} else {
k.Logger(ctx).Info("sending funds", "for", withdrawal.Delegator, "delegate_account", zone.DelegationAddress.GetAddress(), "to", withdrawal.Recipient, "amount", withdrawal.Amount)
k.UpdateWithdrawalRecordStatus(ctx, &withdrawal, types.WithdrawStatusSend)
}
}
return false
})
return nil
}

func (k *Keeper) GetInflightUnbondingAmount(ctx sdk.Context, zone *types.Zone) sdk.Coin {
outCoin := sdk.NewCoin(zone.BaseDenom, sdk.ZeroInt())
k.IterateZoneWithdrawalRecords(ctx, zone.ChainId, func(idx int64, withdrawal types.WithdrawalRecord) bool {
Expand Down
38 changes: 38 additions & 0 deletions x/interchainstaking/keeper/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/quicksilver-zone/quicksilver/utils"
Expand Down Expand Up @@ -462,3 +463,40 @@ WITHDRAWAL:

return coinsOutPerValidator, txHashesPerValidator, distributionsPerWithdrawal, nil
}

func (k *Keeper) PayoutUnbondings(ctx sdk.Context, epoch int64, chainId string) error {

Check failure on line 467 in x/interchainstaking/keeper/redemptions.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: method parameter chainId should be chainID (stylecheck)
zone, ok := k.GetZone(ctx, chainId)
if !ok {
return fmt.Errorf("zone not found")
}
k.IterateZoneStatusWithdrawalRecords(ctx, chainId, types.WithdrawStatusUnbond, func(idx int64, withdrawal types.WithdrawalRecord) bool {
if ctx.BlockTime().After(withdrawal.CompletionTime) && withdrawal.Acknowledged { // completion date has passed.
k.Logger(ctx).Info("found completed unbonding")
sendMsg := &banktypes.MsgSend{FromAddress: zone.DelegationAddress.GetAddress(), ToAddress: withdrawal.Recipient, Amount: sdk.Coins{withdrawal.Amount[0]}}
err := k.SubmitTx(ctx, []sdk.Msg{sendMsg}, zone.DelegationAddress, types.TxUnbondSendMemo(withdrawal.Txhash), zone.MessagesPerTx)

if err != nil {
k.Logger(ctx).Error("error submitting transaction - requeue withdrawal", "error", err)

// do not update status and increment completion time
withdrawal.DelayCompletion(ctx, types.DefaultWithdrawalRequeueDelay)
err = k.SetWithdrawalRecord(ctx, withdrawal)
if err != nil {
k.Logger(ctx).Error("error updating withdrawal record", "error", err)
}

} else {
k.Logger(ctx).Info("sending funds", "for", withdrawal.Delegator, "delegate_account", zone.DelegationAddress.GetAddress(), "to", withdrawal.Recipient, "amount", withdrawal.Amount)
k.UpdateWithdrawalRecordStatus(ctx, &withdrawal, types.WithdrawStatusSend)
}
}
return false
})

return nil
}

func (k *Keeper) HandleMaturedUnbondings(ctx sdk.Context, zone *types.Zone) error {

return nil
}
2 changes: 1 addition & 1 deletion x/interchainstaking/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ type AuthzKeeper interface {

type EventManagerKeeper interface {
AddEvent(ctx sdk.Context, module, chainID, identifier, callback string, eventType, status int32, condtion emtypes.ConditionI, payload []byte)
AddEventWithExpiry(ctx sdk.Context, module, chainID, identifier, eventType, status int32, expiry time.Time)
AddEventWithExpiry(ctx sdk.Context, module, chainID, identifier string, eventType, status int32, expiry time.Time)
MarkCompleted(ctx sdk.Context, module string, chainID string, identifier string)
}

0 comments on commit 806398f

Please sign in to comment.