Skip to content

Commit

Permalink
Migrations for quicksilver
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed Jan 4, 2023
1 parent 2feeba7 commit 1f07652
Showing 1 changed file with 11 additions and 34 deletions.
45 changes: 11 additions & 34 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"

"github.com/cosmos/gaia/v8/app/keepers"
)
Expand Down Expand Up @@ -55,7 +54,6 @@ func FixBankMetadata(ctx sdk.Context, keepers *keepers.AppKeepers) error {
func QuicksilverFix(ctx sdk.Context, keepers *keepers.AppKeepers) error {
// Refund stuck coins from ica address
sourceAddress, err := sdk.AccAddressFromBech32("cosmos13dqvh4qtg4gzczuktgnw8gc2ewnwmhdwnctekxctyr4azz4dcyysecgq7e")

if err != nil {
return errors.New("invalid source address")
}
Expand All @@ -67,50 +65,29 @@ func QuicksilverFix(ctx sdk.Context, keepers *keepers.AppKeepers) error {
// Get balance from stuck address and subtract 1 uatom sent by bad actor
sourceBalance := keepers.BankKeeper.GetBalance(ctx, sourceAddress, "uatom")
refundBalance := sourceBalance.SubAmount(sdk.NewInt(1))
keepers.BankKeeper.SendCoins(ctx, sourceAddress, destinationAddress, sdk.NewCoins(refundBalance))

// Get connection to quicksilver chain
connectionId, err := getConnectionIdForChainId(ctx, keepers, "quicksilver-1")
err = keepers.BankKeeper.SendCoins(ctx, sourceAddress, destinationAddress, sdk.NewCoins(refundBalance))
if err != nil {
return err
return errors.New("unable to refund coins")
}

// Close channels
closeChannel(keepers, ctx, connectionId, "icacontroller-cosmoshub-4.deposit")
closeChannel(keepers, ctx, connectionId, "icacontroller-cosmoshub-4.withdrawal")
closeChannel(keepers, ctx, connectionId, "icacontroller-cosmoshub-4.performance")
closeChannel(keepers, ctx, connectionId, "icacontroller-cosmoshub-4.delegate")
closeChannel(keepers, ctx, "channel-462")
closeChannel(keepers, ctx, "channel-463")
closeChannel(keepers, ctx, "channel-464")
closeChannel(keepers, ctx, "channel-465")
closeChannel(keepers, ctx, "channel-466")

return nil
}

func closeChannel(keepers *keepers.AppKeepers, ctx sdk.Context, connectionId string, port string) {
activeChannelId, found := keepers.ICAHostKeeper.GetActiveChannelID(ctx, connectionId, port)
func closeChannel(keepers *keepers.AppKeepers, ctx sdk.Context, channelID string) {
channel, found := keepers.IBCKeeper.ChannelKeeper.GetChannel(ctx, icatypes.PortID, channelID)
if found {
channel, found := keepers.IBCKeeper.ChannelKeeper.GetChannel(ctx, icatypes.PortID, activeChannelId)
if found {
channel.State = ibcchanneltypes.CLOSED
keepers.IBCKeeper.ChannelKeeper.SetChannel(ctx, icatypes.PortID, activeChannelId, channel)
}
channel.State = ibcchanneltypes.CLOSED
keepers.IBCKeeper.ChannelKeeper.SetChannel(ctx, icatypes.PortID, channelID, channel)
}
}

func getConnectionIdForChainId(ctx sdk.Context, keepers *keepers.AppKeepers, chainId string) (string, error) {
connections := keepers.IBCKeeper.ConnectionKeeper.GetAllConnections(ctx)
for _, conn := range connections {
clientState, found := keepers.IBCKeeper.ClientKeeper.GetClientState(ctx, conn.ClientId)
if !found {
continue
}
client, ok := clientState.(*ibctmtypes.ClientState)
if ok && client.ChainId == chainId {
return conn.Id, nil
}
}

return "", errors.New("failed to get connection for the chain id")
}

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
Expand Down

0 comments on commit 1f07652

Please # to comment.