From 175673a39cdfd0ae92b8de9487626625f283a9f7 Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Tue, 23 Jul 2024 14:00:45 +0200 Subject: [PATCH 1/2] chore: update dev version Signed-off-by: Jeremy Letang --- .../blockexplorer/api/v1/blockexplorer.pb.go | 11 +++++----- protos/data-node/api/v2/trading_data.pb.go | 22 +++++++++---------- .../blockexplorer/api/v1/blockexplorer.proto | 2 +- .../data-node/api/v2/trading_data.proto | 2 +- protos/sources/vega/api/v1/core.proto | 2 +- protos/sources/vega/api/v1/corestate.proto | 2 +- protos/vega/api/v1/core.pb.go | 12 +++++----- protos/vega/api/v1/corestate.pb.go | 12 +++++----- version/version.go | 2 +- 9 files changed, 34 insertions(+), 33 deletions(-) diff --git a/protos/blockexplorer/api/v1/blockexplorer.pb.go b/protos/blockexplorer/api/v1/blockexplorer.pb.go index a4bb8dfa2d..a360806d40 100644 --- a/protos/blockexplorer/api/v1/blockexplorer.pb.go +++ b/protos/blockexplorer/api/v1/blockexplorer.pb.go @@ -650,15 +650,16 @@ var file_blockexplorer_api_v1_blockexplorer_proto_rawDesc = []byte{ 0x6c, 0x6f, 0x72, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x78, 0x70, 0x6c, 0x6f, 0x72, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, - 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x78, 0x5a, 0x35, + 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x7c, 0x5a, 0x35, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e, 0x69, 0x6f, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x78, 0x70, 0x6c, 0x6f, 0x72, 0x65, 0x72, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, 0x3e, 0x12, 0x23, 0x0a, 0x18, 0x56, 0x65, 0x67, 0x61, + 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, 0x42, 0x12, 0x27, 0x0a, 0x18, 0x56, 0x65, 0x67, 0x61, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x20, 0x65, 0x78, 0x70, 0x6c, 0x6f, 0x72, 0x65, 0x72, 0x20, - 0x41, 0x50, 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x37, 0x2e, 0x35, 0x1a, 0x13, 0x6c, - 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, - 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x41, 0x50, 0x49, 0x73, 0x32, 0x0b, 0x76, 0x30, 0x2e, 0x37, 0x38, 0x2e, 0x30, 0x2d, 0x64, 0x65, + 0x76, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, + 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/protos/data-node/api/v2/trading_data.pb.go b/protos/data-node/api/v2/trading_data.pb.go index d83567e99c..42c27e1ecb 100644 --- a/protos/data-node/api/v2/trading_data.pb.go +++ b/protos/data-node/api/v2/trading_data.pb.go @@ -32004,20 +32004,20 @@ var file_data_node_api_v2_trading_data_proto_rawDesc = []byte{ 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x09, 0x92, 0x41, 0x06, 0x0a, 0x04, 0x4d, - 0x69, 0x73, 0x63, 0x42, 0xc6, 0x01, 0x5a, 0x31, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x76, 0x65, 0x67, + 0x69, 0x73, 0x63, 0x42, 0xca, 0x01, 0x5a, 0x31, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e, 0x69, 0x6f, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x2d, 0x6e, 0x6f, - 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x92, 0x41, 0x8f, 0x01, 0x12, 0x1e, 0x0a, + 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x92, 0x41, 0x93, 0x01, 0x12, 0x22, 0x0a, 0x13, 0x56, 0x65, 0x67, 0x61, 0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x6e, 0x6f, 0x64, 0x65, 0x20, - 0x41, 0x50, 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x37, 0x2e, 0x35, 0x1a, 0x1c, 0x68, - 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, - 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x32, - 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, 0x6f, - 0x6e, 0x52, 0x39, 0x0a, 0x03, 0x35, 0x30, 0x30, 0x12, 0x32, 0x0a, 0x18, 0x41, 0x6e, 0x20, 0x69, - 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x65, - 0x72, 0x72, 0x6f, 0x72, 0x12, 0x16, 0x0a, 0x14, 0x1a, 0x12, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x41, 0x50, 0x49, 0x73, 0x32, 0x0b, 0x76, 0x30, 0x2e, 0x37, 0x38, 0x2e, 0x30, 0x2d, 0x64, 0x65, + 0x76, 0x1a, 0x1c, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, + 0x02, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x52, 0x39, 0x0a, 0x03, 0x35, 0x30, 0x30, 0x12, 0x32, 0x0a, 0x18, + 0x41, 0x6e, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x16, 0x0a, 0x14, 0x1a, 0x12, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/protos/sources/blockexplorer/api/v1/blockexplorer.proto b/protos/sources/blockexplorer/api/v1/blockexplorer.proto index 033ea95486..7564ac6dd8 100644 --- a/protos/sources/blockexplorer/api/v1/blockexplorer.proto +++ b/protos/sources/blockexplorer/api/v1/blockexplorer.proto @@ -11,7 +11,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/blockexplorer/api/v1"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega block explorer APIs"; - version: "v0.77.5"; + version: "v0.78.0-dev"; } schemes: [ HTTP, diff --git a/protos/sources/data-node/api/v2/trading_data.proto b/protos/sources/data-node/api/v2/trading_data.proto index 697a6ec44a..bfe75498b5 100644 --- a/protos/sources/data-node/api/v2/trading_data.proto +++ b/protos/sources/data-node/api/v2/trading_data.proto @@ -17,7 +17,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/data-node/api/v2"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega data node APIs"; - version: "v0.77.5"; + version: "v0.78.0-dev"; } schemes: [ HTTP, diff --git a/protos/sources/vega/api/v1/core.proto b/protos/sources/vega/api/v1/core.proto index f423907ba6..2ae0d17524 100644 --- a/protos/sources/vega/api/v1/core.proto +++ b/protos/sources/vega/api/v1/core.proto @@ -12,7 +12,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/vega/api/v1"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega core APIs"; - version: "v0.77.5"; + version: "v0.78.0-dev"; } schemes: [ HTTP, diff --git a/protos/sources/vega/api/v1/corestate.proto b/protos/sources/vega/api/v1/corestate.proto index 47706ef803..d98f12c1f7 100644 --- a/protos/sources/vega/api/v1/corestate.proto +++ b/protos/sources/vega/api/v1/corestate.proto @@ -13,7 +13,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/vega/api/v1"; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Vega core state APIs"; - version: "v0.77.5"; + version: "v0.78.0-dev"; } schemes: [ HTTP, diff --git a/protos/vega/api/v1/core.pb.go b/protos/vega/api/v1/core.pb.go index 99e9bd06b4..abf53d5f9b 100644 --- a/protos/vega/api/v1/core.pb.go +++ b/protos/vega/api/v1/core.pb.go @@ -2791,14 +2791,14 @@ var file_vega_api_v1_core_proto_rawDesc = []byte{ 0x53, 0x70, 0x61, 0x6d, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x70, 0x61, 0x6d, 0x53, 0x74, 0x61, 0x74, 0x69, - 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x65, 0x5a, + 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x69, 0x5a, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e, 0x69, 0x6f, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x73, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, 0x34, - 0x12, 0x19, 0x0a, 0x0e, 0x56, 0x65, 0x67, 0x61, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x20, 0x41, 0x50, - 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x37, 0x2e, 0x35, 0x1a, 0x13, 0x6c, 0x62, 0x2e, - 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, - 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, 0x38, + 0x12, 0x1d, 0x0a, 0x0e, 0x56, 0x65, 0x67, 0x61, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x20, 0x41, 0x50, + 0x49, 0x73, 0x32, 0x0b, 0x76, 0x30, 0x2e, 0x37, 0x38, 0x2e, 0x30, 0x2d, 0x64, 0x65, 0x76, 0x1a, + 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, + 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/protos/vega/api/v1/corestate.pb.go b/protos/vega/api/v1/corestate.pb.go index 74df7de44b..53d945c698 100644 --- a/protos/vega/api/v1/corestate.pb.go +++ b/protos/vega/api/v1/corestate.pb.go @@ -1506,15 +1506,15 @@ var file_vega_api_v1_corestate_proto_rawDesc = []byte{ 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x24, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x65, 0x6c, 0x65, 0x67, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6b, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x6f, 0x5a, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e, 0x69, 0x6f, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x76, 0x65, 0x67, 0x61, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x92, 0x41, - 0x3a, 0x12, 0x1f, 0x0a, 0x14, 0x56, 0x65, 0x67, 0x61, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x20, 0x73, - 0x74, 0x61, 0x74, 0x65, 0x20, 0x41, 0x50, 0x49, 0x73, 0x32, 0x07, 0x76, 0x30, 0x2e, 0x37, 0x37, - 0x2e, 0x35, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, 0x65, 0x74, 0x2e, 0x76, - 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x3e, 0x12, 0x23, 0x0a, 0x14, 0x56, 0x65, 0x67, 0x61, 0x20, 0x63, 0x6f, 0x72, 0x65, 0x20, 0x73, + 0x74, 0x61, 0x74, 0x65, 0x20, 0x41, 0x50, 0x49, 0x73, 0x32, 0x0b, 0x76, 0x30, 0x2e, 0x37, 0x38, + 0x2e, 0x30, 0x2d, 0x64, 0x65, 0x76, 0x1a, 0x13, 0x6c, 0x62, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x6e, + 0x65, 0x74, 0x2e, 0x76, 0x65, 0x67, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2a, 0x02, 0x01, 0x02, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/version/version.go b/version/version.go index 3ff0be5a41..41ef58b8ef 100644 --- a/version/version.go +++ b/version/version.go @@ -22,7 +22,7 @@ import ( var ( cliVersionHash = "" - cliVersion = "v0.77.5" + cliVersion = "v0.78.0-dev" ) func init() { From 7ab741865f4dc7eaec5d24df851ff1555eb6e93f Mon Sep 17 00:00:00 2001 From: ze97286 Date: Wed, 31 Jul 2024 17:47:32 +0100 Subject: [PATCH 2/2] fix: order spam check for amends fixed --- CHANGELOG.md | 2 +- core/execution/future/market.go | 77 ++++++++++++++------------------- core/execution/spot/market.go | 67 +++++++++++++--------------- 3 files changed, 63 insertions(+), 83 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7ee588a1..5ffc83fb51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ ### 🐛 Fixes - [11513](https://github.com/vegaprotocol/vega/issues/11513) - Rollback CometBFT to version `v0.38.8`. - +- [11516](https://github.com/vegaprotocol/vega/issues/11516) - Fix order spam check for amends. ## 0.77.4 diff --git a/core/execution/future/market.go b/core/execution/future/market.go index 663b89b106..c487c71a53 100644 --- a/core/execution/future/market.go +++ b/core/execution/future/market.go @@ -5281,81 +5281,68 @@ func (m *Market) emitPartyMarginModeUpdated(ctx context.Context, party string, m m.broker.Send(events.NewPartyMarginModeUpdatedEvent(ctx, e)) } -func (m *Market) checkOrderAmendForSpam(order *types.Order) error { - rf := num.DecimalOne() - - factor := m.mkt.LinearSlippageFactor - if m.risk.IsRiskFactorInitialised() { - if order.Side == types.SideBuy { - rf = m.risk.GetRiskFactors().Long - } else { - rf = m.risk.GetRiskFactors().Short - } - } - var price *num.Uint - if order.PeggedOrder == nil { - price, _ = num.UintFromDecimal(order.Price.ToDecimal().Mul(m.priceFactor)) - } else { - priceInMarket, _ := num.UintFromDecimal(m.getCurrentMarkPrice().ToDecimal().Div(m.priceFactor)) - if order.Side == types.SideBuy { - priceInMarket.AddSum(order.PeggedOrder.Offset) - } else { - priceInMarket = priceInMarket.Sub(priceInMarket, order.PeggedOrder.Offset) - } - price, _ = num.UintFromDecimal(priceInMarket.ToDecimal().Mul(m.priceFactor)) - } - margins := num.UintZero().Mul(price, num.NewUint(order.TrueRemaining())).ToDecimal().Div(m.positionFactor) - assetQuantum, err := m.collateral.GetAssetQuantum(m.settlementAsset) - if err != nil { - return err - } - if margins.Mul(rf.Add(factor)).Div(assetQuantum).LessThan(m.minMaintenanceMarginQuantumMultiplier.Mul(assetQuantum)) { - return fmt.Errorf("order value is less than minimum maintenance margin for spam") - } - return nil -} - -func (m *Market) CheckOrderSubmissionForSpam(orderSubmission *types.OrderSubmission, party string, quantumMultiplier num.Decimal) error { +func (m *Market) checkOrderForSpam(side types.Side, orderPrice *num.Uint, orderSize uint64, peggedOrder *types.PeggedOrder, orderType vegapb.Order_Type, quantumMultiplier num.Decimal) error { rf := num.DecimalOne() factor := m.mkt.LinearSlippageFactor if m.risk.IsRiskFactorInitialised() { - if orderSubmission.Side == types.SideBuy { + if side == types.SideBuy { rf = m.risk.GetRiskFactors().Long } else { rf = m.risk.GetRiskFactors().Short } } - var price *num.Uint - if orderSubmission.PeggedOrder != nil || orderSubmission.Type == vega.Order_TYPE_MARKET { + if peggedOrder != nil || orderType == vega.Order_TYPE_MARKET { priceInMarket, _ := num.UintFromDecimal(m.getCurrentMarkPrice().ToDecimal().Div(m.priceFactor)) offset := num.UintZero() - if orderSubmission.PeggedOrder != nil { - offset = orderSubmission.PeggedOrder.Offset + if peggedOrder != nil { + offset = peggedOrder.Offset } - if orderSubmission.Side == types.SideBuy { + if side == types.SideBuy { priceInMarket.AddSum(offset) } else { priceInMarket = priceInMarket.Sub(priceInMarket, offset) } price, _ = num.UintFromDecimal(priceInMarket.ToDecimal().Mul(m.priceFactor)) } else { - price, _ = num.UintFromDecimal(orderSubmission.Price.ToDecimal().Mul(m.priceFactor)) + price, _ = num.UintFromDecimal(orderPrice.ToDecimal().Mul(m.priceFactor)) } - margins := num.UintZero().Mul(price, num.NewUint(orderSubmission.Size)).ToDecimal().Div(m.positionFactor) + margins := num.UintZero().Mul(price, num.NewUint(orderSize)).ToDecimal().Div(m.positionFactor) assetQuantum, err := m.collateral.GetAssetQuantum(m.settlementAsset) if err != nil { return err } - if margins.Mul(rf.Add(factor)).LessThan(quantumMultiplier.Mul(assetQuantum)) { - return fmt.Errorf("order value is less than minimum maintenance margin for spam") + value := margins.Mul(rf.Add(factor)) + required := quantumMultiplier.Mul(assetQuantum) + if value.LessThan(required) { + return fmt.Errorf(fmt.Sprintf("order value (%s) is less than minimum maintenance margin for spam (%s)", value.String(), required.String())) } return nil } +func (m *Market) checkOrderAmendForSpam(order *types.Order) error { + return m.checkOrderForSpam( + order.Side, + order.Price, + order.Size, + order.PeggedOrder, + order.Type, + m.minMaintenanceMarginQuantumMultiplier) +} + +func (m *Market) CheckOrderSubmissionForSpam(orderSubmission *types.OrderSubmission, party string, quantumMultiplier num.Decimal) error { + return m.checkOrderForSpam( + orderSubmission.Side, + orderSubmission.Price, + orderSubmission.Size, + orderSubmission.PeggedOrder, + orderSubmission.Type, + quantumMultiplier) +} + func (m *Market) GetFillPrice(volume uint64, side types.Side) (*num.Uint, error) { return m.matching.GetFillPrice(volume, side) } diff --git a/core/execution/spot/market.go b/core/execution/spot/market.go index 8fdcb2a820..a2e40ab43d 100644 --- a/core/execution/spot/market.go +++ b/core/execution/spot/market.go @@ -3323,62 +3323,55 @@ type IDGen interface { NextID() string } -func (m *Market) checkOrderAmendForSpam(order *types.Order) error { - assetQuantum, err := m.collateral.GetAssetQuantum(m.quoteAsset) - if err != nil { - return err - } - - var price *num.Uint - if order.PeggedOrder == nil { - price, _ = num.UintFromDecimal(order.Price.ToDecimal().Mul(m.priceFactor)) - } else { - priceInMarket, _ := num.UintFromDecimal(m.getCurrentMarkPrice().ToDecimal().Div(m.priceFactor)) - if order.Side == types.SideBuy { - priceInMarket.AddSum(order.PeggedOrder.Offset) - } else { - priceInMarket = priceInMarket.Sub(priceInMarket, order.PeggedOrder.Offset) - } - price, _ = num.UintFromDecimal(priceInMarket.ToDecimal().Mul(m.priceFactor)) - } - - minQuantum := assetQuantum.Mul(m.minHoldingQuantumMultiplier) - value := num.UintZero().Mul(num.NewUint(order.Size), price).ToDecimal() - value = value.Div(m.positionFactor).Div(assetQuantum) - if value.LessThan(minQuantum.Mul(assetQuantum)) { - return fmt.Errorf("order value is less than minimum holding requirement for spam") - } - return nil -} - -func (m *Market) CheckOrderSubmissionForSpam(orderSubmission *types.OrderSubmission, party string, quantumMultiplier num.Decimal) error { +func (m *Market) checkOrderForSpam(side types.Side, orderPrice *num.Uint, orderSize uint64, peggedOrder *types.PeggedOrder, orderType vega.Order_Type, quantumMultiplier num.Decimal) error { assetQuantum, err := m.collateral.GetAssetQuantum(m.quoteAsset) if err != nil { return err } var price *num.Uint - if orderSubmission.PeggedOrder != nil || orderSubmission.Type == vega.Order_TYPE_MARKET { + if peggedOrder != nil || orderType == vega.Order_TYPE_MARKET { priceInMarket, _ := num.UintFromDecimal(m.getCurrentMarkPrice().ToDecimal().Div(m.priceFactor)) offset := num.UintZero() - if orderSubmission.PeggedOrder != nil { - offset = orderSubmission.PeggedOrder.Offset + if peggedOrder != nil { + offset = peggedOrder.Offset } - if orderSubmission.Side == types.SideBuy { + if side == types.SideBuy { priceInMarket.AddSum(offset) } else { priceInMarket = priceInMarket.Sub(priceInMarket, offset) } price, _ = num.UintFromDecimal(priceInMarket.ToDecimal().Mul(m.priceFactor)) } else { - price, _ = num.UintFromDecimal(orderSubmission.Price.ToDecimal().Mul(m.priceFactor)) + price, _ = num.UintFromDecimal(orderPrice.ToDecimal().Mul(m.priceFactor)) } minQuantum := assetQuantum.Mul(quantumMultiplier) - value := num.UintZero().Mul(num.NewUint(orderSubmission.Size), price).ToDecimal() + value := num.UintZero().Mul(num.NewUint(orderSize), price).ToDecimal() value = value.Div(m.positionFactor) - if value.LessThan(minQuantum.Mul(assetQuantum)) { - return fmt.Errorf("order value is less than minimum holding requirement for spam") + required := minQuantum.Mul(assetQuantum) + if value.LessThan(required) { + return fmt.Errorf(fmt.Sprintf("order value (%s) is less than minimum holding requirement for spam (%s)", value.String(), required.String())) } return nil } + +func (m *Market) checkOrderAmendForSpam(order *types.Order) error { + return m.checkOrderForSpam( + order.Side, + order.Price, + order.Size, + order.PeggedOrder, + order.Type, + m.minHoldingQuantumMultiplier) +} + +func (m *Market) CheckOrderSubmissionForSpam(orderSubmission *types.OrderSubmission, party string, quantumMultiplier num.Decimal) error { + return m.checkOrderForSpam( + orderSubmission.Side, + orderSubmission.Price, + orderSubmission.Size, + orderSubmission.PeggedOrder, + orderSubmission.Type, + quantumMultiplier) +}