Skip to content

Commit 0636472

Browse files
authored
Merge pull request #31 from InjectiveLabs/f/register-as-dmm
Update with RegisterAsDMM message
2 parents abb3094 + e13b3b6 commit 0636472

File tree

8 files changed

+1340
-475
lines changed

8 files changed

+1340
-475
lines changed

chain/exchange/types/codec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
3232
cdc.RegisterConcrete(&MsgIncreasePositionMargin{}, "exchange/MsgIncreasePositionMargin", nil)
3333
cdc.RegisterConcrete(&MsgLiquidatePosition{}, "exchange/MsgLiquidatePosition", nil)
3434
cdc.RegisterConcrete(&MsgBatchUpdateOrders{}, "exchange/MsgBatchUpdateOrders", nil)
35-
35+
cdc.RegisterConcrete(&MsgRegisterAsDMM{}, "exchange/MsgRegisterAsDMM", nil)
3636
cdc.RegisterConcrete(&ExchangeEnableProposal{}, "exchange/ExchangeEnableProposal", nil)
3737
cdc.RegisterConcrete(&BatchExchangeModificationProposal{}, "exchange/BatchExchangeModificationProposal", nil)
3838
cdc.RegisterConcrete(&SpotMarketParamUpdateProposal{}, "exchange/SpotMarketParamUpdateProposal", nil)
@@ -69,6 +69,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
6969
&MsgIncreasePositionMargin{},
7070
&MsgLiquidatePosition{},
7171
&MsgBatchUpdateOrders{},
72+
&MsgRegisterAsDMM{},
7273
)
7374

7475
registry.RegisterImplementations(

chain/exchange/types/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ var (
6565
ErrInvalidBatchMsgUpdate = sdkerrors.Register(ModuleName, 58, "Invalid batch msg update")
6666
ErrExceedsTopOfBookPrice = sdkerrors.Register(ModuleName, 59, "Post-only order exceeds top of book price")
6767
ErrInvalidOrderTypeForMessage = sdkerrors.Register(ModuleName, 60, "Order type not supported for given message")
68+
ErrInvalidDMMSender = sdkerrors.Register(ModuleName, 61, "Sender must match dmm account")
69+
ErrDMMAlreadyRegistered = sdkerrors.Register(ModuleName, 62, "DMM is already registered")
6870
)

chain/exchange/types/exchange.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ func (p *PointsMultiplier) GetMultiplier(e ExecutionType) sdk.Dec {
6565
if e.IsMaker() {
6666
return p.MakerPointsMultiplier
6767
}
68+
6869
return p.TakerPointsMultiplier
6970
}

chain/exchange/types/genesis.pb.go

Lines changed: 149 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain/exchange/types/key.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ var (
7878
FeeDiscountAccountTierPrefix = []byte{0x56} // prefix to each account's fee discount tier and TTL timestamp
7979
FeeDiscountBucketAccountFeesPaidPrefix = []byte{0x57} // prefix to each account's fee paid amount for a given bucket
8080
FeeDiscountAccountPastBucketTotalFeesPaidAmountPrefix = []byte{0x58} // prefix to each account's total past bucket fees paid amount FeeDiscountAccountIndicatorPrefix
81-
FeeDiscountAccountOrderIndicatorPrefix = []byte{0x59} // prefix to each account's transient indicator if the account has placed an order that block
81+
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
82+
83+
IsRegisteredDMMPrefix = []byte{0x60} // prefix to each account's is registered DMM address key
8284
)
8385

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

137+
// GetIsRegisteredDMMKey provides the key for the registered DMM address
138+
func GetIsRegisteredDMMKey(account sdk.AccAddress) []byte {
139+
accountBz := account.Bytes()
140+
141+
buf := make([]byte, 0, len(IsRegisteredDMMPrefix)+len(accountBz))
142+
buf = append(buf, IsRegisteredDMMPrefix...)
143+
buf = append(buf, accountBz...)
144+
return buf
145+
}
146+
135147
// GetFeeDiscountMarketQualificationKey provides the key for the market fee discount qualification status
136148
func GetFeeDiscountMarketQualificationKey(marketID common.Hash) []byte {
137149
return append(FeeDiscountMarketQualificationPrefix, marketID.Bytes()...)

chain/exchange/types/msgs.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types
22

33
import (
44
"bytes"
5+
"fmt"
56

67
sdk "github.com/cosmos/cosmos-sdk/types"
78
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -31,6 +32,7 @@ var (
3132
_ sdk.Msg = &MsgInstantPerpetualMarketLaunch{}
3233
_ sdk.Msg = &MsgInstantExpiryFuturesMarketLaunch{}
3334
_ sdk.Msg = &MsgBatchUpdateOrders{}
35+
_ sdk.Msg = &MsgRegisterAsDMM{}
3436
)
3537

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

929+
func (msg *MsgRegisterAsDMM) Route() string {
930+
return RouterKey
931+
}
932+
933+
func (msg *MsgRegisterAsDMM) Type() string {
934+
return "registerAsDMM"
935+
}
936+
937+
func (msg *MsgRegisterAsDMM) ValidateBasic() error {
938+
if msg.Sender != msg.DmmAccount {
939+
return sdkerrors.Wrap(ErrInvalidDMMSender, fmt.Sprintf("Sender: %s doesn't match dmm account: %s", msg.Sender, msg.DmmAccount))
940+
}
941+
942+
return nil
943+
}
944+
945+
func (msg *MsgRegisterAsDMM) GetSignBytes() []byte {
946+
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
947+
}
948+
949+
func (msg *MsgRegisterAsDMM) GetSigners() []sdk.AccAddress {
950+
sender, err := sdk.AccAddressFromBech32(msg.Sender)
951+
if err != nil {
952+
panic(err)
953+
}
954+
return []sdk.AccAddress{sender}
955+
}
956+
927957
func (msg *MsgLiquidatePosition) Route() string {
928958
return RouterKey
929959
}

0 commit comments

Comments
 (0)