-
Notifications
You must be signed in to change notification settings - Fork 115
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
[TRA-512] Add MsgCreateMarketPermissionless msg #1991
Changes from 2 commits
8cdc632
de6bb39
ce02959
ac24a73
50d8a52
bf21e78
f985aab
4386562
e870e76
4944f91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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 {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a type alias for the empty interface. An empty interface is equivalent to - export interface MsgCreateMarketPermissionlessResponseSDKType {}
+ export type MsgCreateMarketPermissionlessResponseSDKType = {}; Committable suggestion
Suggested change
ToolsBiome
|
||||||
|
||||||
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>): 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>): MsgCreateMarketPermissionlessResponse { | ||||||
const message = createBaseMsgCreateMarketPermissionlessResponse(); | ||||||
return message; | ||||||
} | ||||||
|
||||||
shrenujb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why check num perpetuals instead of num markets? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason. Shouldn't really make a difference |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Implement the vault deposit logic. The TODO comment indicates that the vault deposit logic for PML is missing. Do you want me to generate the implementation code or open a GitHub issue to track this task? |
||
|
||
return &types.MsgCreateMarketPermissionlessResponse{}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a type alias for the empty interface.
An empty interface is equivalent to
{}
. Use a type alias instead.Committable suggestion
Tools
Biome