From 8cdc63264fe46ac8e2182589789465ace9381d91 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Tue, 30 Jul 2024 14:13:35 -0400 Subject: [PATCH 1/8] Add MsgCreateMarketPermissionless msg Signed-off-by: Shrenuj Bansal --- .../src/codegen/dydxprotocol/listing/tx.ts | 130 +++++ proto/dydxprotocol/listing/tx.proto | 24 + protocol/app/msgs/all_msgs.go | 6 +- protocol/app/msgs/internal_msgs.go | 6 +- protocol/app/msgs/internal_msgs_test.go | 2 + .../msg_create_market_permissionless.go | 40 ++ protocol/x/listing/types/errors.go | 6 + protocol/x/listing/types/expected_keepers.go | 1 + protocol/x/listing/types/tx.pb.go | 456 +++++++++++++++++- 9 files changed, 646 insertions(+), 25 deletions(-) create mode 100644 protocol/x/listing/keeper/msg_create_market_permissionless.go diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts index c1210fdd39..fda20a00b7 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts @@ -1,3 +1,4 @@ +import { SubaccountId, SubaccountIdSDKType } from "../subaccounts/subaccount"; import * as _m0 from "protobufjs/minimal"; import { DeepPartial } from "../../helpers"; /** @@ -28,6 +29,36 @@ export interface MsgSetMarketsHardCapResponse {} /** MsgSetMarketsHardCapResponse defines the MsgSetMarketsHardCap response */ export interface MsgSetMarketsHardCapResponseSDKType {} +/** MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov */ + +export interface MsgCreateMarketPermissionless { + /** The name of the `Perpetual` (e.g. `BTC-USD`). */ + ticker: string; + /** The subaccount to deposit from. */ + + subaccountId?: SubaccountId; + /** Number of quote quantums to deposit. */ + + quoteQuantums: Uint8Array; +} +/** MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov */ + +export interface MsgCreateMarketPermissionlessSDKType { + /** The name of the `Perpetual` (e.g. `BTC-USD`). */ + ticker: string; + /** The subaccount to deposit from. */ + + subaccount_id?: SubaccountIdSDKType; + /** Number of quote quantums to deposit. */ + + quote_quantums: Uint8Array; +} +/** MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response */ + +export interface MsgCreateMarketPermissionlessResponse {} +/** MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response */ + +export interface MsgCreateMarketPermissionlessResponseSDKType {} function createBaseMsgSetMarketsHardCap(): MsgSetMarketsHardCap { return { @@ -116,4 +147,103 @@ export const MsgSetMarketsHardCapResponse = { return message; } +}; + +function createBaseMsgCreateMarketPermissionless(): MsgCreateMarketPermissionless { + return { + ticker: "", + subaccountId: undefined, + quoteQuantums: new Uint8Array() + }; +} + +export const MsgCreateMarketPermissionless = { + encode(message: MsgCreateMarketPermissionless, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.ticker !== "") { + writer.uint32(10).string(message.ticker); + } + + if (message.subaccountId !== undefined) { + SubaccountId.encode(message.subaccountId, writer.uint32(18).fork()).ldelim(); + } + + if (message.quoteQuantums.length !== 0) { + writer.uint32(26).bytes(message.quoteQuantums); + } + + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgCreateMarketPermissionless { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgCreateMarketPermissionless(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + case 1: + message.ticker = reader.string(); + break; + + case 2: + message.subaccountId = SubaccountId.decode(reader, reader.uint32()); + break; + + case 3: + message.quoteQuantums = reader.bytes(); + break; + + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(object: DeepPartial): MsgCreateMarketPermissionless { + const message = createBaseMsgCreateMarketPermissionless(); + message.ticker = object.ticker ?? ""; + message.subaccountId = object.subaccountId !== undefined && object.subaccountId !== null ? SubaccountId.fromPartial(object.subaccountId) : undefined; + message.quoteQuantums = object.quoteQuantums ?? new Uint8Array(); + return message; + } + +}; + +function createBaseMsgCreateMarketPermissionlessResponse(): MsgCreateMarketPermissionlessResponse { + return {}; +} + +export const MsgCreateMarketPermissionlessResponse = { + encode(_: MsgCreateMarketPermissionlessResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgCreateMarketPermissionlessResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgCreateMarketPermissionlessResponse(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(_: DeepPartial): MsgCreateMarketPermissionlessResponse { + const message = createBaseMsgCreateMarketPermissionlessResponse(); + return message; + } + }; \ No newline at end of file diff --git a/proto/dydxprotocol/listing/tx.proto b/proto/dydxprotocol/listing/tx.proto index 7a853ab619..31e4a2548a 100644 --- a/proto/dydxprotocol/listing/tx.proto +++ b/proto/dydxprotocol/listing/tx.proto @@ -3,6 +3,9 @@ package dydxprotocol.listing; import "cosmos_proto/cosmos.proto"; import "cosmos/msg/v1/msg.proto"; +import "gogoproto/gogo.proto"; +import "dydxprotocol/subaccounts/subaccount.proto"; + option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/listing/types"; @@ -27,3 +30,24 @@ message MsgSetMarketsHardCap { // MsgSetMarketsHardCapResponse defines the MsgSetMarketsHardCap response message MsgSetMarketsHardCapResponse {} + +// MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov +message MsgCreateMarketPermissionless { + option (cosmos.msg.v1.signer) = "subaccount_id"; + + // The name of the `Perpetual` (e.g. `BTC-USD`). + string ticker = 1; + + // The subaccount to deposit from. + dydxprotocol.subaccounts.SubaccountId subaccount_id = 2; + + // Number of quote quantums to deposit. + bytes quote_quantums = 3 [ + (gogoproto.customtype) = + "github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt", + (gogoproto.nullable) = false + ]; +} + +// MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response +message MsgCreateMarketPermissionlessResponse {} diff --git a/protocol/app/msgs/all_msgs.go b/protocol/app/msgs/all_msgs.go index 14019a0896..5899cc2b2b 100644 --- a/protocol/app/msgs/all_msgs.go +++ b/protocol/app/msgs/all_msgs.go @@ -197,8 +197,10 @@ var ( "/dydxprotocol.govplus.MsgSlashValidatorResponse": {}, // listing - "/dydxprotocol.listing.MsgSetMarketsHardCap": {}, - "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": {}, + "/dydxprotocol.listing.MsgSetMarketsHardCap": {}, + "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": {}, + "/dydxprotocol.listing.MsgCreateMarketPermissionless": {}, + "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": {}, // perpetuals "/dydxprotocol.perpetuals.MsgAddPremiumVotes": {}, diff --git a/protocol/app/msgs/internal_msgs.go b/protocol/app/msgs/internal_msgs.go index a1a2889af0..74c6d44cef 100644 --- a/protocol/app/msgs/internal_msgs.go +++ b/protocol/app/msgs/internal_msgs.go @@ -144,8 +144,10 @@ var ( "/dydxprotocol.govplus.MsgSlashValidatorResponse": nil, // listing - "/dydxprotocol.listing.MsgSetMarketsHardCap": &listing.MsgSetMarketsHardCap{}, - "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": nil, + "/dydxprotocol.listing.MsgSetMarketsHardCap": &listing.MsgSetMarketsHardCap{}, + "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": nil, + "/dydxprotocol.listing.MsgCreateMarketPermissionless": &listing.MsgCreateMarketPermissionless{}, + "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": nil, // perpetuals "/dydxprotocol.perpetuals.MsgCreatePerpetual": &perpetuals.MsgCreatePerpetual{}, diff --git a/protocol/app/msgs/internal_msgs_test.go b/protocol/app/msgs/internal_msgs_test.go index da50b0e1c3..15fd9f62fb 100644 --- a/protocol/app/msgs/internal_msgs_test.go +++ b/protocol/app/msgs/internal_msgs_test.go @@ -104,6 +104,8 @@ func TestInternalMsgSamples_Gov_Key(t *testing.T) { // listing "/dydxprotocol.listing.MsgSetMarketsHardCap", "/dydxprotocol.listing.MsgSetMarketsHardCapResponse", + "/dydxprotocol.listing.MsgCreateMarketPermissionless", + "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse", // perpeutals "/dydxprotocol.perpetuals.MsgCreatePerpetual", diff --git a/protocol/x/listing/keeper/msg_create_market_permissionless.go b/protocol/x/listing/keeper/msg_create_market_permissionless.go new file mode 100644 index 0000000000..96d4d5a176 --- /dev/null +++ b/protocol/x/listing/keeper/msg_create_market_permissionless.go @@ -0,0 +1,40 @@ +package keeper + +import ( + "context" + + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" +) + +func (k msgServer) CreateMarketPermissionless( + goCtx context.Context, + msg *types.MsgCreateMarketPermissionless, +) (*types.MsgCreateMarketPermissionlessResponse, error) { + ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) + + // Check if the number of listed markets is above the hard cap + numPerpetuals := len(k.PerpetualsKeeper.GetAllPerpetuals(ctx)) + if uint32(numPerpetuals) > k.Keeper.GetMarketsHardCap(ctx) { + return nil, types.ErrMarketsHardCapReached + } + + marketId, err := k.Keeper.CreateMarket(ctx, msg.Ticker) + if err != nil { + return nil, err + } + + perpetualId, err := k.Keeper.CreatePerpetual(ctx, marketId, msg.Ticker) + if err != nil { + return nil, err + } + + _, err = k.Keeper.CreateClobPair(ctx, perpetualId) + if err != nil { + return nil, err + } + + // TODO: vault deposit for PML + + return &types.MsgCreateMarketPermissionlessResponse{}, nil +} diff --git a/protocol/x/listing/types/errors.go b/protocol/x/listing/types/errors.go index 4476f39da7..6ac9bd7237 100644 --- a/protocol/x/listing/types/errors.go +++ b/protocol/x/listing/types/errors.go @@ -9,4 +9,10 @@ var ( 1, "reference price is zero", ) + + ErrMarketsHardCapReached = errorsmod.Register( + ModuleName, + 2, + "listed markets hard cap reached", + ) ) diff --git a/protocol/x/listing/types/expected_keepers.go b/protocol/x/listing/types/expected_keepers.go index 1f694d1b17..14358d07b1 100644 --- a/protocol/x/listing/types/expected_keepers.go +++ b/protocol/x/listing/types/expected_keepers.go @@ -50,4 +50,5 @@ type PerpetualsKeeper interface { marketType perpetualtypes.PerpetualMarketType, ) (perpetualtypes.Perpetual, error) AcquireNextPerpetualID(ctx sdk.Context) uint32 + GetAllPerpetuals(ctx sdk.Context) (list []perpetualtypes.Perpetual) } diff --git a/protocol/x/listing/types/tx.pb.go b/protocol/x/listing/types/tx.pb.go index faf1455764..c26874be46 100644 --- a/protocol/x/listing/types/tx.pb.go +++ b/protocol/x/listing/types/tx.pb.go @@ -8,8 +8,11 @@ import ( fmt "fmt" _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" + github_com_dydxprotocol_v4_chain_protocol_dtypes "github.com/dydxprotocol/v4-chain/protocol/dtypes" + types "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -121,35 +124,142 @@ func (m *MsgSetMarketsHardCapResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetMarketsHardCapResponse proto.InternalMessageInfo +// MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov +type MsgCreateMarketPermissionless struct { + // The name of the `Perpetual` (e.g. `BTC-USD`). + Ticker string `protobuf:"bytes,1,opt,name=ticker,proto3" json:"ticker,omitempty"` + // The subaccount to deposit from. + SubaccountId *types.SubaccountId `protobuf:"bytes,2,opt,name=subaccount_id,json=subaccountId,proto3" json:"subaccount_id,omitempty"` + // Number of quote quantums to deposit. + QuoteQuantums github_com_dydxprotocol_v4_chain_protocol_dtypes.SerializableInt `protobuf:"bytes,3,opt,name=quote_quantums,json=quoteQuantums,proto3,customtype=github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt" json:"quote_quantums"` +} + +func (m *MsgCreateMarketPermissionless) Reset() { *m = MsgCreateMarketPermissionless{} } +func (m *MsgCreateMarketPermissionless) String() string { return proto.CompactTextString(m) } +func (*MsgCreateMarketPermissionless) ProtoMessage() {} +func (*MsgCreateMarketPermissionless) Descriptor() ([]byte, []int) { + return fileDescriptor_144a579c1e2dcb94, []int{2} +} +func (m *MsgCreateMarketPermissionless) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateMarketPermissionless) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateMarketPermissionless.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateMarketPermissionless) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateMarketPermissionless.Merge(m, src) +} +func (m *MsgCreateMarketPermissionless) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateMarketPermissionless) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateMarketPermissionless.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateMarketPermissionless proto.InternalMessageInfo + +func (m *MsgCreateMarketPermissionless) GetTicker() string { + if m != nil { + return m.Ticker + } + return "" +} + +func (m *MsgCreateMarketPermissionless) GetSubaccountId() *types.SubaccountId { + if m != nil { + return m.SubaccountId + } + return nil +} + +// MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response +type MsgCreateMarketPermissionlessResponse struct { +} + +func (m *MsgCreateMarketPermissionlessResponse) Reset() { *m = MsgCreateMarketPermissionlessResponse{} } +func (m *MsgCreateMarketPermissionlessResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateMarketPermissionlessResponse) ProtoMessage() {} +func (*MsgCreateMarketPermissionlessResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_144a579c1e2dcb94, []int{3} +} +func (m *MsgCreateMarketPermissionlessResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateMarketPermissionlessResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateMarketPermissionlessResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateMarketPermissionlessResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateMarketPermissionlessResponse.Merge(m, src) +} +func (m *MsgCreateMarketPermissionlessResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateMarketPermissionlessResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateMarketPermissionlessResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateMarketPermissionlessResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSetMarketsHardCap)(nil), "dydxprotocol.listing.MsgSetMarketsHardCap") proto.RegisterType((*MsgSetMarketsHardCapResponse)(nil), "dydxprotocol.listing.MsgSetMarketsHardCapResponse") + proto.RegisterType((*MsgCreateMarketPermissionless)(nil), "dydxprotocol.listing.MsgCreateMarketPermissionless") + proto.RegisterType((*MsgCreateMarketPermissionlessResponse)(nil), "dydxprotocol.listing.MsgCreateMarketPermissionlessResponse") } func init() { proto.RegisterFile("dydxprotocol/listing/tx.proto", fileDescriptor_144a579c1e2dcb94) } var fileDescriptor_144a579c1e2dcb94 = []byte{ - // 310 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4d, 0xa9, 0x4c, 0xa9, - 0x28, 0x28, 0xca, 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xaf, 0x38, 0xd5, 0xa8, 0x8a, 0x8b, 0xd9, 0xb7, - 0x38, 0x5d, 0xa8, 0x98, 0x4b, 0x10, 0xd3, 0xd1, 0x5a, 0x7a, 0xd8, 0x02, 0x46, 0x0f, 0x9b, 0x79, - 0x52, 0x46, 0xc4, 0xab, 0x85, 0xd9, 0xed, 0x14, 0x7c, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, - 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, - 0x72, 0x0c, 0x51, 0x96, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x28, - 0x71, 0x57, 0x66, 0xa2, 0x9b, 0x9c, 0x91, 0x98, 0x99, 0xa7, 0x0f, 0x17, 0xa9, 0x40, 0xc4, 0x67, - 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x58, 0xc6, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xea, 0x0c, - 0xfe, 0xfa, 0xf4, 0x01, 0x00, 0x00, + // 483 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x41, 0x6b, 0x13, 0x41, + 0x14, 0xce, 0xb6, 0x50, 0xe8, 0xd8, 0x14, 0xba, 0x2c, 0x1a, 0x83, 0xdd, 0x86, 0x80, 0x1a, 0x0b, + 0xdd, 0xc5, 0x28, 0x82, 0x3d, 0x69, 0x0a, 0xd2, 0x22, 0x01, 0xdd, 0xbd, 0x79, 0x59, 0x26, 0x3b, + 0xe3, 0xec, 0xd0, 0xdd, 0x99, 0xed, 0xbc, 0xd9, 0x92, 0xf4, 0xe8, 0xcd, 0x93, 0xfe, 0x14, 0x0f, + 0xfe, 0x88, 0x1e, 0x8b, 0x27, 0xf1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xb1, 0x6b, 0x5d, 0x8d, 0x5d, 0xeb, 0xf7, 0xd8, 0xb5, 0xbe, 0x4e, 0xdc, 0xda, 0xd5, + 0xc4, 0xad, 0xfd, 0x9c, 0xb8, 0xb5, 0x0f, 0x2f, 0x57, 0xd7, 0x68, 0x38, 0x7b, 0x45, 0x53, 0xb1, + 0x06, 0x1b, 0x25, 0xf2, 0xec, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x21, 0x72, 0xd2, 0x5a, 0x6a, + 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -292,6 +402,81 @@ func (m *MsgSetMarketsHardCapResponse) MarshalToSizedBuffer(dAtA []byte) (int, e return len(dAtA) - i, nil } +func (m *MsgCreateMarketPermissionless) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateMarketPermissionless) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateMarketPermissionless) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.QuoteQuantums.Size() + i -= size + if _, err := m.QuoteQuantums.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.SubaccountId != nil { + { + size, err := m.SubaccountId.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Ticker) > 0 { + i -= len(m.Ticker) + copy(dAtA[i:], m.Ticker) + i = encodeVarintTx(dAtA, i, uint64(len(m.Ticker))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateMarketPermissionlessResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateMarketPermissionlessResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateMarketPermissionlessResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -328,6 +513,34 @@ func (m *MsgSetMarketsHardCapResponse) Size() (n int) { return n } +func (m *MsgCreateMarketPermissionless) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Ticker) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.SubaccountId != nil { + l = m.SubaccountId.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = m.QuoteQuantums.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgCreateMarketPermissionlessResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -485,6 +698,207 @@ func (m *MsgSetMarketsHardCapResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgCreateMarketPermissionless) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateMarketPermissionless: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateMarketPermissionless: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ticker", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ticker = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountId", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.SubaccountId == nil { + m.SubaccountId = &types.SubaccountId{} + } + if err := m.SubaccountId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteQuantums", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.QuoteQuantums.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateMarketPermissionlessResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateMarketPermissionlessResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateMarketPermissionlessResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From de6bb39160015aa2139dfb447339973f4df8f9c4 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Tue, 30 Jul 2024 14:58:10 -0400 Subject: [PATCH 2/8] fix stuff Signed-off-by: Shrenuj Bansal --- proto/dydxprotocol/listing/tx.proto | 7 ++++--- protocol/app/msgs/internal_msgs.go | 6 ++---- protocol/app/msgs/internal_msgs_test.go | 2 -- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/proto/dydxprotocol/listing/tx.proto b/proto/dydxprotocol/listing/tx.proto index 31e4a2548a..5b9d0052a4 100644 --- a/proto/dydxprotocol/listing/tx.proto +++ b/proto/dydxprotocol/listing/tx.proto @@ -6,7 +6,6 @@ import "cosmos/msg/v1/msg.proto"; import "gogoproto/gogo.proto"; import "dydxprotocol/subaccounts/subaccount.proto"; - option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/listing/types"; // Msg defines the Msg service. @@ -31,7 +30,8 @@ message MsgSetMarketsHardCap { // MsgSetMarketsHardCapResponse defines the MsgSetMarketsHardCap response message MsgSetMarketsHardCapResponse {} -// MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov +// MsgCreateMarketPermissionless is a message used to create new markets without +// // going through x/gov message MsgCreateMarketPermissionless { option (cosmos.msg.v1.signer) = "subaccount_id"; @@ -49,5 +49,6 @@ message MsgCreateMarketPermissionless { ]; } -// MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response +// MsgCreateMarketPermissionlessResponse defines the +// MsgCreateMarketPermissionless response message MsgCreateMarketPermissionlessResponse {} diff --git a/protocol/app/msgs/internal_msgs.go b/protocol/app/msgs/internal_msgs.go index 74c6d44cef..a1a2889af0 100644 --- a/protocol/app/msgs/internal_msgs.go +++ b/protocol/app/msgs/internal_msgs.go @@ -144,10 +144,8 @@ var ( "/dydxprotocol.govplus.MsgSlashValidatorResponse": nil, // listing - "/dydxprotocol.listing.MsgSetMarketsHardCap": &listing.MsgSetMarketsHardCap{}, - "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": nil, - "/dydxprotocol.listing.MsgCreateMarketPermissionless": &listing.MsgCreateMarketPermissionless{}, - "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": nil, + "/dydxprotocol.listing.MsgSetMarketsHardCap": &listing.MsgSetMarketsHardCap{}, + "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": nil, // perpetuals "/dydxprotocol.perpetuals.MsgCreatePerpetual": &perpetuals.MsgCreatePerpetual{}, diff --git a/protocol/app/msgs/internal_msgs_test.go b/protocol/app/msgs/internal_msgs_test.go index 15fd9f62fb..da50b0e1c3 100644 --- a/protocol/app/msgs/internal_msgs_test.go +++ b/protocol/app/msgs/internal_msgs_test.go @@ -104,8 +104,6 @@ func TestInternalMsgSamples_Gov_Key(t *testing.T) { // listing "/dydxprotocol.listing.MsgSetMarketsHardCap", "/dydxprotocol.listing.MsgSetMarketsHardCapResponse", - "/dydxprotocol.listing.MsgCreateMarketPermissionless", - "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse", // perpeutals "/dydxprotocol.perpetuals.MsgCreatePerpetual", From ce029599e81538cd52e1c64c7407bb42d855be91 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Tue, 30 Jul 2024 16:06:50 -0400 Subject: [PATCH 3/8] indexer gen Signed-off-by: Shrenuj Bansal --- .../src/codegen/dydxprotocol/listing/tx.ts | 20 +++++++++++++++---- protocol/x/listing/types/tx.pb.go | 6 ++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts index fda20a00b7..f81df0f61a 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts @@ -29,7 +29,10 @@ export interface MsgSetMarketsHardCapResponse {} /** MsgSetMarketsHardCapResponse defines the MsgSetMarketsHardCap response */ export interface MsgSetMarketsHardCapResponseSDKType {} -/** MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov */ +/** + * MsgCreateMarketPermissionless is a message used to create new markets without + * // going through x/gov + */ export interface MsgCreateMarketPermissionless { /** The name of the `Perpetual` (e.g. `BTC-USD`). */ @@ -41,7 +44,10 @@ export interface MsgCreateMarketPermissionless { quoteQuantums: Uint8Array; } -/** MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov */ +/** + * MsgCreateMarketPermissionless is a message used to create new markets without + * // going through x/gov + */ export interface MsgCreateMarketPermissionlessSDKType { /** The name of the `Perpetual` (e.g. `BTC-USD`). */ @@ -53,10 +59,16 @@ export interface MsgCreateMarketPermissionlessSDKType { quote_quantums: Uint8Array; } -/** MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response */ +/** + * MsgCreateMarketPermissionlessResponse defines the + * MsgCreateMarketPermissionless response + */ export interface MsgCreateMarketPermissionlessResponse {} -/** MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response */ +/** + * MsgCreateMarketPermissionlessResponse defines the + * MsgCreateMarketPermissionless response + */ export interface MsgCreateMarketPermissionlessResponseSDKType {} diff --git a/protocol/x/listing/types/tx.pb.go b/protocol/x/listing/types/tx.pb.go index c26874be46..8304a6565e 100644 --- a/protocol/x/listing/types/tx.pb.go +++ b/protocol/x/listing/types/tx.pb.go @@ -124,7 +124,8 @@ func (m *MsgSetMarketsHardCapResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetMarketsHardCapResponse proto.InternalMessageInfo -// MsgCreateMarketPermissionless is a message used to create new markets without // going through x/gov +// MsgCreateMarketPermissionless is a message used to create new markets without +// // going through x/gov type MsgCreateMarketPermissionless struct { // The name of the `Perpetual` (e.g. `BTC-USD`). Ticker string `protobuf:"bytes,1,opt,name=ticker,proto3" json:"ticker,omitempty"` @@ -181,7 +182,8 @@ func (m *MsgCreateMarketPermissionless) GetSubaccountId() *types.SubaccountId { return nil } -// MsgCreateMarketPermissionlessResponse defines the MsgCreateMarketPermissionless response +// MsgCreateMarketPermissionlessResponse defines the +// MsgCreateMarketPermissionless response type MsgCreateMarketPermissionlessResponse struct { } From 50d8a520401f6427a8719bf2c18090bb5ba875a2 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Tue, 30 Jul 2024 16:50:51 -0400 Subject: [PATCH 4/8] add to normal_msgs Signed-off-by: Shrenuj Bansal --- protocol/app/msgs/normal_msgs.go | 5 +++++ protocol/app/msgs/normal_msgs_test.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/protocol/app/msgs/normal_msgs.go b/protocol/app/msgs/normal_msgs.go index c4d0ab5eeb..6f2385bc01 100644 --- a/protocol/app/msgs/normal_msgs.go +++ b/protocol/app/msgs/normal_msgs.go @@ -18,6 +18,7 @@ import ( ibccore "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" "github.com/dydxprotocol/v4-chain/protocol/lib" clob "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" + listing "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" sending "github.com/dydxprotocol/v4-chain/protocol/x/sending/types" vault "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" marketmapmoduletypes "github.com/skip-mev/slinky/x/marketmap/types" @@ -224,6 +225,10 @@ var ( "/dydxprotocol.clob.MsgPlaceOrder": &clob.MsgPlaceOrder{}, "/dydxprotocol.clob.MsgPlaceOrderResponse": nil, + // listing + "/dydxprotocol.listing.MsgCreateMarketPermissionless": &listing.MsgCreateMarketPermissionless{}, + "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": nil, + // perpetuals // prices diff --git a/protocol/app/msgs/normal_msgs_test.go b/protocol/app/msgs/normal_msgs_test.go index 963423c541..c13d49aaba 100644 --- a/protocol/app/msgs/normal_msgs_test.go +++ b/protocol/app/msgs/normal_msgs_test.go @@ -126,6 +126,10 @@ func TestNormalMsgs_Key(t *testing.T) { "/dydxprotocol.clob.MsgPlaceOrder", "/dydxprotocol.clob.MsgPlaceOrderResponse", + // listing + "/dydxprotocol.listing.MsgCreateMarketPermissionless", + "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse", + // perpetuals // prices From bf21e7835c7ddea9cabcaa2b8d050125baf0f590 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Tue, 30 Jul 2024 21:03:20 -0400 Subject: [PATCH 5/8] fix proto Signed-off-by: Shrenuj Bansal --- .../dydxprotocol/listing/tx.rpc.msg.ts | 12 +- proto/dydxprotocol/listing/tx.proto | 4 + protocol/app/module/interface_registry.go | 3 + protocol/x/listing/types/tx.pb.go | 103 ++++++++++++------ 4 files changed, 89 insertions(+), 33 deletions(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts index cf837601bb..1a2a52f3fa 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts @@ -1,11 +1,14 @@ import { Rpc } from "../../helpers"; import * as _m0 from "protobufjs/minimal"; -import { MsgSetMarketsHardCap, MsgSetMarketsHardCapResponse } from "./tx"; +import { MsgSetMarketsHardCap, MsgSetMarketsHardCapResponse, MsgCreateMarketPermissionless, MsgCreateMarketPermissionlessResponse } from "./tx"; /** Msg defines the Msg service. */ export interface Msg { /** SetMarketsHardCap sets a hard cap on the number of markets listed */ setMarketsHardCap(request: MsgSetMarketsHardCap): Promise; + /** CreateMarketPermissionless creates a new market without going through x/gov */ + + createMarketPermissionless(request: MsgCreateMarketPermissionless): Promise; } export class MsgClientImpl implements Msg { private readonly rpc: Rpc; @@ -13,6 +16,7 @@ export class MsgClientImpl implements Msg { constructor(rpc: Rpc) { this.rpc = rpc; this.setMarketsHardCap = this.setMarketsHardCap.bind(this); + this.createMarketPermissionless = this.createMarketPermissionless.bind(this); } setMarketsHardCap(request: MsgSetMarketsHardCap): Promise { @@ -21,4 +25,10 @@ export class MsgClientImpl implements Msg { return promise.then(data => MsgSetMarketsHardCapResponse.decode(new _m0.Reader(data))); } + createMarketPermissionless(request: MsgCreateMarketPermissionless): Promise { + const data = MsgCreateMarketPermissionless.encode(request).finish(); + const promise = this.rpc.request("dydxprotocol.listing.Msg", "CreateMarketPermissionless", data); + return promise.then(data => MsgCreateMarketPermissionlessResponse.decode(new _m0.Reader(data))); + } + } \ No newline at end of file diff --git a/proto/dydxprotocol/listing/tx.proto b/proto/dydxprotocol/listing/tx.proto index 5b9d0052a4..f625268e2e 100644 --- a/proto/dydxprotocol/listing/tx.proto +++ b/proto/dydxprotocol/listing/tx.proto @@ -13,6 +13,10 @@ service Msg { // SetMarketsHardCap sets a hard cap on the number of markets listed rpc SetMarketsHardCap(MsgSetMarketsHardCap) returns (MsgSetMarketsHardCapResponse); + + // CreateMarketPermissionless creates a new market without going through x/gov + rpc CreateMarketPermissionless(MsgCreateMarketPermissionless) + returns (MsgCreateMarketPermissionlessResponse); } // MsgSetMarketsHardCap is used to set a hard cap on the number of markets diff --git a/protocol/app/module/interface_registry.go b/protocol/app/module/interface_registry.go index 3246180a27..4bf55b8353 100644 --- a/protocol/app/module/interface_registry.go +++ b/protocol/app/module/interface_registry.go @@ -95,6 +95,9 @@ func NewInterfaceRegistry(addrPrefix string, valAddrPrefix string) (types.Interf "dydxprotocol.vault.MsgDepositToVault": getLegacyMsgSignerFn( []string{"subaccount_id", "owner"}, ), + "dydxprotocol.listing.MsgCreateMarketPermissionless": getLegacyMsgSignerFn( + []string{"subaccount_id", "owner"}, + ), // App injected messages have no signers. "dydxprotocol.bridge.MsgAcknowledgeBridges": noSigners, diff --git a/protocol/x/listing/types/tx.pb.go b/protocol/x/listing/types/tx.pb.go index 8304a6565e..2122f2fb5a 100644 --- a/protocol/x/listing/types/tx.pb.go +++ b/protocol/x/listing/types/tx.pb.go @@ -230,38 +230,39 @@ func init() { func init() { proto.RegisterFile("dydxprotocol/listing/tx.proto", fileDescriptor_144a579c1e2dcb94) } var fileDescriptor_144a579c1e2dcb94 = []byte{ - // 483 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x41, 0x6b, 0x13, 0x41, - 0x14, 0xce, 0xb6, 0x50, 0xe8, 0xd8, 0x14, 0xba, 0x2c, 0x1a, 0x83, 0xdd, 0x86, 0x80, 0x1a, 0x0b, - 0xdd, 0xc5, 0x28, 0x82, 0x3d, 0x69, 0x0a, 0xd2, 0x22, 0x01, 0xdd, 0xbd, 0x79, 0x59, 0x26, 0x3b, - 0xe3, 0xec, 0xd0, 0xdd, 0x99, 0xed, 0xbc, 0xd9, 0x92, 0xf4, 0xe8, 0xcd, 0x93, 0xfe, 0x14, 0x0f, - 0xfe, 0x88, 0x1e, 0x8b, 0x27, 0xf1, 0x50, 0x24, 0x39, 0xf8, 0x37, 0x24, 0x3b, 0xdb, 0x26, 0xc1, - 0x20, 0x39, 0xed, 0x7b, 0xef, 0x7b, 0xf3, 0xbd, 0x37, 0xdf, 0xb7, 0x83, 0x76, 0xc9, 0x88, 0x0c, - 0x73, 0x25, 0xb5, 0x8c, 0x65, 0xea, 0xa7, 0x1c, 0x34, 0x17, 0xcc, 0xd7, 0x43, 0xaf, 0xac, 0xd9, - 0xce, 0x3c, 0xec, 0x55, 0x70, 0xf3, 0x7e, 0x2c, 0x21, 0x93, 0x10, 0x95, 0x80, 0x6f, 0x12, 0x73, - 0xa0, 0x79, 0xcf, 0x64, 0x7e, 0x06, 0xcc, 0x3f, 0x7f, 0x3a, 0xfd, 0x54, 0x80, 0xc3, 0x24, 0x93, - 0xe6, 0xc0, 0x34, 0xaa, 0xaa, 0x4f, 0x16, 0xc6, 0x43, 0x31, 0xc0, 0x71, 0x2c, 0x0b, 0xa1, 0x61, - 0x2e, 0x36, 0xad, 0xed, 0x2f, 0x16, 0x72, 0xfa, 0xc0, 0x42, 0xaa, 0xfb, 0x58, 0x9d, 0x52, 0x0d, - 0xc7, 0x58, 0x91, 0x23, 0x9c, 0xdb, 0x2f, 0xd0, 0x26, 0x2e, 0x74, 0x22, 0x15, 0xd7, 0xa3, 0x86, - 0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x2f, 0xa4, 0x8a, 0xe3, 0x94, 0x5f, 0xe0, 0x41, 0x4a, 0x4f, - 0x84, 0x0e, 0xea, 0x25, 0xff, 0xfb, 0x8a, 0xfe, 0xd0, 0x9e, 0xea, 0xb4, 0x78, 0x81, 0xf6, 0x63, - 0xf4, 0xf0, 0xbf, 0x52, 0xdc, 0x88, 0xd6, 0xbd, 0x40, 0xeb, 0x7d, 0x60, 0x36, 0xa0, 0x9d, 0x7f, - 0x9d, 0xde, 0xf7, 0x96, 0xfd, 0x8e, 0xde, 0x32, 0x13, 0x9a, 0xdd, 0xd5, 0x7b, 0x6f, 0x66, 0xf7, - 0xc2, 0xcb, 0xb1, 0x6b, 0x5d, 0x8d, 0x5d, 0xeb, 0xf7, 0xd8, 0xb5, 0xbe, 0x4e, 0xdc, 0xda, 0xd5, - 0xc4, 0xad, 0xfd, 0x9c, 0xb8, 0xb5, 0x0f, 0x2f, 0x57, 0xd7, 0x68, 0x38, 0x7b, 0x45, 0x53, 0xb1, - 0x06, 0x1b, 0x25, 0xf2, 0xec, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x21, 0x72, 0xd2, 0x5a, 0x6a, - 0x03, 0x00, 0x00, + // 505 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x51, 0x6b, 0xd3, 0x50, + 0x14, 0x6e, 0x3a, 0x18, 0xec, 0xba, 0x0e, 0x16, 0x82, 0xd6, 0xe0, 0xb2, 0x52, 0x50, 0xeb, 0x60, + 0x09, 0x76, 0x22, 0x38, 0x5f, 0xb4, 0x03, 0xd9, 0x90, 0x82, 0x26, 0x6f, 0xbe, 0x84, 0xdb, 0xe4, + 0x7a, 0x73, 0x59, 0x92, 0x9b, 0xdd, 0x73, 0x33, 0x5a, 0x1f, 0x7d, 0x13, 0x41, 0xfd, 0x29, 0x3e, + 0xf8, 0x23, 0xf6, 0x38, 0x7c, 0x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0xfa, 0x17, 0x0d, 0x99, 0xd7, 0xd8, 0xb5, 0x77, 0x25, 0xe5, 0xd5, 0x43, 0xe6, + 0xf3, 0x1b, 0x0c, 0x4d, 0x04, 0x75, 0xbc, 0xb3, 0xa1, 0xa5, 0x9d, 0x0f, 0x2d, 0xed, 0xcf, 0xd0, + 0xd2, 0xbe, 0x8d, 0xac, 0xca, 0xf9, 0xc8, 0xaa, 0xfc, 0x1a, 0x59, 0x95, 0x77, 0xcf, 0x96, 0x77, + 0xad, 0x3f, 0xfd, 0xae, 0xc7, 0xf6, 0xf5, 0x56, 0x0b, 0x64, 0xef, 0x5f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x8a, 0xf1, 0x01, 0x5e, 0xfc, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -278,6 +279,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // SetMarketsHardCap sets a hard cap on the number of markets listed SetMarketsHardCap(ctx context.Context, in *MsgSetMarketsHardCap, opts ...grpc.CallOption) (*MsgSetMarketsHardCapResponse, error) + // CreateMarketPermissionless creates a new market without going through x/gov + CreateMarketPermissionless(ctx context.Context, in *MsgCreateMarketPermissionless, opts ...grpc.CallOption) (*MsgCreateMarketPermissionlessResponse, error) } type msgClient struct { @@ -297,10 +300,21 @@ func (c *msgClient) SetMarketsHardCap(ctx context.Context, in *MsgSetMarketsHard return out, nil } +func (c *msgClient) CreateMarketPermissionless(ctx context.Context, in *MsgCreateMarketPermissionless, opts ...grpc.CallOption) (*MsgCreateMarketPermissionlessResponse, error) { + out := new(MsgCreateMarketPermissionlessResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.listing.Msg/CreateMarketPermissionless", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // SetMarketsHardCap sets a hard cap on the number of markets listed SetMarketsHardCap(context.Context, *MsgSetMarketsHardCap) (*MsgSetMarketsHardCapResponse, error) + // CreateMarketPermissionless creates a new market without going through x/gov + CreateMarketPermissionless(context.Context, *MsgCreateMarketPermissionless) (*MsgCreateMarketPermissionlessResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -310,6 +324,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) SetMarketsHardCap(ctx context.Context, req *MsgSetMarketsHardCap) (*MsgSetMarketsHardCapResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetMarketsHardCap not implemented") } +func (*UnimplementedMsgServer) CreateMarketPermissionless(ctx context.Context, req *MsgCreateMarketPermissionless) (*MsgCreateMarketPermissionlessResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateMarketPermissionless not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -333,6 +350,24 @@ func _Msg_SetMarketsHardCap_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _Msg_CreateMarketPermissionless_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateMarketPermissionless) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateMarketPermissionless(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.listing.Msg/CreateMarketPermissionless", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateMarketPermissionless(ctx, req.(*MsgCreateMarketPermissionless)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.listing.Msg", HandlerType: (*MsgServer)(nil), @@ -341,6 +376,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SetMarketsHardCap", Handler: _Msg_SetMarketsHardCap_Handler, }, + { + MethodName: "CreateMarketPermissionless", + Handler: _Msg_CreateMarketPermissionless_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/listing/tx.proto", From f985aab0716d25827072d2fe3ad36c75df33d965 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Wed, 31 Jul 2024 11:44:31 -0400 Subject: [PATCH 6/8] wip --- .../msg_create_market_permissionless_test.go | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 protocol/x/listing/keeper/msg_create_market_permissionless_test.go diff --git a/protocol/x/listing/keeper/msg_create_market_permissionless_test.go b/protocol/x/listing/keeper/msg_create_market_permissionless_test.go new file mode 100644 index 0000000000..d9ea9333e7 --- /dev/null +++ b/protocol/x/listing/keeper/msg_create_market_permissionless_test.go @@ -0,0 +1,63 @@ +package keeper_test + +import ( + "github.com/dydxprotocol/v4-chain/protocol/dtypes" + testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" + "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" + subaccounttypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" + "github.com/stretchr/testify/require" + + "testing" +) + +func TestMsgCreateMarketPermissionless(t *testing.T) { + tests := map[string]struct { + ticker string + hardCap uint32 + + expectedErr error + }{ + "success": { + ticker: "TEST-USD", + hardCap: 300, + expectedErr: nil, + }, + "failure - hard cap set to 0": { + ticker: "TEST-USD", + hardCap: 0, + expectedErr: types.ErrMarketsHardCapReached, + }, + } + + for name, tc := range tests { + t.Run( + name, func(t *testing.T) { + tApp := testapp.NewTestAppBuilder(t).Build() + ctx := tApp.InitChain() + k := tApp.App.ListingKeeper + ms := keeper.NewMsgServerImpl(k) + + err := k.SetMarketsHardCap(ctx, tc.hardCap) + require.NoError(t, err) + + msg := types.MsgCreateMarketPermissionless{ + Ticker: tc.ticker, + SubaccountId: &subaccounttypes.SubaccountId{ + Owner: constants.AliceAccAddress.String(), + Number: 0, + }, + QuoteQuantums: dtypes.SerializableInt{}, + } + + _, err = ms.CreateMarketPermissionless(ctx, &msg) + if tc.expectedErr != nil { + require.ErrorContains(t, err, tc.expectedErr.Error()) + } else { + require.NoError(t, err) + } + }, + ) + } +} From e870e760bbbf0cd81a076493fe8ac7dcb8e824f5 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Wed, 31 Jul 2024 13:57:42 -0400 Subject: [PATCH 7/8] add/fix tests for MsgCreateMarketPermissionless Signed-off-by: Shrenuj Bansal --- protocol/testutil/constants/genesis.go | 20 ++++++++ .../msg_create_market_permissionless_test.go | 49 +++++++++++++++++-- protocol/x/listing/types/errors.go | 2 +- protocol/x/listing/types/expected_keepers.go | 5 ++ 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/protocol/testutil/constants/genesis.go b/protocol/testutil/constants/genesis.go index fd3231fa60..80cfe6194b 100644 --- a/protocol/testutil/constants/genesis.go +++ b/protocol/testutil/constants/genesis.go @@ -883,6 +883,26 @@ const GenesisState = `{ "initial_margin_ppm": 50000, "maintenance_fraction_ppm": 600000, "name": "Large-Cap" + }, + { + "id": 1, + "name": "Mid-Cap", + "initial_margin_ppm": 100000, + "maintenance_fraction_ppm": 500000, + "base_position_notional": 250000000000, + "impact_notional": 5000000000, + "open_interest_lower_cap": 20000000000000, + "open_interest_upper_cap": 50000000000000 + }, + { + "id": 2, + "name": "Long-Tail", + "initial_margin_ppm": 200000, + "maintenance_fraction_ppm": 500000, + "base_position_notional": 100000000000, + "impact_notional": 2500000000, + "open_interest_lower_cap": 5000000000000, + "open_interest_upper_cap": 10000000000000 } ], "params": { diff --git a/protocol/x/listing/keeper/msg_create_market_permissionless_test.go b/protocol/x/listing/keeper/msg_create_market_permissionless_test.go index d9ea9333e7..8a595d5e75 100644 --- a/protocol/x/listing/keeper/msg_create_market_permissionless_test.go +++ b/protocol/x/listing/keeper/msg_create_market_permissionless_test.go @@ -6,7 +6,11 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" + pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" subaccounttypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" + oracletypes "github.com/skip-mev/slinky/pkg/types" + marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types" + "github.com/skip-mev/slinky/x/marketmap/types/tickermetadata" "github.com/stretchr/testify/require" "testing" @@ -20,15 +24,25 @@ func TestMsgCreateMarketPermissionless(t *testing.T) { expectedErr error }{ "success": { - ticker: "TEST-USD", + ticker: "TEST2-USD", hardCap: 300, expectedErr: nil, }, - "failure - hard cap set to 0": { - ticker: "TEST-USD", + "failure - hard cap reached": { + ticker: "TEST2-USD", hardCap: 0, expectedErr: types.ErrMarketsHardCapReached, }, + "failure - ticker not found": { + ticker: "INVALID-USD", + hardCap: 300, + expectedErr: types.ErrMarketNotFound, + }, + "failure - market already listed": { + ticker: "BTC-USD", + hardCap: 300, + expectedErr: pricestypes.ErrMarketParamPairAlreadyExists, + }, } for name, tc := range tests { @@ -39,9 +53,38 @@ func TestMsgCreateMarketPermissionless(t *testing.T) { k := tApp.App.ListingKeeper ms := keeper.NewMsgServerImpl(k) + // Set hard cap err := k.SetMarketsHardCap(ctx, tc.hardCap) require.NoError(t, err) + // Add TEST2-USD market to market map + dydxMetadata, err := tickermetadata.MarshalDyDx( + tickermetadata.DyDx{ + ReferencePrice: 10000000, + Liquidity: 0, + AggregateIDs: nil, + }, + ) + + require.NoError(t, err) + market := marketmaptypes.Market{ + Ticker: marketmaptypes.Ticker{ + CurrencyPair: oracletypes.CurrencyPair{Base: "TEST2", Quote: "USD"}, + Decimals: 6, + MinProviderCount: 2, + Enabled: false, + Metadata_JSON: string(dydxMetadata), + }, + ProviderConfigs: []marketmaptypes.ProviderConfig{ + { + Name: "binance_ws", + OffChainTicker: "TEST2USDT", + }, + }, + } + err = k.MarketMapKeeper.CreateMarket(ctx, market) + require.NoError(t, err) + msg := types.MsgCreateMarketPermissionless{ Ticker: tc.ticker, SubaccountId: &subaccounttypes.SubaccountId{ diff --git a/protocol/x/listing/types/errors.go b/protocol/x/listing/types/errors.go index a1beac6dd9..005ed389d3 100644 --- a/protocol/x/listing/types/errors.go +++ b/protocol/x/listing/types/errors.go @@ -18,7 +18,7 @@ var ( ErrMarketsHardCapReached = errorsmod.Register( ModuleName, - 2, + 3, "listed markets hard cap reached", ) ) diff --git a/protocol/x/listing/types/expected_keepers.go b/protocol/x/listing/types/expected_keepers.go index 14358d07b1..2e071d7ed4 100644 --- a/protocol/x/listing/types/expected_keepers.go +++ b/protocol/x/listing/types/expected_keepers.go @@ -36,6 +36,11 @@ type MarketMapKeeper interface { ctx sdk.Context, ticker string, ) (marketmaptypes.Market, error) + // Only used for testing purposes + CreateMarket( + ctx sdk.Context, + market marketmaptypes.Market, + ) error } type PerpetualsKeeper interface { From 4944f91df47da782353f69fd5734174b3909be8b Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Wed, 31 Jul 2024 16:06:25 -0400 Subject: [PATCH 8/8] fix lint Signed-off-by: Shrenuj Bansal --- .../x/listing/keeper/msg_create_market_permissionless_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/x/listing/keeper/msg_create_market_permissionless_test.go b/protocol/x/listing/keeper/msg_create_market_permissionless_test.go index 8a595d5e75..61e7dda62d 100644 --- a/protocol/x/listing/keeper/msg_create_market_permissionless_test.go +++ b/protocol/x/listing/keeper/msg_create_market_permissionless_test.go @@ -7,7 +7,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" - subaccounttypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" + satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" oracletypes "github.com/skip-mev/slinky/pkg/types" marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types" "github.com/skip-mev/slinky/x/marketmap/types/tickermetadata" @@ -87,7 +87,7 @@ func TestMsgCreateMarketPermissionless(t *testing.T) { msg := types.MsgCreateMarketPermissionless{ Ticker: tc.ticker, - SubaccountId: &subaccounttypes.SubaccountId{ + SubaccountId: &satypes.SubaccountId{ Owner: constants.AliceAccAddress.String(), Number: 0, },