Skip to content

Commit

Permalink
Implement legacy msg interface for liquid vesting (#297)
Browse files Browse the repository at this point in the history
* implement legacy msg interface

* change msg namespace

* chore: bump app version, add upgrade handler

---------

Co-authored-by: Petr Ivanov <[email protected]>
Co-authored-by: Yuri Surbashev <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2024
1 parent 8372d3d commit a4acbbe
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v1.7.3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v173

const (
// UpgradeName is the shared upgrade plan name for mainnet and testnet
UpgradeName = "v1.7.3"
)
20 changes: 20 additions & 0 deletions app/upgrades/v1.7.3/upgrades.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
30 changes: 30 additions & 0 deletions x/liquidvesting/types/codec.go
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 10 additions & 0 deletions x/liquidvesting/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a4acbbe

Please sign in to comment.