diff --git a/crates/autopilot/src/infra/solvers/dto/reveal.rs b/crates/autopilot/src/infra/solvers/dto/reveal.rs index f963fce1a5..41971d28b1 100644 --- a/crates/autopilot/src/infra/solvers/dto/reveal.rs +++ b/crates/autopilot/src/infra/solvers/dto/reveal.rs @@ -9,7 +9,6 @@ use { #[serde(rename_all = "camelCase")] pub struct Request { /// Unique ID of the solution (per driver competition), to reveal. - #[serde_as(as = "serde_with::DisplayFromStr")] pub solution_id: u64, /// Auction ID in which the specified solution ID is competing. #[serde_as(as = "Option")] diff --git a/crates/autopilot/src/infra/solvers/dto/settle.rs b/crates/autopilot/src/infra/solvers/dto/settle.rs index 3abdf15dbe..5277eef76e 100644 --- a/crates/autopilot/src/infra/solvers/dto/settle.rs +++ b/crates/autopilot/src/infra/solvers/dto/settle.rs @@ -9,7 +9,6 @@ use { #[serde(rename_all = "camelCase")] pub struct Request { /// Unique ID of the solution (per driver competition), to settle. - #[serde_as(as = "serde_with::DisplayFromStr")] pub solution_id: u64, /// The last block number in which the solution TX can be included pub submission_deadline_latest_block: u64, diff --git a/crates/autopilot/src/infra/solvers/dto/solve.rs b/crates/autopilot/src/infra/solvers/dto/solve.rs index a54c143f70..ad793a7f2f 100644 --- a/crates/autopilot/src/infra/solvers/dto/solve.rs +++ b/crates/autopilot/src/infra/solvers/dto/solve.rs @@ -170,7 +170,6 @@ pub enum Side { pub struct Solution { /// Unique ID of the solution (per driver competition), used to identify /// it in subsequent requests (reveal, settle). - #[serde(deserialize_with = "deserialize_solution_id")] pub solution_id: u64, #[serde_as(as = "HexOrDecimalU256")] pub score: U256, @@ -182,37 +181,6 @@ pub struct Solution { pub gas: Option, } -fn deserialize_solution_id<'de, D>(deserializer: D) -> Result -where - D: serde::Deserializer<'de>, -{ - struct SolutionIdVisitor; - - impl serde::de::Visitor<'_> for SolutionIdVisitor { - type Value = u64; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("a string or integer representing a solution ID") - } - - fn visit_u64(self, value: u64) -> Result - where - E: serde::de::Error, - { - Ok(value) - } - - fn visit_str(self, value: &str) -> Result - where - E: serde::de::Error, - { - value.parse::().map_err(serde::de::Error::custom) - } - } - - deserializer.deserialize_any(SolutionIdVisitor) -} - #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Response { diff --git a/crates/driver/src/infra/api/routes/mod.rs b/crates/driver/src/infra/api/routes/mod.rs index 434846385e..ee1027b0e9 100644 --- a/crates/driver/src/infra/api/routes/mod.rs +++ b/crates/driver/src/infra/api/routes/mod.rs @@ -15,34 +15,3 @@ pub(super) use { settle::settle, solve::{solve, AuctionError}, }; - -pub(crate) fn deserialize_solution_id<'de, D>(deserializer: D) -> Result -where - D: serde::Deserializer<'de>, -{ - struct SolutionIdVisitor; - - impl serde::de::Visitor<'_> for SolutionIdVisitor { - type Value = u64; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("a string or integer representing a solution ID") - } - - fn visit_u64(self, value: u64) -> Result - where - E: serde::de::Error, - { - Ok(value) - } - - fn visit_str(self, value: &str) -> Result - where - E: serde::de::Error, - { - value.parse::().map_err(serde::de::Error::custom) - } - } - - deserializer.deserialize_any(SolutionIdVisitor) -} diff --git a/crates/driver/src/infra/api/routes/reveal/dto/solution.rs b/crates/driver/src/infra/api/routes/reveal/dto/solution.rs index 0c8d55fa49..b0a75e1e1c 100644 --- a/crates/driver/src/infra/api/routes/reveal/dto/solution.rs +++ b/crates/driver/src/infra/api/routes/reveal/dto/solution.rs @@ -1,11 +1,10 @@ -use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_with::serde_as}; +use {serde::Deserialize, serde_with::serde_as}; #[serde_as] #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Solution { /// Unique ID of the solution (per driver competition), to reveal. - #[serde(deserialize_with = "deserialize_solution_id")] pub solution_id: u64, /// Auction ID in which the specified solution ID is competing. #[serde_as(as = "Option")] diff --git a/crates/driver/src/infra/api/routes/settle/dto/solution.rs b/crates/driver/src/infra/api/routes/settle/dto/solution.rs index 6c62cd0cdd..fbe8ea4501 100644 --- a/crates/driver/src/infra/api/routes/settle/dto/solution.rs +++ b/crates/driver/src/infra/api/routes/settle/dto/solution.rs @@ -1,11 +1,10 @@ -use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_with::serde_as}; +use {serde::Deserialize, serde_with::serde_as}; #[serde_as] #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Solution { /// Unique ID of the solution (per driver competition), to settle. - #[serde(deserialize_with = "deserialize_solution_id")] pub solution_id: u64, /// The last block number in which the solution TX can be included pub submission_deadline_latest_block: u64, diff --git a/crates/driver/src/tests/cases/buy_eth.rs b/crates/driver/src/tests/cases/buy_eth.rs index 204dc7b2bd..35bf50f699 100644 --- a/crates/driver/src/tests/cases/buy_eth.rs +++ b/crates/driver/src/tests/cases/buy_eth.rs @@ -16,5 +16,5 @@ async fn test() { .await; let id = test.solve().await.ok().orders(&[order]).id(); - test.settle(&id).await.ok().await.eth_order_executed().await; + test.settle(id).await.ok().await.eth_order_executed().await; } diff --git a/crates/driver/src/tests/cases/merge_settlements.rs b/crates/driver/src/tests/cases/merge_settlements.rs index ae27ac6f4b..8c16ecaa6f 100644 --- a/crates/driver/src/tests/cases/merge_settlements.rs +++ b/crates/driver/src/tests/cases/merge_settlements.rs @@ -35,8 +35,8 @@ async fn possible() { .await; let id = test.solve().await.ok().orders(&[ab_order, cd_order]).id(); - test.reveal(&id).await.ok().calldata(); - test.settle(&id) + test.reveal(id).await.ok().calldata(); + test.settle(id) .await // Even though the solver returned two solutions, the executed settlement is a // combination of the two, meaning the settlements were merged successfully. @@ -91,8 +91,8 @@ async fn impossible() { // Only the first A-B order gets settled. let id = test.solve().await.ok().orders(&[order]).id(); - test.reveal(&id).await.ok().calldata(); - test.settle(&id).await.ok().await.ab_order_executed().await; + test.reveal(id).await.ok().calldata(); + test.settle(id).await.ok().await.ab_order_executed().await; } /// Test that mergable solutions don't get merged if feature was not enabled. @@ -114,6 +114,6 @@ async fn possible_but_forbidden() { // Even though the solutions could be combined (see test "possible") they were // not because solution merging is not enabled by default. let id = test.solve().await.ok().orders(&[ab_order]).id(); - test.reveal(&id).await.ok().calldata(); - test.settle(&id).await.ok().await.ab_order_executed().await; + test.reveal(id).await.ok().calldata(); + test.settle(id).await.ok().await.ab_order_executed().await; } diff --git a/crates/driver/src/tests/cases/multiple_solutions.rs b/crates/driver/src/tests/cases/multiple_solutions.rs index f5da54e33b..33c78efd5d 100644 --- a/crates/driver/src/tests/cases/multiple_solutions.rs +++ b/crates/driver/src/tests/cases/multiple_solutions.rs @@ -18,7 +18,7 @@ async fn valid() { .await; let id = test.solve().await.ok().orders(&[order]).id(); - test.reveal(&id).await.ok().calldata(); + test.reveal(id).await.ok().calldata(); } /// Test that the invalid solution is discarded when the /solve endpoint @@ -36,5 +36,5 @@ async fn invalid() { .await; let id = test.solve().await.ok().orders(&[order]).id(); - test.reveal(&id).await.ok().calldata(); + test.reveal(id).await.ok().calldata(); } diff --git a/crates/driver/src/tests/cases/parallel_auctions.rs b/crates/driver/src/tests/cases/parallel_auctions.rs index 12445d2f8b..cac7e3f186 100644 --- a/crates/driver/src/tests/cases/parallel_auctions.rs +++ b/crates/driver/src/tests/cases/parallel_auctions.rs @@ -25,25 +25,25 @@ async fn driver_handles_solutions_based_on_id() { // calling `/reveal` or `/settle` with incorrect solution ids // results in an error. - test.settle("99").await.err().kind("SolutionNotAvailable"); - test.reveal("99").await.err().kind("SolutionNotAvailable"); + test.settle(99).await.err().kind("SolutionNotAvailable"); + test.reveal(99).await.err().kind("SolutionNotAvailable"); // calling `/reveal` or `/settle` with a reasonable id works // but wrong auction id results in an error. test.set_auction_id(100); - test.reveal(&solution_id) + test.reveal(solution_id) .await .err() .kind("SolutionNotAvailable"); - test.settle(&solution_id) + test.settle(solution_id) .await .err() .kind("SolutionNotAvailable"); // calling `/reveal` or `/settle` with a reasonable id works. test.set_auction_id(1); - test.reveal(&solution_id).await.ok(); - test.settle(&solution_id) + test.reveal(solution_id).await.ok(); + test.settle(solution_id) .await .ok() .await @@ -52,11 +52,11 @@ async fn driver_handles_solutions_based_on_id() { // calling `/reveal` or `/settle` with for a legit solution that // has already been settled also fails. - test.settle(&solution_id) + test.settle(solution_id) .await .err() .kind("SolutionNotAvailable"); - test.reveal(&solution_id) + test.reveal(solution_id) .await .err() .kind("SolutionNotAvailable"); @@ -89,12 +89,7 @@ async fn driver_can_settle_old_solutions() { // Technically this is not super convincing since all remembered solutions // are identical but this is the best we are going to get without needing // to heavily modify the testing framework. - test.settle(&id1) - .await - .ok() - .await - .eth_order_executed() - .await; + test.settle(id1).await.ok().await.eth_order_executed().await; } /// Tests that the driver only remembers a relatively small number of solutions. @@ -118,12 +113,12 @@ async fn driver_has_a_short_memory() { let id6 = test.solve().await.ok().id(); // recalling the 5 most recent solutions works - test.reveal(&id2).await.ok(); - test.reveal(&id3).await.ok(); - test.reveal(&id4).await.ok(); - test.reveal(&id5).await.ok(); - test.reveal(&id6).await.ok(); + test.reveal(id2).await.ok(); + test.reveal(id3).await.ok(); + test.reveal(id4).await.ok(); + test.reveal(id5).await.ok(); + test.reveal(id6).await.ok(); // recalling an older solution doesn't work - test.reveal(&id1).await.err().kind("SolutionNotAvailable"); + test.reveal(id1).await.err().kind("SolutionNotAvailable"); } diff --git a/crates/driver/src/tests/cases/settle.rs b/crates/driver/src/tests/cases/settle.rs index 110d138734..fd50e1779c 100644 --- a/crates/driver/src/tests/cases/settle.rs +++ b/crates/driver/src/tests/cases/settle.rs @@ -30,7 +30,7 @@ async fn matrix() { .await; let id = test.solve().await.ok().id(); - test.settle(&id).await.ok().await.ab_order_executed().await; + test.settle(id).await.ok().await.ab_order_executed().await; } } } @@ -47,7 +47,7 @@ async fn solution_not_available() { .done() .await; - test.settle("99").await.err().kind("SolutionNotAvailable"); + test.settle(99).await.err().kind("SolutionNotAvailable"); } /// Checks that settlements with revert risk are not submitted via public @@ -71,7 +71,7 @@ async fn private_rpc_with_high_risk_solution() { let id = test.solve().await.ok().id(); // Public cannot be used and private RPC is not available - test.settle(&id).await.err().kind("FailedToSubmit"); + test.settle(id).await.err().kind("FailedToSubmit"); } #[tokio::test] @@ -108,5 +108,5 @@ async fn high_gas_limit() { .execute("evm_setBlockGasLimit", vec![serde_json::json!(9_000_000)]) .await .unwrap(); - test.settle(&id).await.ok().await; + test.settle(id).await.ok().await; } diff --git a/crates/driver/src/tests/cases/solver_balance.rs b/crates/driver/src/tests/cases/solver_balance.rs index 04a12b4408..3294d3405e 100644 --- a/crates/driver/src/tests/cases/solver_balance.rs +++ b/crates/driver/src/tests/cases/solver_balance.rs @@ -42,7 +42,7 @@ async fn test_just_enough_funded() { .await; let id = test.solve_with_solver("barely_funded").await.ok().id(); - test.settle_with_solver("barely_funded", &id) + test.settle_with_solver("barely_funded", id) .await .ok() .await; diff --git a/crates/driver/src/tests/setup/driver.rs b/crates/driver/src/tests/setup/driver.rs index 6cf08b1cc6..cd7115fe38 100644 --- a/crates/driver/src/tests/setup/driver.rs +++ b/crates/driver/src/tests/setup/driver.rs @@ -147,7 +147,7 @@ pub fn solve_req(test: &Test) -> serde_json::Value { } /// Create a request for the driver /reveal endpoint. -pub fn reveal_req(solution_id: &str, auction_id: &str) -> serde_json::Value { +pub fn reveal_req(solution_id: u64, auction_id: &str) -> serde_json::Value { json!({ "solutionId": solution_id, "auctionId": auction_id, @@ -157,7 +157,7 @@ pub fn reveal_req(solution_id: &str, auction_id: &str) -> serde_json::Value { /// Create a request for the driver /settle endpoint. pub fn settle_req( submission_deadline_latest_block: u64, - solution_id: &str, + solution_id: u64, auction_id: &str, ) -> serde_json::Value { json!({ diff --git a/crates/driver/src/tests/setup/mod.rs b/crates/driver/src/tests/setup/mod.rs index 171ebc6261..dc22169e29 100644 --- a/crates/driver/src/tests/setup/mod.rs +++ b/crates/driver/src/tests/setup/mod.rs @@ -1039,7 +1039,7 @@ impl Test { } /// Call the /reveal endpoint. - pub async fn reveal(&self, solution_id: &str) -> Reveal { + pub async fn reveal(&self, solution_id: u64) -> Reveal { let res = self .client .post(format!( @@ -1089,11 +1089,11 @@ impl Test { } /// Call the /settle endpoint. - pub async fn settle(&self, solution_id: &str) -> Settle { + pub async fn settle(&self, solution_id: u64) -> Settle { self.settle_with_solver(solver::NAME, solution_id).await } - pub async fn settle_with_solver(&self, solver_name: &str, solution_id: &str) -> Settle { + pub async fn settle_with_solver(&self, solver_name: &str, solution_id: u64) -> Settle { /// The maximum number of blocks to wait for a settlement to appear on /// chain. const SUBMISSION_DEADLINE: u64 = 3; @@ -1213,13 +1213,12 @@ impl SolveOk<'_> { /// Extracts the solution id from the response. Since response can contain /// multiple solutions, it takes the id from the first solution. - pub fn id(&self) -> String { + pub fn id(&self) -> u64 { let solution = self.solution(); solution .get("solutionId") .unwrap() .as_u64() - .map(|id| id.to_string()) .unwrap() .to_owned() }