diff --git a/proto/dex/enums.proto b/proto/dex/enums.proto index cdaf133e70..77e6f9540b 100644 --- a/proto/dex/enums.proto +++ b/proto/dex/enums.proto @@ -16,6 +16,7 @@ enum PositionEffect { enum OrderType { LIMIT = 0; MARKET = 1; + LIQUIDATION = 2; } enum Denom { diff --git a/proto/dex/settlement.proto b/proto/dex/settlement.proto index 216eae958a..aae673779a 100644 --- a/proto/dex/settlement.proto +++ b/proto/dex/settlement.proto @@ -36,6 +36,7 @@ message SettlementEntry { (gogoproto.nullable) = false, (gogoproto.jsontag) = "leverage" ]; + string orderType = 10 [(gogoproto.jsontag) = "order_type"]; } message Settlements { diff --git a/x/dex/cache/cache.go b/x/dex/cache/cache.go index 48d186897e..3839da6b68 100644 --- a/x/dex/cache/cache.go +++ b/x/dex/cache/cache.go @@ -154,17 +154,16 @@ func NewOrders() *Orders { } type OrderPlacement struct { - Id uint64 - Price sdk.Dec - Quantity sdk.Dec - Creator string - OrderType types.OrderType - Direction types.PositionDirection - Effect types.PositionEffect - PriceDenom types.Denom - AssetDenom types.Denom - Leverage sdk.Dec - Liquidation bool + Id uint64 + Price sdk.Dec + Quantity sdk.Dec + Creator string + OrderType types.OrderType + Direction types.PositionDirection + Effect types.PositionEffect + PriceDenom types.Denom + AssetDenom types.Denom + Leverage sdk.Dec } type OrderPlacements struct { @@ -211,17 +210,16 @@ func FromLiquidationOrder(liquidationOrder types.LiquidationOrder, orderId uint6 panic(err) } return OrderPlacement{ - Id: orderId, - Price: types.ConvertDecToStandard(priceUnit, price), - Quantity: types.ConvertDecToStandard(assetUnit, liquidationOrder.Quantity), - Creator: liquidationOrder.Account, - OrderType: types.OrderType_MARKET, - Direction: direction, - Effect: types.PositionEffect_CLOSE, - PriceDenom: priceDenom, - AssetDenom: assetDenom, - Leverage: liquidationOrder.Leverage, - Liquidation: true, + Id: orderId, + Price: types.ConvertDecToStandard(priceUnit, price), + Quantity: types.ConvertDecToStandard(assetUnit, liquidationOrder.Quantity), + Creator: liquidationOrder.Account, + OrderType: types.OrderType_LIQUIDATION, + Direction: direction, + Effect: types.PositionEffect_CLOSE, + PriceDenom: priceDenom, + AssetDenom: assetDenom, + Leverage: liquidationOrder.Leverage, } } diff --git a/x/dex/exchange/limit_order_test.go b/x/dex/exchange/limit_order_test.go index f31eff7245..7c23bc121b 100644 --- a/x/dex/exchange/limit_order_test.go +++ b/x/dex/exchange/limit_order_test.go @@ -68,6 +68,7 @@ func TestMatchSingleOrder(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -77,6 +78,7 @@ func TestMatchSingleOrder(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) } @@ -290,6 +292,7 @@ func TestMatchSingleOrderFromShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -299,6 +302,7 @@ func TestMatchSingleOrderFromShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) } @@ -356,6 +360,7 @@ func TestMatchSingleOrderFromLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -365,6 +370,7 @@ func TestMatchSingleOrderFromLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) } @@ -443,6 +449,7 @@ func TestMatchSingleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(95), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -452,6 +459,7 @@ func TestMatchSingleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(95), ExpectedCostOrProceed: sdk.NewDec(90), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -461,6 +469,7 @@ func TestMatchSingleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -470,6 +479,7 @@ func TestMatchSingleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -479,6 +489,7 @@ func TestMatchSingleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -488,6 +499,7 @@ func TestMatchSingleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) } @@ -566,6 +578,7 @@ func TestMatchSingleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(105), ExpectedCostOrProceed: sdk.NewDec(110), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -575,6 +588,7 @@ func TestMatchSingleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(105), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -584,6 +598,7 @@ func TestMatchSingleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -593,6 +608,7 @@ func TestMatchSingleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -602,6 +618,7 @@ func TestMatchSingleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -611,6 +628,7 @@ func TestMatchSingleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) } @@ -718,6 +736,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(97), ExpectedCostOrProceed: sdk.NewDec(104), Account: "jkl", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -727,6 +746,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(97), ExpectedCostOrProceed: sdk.NewDec(90), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -736,6 +756,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(95), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -745,6 +766,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(95), ExpectedCostOrProceed: sdk.NewDec(90), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -754,6 +776,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -763,6 +786,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[6], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -772,6 +796,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[7], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -781,6 +806,7 @@ func TestMatchMultipleOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) } @@ -888,6 +914,7 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(103), ExpectedCostOrProceed: sdk.NewDec(110), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -897,6 +924,7 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(103), ExpectedCostOrProceed: sdk.NewDec(96), Account: "jkl", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -906,6 +934,7 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(105), ExpectedCostOrProceed: sdk.NewDec(110), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -915,6 +944,7 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(105), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -924,6 +954,7 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -933,6 +964,7 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[6], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -942,6 +974,7 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[7], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -951,5 +984,6 @@ func TestMatchMultipleOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) } diff --git a/x/dex/exchange/market_order.go b/x/dex/exchange/market_order.go index 5db98e9807..7682a2ceb8 100644 --- a/x/dex/exchange/market_order.go +++ b/x/dex/exchange/market_order.go @@ -44,7 +44,21 @@ func MatchMarketOrders( executed.Mul(existingOrder.GetPrice()), ) dirtyPrices.Add(existingOrder.GetPrice()) - takerSettlements, makerSettlements := Settle(marketOrder.FormattedCreatorWithSuffix(), executed, existingOrder, direction, marketOrder.WorstPrice) + + var orderType types.OrderType + if marketOrder.IsLiquidation { + orderType = types.OrderType_LIQUIDATION + } else { + orderType = types.OrderType_MARKET + } + takerSettlements, makerSettlements := Settle( + marketOrder.FormattedCreatorWithSuffix(), + executed, + existingOrder, + direction, + marketOrder.WorstPrice, + orderType, + ) *settlements = append(*settlements, makerSettlements...) // taker settlements' clearing price will need to be adjusted after all market order executions finish allTakerSettlements = append(allTakerSettlements, takerSettlements...) diff --git a/x/dex/exchange/market_order_test.go b/x/dex/exchange/market_order_test.go index d2fa8bbe38..bcea54fa6d 100644 --- a/x/dex/exchange/market_order_test.go +++ b/x/dex/exchange/market_order_test.go @@ -57,6 +57,7 @@ func TestMatchSingleMarketOrderFromShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -66,6 +67,7 @@ func TestMatchSingleMarketOrderFromShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) } @@ -114,6 +116,7 @@ func TestMatchSingleMarketOrderFromLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -123,6 +126,7 @@ func TestMatchSingleMarketOrderFromLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) } @@ -192,6 +196,7 @@ func TestMatchSingleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(90), ExpectedCostOrProceed: sdk.NewDec(90), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -201,6 +206,7 @@ func TestMatchSingleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -210,6 +216,7 @@ func TestMatchSingleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -219,6 +226,7 @@ func TestMatchSingleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(96), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -228,6 +236,7 @@ func TestMatchSingleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(96), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -237,6 +246,7 @@ func TestMatchSingleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(96), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) } @@ -306,6 +316,7 @@ func TestMatchSingleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(110), ExpectedCostOrProceed: sdk.NewDec(110), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -315,6 +326,7 @@ func TestMatchSingleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -324,6 +336,7 @@ func TestMatchSingleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -333,6 +346,7 @@ func TestMatchSingleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(104), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -342,6 +356,7 @@ func TestMatchSingleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(104), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -351,6 +366,7 @@ func TestMatchSingleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(104), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_MARKET, }) } @@ -432,6 +448,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(90), ExpectedCostOrProceed: sdk.NewDec(90), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -441,6 +458,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(90), ExpectedCostOrProceed: sdk.NewDec(90), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -450,6 +468,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "def", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -459,6 +478,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -468,6 +488,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("96.666666666666666667"), ExpectedCostOrProceed: sdk.NewDec(104), Account: "jkl", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -477,6 +498,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("96.666666666666666667"), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[6], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -486,6 +508,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("96.666666666666666667"), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[7], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -495,6 +518,7 @@ func TestMatchMultipleMarketOrderFromMultipleShortBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("96.666666666666666667"), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) } @@ -576,6 +600,7 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(110), ExpectedCostOrProceed: sdk.NewDec(110), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[1], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -585,6 +610,7 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(110), ExpectedCostOrProceed: sdk.NewDec(110), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[2], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -594,6 +620,7 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[3], types.Settlement{ Direction: types.PositionDirection_LONG, @@ -603,6 +630,7 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.NewDec(100), ExpectedCostOrProceed: sdk.NewDec(100), Account: "ghi", + OrderType: types.OrderType_LIMIT, }) assert.Equal(t, *settlements[4], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -612,6 +640,7 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("103.333333333333333333"), ExpectedCostOrProceed: sdk.NewDec(96), Account: "jkl", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[5], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -621,6 +650,7 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("103.333333333333333333"), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[6], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -630,6 +660,7 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("103.333333333333333333"), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) assert.Equal(t, *settlements[7], types.Settlement{ Direction: types.PositionDirection_SHORT, @@ -639,5 +670,6 @@ func TestMatchMultipleMarketOrderFromMultipleLongBook(t *testing.T) { ExecutionCostOrProceed: sdk.MustNewDecFromStr("103.333333333333333333"), ExpectedCostOrProceed: sdk.NewDec(100), Account: "abc", + OrderType: types.OrderType_MARKET, }) } diff --git a/x/dex/exchange/settlement.go b/x/dex/exchange/settlement.go index 9ae7c4772b..a02e115dec 100644 --- a/x/dex/exchange/settlement.go +++ b/x/dex/exchange/settlement.go @@ -16,7 +16,11 @@ func Settle( order types.OrderBook, takerDirection types.PositionDirection, worstPrice sdk.Dec, + takerOrderType types.OrderType, ) ([]*types.Settlement, []*types.Settlement) { + // settlement of one liquidity taker's order is allocated to all liquidity + // providers at the matched price level, propotional to the amount of liquidity + // provided by each LP. takerSettlements := []*types.Settlement{} makerSettlements := []*types.Settlement{} order.GetEntry().Quantity = order.GetEntry().Quantity.Sub(quantityTaken) @@ -46,6 +50,7 @@ func Settle( toSettle.amount, worstPrice, worstPrice, + takerOrderType, )) makerSettlements = append(makerSettlements, types.NewSettlement( toSettle.creator, @@ -55,6 +60,7 @@ func Settle( toSettle.amount, order.GetEntry().Price, order.GetEntry().Price, + types.OrderType_LIMIT, )) } return takerSettlements, makerSettlements @@ -65,6 +71,9 @@ func SettleFromBook( shortOrder types.OrderBook, executedQuantity sdk.Dec, ) []*types.Settlement { + // settlement from within the order book is also allocated to all liquidity + // providers at the matched price level on both sides, propotional to the + // amount of liquidity provided by each LP. settlements := []*types.Settlement{} longOrder.GetEntry().Quantity = longOrder.GetEntry().Quantity.Sub(executedQuantity) shortOrder.GetEntry().Quantity = shortOrder.GetEntry().Quantity.Sub(executedQuantity) @@ -119,6 +128,7 @@ func SettleFromBook( quantity, avgPrice, longOrder.GetPrice(), + types.OrderType_LIMIT, ), types.NewSettlement( shortToSettle.creator, types.PositionDirection_SHORT, @@ -127,6 +137,7 @@ func SettleFromBook( quantity, avgPrice, shortOrder.GetPrice(), + types.OrderType_LIMIT, )) newLongToSettle[longPtr] = ToSettle{creator: longToSettle.creator, amount: longToSettle.amount.Sub(quantity)} newShortToSettle[shortPtr] = ToSettle{creator: shortToSettle.creator, amount: shortToSettle.amount.Sub(quantity)} diff --git a/x/dex/keeper/end_block_place_orders.go b/x/dex/keeper/end_block_place_orders.go index 4785fea6e1..b32a3817b1 100644 --- a/x/dex/keeper/end_block_place_orders.go +++ b/x/dex/keeper/end_block_place_orders.go @@ -36,32 +36,47 @@ func (k *Keeper) HandleEBPlaceOrders(ctx context.Context, sdkCtx sdk.Context, tr orderPlacements.FilterOutIds(response.UnsuccessfulOrderIds) } for _, orderPlacement := range orderPlacements.Orders { - switch orderPlacement.OrderType { - case types.OrderType_LIMIT: - k.Orders[contractAddr][pairStr].AddLimitOrder(dexcache.LimitOrder{ - Creator: orderPlacement.Creator, - Price: orderPlacement.Price, - Quantity: orderPlacement.Quantity, - Direction: orderPlacement.Direction, - Effect: orderPlacement.Effect, - Leverage: orderPlacement.Leverage, - }) - case types.OrderType_MARKET: - k.Orders[contractAddr][pairStr].AddMarketOrder(dexcache.MarketOrder{ - Creator: orderPlacement.Creator, - WorstPrice: orderPlacement.Price, - Quantity: orderPlacement.Quantity, - Direction: orderPlacement.Direction, - Effect: orderPlacement.Effect, - Leverage: orderPlacement.Leverage, - }) - } + k.AddOrderFromOrderPlacement(contractAddr, pairStr, orderPlacement) } } } span.End() } +func (k *Keeper) AddOrderFromOrderPlacement(contractAddr string, pairStr string, orderPlacement dexcache.OrderPlacement) { + switch orderPlacement.OrderType { + case types.OrderType_LIMIT: + k.Orders[contractAddr][pairStr].AddLimitOrder(dexcache.LimitOrder{ + Creator: orderPlacement.Creator, + Price: orderPlacement.Price, + Quantity: orderPlacement.Quantity, + Direction: orderPlacement.Direction, + Effect: orderPlacement.Effect, + Leverage: orderPlacement.Leverage, + }) + case types.OrderType_MARKET: + k.Orders[contractAddr][pairStr].AddMarketOrder(dexcache.MarketOrder{ + Creator: orderPlacement.Creator, + WorstPrice: orderPlacement.Price, + Quantity: orderPlacement.Quantity, + Direction: orderPlacement.Direction, + Effect: orderPlacement.Effect, + Leverage: orderPlacement.Leverage, + IsLiquidation: false, + }) + case types.OrderType_LIQUIDATION: + k.Orders[contractAddr][pairStr].AddMarketOrder(dexcache.MarketOrder{ + Creator: orderPlacement.Creator, + WorstPrice: orderPlacement.Price, + Quantity: orderPlacement.Quantity, + Direction: orderPlacement.Direction, + Effect: orderPlacement.Effect, + Leverage: orderPlacement.Leverage, + IsLiquidation: true, + }) + } +} + func (k *Keeper) GetPlaceSudoMsg(contractAddr string, registeredPairs []types.Pair) []types.SudoOrderPlacementMsg { contractDepositInfo := []types.ContractDepositInfo{} for _, depositInfo := range k.DepositInfo[contractAddr].DepositInfoList { @@ -79,7 +94,7 @@ func (k *Keeper) GetPlaceSudoMsg(contractAddr string, registeredPairs []types.Pa for _, pair := range registeredPairs { if orderPlacements, ok := k.OrderPlacements[contractAddr][pair.String()]; ok { for _, orderPlacement := range orderPlacements.Orders { - if !orderPlacement.Liquidation { + if orderPlacement.OrderType != types.OrderType_LIQUIDATION { contractOrderPlacements = append(contractOrderPlacements, dexcache.ToContractOrderPlacement(orderPlacement)) if len(contractOrderPlacements) == MAX_ORDERS_PER_SUDO_CALL { msgs = append(msgs, types.SudoOrderPlacementMsg{ diff --git a/x/dex/keeper/end_block_place_orders_test.go b/x/dex/keeper/end_block_place_orders_test.go index 16036f9e80..ebf308aed8 100644 --- a/x/dex/keeper/end_block_place_orders_test.go +++ b/x/dex/keeper/end_block_place_orders_test.go @@ -33,3 +33,54 @@ func TestGetPlaceSudoMsg(t *testing.T) { msgs := keeper.GetPlaceSudoMsg(TEST_CONTRACT, []types.Pair{pair}) require.Equal(t, 2, len(msgs)) } + +func TestAddOrderFromOrderPlacement(t *testing.T) { + pair := types.Pair{PriceDenom: TEST_PRICE_DENOM, AssetDenom: TEST_ASSET_DENOM} + keeper, _ := keepertest.DexKeeper(t) + keeper.DepositInfo[TEST_CONTRACT] = dex.NewDepositInfo() + keeper.OrderPlacements[TEST_CONTRACT] = map[string]*dex.OrderPlacements{} + keeper.OrderPlacements[TEST_CONTRACT][pair.String()] = dex.NewOrderPlacements() + keeper.Orders[TEST_CONTRACT] = map[string]*dex.Orders{} + keeper.Orders[TEST_CONTRACT][pair.String()] = dex.NewOrders() + + limitOrderPlacement := dex.OrderPlacement{ + Id: 0, + Price: sdk.OneDec(), + Quantity: sdk.OneDec(), + PriceDenom: TEST_PRICE_DENOM, + AssetDenom: TEST_ASSET_DENOM, + OrderType: types.OrderType_LIMIT, + Direction: types.PositionDirection_LONG, + Effect: types.PositionEffect_OPEN, + Leverage: sdk.OneDec(), + } + marketOrderPlacement := dex.OrderPlacement{ + Id: 0, + Price: sdk.OneDec(), + Quantity: sdk.OneDec(), + PriceDenom: TEST_PRICE_DENOM, + AssetDenom: TEST_ASSET_DENOM, + OrderType: types.OrderType_MARKET, + Direction: types.PositionDirection_LONG, + Effect: types.PositionEffect_OPEN, + Leverage: sdk.OneDec(), + } + liquidationOrderPlacement := dex.OrderPlacement{ + Id: 0, + Price: sdk.OneDec(), + Quantity: sdk.OneDec(), + PriceDenom: TEST_PRICE_DENOM, + AssetDenom: TEST_ASSET_DENOM, + OrderType: types.OrderType_LIQUIDATION, + Direction: types.PositionDirection_LONG, + Effect: types.PositionEffect_OPEN, + Leverage: sdk.OneDec(), + } + + keeper.AddOrderFromOrderPlacement(TEST_CONTRACT, pair.String(), limitOrderPlacement) + keeper.AddOrderFromOrderPlacement(TEST_CONTRACT, pair.String(), marketOrderPlacement) + keeper.AddOrderFromOrderPlacement(TEST_CONTRACT, pair.String(), liquidationOrderPlacement) + + require.Equal(t, 1, len(keeper.Orders[TEST_CONTRACT][pair.String()].LimitBuys)) + require.Equal(t, 2, len(keeper.Orders[TEST_CONTRACT][pair.String()].MarketBuys)) +} diff --git a/x/dex/keeper/msg_server_place_orders.go b/x/dex/keeper/msg_server_place_orders.go index 81040e2a83..4cca68fa0d 100644 --- a/x/dex/keeper/msg_server_place_orders.go +++ b/x/dex/keeper/msg_server_place_orders.go @@ -69,17 +69,16 @@ func (k msgServer) PlaceOrders(goCtx context.Context, msg *types.MsgPlaceOrders) (*pairToOrderPlacements[pair.String()]).Orders = append( (*pairToOrderPlacements[pair.String()]).Orders, dexcache.OrderPlacement{ - Id: nextId, - Price: orderPlacement.Price, - Quantity: orderPlacement.Quantity, - Creator: msg.Creator, - PriceDenom: orderPlacement.PriceDenom, - AssetDenom: orderPlacement.AssetDenom, - OrderType: orderPlacement.OrderType, - Direction: orderPlacement.PositionDirection, - Effect: orderPlacement.PositionEffect, - Leverage: orderPlacement.Leverage, - Liquidation: false, + Id: nextId, + Price: orderPlacement.Price, + Quantity: orderPlacement.Quantity, + Creator: msg.Creator, + PriceDenom: orderPlacement.PriceDenom, + AssetDenom: orderPlacement.AssetDenom, + OrderType: orderPlacement.OrderType, + Direction: orderPlacement.PositionDirection, + Effect: orderPlacement.PositionEffect, + Leverage: orderPlacement.Leverage, }, ) idsInResp = append(idsInResp, nextId) diff --git a/x/dex/types/enums.go b/x/dex/types/enums.go index 0bb021af2d..bffdc4e612 100644 --- a/x/dex/types/enums.go +++ b/x/dex/types/enums.go @@ -46,7 +46,7 @@ func getEnumFromStr(str string, enumMap map[string]int32) (int32, error) { } func GetContractDenomName(denom Denom) string { - return strings.ToLower(Denom_name[int32(denom)]) + return strings.ToUpper(Denom_name[int32(denom)]) } func GetContractPositionDirection(direction PositionDirection) string { diff --git a/x/dex/types/enums.pb.go b/x/dex/types/enums.pb.go index dbe3349319..15f29a90b7 100644 --- a/x/dex/types/enums.pb.go +++ b/x/dex/types/enums.pb.go @@ -73,18 +73,21 @@ func (PositionEffect) EnumDescriptor() ([]byte, []int) { type OrderType int32 const ( - OrderType_LIMIT OrderType = 0 - OrderType_MARKET OrderType = 1 + OrderType_LIMIT OrderType = 0 + OrderType_MARKET OrderType = 1 + OrderType_LIQUIDATION OrderType = 2 ) var OrderType_name = map[int32]string{ 0: "LIMIT", 1: "MARKET", + 2: "LIQUIDATION", } var OrderType_value = map[string]int32{ - "LIMIT": 0, - "MARKET": 1, + "LIMIT": 0, + "MARKET": 1, + "LIQUIDATION": 2, } func (x OrderType) String() string { @@ -183,26 +186,27 @@ func init() { func init() { proto.RegisterFile("dex/enums.proto", fileDescriptor_b8c5bb23c6eb0b88) } var fileDescriptor_b8c5bb23c6eb0b88 = []byte{ - // 331 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x90, 0xcd, 0x6a, 0xe3, 0x30, - 0x14, 0x85, 0xad, 0xfc, 0x47, 0x0c, 0x33, 0x77, 0xbc, 0x9a, 0x95, 0x17, 0x03, 0x85, 0x62, 0x88, - 0xbd, 0x68, 0x5f, 0x40, 0xb1, 0x45, 0x62, 0x6a, 0x5b, 0xc1, 0x56, 0x4a, 0x29, 0x74, 0xd1, 0x38, - 0x4a, 0x23, 0x68, 0xac, 0x60, 0x3b, 0x90, 0xbc, 0x45, 0x1f, 0xab, 0xcb, 0x2c, 0xbb, 0x2c, 0xc9, - 0x8b, 0x14, 0x29, 0x64, 0xf7, 0xe9, 0xea, 0xbb, 0x97, 0xc3, 0xc1, 0x7f, 0x96, 0x62, 0xef, 0x8b, - 0x72, 0xb7, 0xa9, 0xbd, 0x6d, 0xa5, 0x1a, 0x65, 0xff, 0xab, 0x85, 0x34, 0x54, 0xa8, 0x77, 0xaf, - 0x16, 0xb2, 0x58, 0xbf, 0xca, 0xd2, 0x5b, 0x8a, 0xbd, 0x7b, 0x8b, 0xff, 0xce, 0x54, 0x2d, 0x1b, - 0xa9, 0xca, 0x50, 0x56, 0xa2, 0xd0, 0x60, 0x0f, 0x70, 0x27, 0x66, 0xe9, 0x04, 0x2c, 0x7b, 0x88, - 0xbb, 0xf9, 0x94, 0x65, 0x1c, 0x90, 0x7b, 0x83, 0x7f, 0x5f, 0x4d, 0xba, 0x5a, 0x89, 0xa2, 0xd1, - 0x1a, 0x9b, 0xd1, 0xf4, 0xa2, 0x05, 0x31, 0xcb, 0x29, 0x20, 0xf7, 0x3f, 0x1e, 0xb2, 0x6a, 0x29, - 0x2a, 0x7e, 0xd8, 0x0a, 0x3d, 0x8f, 0xa3, 0x24, 0xe2, 0x60, 0xd9, 0x18, 0xf7, 0x12, 0x92, 0x3d, - 0x50, 0x7d, 0xea, 0x05, 0x77, 0x43, 0x51, 0xaa, 0x8d, 0xdd, 0xc7, 0xed, 0x9c, 0x46, 0x60, 0xe9, - 0x53, 0x84, 0xb3, 0x04, 0x90, 0x1e, 0x8d, 0x79, 0x00, 0x2d, 0x0d, 0x94, 0x4f, 0xa1, 0x6d, 0x24, - 0x16, 0x43, 0xc7, 0x48, 0x8f, 0xe4, 0x09, 0xba, 0x9a, 0xe6, 0x79, 0x18, 0x40, 0x4f, 0x53, 0x4a, - 0x49, 0x06, 0x7d, 0x93, 0x26, 0x4f, 0x18, 0x0c, 0xdc, 0x7b, 0xdc, 0x99, 0x97, 0xb2, 0xb1, 0x7f, - 0xe1, 0x41, 0xce, 0x49, 0x1a, 0x92, 0x2c, 0xbc, 0x64, 0x4c, 0xa2, 0x38, 0x8e, 0x00, 0x5d, 0x30, - 0xc8, 0x18, 0xb4, 0xcc, 0x3e, 0x49, 0x19, 0xb4, 0xc7, 0x93, 0xcf, 0x93, 0x83, 0x8e, 0x27, 0x07, - 0x7d, 0x9f, 0x1c, 0xf4, 0x71, 0x76, 0xac, 0xe3, 0xd9, 0xb1, 0xbe, 0xce, 0x8e, 0xf5, 0x3c, 0x7a, - 0x93, 0xcd, 0x7a, 0xb7, 0xf0, 0x0a, 0xb5, 0xf1, 0x6b, 0x21, 0x47, 0xd7, 0x26, 0xcd, 0xc3, 0x54, - 0xe9, 0xef, 0x7d, 0x5d, 0x79, 0x73, 0xd8, 0x8a, 0x7a, 0xd1, 0x33, 0xff, 0x77, 0x3f, 0x01, 0x00, - 0x00, 0xff, 0xff, 0xa8, 0x8d, 0x02, 0x9c, 0x86, 0x01, 0x00, 0x00, + // 344 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x91, 0xbf, 0x6e, 0xea, 0x30, + 0x14, 0xc6, 0x63, 0xfe, 0xe3, 0x7b, 0x75, 0x39, 0x37, 0x53, 0xa7, 0x6c, 0x95, 0xaa, 0x48, 0x24, + 0x03, 0x7d, 0x01, 0x93, 0x44, 0x60, 0x35, 0x89, 0x69, 0x62, 0xaa, 0xaa, 0x52, 0x87, 0x12, 0x4c, + 0xb1, 0x54, 0x12, 0x94, 0x04, 0x09, 0xde, 0xa2, 0x8f, 0xd5, 0x91, 0xb1, 0x63, 0x05, 0x2f, 0x52, + 0xd9, 0x88, 0xed, 0xe7, 0xe3, 0x9f, 0xad, 0x4f, 0xdf, 0xc1, 0x83, 0xa5, 0xd8, 0xbb, 0x22, 0xdf, + 0x6d, 0x2a, 0x67, 0x5b, 0x16, 0x75, 0x61, 0xde, 0x54, 0x42, 0x6a, 0xca, 0x8a, 0x0f, 0xa7, 0x12, + 0x32, 0x5b, 0xbf, 0xc9, 0xdc, 0x59, 0x8a, 0xbd, 0x7d, 0x87, 0xff, 0xcf, 0x8a, 0x4a, 0xd6, 0xb2, + 0xc8, 0x7d, 0x59, 0x8a, 0x4c, 0x81, 0xd9, 0xc3, 0xad, 0x90, 0xc5, 0x13, 0x30, 0xcc, 0x3e, 0x6e, + 0xa7, 0x53, 0x96, 0x70, 0x40, 0xf6, 0x2d, 0xfe, 0x77, 0x35, 0x83, 0xd5, 0x4a, 0x64, 0xb5, 0xd2, + 0xd8, 0x2c, 0x88, 0x2f, 0x9a, 0x17, 0xb2, 0x34, 0x00, 0x64, 0x8f, 0x70, 0x9f, 0x95, 0x4b, 0x51, + 0xf2, 0xc3, 0x56, 0xa8, 0x79, 0x48, 0x23, 0xca, 0xc1, 0x30, 0x31, 0xee, 0x44, 0x24, 0x79, 0x08, + 0x38, 0x20, 0x73, 0x80, 0xff, 0x84, 0xf4, 0x71, 0x4e, 0x7d, 0xc2, 0x29, 0x8b, 0xa1, 0x61, 0xbf, + 0xe2, 0xb6, 0x2f, 0xf2, 0x62, 0x63, 0x76, 0x71, 0x33, 0x0d, 0x28, 0x18, 0xea, 0x6f, 0xc2, 0x59, + 0x04, 0x48, 0x8d, 0xc6, 0xdc, 0x83, 0x86, 0x82, 0x80, 0x4f, 0xa1, 0xa9, 0x25, 0x16, 0x42, 0x4b, + 0x4b, 0x4f, 0xe4, 0x19, 0xda, 0x8a, 0xe6, 0xa9, 0xef, 0x41, 0x47, 0x51, 0x1c, 0x90, 0x04, 0xba, + 0x3a, 0x5e, 0x1a, 0x31, 0xe8, 0xd9, 0xf7, 0xb8, 0x35, 0xcf, 0x65, 0x6d, 0xfe, 0xc5, 0xbd, 0x94, + 0x93, 0xd8, 0x27, 0x89, 0x7f, 0x09, 0x1d, 0xd1, 0x30, 0xa4, 0x80, 0x2e, 0xe8, 0x25, 0x0c, 0x1a, + 0xfa, 0x3d, 0x89, 0x19, 0x34, 0xc7, 0x93, 0xaf, 0x93, 0x85, 0x8e, 0x27, 0x0b, 0xfd, 0x9c, 0x2c, + 0xf4, 0x79, 0xb6, 0x8c, 0xe3, 0xd9, 0x32, 0xbe, 0xcf, 0x96, 0xf1, 0x32, 0x7c, 0x97, 0xf5, 0x7a, + 0xb7, 0x70, 0xb2, 0x62, 0xe3, 0x56, 0x42, 0x0e, 0xaf, 0xd5, 0xea, 0x83, 0xee, 0xd6, 0xdd, 0xbb, + 0x6a, 0x07, 0xf5, 0x61, 0x2b, 0xaa, 0x45, 0x47, 0xdf, 0x8f, 0x7e, 0x03, 0x00, 0x00, 0xff, 0xff, + 0x6c, 0x7d, 0x43, 0x93, 0x97, 0x01, 0x00, 0x00, } diff --git a/x/dex/types/settlement.go b/x/dex/types/settlement.go index 7640cc3062..123bc74bde 100644 --- a/x/dex/types/settlement.go +++ b/x/dex/types/settlement.go @@ -28,6 +28,7 @@ type Settlement struct { Account string Effect PositionEffect Leverage sdk.Dec + OrderType OrderType } func NewSettlement( @@ -38,6 +39,7 @@ func NewSettlement( quantity sdk.Dec, executionCostOrProceed sdk.Dec, expectedCostOrProceed sdk.Dec, + orderType OrderType, ) *Settlement { parts := strings.Split(formattedAccount, FORMATTED_ACCOUNT_DELIMITER) leverage, _ := sdk.NewDecFromStr(parts[2]) @@ -51,6 +53,7 @@ func NewSettlement( Account: parts[0], Effect: SUFFIX_TO_POSITION_EFFECT[OPEN_ORDER_CREATOR_SUFFIX], Leverage: leverage, + OrderType: orderType, } } @@ -70,5 +73,6 @@ func (s *Settlement) ToEntry() SettlementEntry { PositionDirection: GetContractPositionDirection(s.Direction), PositionEffect: GetContractPositionEffect(s.Effect), Leverage: s.Leverage, + OrderType: GetContractOrderType(s.OrderType), } } diff --git a/x/dex/types/settlement.pb.go b/x/dex/types/settlement.pb.go index 30b9eac693..5bfa87539e 100644 --- a/x/dex/types/settlement.pb.go +++ b/x/dex/types/settlement.pb.go @@ -34,6 +34,7 @@ type SettlementEntry struct { PositionDirection string `protobuf:"bytes,7,opt,name=positionDirection,proto3" json:"position_direction"` PositionEffect string `protobuf:"bytes,8,opt,name=positionEffect,proto3" json:"position_effect"` Leverage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=leverage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"leverage" yaml:"leverage"` + OrderType string `protobuf:"bytes,10,opt,name=orderType,proto3" json:"order_type"` } func (m *SettlementEntry) Reset() { *m = SettlementEntry{} } @@ -104,6 +105,13 @@ func (m *SettlementEntry) GetPositionEffect() string { return "" } +func (m *SettlementEntry) GetOrderType() string { + if m != nil { + return m.OrderType + } + return "" +} + type Settlements struct { Epoch int64 `protobuf:"varint,1,opt,name=epoch,proto3" json:"epoch"` Entries []*SettlementEntry `protobuf:"bytes,2,rep,name=entries,proto3" json:"entries"` @@ -164,41 +172,43 @@ func init() { func init() { proto.RegisterFile("dex/settlement.proto", fileDescriptor_c24d83c09612bb1c) } var fileDescriptor_c24d83c09612bb1c = []byte{ - // 541 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x3d, 0x6f, 0xd3, 0x40, - 0x18, 0x8e, 0x5b, 0xfa, 0x91, 0x8b, 0x44, 0xc4, 0xd1, 0x56, 0x47, 0x07, 0x5f, 0xe4, 0x01, 0x95, - 0x21, 0xb6, 0x04, 0x1b, 0x6c, 0x21, 0x15, 0x13, 0xa2, 0x32, 0x1b, 0x8b, 0xe5, 0x9e, 0xdf, 0x26, - 0x27, 0x62, 0x9f, 0xf1, 0x5d, 0x50, 0xb2, 0xf1, 0x13, 0xf8, 0x0f, 0x0c, 0xfc, 0x03, 0x7e, 0x43, - 0xc7, 0x8e, 0x88, 0xc1, 0x42, 0xc9, 0xe6, 0xb1, 0xbf, 0x00, 0xdd, 0xb9, 0xe7, 0x94, 0x92, 0x0c, - 0x65, 0xf2, 0x7b, 0xcf, 0xfb, 0x3c, 0xcf, 0xfb, 0x9c, 0x74, 0xaf, 0xd1, 0x41, 0x02, 0xb3, 0x40, - 0x82, 0x52, 0x13, 0x48, 0x21, 0x53, 0x7e, 0x5e, 0x08, 0x25, 0x30, 0x91, 0xc0, 0x4d, 0xc5, 0xc4, - 0xc4, 0x97, 0xc0, 0xd9, 0x38, 0xe6, 0x99, 0x9f, 0xc0, 0xec, 0xf8, 0x50, 0xf3, 0x45, 0x91, 0x40, - 0x11, 0x41, 0xa6, 0x8a, 0x79, 0x2d, 0x38, 0x3e, 0x18, 0x89, 0x91, 0x30, 0x65, 0xa0, 0xab, 0x1b, - 0xb4, 0xab, 0xc9, 0x90, 0x4d, 0x53, 0x59, 0x03, 0xde, 0x8f, 0x5d, 0xd4, 0x7d, 0xdf, 0x0c, 0x3b, - 0xd5, 0x06, 0x98, 0xa0, 0xbd, 0x98, 0x31, 0x31, 0xcd, 0x14, 0x71, 0x7a, 0xce, 0x49, 0x3b, 0xb4, - 0x47, 0x1c, 0x20, 0x94, 0x17, 0x9c, 0xc1, 0x10, 0x32, 0x91, 0x92, 0x2d, 0xdd, 0x1c, 0x74, 0xab, - 0x92, 0x76, 0x0c, 0x1a, 0x25, 0x1a, 0x0e, 0x6f, 0x51, 0xb4, 0x20, 0x96, 0x12, 0x54, 0x2d, 0xd8, - 0x5e, 0x09, 0x0c, 0x6a, 0x05, 0x2b, 0x0a, 0xe6, 0x68, 0xff, 0xd3, 0x34, 0xce, 0x14, 0x57, 0x73, - 0xf2, 0xc0, 0xd0, 0xdf, 0x5e, 0x96, 0xb4, 0xf5, 0xab, 0xa4, 0x4f, 0x47, 0x5c, 0x8d, 0xa7, 0xe7, - 0x3e, 0x13, 0x69, 0xc0, 0x84, 0x4c, 0x85, 0xbc, 0xf9, 0xf4, 0x65, 0xf2, 0x31, 0x50, 0xf3, 0x1c, - 0xa4, 0x3f, 0x04, 0x56, 0x95, 0xb4, 0x71, 0xb8, 0x2e, 0x69, 0x77, 0x1e, 0xa7, 0x93, 0x97, 0x9e, - 0x45, 0xbc, 0xb0, 0x69, 0xe2, 0xef, 0x0e, 0x3a, 0x82, 0x19, 0xb0, 0xa9, 0xe2, 0x22, 0x7b, 0x2d, - 0xa4, 0x7a, 0x57, 0x9c, 0x15, 0x82, 0x01, 0x24, 0x64, 0xc7, 0x4c, 0x16, 0xf7, 0x9e, 0xfc, 0xa4, - 0xf1, 0x8b, 0x98, 0x90, 0x2a, 0x12, 0x45, 0x94, 0xd7, 0x96, 0xd7, 0x25, 0xed, 0xd5, 0x51, 0x36, - 0x52, 0xbc, 0x70, 0x43, 0x1c, 0xfc, 0xcd, 0x41, 0x87, 0x30, 0xcb, 0x81, 0x29, 0x48, 0xfe, 0x0e, - 0xba, 0x6b, 0x82, 0xa6, 0xf7, 0x0e, 0x4a, 0xac, 0xdd, 0x9a, 0x9c, 0xd4, 0xe6, 0x5c, 0xcf, 0xf0, - 0xc2, 0xf5, 0x59, 0xf0, 0x10, 0x3d, 0xca, 0x85, 0xe4, 0x3a, 0xfe, 0x90, 0x17, 0xc0, 0x74, 0x41, - 0xf6, 0x4c, 0xc0, 0xa3, 0xaa, 0xa4, 0xd8, 0x36, 0xa3, 0xc4, 0x76, 0xc3, 0x7f, 0x05, 0xf8, 0x15, - 0x7a, 0x68, 0xc1, 0xd3, 0x8b, 0x0b, 0x60, 0x8a, 0xec, 0x1b, 0x8b, 0xc7, 0x55, 0x49, 0xbb, 0x8d, - 0x05, 0x98, 0x56, 0x78, 0x87, 0xaa, 0x5f, 0xcf, 0x04, 0x3e, 0x43, 0x11, 0x8f, 0x80, 0xb4, 0xff, - 0xf7, 0xf5, 0x58, 0x87, 0xd5, 0xeb, 0xb1, 0x88, 0x17, 0x36, 0x4d, 0xef, 0x8b, 0x83, 0x3a, 0xab, - 0xc5, 0x91, 0x98, 0xa2, 0x1d, 0xc8, 0x05, 0x1b, 0x9b, 0x95, 0xd9, 0x1e, 0xb4, 0xab, 0x92, 0xd6, - 0x40, 0x58, 0x7f, 0xf0, 0x19, 0xda, 0xd3, 0xfb, 0xc9, 0x41, 0x92, 0xad, 0xde, 0xf6, 0x49, 0xe7, - 0xf9, 0x33, 0x7f, 0xd3, 0x4e, 0xfb, 0x77, 0x36, 0x72, 0xd0, 0xa9, 0x4a, 0x6a, 0xd5, 0xa1, 0x2d, - 0x06, 0x6f, 0x2e, 0x17, 0xae, 0x73, 0xb5, 0x70, 0x9d, 0xdf, 0x0b, 0xd7, 0xf9, 0xba, 0x74, 0x5b, - 0x57, 0x4b, 0xb7, 0xf5, 0x73, 0xe9, 0xb6, 0x3e, 0xf4, 0x6f, 0xdd, 0x56, 0x02, 0xef, 0xdb, 0x29, - 0xe6, 0x60, 0xc6, 0x04, 0xb3, 0x40, 0xff, 0x0a, 0xcc, 0xc5, 0xcf, 0x77, 0x4d, 0xff, 0xc5, 0x9f, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x4b, 0x69, 0x87, 0x7b, 0x04, 0x00, 0x00, + // 564 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0x8d, 0xdb, 0xaf, 0x3f, 0x99, 0x48, 0x8d, 0xbe, 0xa1, 0xad, 0x86, 0x2e, 0x3c, 0x95, 0x17, + 0xa8, 0x48, 0xc4, 0x96, 0x60, 0x07, 0xbb, 0x90, 0x8a, 0x15, 0xa2, 0x32, 0xac, 0xd8, 0x58, 0xee, + 0xf8, 0x36, 0x19, 0x11, 0x7b, 0x8c, 0x67, 0x82, 0x92, 0x1d, 0x8f, 0xc0, 0x3b, 0xb0, 0xe0, 0x55, + 0xba, 0xec, 0x12, 0xb1, 0xb0, 0x50, 0xc2, 0xca, 0xcb, 0x3e, 0x01, 0x9a, 0x71, 0xc7, 0x29, 0x25, + 0x59, 0x94, 0x95, 0xaf, 0xcf, 0x3d, 0xe7, 0xdc, 0xa3, 0xd1, 0xdc, 0x41, 0xfb, 0x09, 0x4c, 0x03, + 0x09, 0x4a, 0x8d, 0x21, 0x85, 0x4c, 0xf9, 0x79, 0x21, 0x94, 0xc0, 0x44, 0x02, 0x37, 0x15, 0x13, + 0x63, 0x5f, 0x02, 0x67, 0xa3, 0x98, 0x67, 0x7e, 0x02, 0xd3, 0xa3, 0x03, 0xcd, 0x17, 0x45, 0x02, + 0x45, 0x04, 0x99, 0x2a, 0x66, 0xb5, 0xe0, 0x68, 0x7f, 0x28, 0x86, 0xc2, 0x94, 0x81, 0xae, 0x6e, + 0xd0, 0xae, 0x26, 0x43, 0x36, 0x49, 0x65, 0x0d, 0x78, 0xbf, 0xb6, 0x51, 0xf7, 0x6d, 0x33, 0xec, + 0x54, 0x1b, 0x60, 0x82, 0x76, 0x62, 0xc6, 0xc4, 0x24, 0x53, 0xc4, 0x39, 0x76, 0x4e, 0xda, 0xa1, + 0xfd, 0xc5, 0x01, 0x42, 0x79, 0xc1, 0x19, 0x0c, 0x20, 0x13, 0x29, 0xd9, 0xd0, 0xcd, 0x7e, 0xb7, + 0x2a, 0x69, 0xc7, 0xa0, 0x51, 0xa2, 0xe1, 0xf0, 0x16, 0x45, 0x0b, 0x62, 0x29, 0x41, 0xd5, 0x82, + 0xcd, 0xa5, 0xc0, 0xa0, 0x56, 0xb0, 0xa4, 0x60, 0x8e, 0x76, 0x3f, 0x4e, 0xe2, 0x4c, 0x71, 0x35, + 0x23, 0xff, 0x19, 0xfa, 0xeb, 0xcb, 0x92, 0xb6, 0x7e, 0x94, 0xf4, 0xd1, 0x90, 0xab, 0xd1, 0xe4, + 0xdc, 0x67, 0x22, 0x0d, 0x98, 0x90, 0xa9, 0x90, 0x37, 0x9f, 0x9e, 0x4c, 0x3e, 0x04, 0x6a, 0x96, + 0x83, 0xf4, 0x07, 0xc0, 0xaa, 0x92, 0x36, 0x0e, 0xd7, 0x25, 0xed, 0xce, 0xe2, 0x74, 0xfc, 0xdc, + 0xb3, 0x88, 0x17, 0x36, 0x4d, 0xfc, 0xcd, 0x41, 0x87, 0x30, 0x05, 0x36, 0x51, 0x5c, 0x64, 0x2f, + 0x85, 0x54, 0x6f, 0x8a, 0xb3, 0x42, 0x30, 0x80, 0x84, 0x6c, 0x99, 0xc9, 0xe2, 0xde, 0x93, 0x1f, + 0x36, 0x7e, 0x11, 0x13, 0x52, 0x45, 0xa2, 0x88, 0xf2, 0xda, 0xf2, 0xba, 0xa4, 0xc7, 0x75, 0x94, + 0xb5, 0x14, 0x2f, 0x5c, 0x13, 0x07, 0x7f, 0x75, 0xd0, 0x01, 0x4c, 0x73, 0x60, 0x0a, 0x92, 0x3f, + 0x83, 0x6e, 0x9b, 0xa0, 0xe9, 0xbd, 0x83, 0x12, 0x6b, 0xb7, 0x22, 0x27, 0xb5, 0x39, 0x57, 0x33, + 0xbc, 0x70, 0x75, 0x16, 0x3c, 0x40, 0xff, 0xe7, 0x42, 0x72, 0x1d, 0x7f, 0xc0, 0x0b, 0x60, 0xba, + 0x20, 0x3b, 0x26, 0xe0, 0x61, 0x55, 0x52, 0x6c, 0x9b, 0x51, 0x62, 0xbb, 0xe1, 0xdf, 0x02, 0xfc, + 0x02, 0xed, 0x59, 0xf0, 0xf4, 0xe2, 0x02, 0x98, 0x22, 0xbb, 0xc6, 0xe2, 0x41, 0x55, 0xd2, 0x6e, + 0x63, 0x01, 0xa6, 0x15, 0xde, 0xa1, 0xea, 0xdb, 0x33, 0x86, 0x4f, 0x50, 0xc4, 0x43, 0x20, 0xed, + 0x7f, 0xbd, 0x3d, 0xd6, 0x61, 0x79, 0x7b, 0x2c, 0xe2, 0x85, 0x4d, 0x13, 0x3f, 0x41, 0x6d, 0xb3, + 0x74, 0xef, 0x66, 0x39, 0x10, 0x64, 0x66, 0xed, 0x55, 0x25, 0x45, 0xf5, 0x26, 0x6a, 0xc3, 0x70, + 0x49, 0xf0, 0x3e, 0x3b, 0xa8, 0xb3, 0x5c, 0x33, 0x89, 0x29, 0xda, 0x82, 0x5c, 0xb0, 0x91, 0x59, + 0xb0, 0xcd, 0x7e, 0xbb, 0x2a, 0x69, 0x0d, 0x84, 0xf5, 0x07, 0x9f, 0xa1, 0x1d, 0xbd, 0xcd, 0x1c, + 0x24, 0xd9, 0x38, 0xde, 0x3c, 0xe9, 0x3c, 0x7d, 0xec, 0xaf, 0x7b, 0x01, 0xfc, 0x3b, 0xfb, 0xdb, + 0xef, 0x54, 0x25, 0xb5, 0xea, 0xd0, 0x16, 0xfd, 0x57, 0x97, 0x73, 0xd7, 0xb9, 0x9a, 0xbb, 0xce, + 0xcf, 0xb9, 0xeb, 0x7c, 0x59, 0xb8, 0xad, 0xab, 0x85, 0xdb, 0xfa, 0xbe, 0x70, 0x5b, 0xef, 0x7b, + 0xb7, 0xce, 0x46, 0x02, 0xef, 0xd9, 0x29, 0xe6, 0xc7, 0x8c, 0x09, 0xa6, 0x81, 0x7e, 0x38, 0xcc, + 0x31, 0x9d, 0x6f, 0x9b, 0xfe, 0xb3, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x35, 0x9b, 0xfd, 0xd3, + 0xa9, 0x04, 0x00, 0x00, } func (m *SettlementEntry) Marshal() (dAtA []byte, err error) { @@ -221,6 +231,13 @@ func (m *SettlementEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.OrderType) > 0 { + i -= len(m.OrderType) + copy(dAtA[i:], m.OrderType) + i = encodeVarintSettlement(dAtA, i, uint64(len(m.OrderType))) + i-- + dAtA[i] = 0x52 + } { size := m.Leverage.Size() i -= size @@ -386,6 +403,10 @@ func (m *SettlementEntry) Size() (n int) { } l = m.Leverage.Size() n += 1 + l + sovSettlement(uint64(l)) + l = len(m.OrderType) + if l > 0 { + n += 1 + l + sovSettlement(uint64(l)) + } return n } @@ -738,6 +759,38 @@ func (m *SettlementEntry) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OrderType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSettlement + } + 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 ErrInvalidLengthSettlement + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSettlement + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OrderType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSettlement(dAtA[iNdEx:])