Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums camel case serialization #2056

Merged
merged 18 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this API is also maintained by balancer and thus may break (but given the non compound words, it may not be an issue here)

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