Skip to content

Commit

Permalink
feat(tradeshield): add tradeshield commands (#889)
Browse files Browse the repository at this point in the history
* feat(tradeshield): add tradeshield commands

* refactor(tradeshield): rename CLIs and add new CLIs

* feat(tradeshield): add close order msg server logic

* feat(tradeshield): add cancel single order CLIs, add tests, marker order executed immediatly, improved UX for open CLIs

* fix trigger logic

* fix

* refactor

* fix tests

* perp fixes

* fix

* add migration

* add validations

* fix tests

* more validations

* more

* fix

* fix

---------

Co-authored-by: Amit Yadav <amy29981@gmail.com>
  • Loading branch information
cosmic-vagabond and amityadav0 authored Oct 31, 2024
1 parent 92a33a9 commit fc39f28
Show file tree
Hide file tree
Showing 59 changed files with 6,006 additions and 2,767 deletions.
1,319 changes: 847 additions & 472 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions proto/elys/perpetual/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ message MsgOpen {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
uint64 poolId = 8;
uint64 pool_id = 8;
}

message MsgBrokerOpen {
Expand All @@ -48,7 +48,7 @@ message MsgBrokerOpen {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
uint64 poolId = 9;
uint64 pool_id = 9;
}

message MsgOpenResponse {
Expand Down
6 changes: 3 additions & 3 deletions proto/elys/tradeshield/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ message QueryGetPendingPerpetualOrderRequest {
}

message QueryGetPendingPerpetualOrderResponse {
PerpetualOrder pending_perpetual_order = 1 [(gogoproto.nullable) = false];
PerpetualOrderExtraInfo pending_perpetual_order = 1 [(gogoproto.nullable) = false];
}

message QueryAllPendingPerpetualOrderRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllPendingPerpetualOrderResponse {
repeated PerpetualOrder pending_perpetual_order = 1 [(gogoproto.nullable) = false];
repeated PerpetualOrderExtraInfo pending_perpetual_order = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

Expand All @@ -101,7 +101,7 @@ message QueryPendingPerpetualOrderForAddressRequest {
}

message QueryPendingPerpetualOrderForAddressResponse {
repeated PerpetualOrder pending_perpetual_orders = 1 [(gogoproto.nullable) = false];
repeated PerpetualOrderExtraInfo pending_perpetual_orders = 1 [(gogoproto.nullable) = false];
}

message QueryPendingSpotOrderForAddressRequest {
Expand Down
130 changes: 75 additions & 55 deletions proto/elys/tradeshield/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,100 @@ option go_package = "github.com/elys-network/elys/x/tradeshield/types";

// Msg defines the Msg service.
service Msg {
rpc CreatePendingSpotOrder (MsgCreatePendingSpotOrder ) returns (MsgCreatePendingSpotOrderResponse );
rpc UpdatePendingSpotOrder (MsgUpdatePendingSpotOrder ) returns (MsgUpdatePendingSpotOrderResponse );
rpc CreatePendingPerpetualOrder (MsgCreatePendingPerpetualOrder) returns (MsgCreatePendingPerpetualOrderResponse);
rpc UpdatePendingPerpetualOrder (MsgUpdatePendingPerpetualOrder) returns (MsgUpdatePendingPerpetualOrderResponse);
rpc CancelPerpetualOrders (MsgCancelPerpetualOrders ) returns (MsgCancelPerpetualOrdersResponse );
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
rpc ExecuteOrders (MsgExecuteOrders ) returns (MsgExecuteOrdersResponse );
rpc CancelSpotOrders (MsgCancelSpotOrders ) returns (MsgCancelSpotOrdersResponse );
}
message MsgCreatePendingSpotOrder {
rpc CreateSpotOrder (MsgCreateSpotOrder ) returns (MsgCreateSpotOrderResponse );
rpc UpdateSpotOrder (MsgUpdateSpotOrder ) returns (MsgUpdateSpotOrderResponse );
rpc CancelSpotOrder (MsgCancelSpotOrder ) returns (MsgCancelSpotOrderResponse );
rpc CancelSpotOrders (MsgCancelSpotOrders ) returns (MsgCancelSpotOrdersResponse );
rpc CreatePerpetualOpenOrder (MsgCreatePerpetualOpenOrder ) returns (MsgCreatePerpetualOpenOrderResponse );
rpc CreatePerpetualCloseOrder (MsgCreatePerpetualCloseOrder) returns (MsgCreatePerpetualCloseOrderResponse);
rpc UpdatePerpetualOrder (MsgUpdatePerpetualOrder ) returns (MsgUpdatePerpetualOrderResponse );
rpc CancelPerpetualOrder (MsgCancelPerpetualOrder ) returns (MsgCancelPerpetualOrderResponse );
rpc CancelPerpetualOrders (MsgCancelPerpetualOrders ) returns (MsgCancelPerpetualOrdersResponse );
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
rpc ExecuteOrders (MsgExecuteOrders ) returns (MsgExecuteOrdersResponse );
}
message MsgCreateSpotOrder {
SpotOrderType order_type = 1;
OrderPrice order_price = 2;
cosmos.base.v1beta1.Coin order_amount = 3;
string owner_address = 4;
string order_target_denom = 5;
}

message MsgCreatePendingSpotOrderResponse {
message MsgCreateSpotOrderResponse {
uint64 order_id = 1;
}

message MsgUpdatePendingSpotOrder {
message MsgUpdateSpotOrder {
string owner_address = 1;
uint64 order_id = 2;
OrderPrice order_price = 3;
}

message MsgUpdateSpotOrderResponse {}

message MsgCancelSpotOrder {
string owner_address = 1;
uint64 order_id = 2;
OrderPrice order_price = 3;
}

message MsgUpdatePendingSpotOrderResponse {}

message MsgCreatePendingPerpetualOrder {
PerpetualOrderType order_type = 1;
OrderPrice trigger_price = 2;
cosmos.base.v1beta1.Coin collateral = 3 [(gogoproto.nullable) = false];
string owner_address = 4;
string trading_asset = 5;
PerpetualPosition position = 6;
string leverage = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string take_profit_price = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string stop_loss_price = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message MsgCreatePendingPerpetualOrderResponse {
}

message MsgCancelSpotOrderResponse {
uint64 order_id = 1;
}

message MsgCancelSpotOrders {
string creator = 1;
repeated uint64 spot_order_ids = 2;
}

message MsgCancelSpotOrdersResponse {}

message MsgCreatePerpetualOpenOrder {
TriggerPrice trigger_price = 1;
cosmos.base.v1beta1.Coin collateral = 2 [(gogoproto.nullable) = false ] ;
string owner_address = 3;
string trading_asset = 4;
PerpetualPosition position = 5;
string leverage = 6 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string take_profit_price = 7 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string stop_loss_price = 8 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
uint64 pool_id = 9;
}

message MsgCreatePerpetualOpenOrderResponse {
uint64 order_id = 1;
}

message MsgCreatePerpetualCloseOrder {
TriggerPrice trigger_price = 1;
string owner_address = 2;
uint64 position_id = 3;
}

message MsgCreatePerpetualCloseOrderResponse {
uint64 order_id = 1;
}

message MsgUpdatePendingPerpetualOrder {
message MsgUpdatePerpetualOrder {
string owner_address = 1;
uint64 order_id = 2;
TriggerPrice trigger_price = 3;
}

message MsgUpdatePerpetualOrderResponse {}

message MsgCancelPerpetualOrder {
string owner_address = 1;
uint64 order_id = 2;
OrderPrice order_price = 3;
}

message MsgUpdatePendingPerpetualOrderResponse {}
message MsgCancelPerpetualOrderResponse {
uint64 order_id = 1;
}

message MsgCancelPerpetualOrders {
string owner_address = 1;
repeated uint64 order_ids = 2;
string owner_address = 1;
repeated uint64 order_ids = 2;
}

message MsgCancelPerpetualOrdersResponse {}
Expand All @@ -92,18 +121,9 @@ message MsgUpdateParams {
message MsgUpdateParamsResponse {}

message MsgExecuteOrders {
string creator = 1;
repeated uint64 spot_order_ids = 2;
string creator = 1;
repeated uint64 spot_order_ids = 2;
repeated uint64 perpetual_order_ids = 3;
}

message MsgExecuteOrdersResponse {}

message MsgUpdateStopLossResponse {}

message MsgCancelSpotOrders {
string creator = 1;
repeated uint64 spot_order_ids = 2;
}

message MsgCancelSpotOrdersResponse {}
41 changes: 32 additions & 9 deletions proto/elys/tradeshield/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ message OrderPrice {
];
}

message TriggerPrice {
string trading_asset_denom = 1;
string rate = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message Date {
uint64 height = 1;
uint64 timestamp = 2;
Expand All @@ -51,11 +59,8 @@ message SpotOrder {
enum PerpetualOrderType {
LIMITOPEN = 0;
LIMITCLOSE = 1;

MARKETOPEN = 2;
MARKETCLOSE = 3;

STOPLOSSPERP = 4;
STOPLOSSPERP = 2;
}

enum PerpetualPosition {
Expand Down Expand Up @@ -86,14 +91,27 @@ message LegacyPerpetualOrder {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin position_size = 13 [(gogoproto.nullable) = false];
string liquidation_price = 14 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string funding_rate = 15 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string borrow_interest_rate = 16 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message PerpetualOrder {
uint64 order_id = 1;
string owner_address = 2;
PerpetualOrderType perpetual_order_type = 3;
PerpetualPosition position = 4;
OrderPrice trigger_price = 5;
TriggerPrice trigger_price = 5;
cosmos.base.v1beta1.Coin collateral = 6 [(gogoproto.nullable) = false];
string trading_asset = 7;
string leverage = 8 [
Expand All @@ -110,16 +128,21 @@ message PerpetualOrder {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin position_size = 13 [(gogoproto.nullable) = false];
string liquidation_price = 14 [
uint64 poolId = 13;
}

message PerpetualOrderExtraInfo {
PerpetualOrder perpetual_order = 1;
cosmos.base.v1beta1.Coin position_size = 2 [(gogoproto.nullable) = false];
string liquidation_price = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string funding_rate = 15 [
string funding_rate = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string borrow_interest_rate = 16 [
string borrow_interest_rate = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
Expand Down
2 changes: 1 addition & 1 deletion x/accountedpool/types/mocks/amm_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/accountedpool/types/mocks/bank_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/accountedpool/types/mocks/perpetual_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/amm/types/mocks/accounted_pool_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/amm/types/mocks/oracle_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/burner/types/mocks/bank_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/leveragelp/types/mocks/bank_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/perpetual/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
const (
FlagDiscount = "discount"
FlagTakeProfitPrice = "take-profit"
FlagStopLossPrice = "stop-loss"
)

// GetTxCmd returns the transaction commands for this module
Expand Down
Loading

0 comments on commit fc39f28

Please sign in to comment.