diff --git a/crates/solvers-dto/src/auction.rs b/crates/solvers-dto/src/auction.rs index 9e532c85a0..8260ddfaf8 100644 --- a/crates/solvers-dto/src/auction.rs +++ b/crates/solvers-dto/src/auction.rs @@ -231,67 +231,49 @@ pub struct TokenInfo { impl ToSchema<'static> for TokenInfo { fn schema() -> (&'static str, RefOr) { - ( - "TokenInfo", - Schema::Object( - ObjectBuilder::new() - .description(Some("Information about an ERC20 token.")) - .required("availableBalance") - .required("trusted") - .property( - "decimals", - ObjectBuilder::new() - .schema_type(SchemaType::Integer) - .description(Some( - "The ERC20.decimals value for this token. This may be missing for \ - ERC20 tokens that don't implement the optional metadata \ - extension.", - )), - ) - .property( - "symbol", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .description(Some( - "The ERC20.symbol value for this token. This may be missing for \ - ERC20 tokens that don't implement the optional metadata \ - extension.", - )), - ) - .property( - "referencePrice", - AllOfBuilder::new() - .description(Some( - "The reference price of this token for the auction used for \ - scoring. This price is only included for tokens for which there \ - are CoW Protocol orders.", - )) - .item(Ref::from_schema_name("NativePrice")), - ) - .property( - "availableBalance", - AllOfBuilder::new() - .description(Some( - "The balance held by the Settlement contract that is available \ - during a settlement.", - )) - .item(Ref::from_schema_name("TokenAmount")), - ) - .property( - "trusted", - ObjectBuilder::new() - .schema_type(SchemaType::Boolean) - .description(Some( - "A flag which indicates that solvers are allowed to perform gas \ - cost optimizations for this token by not routing the trades via \ - an AMM, and instead use its available balances, as specified by \ - CIP-2.", - )), - ) - .build(), - ) - .into(), - ) + let decimals = ObjectBuilder::new() + .schema_type(SchemaType::Integer) + .description(Some( + "The ERC20.decimals value for this token. This may be missing for ERC20 tokens \ + that don't implement the optional metadata extension.", + )); + let symbol = ObjectBuilder::new() + .schema_type(SchemaType::String) + .description(Some( + "The ERC20.symbol value for this token. This may be missing for ERC20 tokens that \ + don't implement the optional metadata extension.", + )); + let reference_price = AllOfBuilder::new() + .description(Some( + "The reference price of this token for the auction used for scoring. This price \ + is only included for tokens for which there are CoW Protocol orders.", + )) + .item(Ref::from_schema_name("NativePrice")); + let available_balance = AllOfBuilder::new() + .description(Some( + "The balance held by the Settlement contract that is available during a \ + settlement.", + )) + .item(Ref::from_schema_name("TokenAmount")); + let trusted = ObjectBuilder::new() + .schema_type(SchemaType::Boolean) + .description(Some( + "A flag which indicates that solvers are allowed to perform gas cost \ + optimizations for this token by not routing the trades via an AMM, and instead \ + use its available balances, as specified by CIP-2.", + )); + let auction = ObjectBuilder::new() + .description(Some("Information about an ERC20 token.")) + .required("availableBalance") + .required("trusted") + .property("decimals", decimals) + .property("symbol", symbol) + .property("referencePrice", reference_price) + .property("availableBalance", available_balance) + .property("trusted", trusted) + .build(); + + ("TokenInfo", Schema::Object(auction).into()) } } @@ -310,57 +292,42 @@ pub enum Liquidity { // automated and deleted. impl ToSchema<'static> for Liquidity { fn schema() -> (&'static str, RefOr) { - ( - "Liquidity", - Schema::AllOf( - AllOfBuilder::new() - .description(Some( - "On-chain liquidity that can be used in a solution. This liquidity is \ - provided to facilitate onboarding new solvers. Additional liquidity that \ - is not included in this set may still be used in solutions.", - )) - .item(Ref::from_schema_name("LiquidityParameters")) - .item(Schema::Object( - ObjectBuilder::new() - .property( - "id", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .description(Some( - "An opaque ID used for uniquely identifying the liquidity \ - within a single auction (note that they are **not** \ - guaranteed to be unique across auctions). This ID is \ - used in the solution for matching interactions with the \ - executed liquidity.", - )), - ) - .property( - "address", - AllOfBuilder::new() - .description(Some( - "A rough approximation of gas units required to use this \ - liquidity on-chain.", - )) - .item(Ref::from_schema_name("Address")), - ) - .property( - "gasEstimate", - AllOfBuilder::new() - .description(Some( - "A rough approximation of gas units required to use this \ - liquidity on-chain.", - )) - .item(Ref::from_schema_name("BigInt")), - ) - .required("id") - .required("address") - .required("gasEstimate") - .build(), - )) - .build(), - ) - .into(), - ) + let id = ObjectBuilder::new() + .schema_type(SchemaType::String) + .description(Some( + "An opaque ID used for uniquely identifying the liquidity within a single auction \ + (note that they are **not** guaranteed to be unique across auctions). This ID is \ + used in the solution for matching interactions with the executed liquidity.", + )); + let address = AllOfBuilder::new() + .description(Some( + "A rough approximation of gas units required to use this liquidity on-chain.", + )) + .item(Ref::from_schema_name("Address")); + let gas_estimate = AllOfBuilder::new() + .description(Some( + "A rough approximation of gas units required to use this liquidity on-chain.", + )) + .item(Ref::from_schema_name("BigInt")); + let liquidity_obj = ObjectBuilder::new() + .property("id", id) + .property("address", address) + .property("gasEstimate", gas_estimate) + .required("id") + .required("address") + .required("gasEstimate") + .build(); + let liquidity = AllOfBuilder::new() + .description(Some( + "On-chain liquidity that can be used in a solution. This liquidity is provided to \ + facilitate onboarding new solvers. Additional liquidity that is not included in \ + this set may still be used in solutions.", + )) + .item(Ref::from_schema_name("LiquidityParameters")) + .item(Schema::Object(liquidity_obj)) + .build(); + + ("Liquidity", Schema::AllOf(liquidity).into()) } } @@ -408,34 +375,29 @@ pub struct ConstantProductPool { impl ToSchema<'static> for ConstantProductPool { fn schema() -> (&'static str, RefOr) { + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["constantProduct"])); + let tokens = ObjectBuilder::new() + .description(Some("A mapping of token address to its reserve amounts.")) + .additional_properties(Some(Ref::from_schema_name("TokenReserve"))); + let constant_product_pool = ObjectBuilder::new() + .description(Some( + "A UniswapV2-like constant product liquidity pool for a token pair.", + )) + .required("kind") + .required("router") + .required("tokens") + .required("fee") + .property("kind", kind) + .property("router", Ref::from_schema_name("Address")) + .property("tokens", tokens) + .property("fee", Ref::from_schema_name("Decimal")) + .build(); + ( "ConstantProductPool", - Schema::Object( - ObjectBuilder::new() - .description(Some( - "A UniswapV2-like constant product liquidity pool for a token pair.", - )) - .required("kind") - .required("router") - .required("tokens") - .required("fee") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["constantProduct"])), - ) - .property("router", Ref::from_schema_name("Address")) - .property( - "tokens", - ObjectBuilder::new() - .description(Some("A mapping of token address to its reserve amounts.")) - .additional_properties(Some(Ref::from_schema_name("TokenReserve"))), - ) - .property("fee", Ref::from_schema_name("Decimal")) - .build(), - ) - .into(), + Schema::Object(constant_product_pool).into(), ) } } @@ -466,56 +428,46 @@ pub struct WeightedProductPool { impl ToSchema<'static> for WeightedProductPool { fn schema() -> (&'static str, RefOr) { - ( - "WeightedProductPool", - Schema::Object( - ObjectBuilder::new() - .description(Some( - "A Balancer-like weighted product liquidity pool of N tokens.", - )) - .required("kind") - .required("tokens") - .required("fee") - .required("balancer_pool_id") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["weightedProduct"])), - ) - .property( - "tokens", - ObjectBuilder::new() - .description(Some( - "A mapping of token address to its reserve amounts with weights.", - )) - .additional_properties(Some(Schema::AllOf( - AllOfBuilder::new() - .item(Ref::from_schema_name("TokenReserve")) - .item( - ObjectBuilder::new() - .required("weight") - .property("weight", Ref::from_schema_name("Decimal")) - .property( - "scalingFactor", - Ref::from_schema_name("Decimal"), - ) - .build(), - ) - .build(), - ))), - ) - .property("fee", Ref::from_schema_name("Decimal")) - .property("balancer_pool_id", Ref::from_schema_name("BalancerPoolId")) - .property( - "version", + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["weightedProduct"])); + let tokens = ObjectBuilder::new() + .description(Some( + "A mapping of token address to its reserve amounts with weights.", + )) + .additional_properties(Some(Schema::AllOf( + AllOfBuilder::new() + .item(Ref::from_schema_name("TokenReserve")) + .item( ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["v0", "v3Plus"])), + .required("weight") + .property("weight", Ref::from_schema_name("Decimal")) + .property("scalingFactor", Ref::from_schema_name("Decimal")) + .build(), ) .build(), - ) - .into(), + ))); + let version = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["v0", "v3Plus"])); + let weighted_product_pool = ObjectBuilder::new() + .description(Some( + "A Balancer-like weighted product liquidity pool of N tokens.", + )) + .required("kind") + .required("tokens") + .required("fee") + .required("balancer_pool_id") + .property("kind", kind) + .property("tokens", tokens) + .property("fee", Ref::from_schema_name("Decimal")) + .property("balancer_pool_id", Ref::from_schema_name("BalancerPoolId")) + .property("version", version) + .build(); + + ( + "WeightedProductPool", + Schema::Object(weighted_product_pool).into(), ) } } @@ -553,50 +505,41 @@ pub struct StablePool { impl ToSchema<'static> for StablePool { fn schema() -> (&'static str, RefOr) { - ( - "StablePool", - Schema::Object( - ObjectBuilder::new() - .description(Some("A Curve-like stable pool of N tokens.")) - .required("kind") - .required("tokens") - .required("amplificationParameter") - .required("fee") - .required("balancer_pool_id") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["stable"])), - ) - .property( - "tokens", + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["stable"])); + let tokens = ObjectBuilder::new() + .description(Some( + "A mapping of token address to token balance and scaling rate.", + )) + .additional_properties(Some(Schema::AllOf( + AllOfBuilder::new() + .item(Ref::from_schema_name("TokenReserve")) + .item( ObjectBuilder::new() - .description(Some( - "A mapping of token address to token balance and scaling rate.", - )) - .additional_properties(Some(Schema::AllOf( - AllOfBuilder::new() - .item(Ref::from_schema_name("TokenReserve")) - .item( - ObjectBuilder::new() - .required("scalingFactor") - .property( - "scalingFactor", - Ref::from_schema_name("Decimal"), - ) - .build(), - ) - .build(), - ))), + .required("scalingFactor") + .property("scalingFactor", Ref::from_schema_name("Decimal")) + .build(), ) - .property("amplificationParameter", Ref::from_schema_name("Decimal")) - .property("fee", Ref::from_schema_name("Decimal")) - .property("balancer_pool_id", Ref::from_schema_name("BalancerPoolId")) .build(), - ) - .into(), - ) + ))); + let stable_pool = Schema::Object( + ObjectBuilder::new() + .description(Some("A Curve-like stable pool of N tokens.")) + .required("kind") + .required("tokens") + .required("amplificationParameter") + .required("fee") + .required("balancer_pool_id") + .property("kind", kind) + .property("tokens", tokens) + .property("amplificationParameter", Ref::from_schema_name("Decimal")) + .property("fee", Ref::from_schema_name("Decimal")) + .property("balancer_pool_id", Ref::from_schema_name("BalancerPoolId")) + .build(), + ); + + ("StablePool", stable_pool.into()) } } @@ -631,43 +574,36 @@ pub struct ConcentratedLiquidityPool { impl ToSchema<'static> for ConcentratedLiquidityPool { fn schema() -> (&'static str, RefOr) { + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["concentratedLiquidity"])); + let liquidity_net = ObjectBuilder::new() + .description(Some("A map of tick indices to their liquidity values.")) + .additional_properties(Some(Ref::from_schema_name("I128"))); + let tokens = ArrayBuilder::new().items(Ref::from_schema_name("Token")); + let concentrated_liquidity_pool = ObjectBuilder::new() + .description(Some("A Uniswap V3-like concentrated liquidity pool.")) + .required("kind") + .required("router") + .required("tokens") + .required("sqrtPrice") + .required("liquidity") + .required("tick") + .required("liquidityNet") + .required("fee") + .property("kind", kind) + .property("router", Ref::from_schema_name("Address")) + .property("tokens", tokens) + .property("sqrtPrice", Ref::from_schema_name("U256")) + .property("liquidity", Ref::from_schema_name("U128")) + .property("tick", Ref::from_schema_name("I32")) + .property("liquidityNet", liquidity_net) + .property("fee", Ref::from_schema_name("Decimal")) + .build(); + ( "ConcentratedLiquidityPool", - Schema::Object( - ObjectBuilder::new() - .description(Some("A Uniswap V3-like concentrated liquidity pool.")) - .required("kind") - .required("router") - .required("tokens") - .required("sqrtPrice") - .required("liquidity") - .required("tick") - .required("liquidityNet") - .required("fee") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["concentratedLiquidity"])), - ) - .property("router", Ref::from_schema_name("Address")) - .property( - "tokens", - ArrayBuilder::new().items(Ref::from_schema_name("Token")), - ) - .property("sqrtPrice", Ref::from_schema_name("U256")) - .property("liquidity", Ref::from_schema_name("U128")) - .property("tick", Ref::from_schema_name("I32")) - .property( - "liquidityNet", - ObjectBuilder::new() - .description(Some("A map of tick indices to their liquidity values.")) - .additional_properties(Some(Ref::from_schema_name("I128"))), - ) - .property("fee", Ref::from_schema_name("Decimal")) - .build(), - ) - .into(), + Schema::Object(concentrated_liquidity_pool).into(), ) } } @@ -695,31 +631,28 @@ pub struct ForeignLimitOrder { impl ToSchema<'static> for ForeignLimitOrder { fn schema() -> (&'static str, RefOr) { + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["limitOrder"])); + let foreign_limit_order = ObjectBuilder::new() + .description(Some("A 0x-like limit order external to CoW Protocol.")) + .required("kind") + .required("makerToken") + .required("takerToken") + .required("makerAmount") + .required("takerAmount") + .required("takerTokenFeeAmount") + .property("kind", kind) + .property("makerToken", Ref::from_schema_name("Token")) + .property("takerToken", Ref::from_schema_name("Token")) + .property("makerAmount", Ref::from_schema_name("TokenAmount")) + .property("takerAmount", Ref::from_schema_name("TokenAmount")) + .property("takerTokenFeeAmount", Ref::from_schema_name("TokenAmount")) + .build(); + ( "ForeignLimitOrder", - Schema::Object( - ObjectBuilder::new() - .description(Some("A 0x-like limit order external to CoW Protocol.")) - .required("kind") - .required("makerToken") - .required("takerToken") - .required("makerAmount") - .required("takerAmount") - .required("takerTokenFeeAmount") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["limitOrder"])), - ) - .property("makerToken", Ref::from_schema_name("Token")) - .property("takerToken", Ref::from_schema_name("Token")) - .property("makerAmount", Ref::from_schema_name("TokenAmount")) - .property("takerAmount", Ref::from_schema_name("TokenAmount")) - .property("takerTokenFeeAmount", Ref::from_schema_name("TokenAmount")) - .build(), - ) - .into(), + Schema::Object(foreign_limit_order).into(), ) } } @@ -816,47 +749,35 @@ pub struct SurplusFee { impl ToSchema<'static> for SurplusFee { fn schema() -> (&'static str, RefOr) { - ( - "SurplusFee", - Schema::Object( - ObjectBuilder::new() - .description(Some( - "If the order receives more than limit price, pay the protocol a factor \ - of the difference.", - )) - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["surplus"])), - ) - .property( - "factor", - ObjectBuilder::new() - .description(Some( - "The factor of the user surplus that the protocol will request \ - from the solver after settling the order", - )) - .schema_type(SchemaType::Number) - .example(Number::from_f64(0.5).map(Value::Number)) - .build(), - ) - .property( - "maxVolumeFactor", - ObjectBuilder::new() - .description(Some( - "Never charge more than that percentage of the order volume.", - )) - .schema_type(SchemaType::Number) - .example(Number::from_f64(0.05).map(Value::Number)) - .minimum(Some(0.0)) - .maximum(Some(0.99999)) - .build(), - ) - .build(), - ) - .into(), - ) + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["surplus"])); + let factor = ObjectBuilder::new() + .description(Some( + "The factor of the user surplus that the protocol will request from the solver \ + after settling the order", + )) + .schema_type(SchemaType::Number) + .example(Number::from_f64(0.5).map(Value::Number)); + let max_volume_factor = ObjectBuilder::new() + .description(Some( + "Never charge more than that percentage of the order volume.", + )) + .schema_type(SchemaType::Number) + .example(Number::from_f64(0.05).map(Value::Number)) + .minimum(Some(0.0)) + .maximum(Some(0.99999)); + let surplus_fee = ObjectBuilder::new() + .description(Some( + "If the order receives more than limit price, pay the protocol a factor of the \ + difference.", + )) + .property("kind", kind) + .property("factor", factor) + .property("maxVolumeFactor", max_volume_factor) + .build(); + + ("SurplusFee", Schema::Object(surplus_fee).into()) } } @@ -868,46 +789,35 @@ pub struct PriceImprovement { impl ToSchema<'static> for PriceImprovement { fn schema() -> (&'static str, RefOr) { - ( - "PriceImprovement", - Schema::Object( - ObjectBuilder::new() - .description(Some( - "A cut from the price improvement over the best quote is taken as a \ - protocol fee.", - )) - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["priceImprovement"])), - ) - .property( - "factor", - ObjectBuilder::new() - .description(Some( - "The factor of the user surplus that the protocol will request \ - from the solver after settling the order", - )) - .schema_type(SchemaType::Number) - .example(Number::from_f64(0.5).map(Value::Number)), - ) - .property( - "maxVolumeFactor", - ObjectBuilder::new() - .description(Some( - "Never charge more than that percentage of the order volume.", - )) - .schema_type(SchemaType::Number) - .example(Number::from_f64(0.01).map(Value::Number)) - .minimum(Some(0.0)) - .maximum(Some(0.99999)), - ) - .property("quote", Ref::from_schema_name("Quote")) - .build(), - ) - .into(), - ) + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["priceImprovement"])); + let factor = ObjectBuilder::new() + .description(Some( + "The factor of the user surplus that the protocol will request from the solver \ + after settling the order", + )) + .schema_type(SchemaType::Number) + .example(Number::from_f64(0.5).map(Value::Number)); + let max_volume_factor = ObjectBuilder::new() + .description(Some( + "Never charge more than that percentage of the order volume.", + )) + .schema_type(SchemaType::Number) + .example(Number::from_f64(0.01).map(Value::Number)) + .minimum(Some(0.0)) + .maximum(Some(0.99999)); + let price_improvement = ObjectBuilder::new() + .description(Some( + "A cut from the price improvement over the best quote is taken as a protocol fee.", + )) + .property("kind", kind) + .property("factor", factor) + .property("maxVolumeFactor", max_volume_factor) + .property("quote", Ref::from_schema_name("Quote")) + .build(); + + ("PriceImprovement", Schema::Object(price_improvement).into()) } } @@ -917,29 +827,21 @@ pub struct VolumeFee { impl ToSchema<'static> for VolumeFee { fn schema() -> (&'static str, RefOr) { - ( - "VolumeFee", - Schema::Object( - ObjectBuilder::new() - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["volume"])), - ) - .property( - "factor", - ObjectBuilder::new() - .description(Some( - "The fraction of the order's volume that the protocol will \ - request from the solver after settling the order.", - )) - .schema_type(SchemaType::Number) - .example(Number::from_f64(0.5).map(Value::Number)), - ) - .build(), - ) - .into(), - ) + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["volume"])); + let factor = ObjectBuilder::new() + .description(Some( + "The fraction of the order's volume that the protocol will request from the \ + solver after settling the order.", + )) + .schema_type(SchemaType::Number) + .example(Number::from_f64(0.5).map(Value::Number)); + let volume_fee = ObjectBuilder::new() + .property("kind", kind) + .property("factor", factor) + .build(); + + ("VolumeFee", Schema::Object(volume_fee).into()) } } diff --git a/crates/solvers-dto/src/notification.rs b/crates/solvers-dto/src/notification.rs index 99471e0f7f..38d001fd90 100644 --- a/crates/solvers-dto/src/notification.rs +++ b/crates/solvers-dto/src/notification.rs @@ -25,59 +25,48 @@ pub struct Notification { // serde(flatten) has a conflict with the current API schema impl ToSchema<'static> for Notification { fn schema() -> (&'static str, RefOr) { - ( - "Notification", - Schema::Object( - ObjectBuilder::new() - .description(Some( - "A notification that informs the solver how its solution performed in the \ - auction. Depending on the notification type additional meta data may be \ - attached but this is not guaranteed to be stable.", - )) - .schema_type(SchemaType::Object) - .property( - "auctionId", - ObjectBuilder::new() - .description(Some( - "The auction ID of the auction that the solution was providedfor.", - )) - .schema_type(SchemaType::String), - ) - .property( - "solutionId", - ObjectBuilder::new() - .description(Some( - "The solution ID within the auction for which the notification \ - applies", - )) - .schema_type(SchemaType::Number), - ) - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some([ - "timeout", - "emptySolution", - "duplicatedSolutionId", - "simulationFailed", - "invalidClearingPrices", - "missingPrice", - "invalidExecutedAmount", - "nonBufferableTokensUsed", - "solverAccountInsufficientBalance", - "success", - "revert", - "driverError", - "cancelled", - "fail", - "postprocessingTimedOut", - ])), - ) - .build(), - ) - .into(), - ) + let auction_id = ObjectBuilder::new() + .description(Some( + "The auction ID of the auction that the solution was providedfor.", + )) + .schema_type(SchemaType::String); + let solution_id = ObjectBuilder::new() + .description(Some( + "The solution ID within the auction for which the notification applies", + )) + .schema_type(SchemaType::Number); + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some([ + "timeout", + "emptySolution", + "duplicatedSolutionId", + "simulationFailed", + "invalidClearingPrices", + "missingPrice", + "invalidExecutedAmount", + "nonBufferableTokensUsed", + "solverAccountInsufficientBalance", + "success", + "revert", + "driverError", + "cancelled", + "fail", + "postprocessingTimedOut", + ])); + let notification = ObjectBuilder::new() + .description(Some( + "A notification that informs the solver how its solution performed in the \ + auction. Depending on the notification type additional meta data may be attached \ + but this is not guaranteed to be stable.", + )) + .schema_type(SchemaType::Object) + .property("auctionId", auction_id) + .property("solutionId", solution_id) + .property("kind", kind) + .build(); + + ("Notification", Schema::Object(notification).into()) } } diff --git a/crates/solvers-dto/src/solution.rs b/crates/solvers-dto/src/solution.rs index 15101c2a73..44e27952bd 100644 --- a/crates/solvers-dto/src/solution.rs +++ b/crates/solvers-dto/src/solution.rs @@ -59,19 +59,15 @@ pub enum Trade { impl ToSchema<'static> for Trade { fn schema() -> (&'static str, RefOr) { - ( - "Trade", - Schema::OneOf( - OneOfBuilder::new() - .description(Some( - "A trade for a CoW Protocol order included in a solution.", - )) - .item(Ref::from_schema_name("Fulfillment")) - .item(Ref::from_schema_name("JitTrade")) - .build(), - ) - .into(), - ) + let trade = OneOfBuilder::new() + .description(Some( + "A trade for a CoW Protocol order included in a solution.", + )) + .item(Ref::from_schema_name("Fulfillment")) + .item(Ref::from_schema_name("JitTrade")) + .build(); + + ("Trade", Schema::OneOf(trade).into()) } } @@ -90,49 +86,36 @@ pub struct Fulfillment { impl ToSchema<'static> for Fulfillment { fn schema() -> (&'static str, RefOr) { - ( - "Fulfillment", - Schema::Object( - ObjectBuilder::new() - .description(Some("A trade which fulfills an order from the auction.")) - .required("kind") - .required("order") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["fulfillment"])), - ) - .property( - "order", - AllOfBuilder::new() - .item(Ref::from_schema_name("OrderUid")) - .description(Some( - "A reference by UID of the order to execute in a solution. The \ - order must be included in the auction input.", - )), - ) - .property( - "executedAmount", - AllOfBuilder::new() - .description(Some( - "The amount of the order that was executed. This is denoted in \ - 'sellToken' for sell orders, and 'buyToken' for buy orders.", - )) - .item(Ref::from_schema_name("TokenAmount")), - ) - .property( - "fee", - ObjectBuilder::new().description(Some( - "The sell token amount that should be taken as a fee for this trade. \ - This only gets returned for limit orders and only refers to the \ - actual amount filled by the trade.", - )), - ) - .build(), - ) - .into(), - ) + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["fulfillment"])); + let order = AllOfBuilder::new() + .item(Ref::from_schema_name("OrderUid")) + .description(Some( + "A reference by UID of the order to execute in a solution. The order must be \ + included in the auction input.", + )); + let executed_amount = AllOfBuilder::new() + .description(Some( + "The amount of the order that was executed. This is denoted in 'sellToken' for \ + sell orders, and 'buyToken' for buy orders.", + )) + .item(Ref::from_schema_name("TokenAmount")); + let fee = ObjectBuilder::new().description(Some( + "The sell token amount that should be taken as a fee for this trade. This only gets \ + returned for limit orders and only refers to the actual amount filled by the trade.", + )); + let fulfillment = ObjectBuilder::new() + .description(Some("A trade which fulfills an order from the auction.")) + .required("kind") + .required("order") + .property("kind", kind) + .property("order", order) + .property("executedAmount", executed_amount) + .property("fee", fee) + .build(); + + ("Fulfillment", Schema::Object(fulfillment).into()) } } @@ -147,41 +130,31 @@ pub struct JitTrade { impl ToSchema<'static> for JitTrade { fn schema() -> (&'static str, RefOr) { - ( - "JitTrade", - Schema::Object( - ObjectBuilder::new() - .description(Some("A trade with a JIT order.")) - .required("kind") - .required("order") - .required("executedAmount") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["jit"])), - ) - .property( - "order", - AllOfBuilder::new() - .description(Some( - "The just-in-time liquidity order to execute in a solution.", - )) - .item(Ref::from_schema_name("JitOrder")), - ) - .property( - "executedAmount", - AllOfBuilder::new() - .description(Some( - "The amount of the order that was executed. This is denoted in \ - 'sellToken' for sell orders, and 'buyToken' for buy orders.", - )) - .item(Ref::from_schema_name("TokenAmount")), - ) - .build(), - ) - .into(), - ) + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["jit"])); + let order = AllOfBuilder::new() + .description(Some( + "The just-in-time liquidity order to execute in a solution.", + )) + .item(Ref::from_schema_name("JitOrder")); + let executed_amount = AllOfBuilder::new() + .description(Some( + "The amount of the order that was executed. This is denoted in 'sellToken' for \ + sell orders, and 'buyToken' for buy orders.", + )) + .item(Ref::from_schema_name("TokenAmount")); + let jit_trade = ObjectBuilder::new() + .description(Some("A trade with a JIT order.")) + .required("kind") + .required("order") + .required("executedAmount") + .property("kind", kind) + .property("order", order) + .property("executedAmount", executed_amount) + .build(); + + ("JitTrade", Schema::Object(jit_trade).into()) } } @@ -237,32 +210,26 @@ pub enum Interaction { // automated and deleted. impl ToSchema<'static> for Interaction { fn schema() -> (&'static str, RefOr) { - ( - "Interaction", - Schema::AllOf( - AllOfBuilder::new() - .description(Some("An interaction to execute as part of a settlement.")) - .item( - ObjectBuilder::new().property( - "internalize", - ObjectBuilder::new() - .schema_type(SchemaType::Boolean) - .description(Some( - "A flag indicating that the interaction should be \ - 'internalized', as specified by CIP-2.", - )) - .build(), - ), - ) - .item( - OneOfBuilder::new() - .item(Ref::from_schema_name("LiquidityInteraction")) - .item(Ref::from_schema_name("CustomInteraction")), - ) - .build(), + let internalize = ObjectBuilder::new().property( + "internalize", + ObjectBuilder::new() + .schema_type(SchemaType::Boolean) + .description(Some( + "A flag indicating that the interaction should be 'internalized', as \ + specified by CIP-2.", + )), + ); + let interaction = AllOfBuilder::new() + .description(Some("An interaction to execute as part of a settlement.")) + .item(internalize) + .item( + OneOfBuilder::new() + .item(Ref::from_schema_name("LiquidityInteraction")) + .item(Ref::from_schema_name("CustomInteraction")), ) - .into(), - ) + .build(); + + ("Interaction", Schema::AllOf(interaction).into()) } } @@ -289,42 +256,36 @@ pub struct LiquidityInteraction { impl ToSchema<'static> for LiquidityInteraction { fn schema() -> (&'static str, RefOr) { + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["liquidity"])); + let id = ObjectBuilder::new() + .schema_type(SchemaType::String) + .description(Some( + "The ID of executed liquidity provided in the auction input.", + )); + let liquidity_interaction = ObjectBuilder::new() + .description(Some( + "Interaction representing the execution of liquidity that was passed in with the \ + auction.", + )) + .required("kind") + .required("id") + .required("inputToken") + .required("outputToken") + .required("inputAmount") + .required("outputAmount") + .property("kind", kind) + .property("id", id) + .property("inputToken", Ref::from_schema_name("Token")) + .property("outputToken", Ref::from_schema_name("Token")) + .property("inputAmount", Ref::from_schema_name("TokenAmount")) + .property("outputAmount", Ref::from_schema_name("TokenAmount")) + .build(); + ( "LiquidityInteraction", - Schema::Object( - ObjectBuilder::new() - .description(Some( - "Interaction representing the execution of liquidity that was passed in \ - with the auction.", - )) - .required("kind") - .required("id") - .required("inputToken") - .required("outputToken") - .required("inputAmount") - .required("outputAmount") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["liquidity"])), - ) - .property( - "id", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .description(Some( - "The ID of executed liquidity provided in the auction input.", - )) - .build(), - ) - .property("inputToken", Ref::from_schema_name("Token")) - .property("outputToken", Ref::from_schema_name("Token")) - .property("inputAmount", Ref::from_schema_name("TokenAmount")) - .property("outputAmount", Ref::from_schema_name("TokenAmount")) - .build(), - ) - .into(), + Schema::Object(liquidity_interaction).into(), ) } } @@ -349,60 +310,43 @@ pub struct CustomInteraction { impl ToSchema<'static> for CustomInteraction { fn schema() -> (&'static str, RefOr) { + let kind = ObjectBuilder::new() + .schema_type(SchemaType::String) + .enum_values(Some(["custom"])); + let call_data = ObjectBuilder::new() + .schema_type(SchemaType::String) + .description(Some("The EVM calldata bytes.")) + .example(Some(Value::String("0x01020304".to_string()))); + let allowances = ArrayBuilder::new() + .items(Ref::from_schema_name("Allowance")) + .description(Some( + "ERC20 allowances that are required for this custom interaction.", + )); + let asset = ArrayBuilder::new() + .items(Ref::from_schema_name("Asset")) + .build(); + let custom_interaction = ObjectBuilder::new() + .description(Some( + "A searcher-specified custom interaction to be included in the final settlement.", + )) + .required("kind") + .required("target") + .required("value") + .required("callData") + .required("inputs") + .required("outputs") + .property("kind", kind) + .property("target", Ref::from_schema_name("Address")) + .property("value", Ref::from_schema_name("TokenAmount")) + .property("callData", call_data) + .property("allowances", allowances) + .property("inputs", asset.clone()) + .property("outputs", asset) + .build(); + ( "CustomInteraction", - Schema::Object( - ObjectBuilder::new() - .description(Some( - "A searcher-specified custom interaction to be included in the final \ - settlement.", - )) - .required("kind") - .required("target") - .required("value") - .required("callData") - .required("inputs") - .required("outputs") - .property( - "kind", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .enum_values(Some(["custom"])), - ) - .property("target", Ref::from_schema_name("Address")) - .property("value", Ref::from_schema_name("TokenAmount")) - .property( - "callData", - ObjectBuilder::new() - .schema_type(SchemaType::String) - .description(Some("The EVM calldata bytes.")) - .example(Some(Value::String("0x01020304".to_string()))) - .build(), - ) - .property( - "allowances", - ArrayBuilder::new() - .items(Ref::from_schema_name("Allowance")) - .description(Some( - "ERC20 allowances that are required for this custom interaction.", - )) - .build(), - ) - .property( - "inputs", - ArrayBuilder::new() - .items(Ref::from_schema_name("Asset")) - .build(), - ) - .property( - "outputs", - ArrayBuilder::new() - .items(Ref::from_schema_name("Asset")) - .build(), - ) - .build(), - ) - .into(), + Schema::Object(custom_interaction).into(), ) } } @@ -445,16 +389,15 @@ pub enum SellTokenBalance { impl ToSchema<'static> for SellTokenBalance { fn schema() -> (&'static str, RefOr) { + let sell_token_balance = ObjectBuilder::new() + .description(Some("Where should the sell token be drawn from?")) + .schema_type(SchemaType::String) + .enum_values(Some(["erc20", "internal", "external"])) + .build(); + ( "SellTokenBalance", - Schema::Object( - ObjectBuilder::new() - .description(Some("Where should the sell token be drawn from?")) - .schema_type(SchemaType::String) - .enum_values(Some(["erc20", "internal", "external"])) - .build(), - ) - .into(), + Schema::Object(sell_token_balance).into(), ) } } @@ -469,17 +412,13 @@ pub enum BuyTokenBalance { impl ToSchema<'static> for BuyTokenBalance { fn schema() -> (&'static str, RefOr) { - ( - "BuyTokenBalance", - Schema::Object( - ObjectBuilder::new() - .description(Some("Where should the buy token be transferred to?")) - .schema_type(SchemaType::String) - .enum_values(Some(["erc20", "internal"])) - .build(), - ) - .into(), - ) + let buy_token_balance = ObjectBuilder::new() + .description(Some("Where should the buy token be transferred to?")) + .schema_type(SchemaType::String) + .enum_values(Some(["erc20", "internal"])) + .build(); + + ("BuyTokenBalance", Schema::Object(buy_token_balance).into()) } } @@ -494,16 +433,12 @@ pub enum SigningScheme { impl ToSchema<'static> for SigningScheme { fn schema() -> (&'static str, RefOr) { - ( - "SigningScheme", - Schema::Object( - ObjectBuilder::new() - .description(Some("How was the order signed?")) - .schema_type(SchemaType::String) - .enum_values(Some(["eip712", "ethSign", "preSign", "eip1271"])) - .build(), - ) - .into(), - ) + let signing_scheme = ObjectBuilder::new() + .description(Some("How was the order signed?")) + .schema_type(SchemaType::String) + .enum_values(Some(["eip712", "ethSign", "preSign", "eip1271"])) + .build(); + + ("SigningScheme", Schema::Object(signing_scheme).into()) } }