Skip to content

Commit

Permalink
Enums camel case serialization (#2171)
Browse files Browse the repository at this point in the history
Fixes #2168

Covered with e2e tests.

---------

Co-authored-by: Devansh Kukreja <[email protected]>
Co-authored-by: Devansh kukreja <[email protected]>
Co-authored-by: Felix Leupold <[email protected]>
  • Loading branch information
4 people authored and sunce86 committed Jan 6, 2024
1 parent 6aa02e4 commit 482ee59
Show file tree
Hide file tree
Showing 31 changed files with 109 additions and 108 deletions.
6 changes: 3 additions & 3 deletions crates/autopilot/src/driver_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod quote {
}

#[derive(Clone, Debug, Default, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Kind {
#[default]
Buy,
Expand Down Expand Up @@ -123,7 +123,7 @@ pub mod solve {
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Class {
Market,
Limit,
Expand All @@ -142,7 +142,7 @@ pub mod solve {
}

#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "lowercase", tag = "kind")]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum FeePolicy {
/// If the order receives more than expected (positive deviation from
/// quoted amounts) pay the protocol a factor of the achieved
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ components:
properties:
kind:
type: string
enum: ["priceimprovement"]
enum: ["priceImprovement"]
maxVolumeFactor:
description: Never charge more than that percentage of the order volume.
type: number
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/api/routes/quote/dto/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Order {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum Kind {
Sell,
Buy,
Expand Down
10 changes: 5 additions & 5 deletions crates/driver/src/infra/api/routes/solve/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ struct Order {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum Kind {
Sell,
Buy,
Expand All @@ -272,7 +272,7 @@ struct Interaction {
}

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum SellTokenBalance {
#[default]
Erc20,
Expand All @@ -281,7 +281,7 @@ enum SellTokenBalance {
}

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum BuyTokenBalance {
#[default]
Erc20,
Expand All @@ -298,15 +298,15 @@ enum SigningScheme {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum Class {
Market,
Limit,
Liquidity,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", tag = "kind", deny_unknown_fields)]
#[serde(rename_all = "camelCase", tag = "kind", deny_unknown_fields)]
enum FeePolicy {
#[serde(rename_all = "camelCase")]
PriceImprovement { factor: f64, max_volume_factor: f64 },
Expand Down
8 changes: 4 additions & 4 deletions crates/driver/src/infra/solver/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ struct Order {
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum Kind {
Sell,
Buy,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum Class {
Market,
Limit,
Expand All @@ -267,7 +267,7 @@ struct Token {
// TODO Remove dead_code
#[allow(dead_code, clippy::enum_variant_names)]
#[derive(Debug, Serialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
#[serde(tag = "kind", rename_all = "camelCase")]
enum Liquidity {
ConstantProduct(ConstantProductPool),
WeightedProduct(WeightedProductPool),
Expand Down Expand Up @@ -325,7 +325,7 @@ struct WeightedProductReserve {
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum WeightedProductVersion {
V0,
V3Plus,
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/solver/dto/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct Notification {

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase", tag = "kind")]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum Kind {
Timeout,
EmptySolution,
Expand Down
14 changes: 7 additions & 7 deletions crates/driver/src/infra/solver/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub struct Solution {
}

#[derive(Debug, Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase", deny_unknown_fields)]
#[serde(tag = "kind", rename_all = "camelCase", deny_unknown_fields)]
enum Trade {
Fulfillment(Fulfillment),
Jit(JitTrade),
Expand Down Expand Up @@ -287,14 +287,14 @@ struct JitOrder {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum Kind {
Sell,
Buy,
}

#[derive(Debug, Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase", deny_unknown_fields)]
#[serde(tag = "kind", rename_all = "camelCase", deny_unknown_fields)]
enum Interaction {
Liquidity(LiquidityInteraction),
Custom(CustomInteraction),
Expand Down Expand Up @@ -350,7 +350,7 @@ struct Allowance {
}

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum SellTokenBalance {
#[default]
Erc20,
Expand All @@ -359,15 +359,15 @@ enum SellTokenBalance {
}

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum BuyTokenBalance {
#[default]
Erc20,
Internal,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum SigningScheme {
Eip712,
EthSign,
Expand All @@ -377,7 +377,7 @@ enum SigningScheme {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields, tag = "kind")]
#[serde(rename_all = "camelCase", deny_unknown_fields, tag = "kind")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/tests/setup/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn solve_req(test: &Test) -> serde_json::Value {
"signingScheme": "eip712",
"signature": format!("0x{}", hex::encode(quote.order_signature(&test.blockchain))),
"feePolicies": [{
"kind": "priceimprovement",
"kind": "priceImprovement",
"factor": 0.5,
"maxVolumeFactor": 0.06,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum Partial {

#[serde_as]
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "lowercase", tag = "kind")]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
Expand Down
5 changes: 3 additions & 2 deletions crates/e2e/tests/e2e/colocation_partial_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
ethcontract::U256,
model::{
order::{OrderCreation, OrderKind},
signature::EcdsaSigningScheme,
signature::{EcdsaSigningScheme, Signature, SigningScheme},
},
secp256k1::SecretKey,
shared::ethrpc::Web3,
Expand Down Expand Up @@ -73,10 +73,11 @@ async fn test(web3: Web3) {
valid_to: model::time::now_in_epoch_seconds() + 300,
partially_fillable: true,
kind: OrderKind::Sell,
signature: Signature::default_with(SigningScheme::EthSign),
..Default::default()
}
.sign(
EcdsaSigningScheme::Eip712,
EcdsaSigningScheme::EthSign,
&onchain.contracts().domain_separator,
SecretKeyRef::from(&SecretKey::from_slice(trader.private_key()).unwrap()),
);
Expand Down
12 changes: 6 additions & 6 deletions crates/solvers/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ components:
properties:
kind:
type: string
enum: [constantproduct]
enum: [constantProduct]
tokens:
description: |
A mapping of token address to its reserve amounts.
Expand All @@ -294,7 +294,7 @@ components:
properties:
kind:
type: string
enum: [weightedproduct]
enum: [weightedProduct]
tokens:
description: |
A mapping of token address to its reserve amounts with weights.
Expand All @@ -314,7 +314,7 @@ components:
$ref: "#/components/schemas/Decimal"
version:
type: string
enum: ["v0", "v3plus"]
enum: ["v0", "v3Plus"]

StablePool:
description: |
Expand Down Expand Up @@ -362,7 +362,7 @@ components:
properties:
kind:
type: string
enum: [concentratedliquidity]
enum: [concentratedLiquidity]
tokens:
type: array
items:
Expand Down Expand Up @@ -397,7 +397,7 @@ components:
properties:
kind:
type: string
enum: [limitorder]
enum: [limitOrder]
hash:
$ref: "#/components/schemas/Digest"
makerToken:
Expand Down Expand Up @@ -763,7 +763,7 @@ components:
properties:
kind:
type: string
enum: [riskadjusted]
enum: [riskAdjusted]
successProbability:
description: |
The revert probability of the solution. Used by the driver to compute a risk-adjusted score.
Expand Down
2 changes: 1 addition & 1 deletion crates/solvers/src/api/routes/notify/dto/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub struct Notification {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", tag = "kind")]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum Kind {
Timeout,
EmptySolution,
Expand Down
8 changes: 4 additions & 4 deletions crates/solvers/src/api/routes/solve/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ struct Order {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum Kind {
Sell,
Buy,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum Class {
Market,
Limit,
Expand All @@ -146,7 +146,7 @@ struct Token {

#[allow(clippy::enum_variant_names)]
#[derive(Debug, Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase", deny_unknown_fields)]
#[serde(tag = "kind", rename_all = "camelCase", deny_unknown_fields)]
enum Liquidity {
ConstantProduct(ConstantProductPool),
WeightedProduct(WeightedProductPool),
Expand Down Expand Up @@ -227,7 +227,7 @@ struct WeightedProductReserve {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum WeightedProductVersion {
V0,
V3Plus,
Expand Down
14 changes: 7 additions & 7 deletions crates/solvers/src/api/routes/solve/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct Solution {
}

#[derive(Debug, Serialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
#[serde(tag = "kind", rename_all = "camelCase")]
enum Trade {
Fulfillment(Fulfillment),
Jit(JitTrade),
Expand Down Expand Up @@ -207,14 +207,14 @@ struct JitOrder {
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum Kind {
Sell,
Buy,
}

#[derive(Debug, Serialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
#[serde(tag = "kind", rename_all = "camelCase")]
enum Interaction {
Liquidity(LiquidityInteraction),
Custom(CustomInteraction),
Expand Down Expand Up @@ -284,7 +284,7 @@ struct Allowance {
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum SellTokenBalance {
#[default]
Erc20,
Expand All @@ -293,15 +293,15 @@ enum SellTokenBalance {
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum BuyTokenBalance {
#[default]
Erc20,
Internal,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum SigningScheme {
Eip712,
EthSign,
Expand All @@ -312,7 +312,7 @@ enum SigningScheme {
/// A score for a solution. The score is used to rank solutions.
#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase", tag = "kind")]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
Expand Down
Loading

0 comments on commit 482ee59

Please sign in to comment.