Skip to content

Commit

Permalink
Enums camel case serialization (#2056)
Browse files Browse the repository at this point in the history
# Description
Copied from the original PR:

> Replaced all occurrences of #[serde(rename_all = "lowercase")] with
`#[serde(rename_all = "camelCase")].
> Ensured that the changes maintain the readability and functionality of
the code.
> This pull request addresses the concern raised about enum variant
readability and serialisation. The changes improve the codebase's
consistency and enhance its clarity.
> Please review the changes, and I'm open to any feedback or adjustments
to ensure the code's quality and maintainability. Thank you for your
time and consideration.

## Related PRs
#2020

fixes: #2016

---------

Co-authored-by: Devansh Kukreja <[email protected]>
Co-authored-by: Devansh kukreja <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2023
1 parent ebe4716 commit a843533
Show file tree
Hide file tree
Showing 36 changed files with 119 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

/target
/.vscode
/.idea
**/testing.*.toml
4 changes: 2 additions & 2 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 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,15 +281,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 @@ -298,7 +298,7 @@ enum SigningScheme {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
enum Class {
Market,
Limit,
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 @@ -238,14 +238,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 @@ -268,7 +268,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 @@ -326,7 +326,7 @@ struct WeightedProductReserve {
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum WeightedProductVersion {
V0,
V3Plus,
Expand Down
6 changes: 3 additions & 3 deletions 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")]
#[serde(rename_all = "camelCase")]
pub enum Kind {
Timeout,
EmptySolution,
Expand Down Expand Up @@ -129,7 +129,7 @@ pub struct Tx {

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum ScoreKind {
ZeroScore,
ScoreHigherThanQuality {
Expand All @@ -152,7 +152,7 @@ pub enum ScoreKind {

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Settlement {
Success { transaction: eth::H256 },
Revert { transaction: eth::H256 },
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)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Framework for setting up tests.
//! Framework for setting up tests .
use {
self::{blockchain::Fulfillment, driver::Driver, solver::Solver},
Expand Down Expand Up @@ -56,7 +56,7 @@ pub enum Partial {

#[serde_as]
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
Expand Down
8 changes: 4 additions & 4 deletions crates/solvers/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ components:
properties:
kind:
type: string
enum: [constantproduct]
enum: [constantProduct]
tokens:
description: |
A mapping of token address to its reserve amounts.
Expand All @@ -264,7 +264,7 @@ components:
properties:
kind:
type: string
enum: [weightedproduct]
enum: [weightedProduct]
tokens:
description: |
A mapping of token address to its reserve amounts with weights.
Expand Down Expand Up @@ -329,7 +329,7 @@ components:
properties:
kind:
type: string
enum: [concentratedliquidity]
enum: [concentratedLiquidity]
tokens:
type: array
items:
Expand Down Expand Up @@ -364,7 +364,7 @@ components:
properties:
kind:
type: string
enum: [limitorder]
enum: [limitOrder]
hash:
$ref: "#/components/schemas/Digest"
makerToken:
Expand Down
6 changes: 3 additions & 3 deletions crates/solvers/src/api/routes/notify/dto/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct Notification {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Kind {
Timeout,
EmptySolution,
Expand Down Expand Up @@ -139,7 +139,7 @@ pub struct Tx {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum ScoreKind {
ZeroScore,
ScoreHigherThanQuality {
Expand All @@ -162,7 +162,7 @@ pub enum ScoreKind {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Settlement {
Success { transaction: H256 },
Revert { transaction: H256 },
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 @@ -161,7 +161,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 @@ -216,14 +216,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 @@ -293,7 +293,7 @@ struct Allowance {
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
enum SellTokenBalance {
#[default]
Erc20,
Expand All @@ -302,15 +302,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 @@ -321,7 +321,7 @@ enum SigningScheme {
/// A score for a solution. The score is used to rank solutions.
#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
Expand Down
2 changes: 1 addition & 1 deletion crates/solvers/src/infra/dex/balancer/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
};

#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum OrderKind {
Sell,
Buy,
Expand Down
Loading

0 comments on commit a843533

Please sign in to comment.