Skip to content

Commit

Permalink
Merge pull request #31 from InjectiveLabs/f/register-as-dmm
Browse files Browse the repository at this point in the history
Update with RegisterAsDMM message
  • Loading branch information
albertchon authored Apr 5, 2022
2 parents abb3094 + e13b3b6 commit 0636472
Show file tree
Hide file tree
Showing 8 changed files with 1,340 additions and 475 deletions.
3 changes: 2 additions & 1 deletion chain/exchange/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgIncreasePositionMargin{}, "exchange/MsgIncreasePositionMargin", nil)
cdc.RegisterConcrete(&MsgLiquidatePosition{}, "exchange/MsgLiquidatePosition", nil)
cdc.RegisterConcrete(&MsgBatchUpdateOrders{}, "exchange/MsgBatchUpdateOrders", nil)

cdc.RegisterConcrete(&MsgRegisterAsDMM{}, "exchange/MsgRegisterAsDMM", nil)
cdc.RegisterConcrete(&ExchangeEnableProposal{}, "exchange/ExchangeEnableProposal", nil)
cdc.RegisterConcrete(&BatchExchangeModificationProposal{}, "exchange/BatchExchangeModificationProposal", nil)
cdc.RegisterConcrete(&SpotMarketParamUpdateProposal{}, "exchange/SpotMarketParamUpdateProposal", nil)
Expand Down Expand Up @@ -69,6 +69,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgIncreasePositionMargin{},
&MsgLiquidatePosition{},
&MsgBatchUpdateOrders{},
&MsgRegisterAsDMM{},
)

registry.RegisterImplementations(
Expand Down
2 changes: 2 additions & 0 deletions chain/exchange/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ var (
ErrInvalidBatchMsgUpdate = sdkerrors.Register(ModuleName, 58, "Invalid batch msg update")
ErrExceedsTopOfBookPrice = sdkerrors.Register(ModuleName, 59, "Post-only order exceeds top of book price")
ErrInvalidOrderTypeForMessage = sdkerrors.Register(ModuleName, 60, "Order type not supported for given message")
ErrInvalidDMMSender = sdkerrors.Register(ModuleName, 61, "Sender must match dmm account")
ErrDMMAlreadyRegistered = sdkerrors.Register(ModuleName, 62, "DMM is already registered")
)
1 change: 1 addition & 0 deletions chain/exchange/types/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ func (p *PointsMultiplier) GetMultiplier(e ExecutionType) sdk.Dec {
if e.IsMaker() {
return p.MakerPointsMultiplier
}

return p.TakerPointsMultiplier
}
238 changes: 149 additions & 89 deletions chain/exchange/types/genesis.pb.go

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion chain/exchange/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ var (
FeeDiscountAccountTierPrefix = []byte{0x56} // prefix to each account's fee discount tier and TTL timestamp
FeeDiscountBucketAccountFeesPaidPrefix = []byte{0x57} // prefix to each account's fee paid amount for a given bucket
FeeDiscountAccountPastBucketTotalFeesPaidAmountPrefix = []byte{0x58} // prefix to each account's total past bucket fees paid amount FeeDiscountAccountIndicatorPrefix
FeeDiscountAccountOrderIndicatorPrefix = []byte{0x59} // prefix to each account's transient indicator if the account has placed an order that block
FeeDiscountAccountOrderIndicatorPrefix = []byte{0x59} // prefix to each account's transient indicator if the account has placed an order that block that is relevant for fee discounts

IsRegisteredDMMPrefix = []byte{0x60} // prefix to each account's is registered DMM address key
)

// GetFeeDiscountAccountFeesPaidInBucketKey provides the key for the account's fees paid in the given bucket
Expand Down Expand Up @@ -132,6 +134,16 @@ func GetFeeDiscountAccountTierKey(account sdk.AccAddress) []byte {
return buf
}

// GetIsRegisteredDMMKey provides the key for the registered DMM address
func GetIsRegisteredDMMKey(account sdk.AccAddress) []byte {
accountBz := account.Bytes()

buf := make([]byte, 0, len(IsRegisteredDMMPrefix)+len(accountBz))
buf = append(buf, IsRegisteredDMMPrefix...)
buf = append(buf, accountBz...)
return buf
}

// GetFeeDiscountMarketQualificationKey provides the key for the market fee discount qualification status
func GetFeeDiscountMarketQualificationKey(marketID common.Hash) []byte {
return append(FeeDiscountMarketQualificationPrefix, marketID.Bytes()...)
Expand Down
30 changes: 30 additions & 0 deletions chain/exchange/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"bytes"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -31,6 +32,7 @@ var (
_ sdk.Msg = &MsgInstantPerpetualMarketLaunch{}
_ sdk.Msg = &MsgInstantExpiryFuturesMarketLaunch{}
_ sdk.Msg = &MsgBatchUpdateOrders{}
_ sdk.Msg = &MsgRegisterAsDMM{}
)

func (o *SpotOrder) ValidateBasic(senderAddr sdk.AccAddress) error {
Expand Down Expand Up @@ -924,6 +926,34 @@ func (msg *MsgIncreasePositionMargin) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sender}
}

func (msg *MsgRegisterAsDMM) Route() string {
return RouterKey
}

func (msg *MsgRegisterAsDMM) Type() string {
return "registerAsDMM"
}

func (msg *MsgRegisterAsDMM) ValidateBasic() error {
if msg.Sender != msg.DmmAccount {
return sdkerrors.Wrap(ErrInvalidDMMSender, fmt.Sprintf("Sender: %s doesn't match dmm account: %s", msg.Sender, msg.DmmAccount))
}

return nil
}

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

func (msg *MsgRegisterAsDMM) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}

func (msg *MsgLiquidatePosition) Route() string {
return RouterKey
}
Expand Down
Loading

0 comments on commit 0636472

Please sign in to comment.