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 17 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 @@ -118,7 +118,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 @@ -35,7 +35,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 @@ -236,7 +236,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 @@ -254,7 +254,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 @@ -263,15 +263,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 @@ -280,7 +280,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)]
#[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 @@ -98,7 +98,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 @@ -135,7 +135,7 @@ pub struct Tx {

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum ScoreKind {
ZeroScore,
ScoreHigherThanQuality {
Expand All @@ -158,7 +158,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 @@ -232,7 +232,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 @@ -285,14 +285,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 @@ -348,7 +348,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 @@ -357,15 +357,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 @@ -374,7 +374,7 @@ enum SigningScheme {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub enum Score {
Solver(eth::U256),
RiskAdjusted(f64),
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 @@ -86,7 +86,7 @@ impl ExecutionDiff {
}

#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Score {
Solver(eth::U256),
RiskAdjusted(f64),
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 @@ -111,7 +111,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 @@ -148,7 +148,7 @@ pub struct Tx {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum ScoreKind {
ZeroScore,
ScoreHigherThanQuality {
Expand All @@ -171,7 +171,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 @@ -145,7 +145,7 @@ struct Token {
}

#[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 @@ -226,7 +226,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 @@ -320,7 +320,7 @@ enum SigningScheme {

/// A score for a solution. The score is used to rank solutions.
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Score {
Solver(U256),
RiskAdjusted(f64),
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