Skip to content

Commit

Permalink
Driver & Autopilot: Remove deny_unknown_fields (#3137)
Browse files Browse the repository at this point in the history
# Description
Remove `deny_unknown_fields` from the `Deserialized` objects in order to
avoid crashing when new fields are added.
  • Loading branch information
m-lord-renkse authored Nov 28, 2024
1 parent 7359612 commit b5fa428
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions crates/autopilot/src/infra/solvers/dto/reveal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Request {

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Calldata {
#[serde(with = "bytes_hex")]
pub internalized: Vec<u8>,
Expand All @@ -27,7 +27,7 @@ pub struct Calldata {
}

#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub calldata: Calldata,
}
4 changes: 2 additions & 2 deletions crates/autopilot/src/infra/solvers/dto/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ pub struct Request {

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub calldata: Calldata,
pub tx_hash: H256,
}

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Calldata {
#[serde(with = "bytes_hex")]
pub internalized: Vec<u8>,
Expand Down
8 changes: 4 additions & 4 deletions crates/autopilot/src/infra/solvers/dto/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Solution {
/// settled on-chain.
#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct TradedOrder {
side: Side,
sell_token: H160,
Expand Down Expand Up @@ -158,15 +158,15 @@ impl TradedOrder {

#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub enum Side {
Buy,
Sell,
}

#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Solution {
/// Unique ID of the solution (per driver competition), used to identify
/// it in subsequent requests (reveal, settle).
Expand Down Expand Up @@ -214,7 +214,7 @@ where
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub solutions: Vec<Solution>,
}
4 changes: 2 additions & 2 deletions crates/driver/src/infra/api/routes/quote/dto/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Order {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Order {
sell_token: eth::H160,
buy_token: eth::H160,
Expand All @@ -36,7 +36,7 @@ pub struct Order {
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
enum Kind {
Sell,
Buy,
Expand Down
22 changes: 11 additions & 11 deletions crates/driver/src/infra/api/routes/solve/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl From<auction::Error> for Error {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Auction {
#[serde_as(as = "serde_with::DisplayFromStr")]
id: i64,
Expand All @@ -216,7 +216,7 @@ impl Auction {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct Token {
pub address: eth::H160,
#[serde_as(as = "Option<serialize::U256>")]
Expand All @@ -226,7 +226,7 @@ struct Token {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct Order {
#[serde_as(as = "serialize::Hex")]
uid: [u8; order::UID_LEN],
Expand Down Expand Up @@ -262,15 +262,15 @@ struct Order {
}

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

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct Interaction {
target: eth::H160,
#[serde_as(as = "serialize::U256")]
Expand All @@ -280,7 +280,7 @@ struct Interaction {
}

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

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

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

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

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
enum FeePolicy {
#[serde(rename_all = "camelCase")]
Surplus { factor: f64, max_volume_factor: f64 },
Expand All @@ -329,7 +329,7 @@ enum FeePolicy {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Quote {
#[serde_as(as = "serialize::U256")]
pub sell_amount: eth::U256,
Expand Down
32 changes: 16 additions & 16 deletions crates/driver/src/infra/solver/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ impl Solutions {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Solutions {
solutions: Vec<Solution>,
}

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Solution {
id: u64,
#[serde_as(as = "HashMap<_, serialize::U256>")]
Expand All @@ -245,15 +245,15 @@ pub struct Solution {
}

#[derive(Debug, Deserialize)]
#[serde(tag = "kind", rename_all = "camelCase", deny_unknown_fields)]
#[serde(tag = "kind", rename_all = "camelCase")]
enum Trade {
Fulfillment(Fulfillment),
Jit(JitTrade),
}

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct Fulfillment {
#[serde_as(as = "serialize::Hex")]
order: [u8; order::UID_LEN],
Expand All @@ -265,7 +265,7 @@ struct Fulfillment {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct JitTrade {
order: JitOrder,
#[serde_as(as = "serialize::U256")]
Expand All @@ -277,7 +277,7 @@ struct JitTrade {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct JitOrder {
sell_token: eth::H160,
buy_token: eth::H160,
Expand Down Expand Up @@ -376,22 +376,22 @@ impl JitOrder {
}

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

#[derive(Debug, Deserialize)]
#[serde(tag = "kind", rename_all = "camelCase", deny_unknown_fields)]
#[serde(tag = "kind", rename_all = "camelCase")]
enum Interaction {
Liquidity(LiquidityInteraction),
Custom(CustomInteraction),
}

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct LiquidityInteraction {
internalize: bool,
#[serde_as(as = "serde_with::DisplayFromStr")]
Expand All @@ -406,7 +406,7 @@ struct LiquidityInteraction {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct CustomInteraction {
internalize: bool,
target: eth::H160,
Expand All @@ -421,7 +421,7 @@ struct CustomInteraction {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct Asset {
token: eth::H160,
#[serde_as(as = "serialize::U256")]
Expand All @@ -430,7 +430,7 @@ struct Asset {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct Allowance {
token: eth::H160,
spender: eth::H160,
Expand All @@ -439,7 +439,7 @@ struct Allowance {
}

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

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

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
enum SigningScheme {
Eip712,
EthSign,
Expand All @@ -467,7 +467,7 @@ enum SigningScheme {
#[serde_as]
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields, tag = "kind")]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
Expand Down

0 comments on commit b5fa428

Please sign in to comment.