Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tendermint liquidity module codec #2

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v1
directories:
- proto
- third_party/proto
48 changes: 48 additions & 0 deletions client/codec/tendermint/liquidity/x/liquidity/types/codecs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

// RegisterLegacyAminoCodec registers concrete types on the codec.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgCreatePool{}, "liquidity/MsgCreatePool", nil)
cdc.RegisterConcrete(&MsgDepositWithinBatch{}, "liquidity/MsgDepositWithinBatch", nil)
cdc.RegisterConcrete(&MsgWithdrawWithinBatch{}, "liquidity/MsgWithdrawWithinBatch", nil)
cdc.RegisterConcrete(&MsgSwapWithinBatch{}, "liquidity/MsgSwapWithinBatch", nil)
}

// RegisterInterfaces registers the x/liquidity interface types with the
// interface registry
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgCreatePool{},
&MsgDepositWithinBatch{},
&MsgWithdrawWithinBatch{},
&MsgSwapWithinBatch{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

// legacy amino codecs
var (
amino = codec.NewLegacyAmino()

// ModuleCdc references the global x/liquidity module codec. Note, the
// codec should ONLY be used in certain instances of tests and for JSON
// encoding as Amino is still used for that purpose.
//
// The actual codec used for serialization should be provided to x/liquidity
// and defined at the application level.
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}
150 changes: 150 additions & 0 deletions client/codec/tendermint/liquidity/x/liquidity/types/msgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
_ sdk.Msg = (*MsgCreatePool)(nil)
_ sdk.Msg = (*MsgDepositWithinBatch)(nil)
_ sdk.Msg = (*MsgWithdrawWithinBatch)(nil)
_ sdk.Msg = (*MsgSwapWithinBatch)(nil)
)

// Message types for the liquidity module
const (
TypeMsgCreatePool = "create_pool"
TypeMsgDepositWithinBatch = "deposit_within_batch"
TypeMsgWithdrawWithinBatch = "withdraw_within_batch"
TypeMsgSwapWithinBatch = "swap_within_batch"
)

func (msg MsgCreatePool) Route() string { return "" }

func (msg MsgCreatePool) Type() string { return TypeMsgCreatePool }

func (msg MsgCreatePool) ValidateBasic() error {
return nil
}

func (msg MsgCreatePool) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgCreatePool) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.PoolCreatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr}
}

func (msg MsgCreatePool) GetPoolCreator() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.PoolCreatorAddress)
if err != nil {
panic(err)
}
return addr
}

// NewMsgDepositWithinBatch creates a new MsgDepositWithinBatch.
func NewMsgDepositWithinBatch(depositor sdk.AccAddress, poolID uint64, depositCoins sdk.Coins) *MsgDepositWithinBatch {
return &MsgDepositWithinBatch{
DepositorAddress: depositor.String(),
PoolId: poolID,
DepositCoins: depositCoins,
}
}

func (msg MsgDepositWithinBatch) Route() string { return "" }

func (msg MsgDepositWithinBatch) Type() string { return TypeMsgDepositWithinBatch }

func (msg MsgDepositWithinBatch) ValidateBasic() error {
return nil
}

func (msg MsgDepositWithinBatch) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgDepositWithinBatch) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.DepositorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr}
}

func (msg MsgDepositWithinBatch) GetDepositor() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.DepositorAddress)
if err != nil {
panic(err)
}
return addr
}

// NewMsgWithdrawWithinBatch creates a new MsgWithdrawWithinBatch.
func NewMsgWithdrawWithinBatch(withdrawer sdk.AccAddress, poolID uint64, poolCoin sdk.Coin) *MsgWithdrawWithinBatch {
return &MsgWithdrawWithinBatch{
WithdrawerAddress: withdrawer.String(),
PoolId: poolID,
PoolCoin: poolCoin,
}
}

func (msg MsgWithdrawWithinBatch) Route() string { return "" }

func (msg MsgWithdrawWithinBatch) Type() string { return TypeMsgWithdrawWithinBatch }

func (msg MsgWithdrawWithinBatch) ValidateBasic() error {
return nil
}

func (msg MsgWithdrawWithinBatch) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgWithdrawWithinBatch) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.WithdrawerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr}
}

func (msg MsgWithdrawWithinBatch) GetWithdrawer() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.WithdrawerAddress)
if err != nil {
panic(err)
}
return addr
}

func (msg MsgSwapWithinBatch) Route() string { return "" }

func (msg MsgSwapWithinBatch) Type() string { return TypeMsgSwapWithinBatch }

func (msg MsgSwapWithinBatch) ValidateBasic() error {
return nil
}

func (msg MsgSwapWithinBatch) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgSwapWithinBatch) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.SwapRequesterAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr}
}

func (msg MsgSwapWithinBatch) GetSwapRequester() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.SwapRequesterAddress)
if err != nil {
panic(err)
}
return addr
}
Loading