diff --git a/x/swaprouter/module/module.go b/x/swaprouter/module/module.go index 0d4c240277f..e6c7d93b245 100644 --- a/x/swaprouter/module/module.go +++ b/x/swaprouter/module/module.go @@ -33,6 +33,7 @@ type AppModuleBasic struct{} func (AppModuleBasic) Name() string { return types.ModuleName } func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) } func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { @@ -69,6 +70,7 @@ func (b AppModuleBasic) GetQueryCmd() *cobra.Command { // RegisterInterfaces registers interfaces and implementations of the gamm module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) } type AppModule struct { @@ -137,8 +139,6 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } // **** simulation implementation **** // GenerateGenesisState creates a randomized GenState of the swaprouter module. -// **** simulation implementation **** -// GenerateGenesisState creates a randomized GenState of the gamm module. func (am AppModule) SimulatorGenesisState(simState *module.SimulationState, s *simtypes.SimCtx) { swaprouterGen := types.DefaultGenesis() // change the pool creation fee denom from uosmo to stake @@ -148,7 +148,5 @@ func (am AppModule) SimulatorGenesisState(simState *module.SimulationState, s *s } func (am AppModule) Actions() []simtypes.Action { - // TODO: uncomment this once simulation is enabled. - // return swaproutersimulation.DefaultActions(am.k, am.gammKeeper) return nil } diff --git a/x/swaprouter/types/codec.go b/x/swaprouter/types/codec.go new file mode 100644 index 00000000000..7fc9fa6ab65 --- /dev/null +++ b/x/swaprouter/types/codec.go @@ -0,0 +1,40 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" +) + +// RegisterLegacyAminoCodec registers the necessary x/gamm interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgSwapExactAmountIn{}, "osmosis/swaprouter/swap-exact-amount-in", nil) + cdc.RegisterConcrete(&MsgSwapExactAmountOut{}, "osmosis/swaprouter/swap-exact-amount-out", nil) +} + +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgSwapExactAmountIn{}, + &MsgSwapExactAmountOut{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be + // used to properly serialize MsgGrant and MsgExec instances + sdk.RegisterLegacyAminoCodec(amino) + RegisterLegacyAminoCodec(authzcodec.Amino) + + amino.Seal() +} diff --git a/x/swaprouter/types/msgs.go b/x/swaprouter/types/msgs.go index ed85dd3d35c..c41a69c90e4 100644 --- a/x/swaprouter/types/msgs.go +++ b/x/swaprouter/types/msgs.go @@ -38,10 +38,8 @@ func (msg MsgSwapExactAmountIn) ValidateBasic() error { return nil } -// TODO: uncomment when types are registered. func (msg MsgSwapExactAmountIn) GetSignBytes() []byte { - // return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) - panic("not implemented") + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } func (msg MsgSwapExactAmountIn) GetSigners() []sdk.AccAddress { @@ -78,10 +76,8 @@ func (msg MsgSwapExactAmountOut) ValidateBasic() error { return nil } -// TODO: uncomment when types are registered. func (msg MsgSwapExactAmountOut) GetSignBytes() []byte { - // return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) - panic("not implemented") + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } func (msg MsgSwapExactAmountOut) GetSigners() []sdk.AccAddress { diff --git a/x/swaprouter/types/msgs_test.go b/x/swaprouter/types/msgs_test.go index bafa98cd88f..92f4ead2e4b 100644 --- a/x/swaprouter/types/msgs_test.go +++ b/x/swaprouter/types/msgs_test.go @@ -275,21 +275,17 @@ func TestMsgSwapExactAmountOut(t *testing.T) { // Test authz serialize and de-serializes for swaprouter msg. func TestAuthzMsg(t *testing.T) { - - // TODO: remove when types are registered. - t.SkipNow() - pk1 := ed25519.GenPrivKey().PubKey() addr1 := sdk.AccAddress(pk1.Address()).String() coin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1)) testCases := []struct { - name string - gammMsg sdk.Msg + name string + msg sdk.Msg }{ { - name: "MsgJoinSwapShareAmountOut", - gammMsg: &types.MsgSwapExactAmountIn{ + name: "MsgSwapExactAmountOut", + msg: &types.MsgSwapExactAmountIn{ Sender: addr1, Routes: []types.SwapAmountInRoute{{ PoolId: 0, @@ -304,7 +300,7 @@ func TestAuthzMsg(t *testing.T) { }, { name: "MsgSwapExactAmountOut", - gammMsg: &types.MsgSwapExactAmountOut{ + msg: &types.MsgSwapExactAmountOut{ Sender: addr1, Routes: []types.SwapAmountOutRoute{{ PoolId: 0, @@ -320,7 +316,7 @@ func TestAuthzMsg(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - apptesting.TestMessageAuthzSerialization(t, tc.gammMsg) + apptesting.TestMessageAuthzSerialization(t, tc.msg) }) } }