Skip to content

Commit

Permalink
Merge branch 'master' into milad/build-race-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
miladz68 authored Dec 19, 2024
2 parents 61b962b + 764cbf9 commit cd43a4d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 47 deletions.
49 changes: 22 additions & 27 deletions x/dex/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const (
GoodTilBlockHeightFlag = "good-til-block-height"
// GoodTilBlockTimeFlag is good til block time flag.
GoodTilBlockTimeFlag = "good-til-block-time"
// OrderTypeLimit is limit order type.
OrderTypeLimit = "limit"
// OrderTypeMarket is limit order market.
OrderTypeMarket = "market"
// TimeInForce is time-in-force flag.
TimeInForce = "time-in-force"
)
Expand Down Expand Up @@ -60,16 +56,19 @@ func GetTxCmd() *cobra.Command {
func CmdPlaceOrder() *cobra.Command {
availableTimeInForces := lo.Values(types.TimeInForce_name)
sort.Strings(availableTimeInForces)
availableOrderTypes := lo.Values(types.OrderType_name)
sort.Strings(availableTimeInForces)
availableSides := lo.Values(types.Side_name)
sort.Strings(availableTimeInForces)
cmd := &cobra.Command{
Use: "place-order [type (limit,market)] [id] [base_denom] [quote_denom] [quantity] [side] --price 123e-2 --time-in-force=" + strings.Join(availableTimeInForces, ",") + " --good-til-block-height=123 --good-til-block-time=1727124446 --from [sender]", //nolint:lll // string example
Use: "place-order [type (" + strings.Join(availableOrderTypes, ",") + ")] [id] [base_denom] [quote_denom] [quantity] [side (" + strings.Join(availableSides, ",") + ")] --price 123e-2 --time-in-force=" + strings.Join(availableTimeInForces, ",") + " --good-til-block-height=123 --good-til-block-time=1727124446 --from [sender]", //nolint:lll // string example
Args: cobra.ExactArgs(6),
Short: "Place new order",
Long: strings.TrimSpace(
fmt.Sprintf(`Place new order.
Example:
$ %s tx %s place-order id1 denom1 denom2 123e-2 10000 buy --from [sender]
`,
$ %s tx %s place-order ORDER_TYPE_LIMIT "my-order-id1" denom1 denom2 1000 SIDE_SELL --price 12e-1 --time-in-force=TIME_IN_FORCE_GTC --from [sender]`, //nolint:lll // string example
version.AppName, types.ModuleName,
),
),
Expand All @@ -81,25 +80,8 @@ $ %s tx %s place-order id1 denom1 denom2 123e-2 10000 buy --from [sender]

sender := clientCtx.GetFromAddress()

var orderType types.OrderType
timeInForceString, err := cmd.Flags().GetString(TimeInForce)
timeInForceInt, ok := types.TimeInForce_value[timeInForceString]
orderType, ok := types.OrderType_value[args[0]]
if !ok {
return errors.Errorf(
"unknown TimeInForce '%s',available TimeInForces: %s",
timeInForceString, strings.Join(availableTimeInForces, ","),
)
}
if err != nil {
return errors.WithStack(err)
}
timeInForce := types.TimeInForce(timeInForceInt)
switch args[0] {
case OrderTypeLimit:
orderType = types.ORDER_TYPE_LIMIT
case OrderTypeMarket:
orderType = types.ORDER_TYPE_MARKET
default:
return errors.Errorf("unknown type '%s'", args[0])
}

Expand All @@ -109,7 +91,7 @@ $ %s tx %s place-order id1 denom1 denom2 123e-2 10000 buy --from [sender]

quantity, ok := sdkmath.NewIntFromString(args[4])
if !ok {
return sdkerrors.Wrap(err, "invalid quantity")
return errors.New("invalid quantity")
}

side, ok := types.Side_value[args[5]]
Expand Down Expand Up @@ -144,9 +126,22 @@ $ %s tx %s place-order id1 denom1 denom2 123e-2 10000 buy --from [sender]
goodTilBlockTime = lo.ToPtr(time.Unix(goodTilBlockTimeNum, 0))
}

timeInForceString, err := cmd.Flags().GetString(TimeInForce)
timeInForceInt, ok := types.TimeInForce_value[timeInForceString]
if !ok {
return errors.Errorf(
"unknown TimeInForce '%s',available TimeInForces: %s",
timeInForceString, strings.Join(availableTimeInForces, ","),
)
}
if err != nil {
return errors.WithStack(err)
}
timeInForce := types.TimeInForce(timeInForceInt)

msg := &types.MsgPlaceOrder{
Sender: sender.String(),
Type: orderType,
Type: types.OrderType(orderType),
ID: id,
BaseDenom: baseDenom,
QuoteDenom: quoteDenom,
Expand Down
12 changes: 1 addition & 11 deletions x/dex/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,8 @@ func placeOrder(
testNetwork *network.Network,
order types.Order,
) {
var orderType string
switch order.Type {
case types.ORDER_TYPE_LIMIT:
orderType = cli.OrderTypeLimit
case types.ORDER_TYPE_MARKET:
orderType = cli.OrderTypeMarket
default:
requireT.Fail(fmt.Sprintf("unknown type '%s'", order.Type))
}

args := []string{
orderType,
order.Type.String(),
order.ID,
order.BaseDenom,
order.QuoteDenom,
Expand Down
18 changes: 9 additions & 9 deletions x/dex/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Users can place orders with the following attributes:
* `quote_denom` - when you buy, you are selling the `quote_denom`, when you sell, you are buying the `quote_denom`.
* `price` - value of one unit of the `base_denom` expressed in terms of the `quote_denom`. It indicates how much of the
`quote_denom` is needed to buy one unit of the `base_denom`.
* `quantity` - is amount of the base `base_denom` being traded.
* `quantity` - is amount of the `base_denom` being traded.
* `side`
* `sell` - means that the order is to sell `base_denom` `quantity` with the `price`.
* `buy` - means that the order is to buy `base_denom` `quantity` with the `price`.
Expand Down Expand Up @@ -158,7 +158,7 @@ Tick size example:

| unified_ref_amount(AAA) | unified_ref_amount(BBB) | price_tick(AAA/BBB) | price_tick(BBB/AAA) |
|-------------------------|-------------------------|---------------------|---------------------|
| 10000.0 | 10000.0 | 10^-5 | 10^-5 |
| 10000.0 | 10000.0 | 10^-8 | 10^-8 |
| 3000.0 | 20.0 | 10^-11 | 10^-6 |
| 3100000.0 | 8.0 | 10^-14 | 10^-3 |
| 0.00017 | 100.0 | 10^-3 | 10^-14 |
Expand Down Expand Up @@ -192,12 +192,12 @@ Examples:

### Balance locking/freezing/whitelisting/clawback.

When a user places an order we lock the coins in the assetft (similar to freezing), both assetft and native coins. Also,
we reserve the expected receiving amount if whitelisting for the token the user expects to receive is enabled.
At the time of the placement we enforce all assetft rules. If, at the time of matching, the assetft rules for the
maker orders are changed, the orders will be still executed with the amounts in the order book. That's why to avoid
unexpected behavior with the `freezing/whitelisting/clawback` the token admin should [cancel](#Order-cancellation) users
orders before update the rules.
When a user places an order we lock the coins in the assetft (similar to freezing). Also, we reserve the expected
receiving amount if whitelisting for the token the user expects to receive is enabled. At the time of the placement we
enforce all assetft rules. If, at the time of matching, the assetft rules for the maker orders are changed, the orders
will be still executed with the amounts in the order book. That's why to avoid unexpected behavior with the
`freezing/whitelisting/clawback` the token admin should [cancel](#Order-cancellation) user's orders before update the
rules.

### Time in force

Expand Down Expand Up @@ -233,7 +233,7 @@ The default reserve amount is `10 CORE` and can be updated by the governance.
### Max orders limit

The number of active orders a user can have for each denom is limited by a value called `max_orders_per_denom`,
which is determined by DEX governance.
which is determined by DEX governance. The default value is 100.

### Events

Expand Down

0 comments on commit cd43a4d

Please sign in to comment.