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

Update SolverEngine API docs #2192

Merged
merged 9 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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,
}
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
78 changes: 70 additions & 8 deletions crates/solvers/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,43 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/Solution"
type: array
items:
$ref: "#/components/schemas/Solution"
400:
description: There is something wrong with the request.
429:
description: The solver cannot keep up. It is too busy to handle more requests.
500:
description: Something went wrong when handling the request.
/notify:
post:
description: |
Receive a status notification about a previously provided solution
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
auctionId:
description: |
The auction ID of the auction that the solution was provided
for.
type: number
solutionId:
description: |
The solution ID within the auction for which the notification applies
type: number
kind:
description: |
The kind of notification.
type: string
enum: [Timeout, EmptySolution, DuplicatedSolutionId, SimulationFailed, ZeroScore, ScoreHigherThanQuality, SuccessProbabilityOutOfRange, ObjectiveValueNonPositive, NonBufferableTokensUsed, SolverAccountInsufficientBalance, Success, Revert, Cancelled, Failed]
responses:
200:
description: notification successfully received.

components:
schemas:
Expand Down Expand Up @@ -282,6 +312,9 @@ components:
$ref: "#/components/schemas/Decimal"
fee:
$ref: "#/components/schemas/Decimal"
version:
type: string
enum: ["v0", "v3plus"]

StablePool:
description: |
Expand Down Expand Up @@ -535,6 +568,11 @@ components:
must be included in the auction input.
allOf:
- $ref: "#/components/schemas/OrderUid"
fee:
description: |
The sell token amount that should be taken as a fee for this
trade. This only gets returned for partially fillable limit
orders and only refers to the actual amount filled by the trade.

JitTrade:
description: |
Expand Down Expand Up @@ -569,11 +607,6 @@ components:
"sellToken" for sell orders, and "buyToken" for buy orders.
allOf:
- $ref: "#/components/schemas/TokenAmount"
Copy link
Contributor

Choose a reason for hiding this comment

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

The executedAmount also appears to be outdated.
It's actually part of JitTrade and Fulfillment and should probably not be listed on the Trade. Also it's not a TokenAmount but a simple U256.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since JitTrade and Fulfillment are flattened this actually checks out (cf the example responses)
image

Will still put it on each type. TokenAmount is just a placeholder for U256 though.

fee:
description: |
The sell token amount that should be taken as a fee for this
trade. This only gets returned for partially fillable limit
orders and only refers to the actual amount filled by the trade.

LiquidityInteraction:
description: |
Expand Down Expand Up @@ -630,7 +663,7 @@ components:
- kind
- target
- value
- callData
- calldata
- inputs
- outputs
properties:
Expand All @@ -641,7 +674,7 @@ components:
$ref: "#/components/schemas/Address"
value:
$ref: "#/components/schemas/TokenAmount"
callData:
calldata:
description: |
The EVM calldata bytes.
type: string
Expand Down Expand Up @@ -681,10 +714,15 @@ components:
The computed solution for a given auction.
type: object
required:
- id
- prices
- trades
- interactions
- score
properties:
id:
description: An opaque identifier for the solution.
type: number
prices:
description: |
A clearing price map of token address to price. The price can have
Expand All @@ -704,3 +742,27 @@ components:
type: array
items:
$ref: "#/components/schemas/Interaction"
score:
description: |
Information required by the driver to score the solution.

Can either be a raw score or a revert probability.
fleupold marked this conversation as resolved.
Show resolved Hide resolved
oneOf:
- type: object
properties:
solver:
type: object
properties:
score:
description: |
The raw score of the solution. This is the score that is
used by the driver to rank solutions.
allOf:
- $ref: "#/components/schemas/Decimal"
- type: object
properties:
riskAdjusted:
description: |
The revert probability of the solution. Used by the driver to compute a risk-adjusted score.
type: number
example: 0.9
Loading
Loading