Skip to content

Commit a4acbbe

Browse files
ivanovpetrPetr IvanovYurist-85
authored
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 <[email protected]> Co-authored-by: Yuri Surbashev <[email protected]>
1 parent 8372d3d commit a4acbbe

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-li
66
DEFAULT_TAG=$(shell git rev-list --tags="v*" --max-count=1)
77
# VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_TAG))) | sed 's/^v//')
88

9-
VERSION := "1.7.2"
9+
VERSION := "1.7.3"
1010
CBFTVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
1111
COMMIT := $(shell git log -1 --format='%H')
1212
LEDGER_ENABLED ?= true

app/app.go

+7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ import (
161161
v170 "github.com/haqq-network/haqq/app/upgrades/v1.7.0"
162162
v171 "github.com/haqq-network/haqq/app/upgrades/v1.7.1"
163163
v172 "github.com/haqq-network/haqq/app/upgrades/v1.7.2"
164+
v173 "github.com/haqq-network/haqq/app/upgrades/v1.7.3"
164165

165166
// NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens
166167
"github.com/haqq-network/haqq/x/ibc/transfer"
@@ -1220,6 +1221,12 @@ func (app *Haqq) setupUpgradeHandlers() {
12201221
v172.CreateUpgradeHandler(app.mm, app.configurator),
12211222
)
12221223

1224+
// v1.7.3 Fix Liquid Vesting Module
1225+
app.UpgradeKeeper.SetUpgradeHandler(
1226+
v173.UpgradeName,
1227+
v173.CreateUpgradeHandler(app.mm, app.configurator),
1228+
)
1229+
12231230
// When a planned update height is reached, the old binary will panic
12241231
// writing on disk the height and name of the update that triggered it
12251232
// This will read that value, and execute the preparations for the upgrade.

app/upgrades/v1.7.3/constants.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package v173
2+
3+
const (
4+
// UpgradeName is the shared upgrade plan name for mainnet and testnet
5+
UpgradeName = "v1.7.3"
6+
)

app/upgrades/v1.7.3/upgrades.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package v173
2+
3+
import (
4+
sdk "github.com/cosmos/cosmos-sdk/types"
5+
"github.com/cosmos/cosmos-sdk/types/module"
6+
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
7+
)
8+
9+
// CreateUpgradeHandler creates an SDK upgrade handler for v1.7.3
10+
func CreateUpgradeHandler(
11+
mm *module.Manager,
12+
configurator module.Configurator,
13+
) upgradetypes.UpgradeHandler {
14+
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
15+
logger := ctx.Logger()
16+
logger.Info("run migration v1.7.3")
17+
18+
return mm.RunMigrations(ctx, configurator, vm)
19+
}
20+
}

x/liquidvesting/types/codec.go

+30
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
package types
22

33
import (
4+
"github.com/cosmos/cosmos-sdk/codec"
45
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
56
sdk "github.com/cosmos/cosmos-sdk/types"
67
"github.com/cosmos/cosmos-sdk/types/msgservice"
78
)
89

10+
var (
11+
amino = codec.NewLegacyAmino()
12+
// AminoCdc is a amino codec created to support amino JSON compatible msgs.
13+
AminoCdc = codec.NewAminoCodec(amino)
14+
)
15+
16+
const (
17+
// Amino names
18+
liquidate = "haqq/MsgLiquidate"
19+
redeem = "haqq/MsgRedeem"
20+
)
21+
22+
// NOTE: This is required for the GetSignBytes function
23+
func init() {
24+
RegisterLegacyAminoCodec(amino)
25+
amino.Seal()
26+
}
27+
28+
// RegisterInterfaces associates protoName with AccountI and VestingAccount
29+
// Interfaces and creates a registry of it's concrete implementations
930
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
1031
registry.RegisterImplementations((*sdk.Msg)(nil),
1132
&MsgLiquidate{},
1233
&MsgRedeem{},
1334
)
35+
1436
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
1537
}
38+
39+
// RegisterLegacyAminoCodec registers the necessary x/erc20 interfaces and
40+
// concrete types on the provided LegacyAmino codec. These types are used for
41+
// Amino JSON serialization and EIP-712 compatibility.
42+
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
43+
cdc.RegisterConcrete(&MsgLiquidate{}, liquidate, nil)
44+
cdc.RegisterConcrete(&MsgRedeem{}, redeem, nil)
45+
}

x/liquidvesting/types/msg.go

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func (msg MsgLiquidate) Route() string { return RouterKey }
2626
// Type returns the action type
2727
func (msg MsgLiquidate) Type() string { return TypeMsgLiquidate }
2828

29+
// GetSignBytes encodes the message for signing
30+
func (msg *MsgLiquidate) GetSignBytes() []byte {
31+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg))
32+
}
33+
2934
// ValidateBasic runs stateless checks on the message
3035
func (msg MsgLiquidate) ValidateBasic() error {
3136
if !msg.Amount.Amount.IsPositive() {
@@ -65,6 +70,11 @@ func (msg MsgRedeem) Route() string { return RouterKey }
6570
// Type returns the action type
6671
func (msg MsgRedeem) Type() string { return TypeMsgRedeem }
6772

73+
// GetSignBytes encodes the message for signing
74+
func (msg *MsgRedeem) GetSignBytes() []byte {
75+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg))
76+
}
77+
6878
// ValidateBasic runs stateless checks on the message
6979
func (msg MsgRedeem) ValidateBasic() error {
7080
if !msg.Amount.Amount.IsPositive() {

0 commit comments

Comments
 (0)