From a4acbbe8b771e6d0ad36040197558d7ff30179b2 Mon Sep 17 00:00:00 2001 From: Petr Ivanov Date: Mon, 19 Feb 2024 15:19:01 +0400 Subject: [PATCH] Implement legacy msg interface for liquid vesting (#297) * implement legacy msg interface * change msg namespace * chore: bump app version, add upgrade handler --------- Co-authored-by: Petr Ivanov Co-authored-by: Yuri Surbashev --- Makefile | 2 +- app/app.go | 7 +++++++ app/upgrades/v1.7.3/constants.go | 6 ++++++ app/upgrades/v1.7.3/upgrades.go | 20 ++++++++++++++++++++ x/liquidvesting/types/codec.go | 30 ++++++++++++++++++++++++++++++ x/liquidvesting/types/msg.go | 10 ++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 app/upgrades/v1.7.3/constants.go create mode 100644 app/upgrades/v1.7.3/upgrades.go diff --git a/Makefile b/Makefile index e4d4cb17..33d8ccc0 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-li DEFAULT_TAG=$(shell git rev-list --tags="v*" --max-count=1) # VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_TAG))) | sed 's/^v//') -VERSION := "1.7.2" +VERSION := "1.7.3" CBFTVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true diff --git a/app/app.go b/app/app.go index dd6ac300..6b2cecec 100644 --- a/app/app.go +++ b/app/app.go @@ -161,6 +161,7 @@ import ( v170 "github.com/haqq-network/haqq/app/upgrades/v1.7.0" v171 "github.com/haqq-network/haqq/app/upgrades/v1.7.1" v172 "github.com/haqq-network/haqq/app/upgrades/v1.7.2" + v173 "github.com/haqq-network/haqq/app/upgrades/v1.7.3" // NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens "github.com/haqq-network/haqq/x/ibc/transfer" @@ -1220,6 +1221,12 @@ func (app *Haqq) setupUpgradeHandlers() { v172.CreateUpgradeHandler(app.mm, app.configurator), ) + // v1.7.3 Fix Liquid Vesting Module + app.UpgradeKeeper.SetUpgradeHandler( + v173.UpgradeName, + v173.CreateUpgradeHandler(app.mm, app.configurator), + ) + // When a planned update height is reached, the old binary will panic // writing on disk the height and name of the update that triggered it // This will read that value, and execute the preparations for the upgrade. diff --git a/app/upgrades/v1.7.3/constants.go b/app/upgrades/v1.7.3/constants.go new file mode 100644 index 00000000..a39cd0e1 --- /dev/null +++ b/app/upgrades/v1.7.3/constants.go @@ -0,0 +1,6 @@ +package v173 + +const ( + // UpgradeName is the shared upgrade plan name for mainnet and testnet + UpgradeName = "v1.7.3" +) diff --git a/app/upgrades/v1.7.3/upgrades.go b/app/upgrades/v1.7.3/upgrades.go new file mode 100644 index 00000000..da98e0ec --- /dev/null +++ b/app/upgrades/v1.7.3/upgrades.go @@ -0,0 +1,20 @@ +package v173 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +// CreateUpgradeHandler creates an SDK upgrade handler for v1.7.3 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + logger := ctx.Logger() + logger.Info("run migration v1.7.3") + + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/x/liquidvesting/types/codec.go b/x/liquidvesting/types/codec.go index 5121b86c..e9b60b52 100644 --- a/x/liquidvesting/types/codec.go +++ b/x/liquidvesting/types/codec.go @@ -1,15 +1,45 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" ) +var ( + amino = codec.NewLegacyAmino() + // AminoCdc is a amino codec created to support amino JSON compatible msgs. + AminoCdc = codec.NewAminoCodec(amino) +) + +const ( + // Amino names + liquidate = "haqq/MsgLiquidate" + redeem = "haqq/MsgRedeem" +) + +// NOTE: This is required for the GetSignBytes function +func init() { + RegisterLegacyAminoCodec(amino) + amino.Seal() +} + +// RegisterInterfaces associates protoName with AccountI and VestingAccount +// Interfaces and creates a registry of it's concrete implementations func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgLiquidate{}, &MsgRedeem{}, ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } + +// RegisterLegacyAminoCodec registers the necessary x/erc20 interfaces and +// concrete types on the provided LegacyAmino codec. These types are used for +// Amino JSON serialization and EIP-712 compatibility. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgLiquidate{}, liquidate, nil) + cdc.RegisterConcrete(&MsgRedeem{}, redeem, nil) +} diff --git a/x/liquidvesting/types/msg.go b/x/liquidvesting/types/msg.go index 9a9eedc9..196b2d96 100644 --- a/x/liquidvesting/types/msg.go +++ b/x/liquidvesting/types/msg.go @@ -26,6 +26,11 @@ func (msg MsgLiquidate) Route() string { return RouterKey } // Type returns the action type func (msg MsgLiquidate) Type() string { return TypeMsgLiquidate } +// GetSignBytes encodes the message for signing +func (msg *MsgLiquidate) GetSignBytes() []byte { + return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg)) +} + // ValidateBasic runs stateless checks on the message func (msg MsgLiquidate) ValidateBasic() error { if !msg.Amount.Amount.IsPositive() { @@ -65,6 +70,11 @@ func (msg MsgRedeem) Route() string { return RouterKey } // Type returns the action type func (msg MsgRedeem) Type() string { return TypeMsgRedeem } +// GetSignBytes encodes the message for signing +func (msg *MsgRedeem) GetSignBytes() []byte { + return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg)) +} + // ValidateBasic runs stateless checks on the message func (msg MsgRedeem) ValidateBasic() error { if !msg.Amount.Amount.IsPositive() {