Skip to content

Commit

Permalink
Update SolverEngine API docs (#2192)
Browse files Browse the repository at this point in the history
# Description
Docs were slightly out of date

# Changes

- [x] Updates all fields and structs on the existing endpoint
- [x] Remove pre-interactions for jit orders (for some reason we didn't
populate post interactions and since those orders aren't really used in
practice anyways, it seemed simpler to remove pre interactions instead
of adding post interactions).
- [x] Flatten notification type to make it consistent with the way we
encode enums elsewhere in the new API (cf. `Liquidity`)
- [x] Flatten Score enum to make it consistent
- [x] Document notify endpoint

## How to test
Past into https://editor.swagger.io/ and compare line by line with the
rust structs

## Related Issues

Fixes #2182
  • Loading branch information
fleupold authored Dec 21, 2023
1 parent c390494 commit 3f89dc2
Show file tree
Hide file tree
Showing 32 changed files with 310 additions and 246 deletions.
111 changes: 52 additions & 59 deletions crates/driver/src/infra/solver/dto/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
competition::{auction, solution},
eth,
},
infra::{notify, notify::SimulationSucceededAtLeastOnce},
infra::notify,
util::serialize,
},
serde::Serialize,
Expand All @@ -25,41 +25,39 @@ impl Notification {
kind: match kind {
notify::Kind::Timeout => Kind::Timeout,
notify::Kind::EmptySolution => Kind::EmptySolution,
notify::Kind::SimulationFailed(block, tx, simulated_once) => {
Kind::SimulationFailed(
block.0,
Tx {
notify::Kind::SimulationFailed(block, tx, succeeded_once) => {
Kind::SimulationFailed {
block: block.0,
tx: Tx {
from: tx.from.into(),
to: tx.to.into(),
input: tx.input.into(),
value: tx.value.into(),
access_list: tx.access_list.into(),
},
simulated_once,
)
}
notify::Kind::ScoringFailed(notify::ScoreKind::ZeroScore) => {
Kind::ScoringFailed(ScoreKind::ZeroScore)
succeeded_once,
}
}
notify::Kind::ScoringFailed(notify::ScoreKind::ZeroScore) => Kind::ZeroScore,
notify::Kind::ScoringFailed(notify::ScoreKind::ScoreHigherThanQuality(
score,
quality,
)) => Kind::ScoringFailed(ScoreKind::ScoreHigherThanQuality {
)) => Kind::ScoreHigherThanQuality {
score: score.0.get(),
quality: quality.0,
}),
},
notify::Kind::ScoringFailed(notify::ScoreKind::SuccessProbabilityOutOfRange(
success_probability,
)) => Kind::ScoringFailed(ScoreKind::SuccessProbabilityOutOfRange {
)) => Kind::SuccessProbabilityOutOfRange {
probability: success_probability,
}),
},
notify::Kind::ScoringFailed(notify::ScoreKind::ObjectiveValueNonPositive(
quality,
gas_cost,
)) => Kind::ScoringFailed(ScoreKind::ObjectiveValueNonPositive {
)) => Kind::ObjectiveValueNonPositive {
quality: quality.0,
gas_cost: gas_cost.get().0,
}),
},
notify::Kind::NonBufferableTokensUsed(tokens) => Kind::NonBufferableTokensUsed {
tokens: tokens.into_iter().map(|token| token.0 .0).collect(),
},
Expand All @@ -69,16 +67,16 @@ impl Notification {
}
}
notify::Kind::DuplicatedSolutionId => Kind::DuplicatedSolutionId,
notify::Kind::Settled(kind) => Kind::Settled(match kind {
notify::Settlement::Success(hash) => Settlement::Success {
notify::Kind::Settled(kind) => match kind {
notify::Settlement::Success(hash) => Kind::Success {
transaction: hash.0,
},
notify::Settlement::Revert(hash) => Settlement::Revert {
notify::Settlement::Revert(hash) => Kind::Revert {
transaction: hash.0,
},
notify::Settlement::SimulationRevert => Settlement::SimulationRevert,
notify::Settlement::Fail => Settlement::Fail,
}),
notify::Settlement::SimulationRevert => Kind::Cancelled,
notify::Settlement::Fail => Kind::Fail,
},
},
}
}
Expand All @@ -95,42 +93,17 @@ pub struct Notification {

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "lowercase", tag = "kind")]
pub enum Kind {
Timeout,
EmptySolution,
DuplicatedSolutionId,
SimulationFailed(BlockNo, Tx, SimulationSucceededAtLeastOnce),
ScoringFailed(ScoreKind),
NonBufferableTokensUsed {
tokens: BTreeSet<eth::H160>,
},
SolverAccountInsufficientBalance {
#[serde_as(as = "serialize::U256")]
required: eth::U256,
#[serde(rename_all = "camelCase")]
SimulationFailed {
block: BlockNo,
tx: Tx,
succeeded_once: bool,
},
Settled(Settlement),
}

type BlockNo = u64;

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Tx {
pub from: eth::H160,
pub to: eth::H160,
#[serde_as(as = "serialize::Hex")]
pub input: Vec<u8>,
#[serde_as(as = "serialize::U256")]
pub value: eth::U256,
pub access_list: AccessList,
}

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum ScoreKind {
ZeroScore,
ScoreHigherThanQuality {
#[serde_as(as = "serialize::U256")]
Expand All @@ -148,14 +121,34 @@ pub enum ScoreKind {
#[serde_as(as = "serialize::U256")]
gas_cost: eth::U256,
},
NonBufferableTokensUsed {
tokens: BTreeSet<eth::H160>,
},
SolverAccountInsufficientBalance {
#[serde_as(as = "serialize::U256")]
required: eth::U256,
},
Success {
transaction: eth::H256,
},
Revert {
transaction: eth::H256,
},
Cancelled,
Fail,
}

type BlockNo = u64;

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Settlement {
Success { transaction: eth::H256 },
Revert { transaction: eth::H256 },
SimulationRevert,
Fail,
#[serde(rename_all = "camelCase")]
pub struct Tx {
pub from: eth::H160,
pub to: eth::H160,
#[serde_as(as = "serialize::Hex")]
pub input: Vec<u8>,
#[serde_as(as = "serialize::U256")]
pub value: eth::U256,
pub access_list: AccessList,
}
11 changes: 6 additions & 5 deletions crates/driver/src/infra/solver/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ impl Solutions {
Score::Solver { score } => {
competition::solution::SolverScore::Solver(score)
}
Score::RiskAdjusted(success_probability) => {
competition::solution::SolverScore::RiskAdjusted(success_probability)
}
Score::RiskAdjusted {
success_probability,
} => competition::solution::SolverScore::RiskAdjusted(success_probability),
},
weth,
)
Expand Down Expand Up @@ -377,11 +377,12 @@ enum SigningScheme {

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[serde(rename_all = "lowercase", deny_unknown_fields, tag = "kind")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
score: eth::U256,
},
RiskAdjusted(f64),
#[serde(rename_all = "camelCase")]
RiskAdjusted { success_probability: f64 },
}
6 changes: 4 additions & 2 deletions crates/driver/src/tests/cases/score_competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn solver_score_winner() {
.pool(ab_pool())
.order(ab_order())
.solution(ab_solution().score(Score::Solver { score: 2902421280589416499u128.into()})) // higher than objective value
.solution(ab_solution().score(Score::RiskAdjusted(0.4)))
.solution(ab_solution().score(Score::RiskAdjusted{ success_probability: 0.4}))
.done()
.await;

Expand All @@ -31,7 +31,9 @@ async fn risk_adjusted_score_winner() {
.solution(ab_solution().score(Score::Solver {
score: DEFAULT_SCORE_MIN.into(),
}))
.solution(ab_solution().score(Score::RiskAdjusted(0.9)))
.solution(ab_solution().score(Score::RiskAdjusted {
success_probability: 0.9,
}))
.done()
.await;

Expand Down
9 changes: 6 additions & 3 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ pub enum Partial {

#[serde_as]
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "lowercase", tag = "kind")]
pub enum Score {
Solver {
#[serde_as(as = "serialize::U256")]
score: eth::U256,
},
RiskAdjusted(f64),
#[serde(rename_all = "camelCase")]
RiskAdjusted { success_probability: f64 },
}

impl Default for Score {
fn default() -> Self {
Self::RiskAdjusted(1.0)
Self::RiskAdjusted {
success_probability: 1.0,
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/shared/src/http_solver/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
ethcontract::{Bytes, H160},
model::{
auction::AuctionId,
order::{Interactions, OrderData, OrderUid},
order::{OrderData, OrderUid},
ratio_as_decimal,
signature::Signature,
},
Expand Down Expand Up @@ -347,8 +347,6 @@ pub struct NativeLiquidityOrder {
pub data: OrderData,
#[serde(flatten)]
pub signature: Signature,
#[serde(default)]
pub interactions: Interactions,
}

#[serde_as]
Expand Down Expand Up @@ -1166,7 +1164,6 @@ mod tests {
..Default::default()
},
signature: Signature::Eip1271(vec![1, 2, 3, 4]),
interactions: Default::default(),
},
exec_sell_amount: 50.into(),
exec_buy_amount: 51.into(),
Expand Down
3 changes: 1 addition & 2 deletions crates/solver/src/solver/http_solver/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn convert_foreign_liquidity_orders(
},
data: liquidity.order.data,
signature: liquidity.order.signature,
interactions: liquidity.order.interactions,
interactions: Default::default(),
};
let converted = order_converter.normalize_limit_order(BalancedOrder::full(order))?;
Ok(ExecutedLimitOrder {
Expand Down Expand Up @@ -609,7 +609,6 @@ mod tests {
..Default::default()
},
signature: Signature::PreSign,
interactions: Default::default(),
},
exec_sell_amount: 101.into(),
exec_buy_amount: 102.into(),
Expand Down
Loading

0 comments on commit 3f89dc2

Please sign in to comment.