MCPcopy Create free account
hub / github.com/cowprotocol/services / new

Method new

crates/driver/src/tests/setup/solver.rs:61–543  ·  view source on GitHub ↗

Set up an HTTP server exposing a solver API and acting as a solver mock.

(config: Config<'_>)

Source from the content-addressed store, hash-verified

59impl Solver {
60 /// Set up an HTTP server exposing a solver API and acting as a solver mock.
61 pub async fn new(config: Config<'_>) -> Self {
62 let mut solutions_json = Vec::new();
63 let mut orders_json = Vec::new();
64 for quote in config.quoted_orders.iter().filter(|q| !q.order.filtered) {
65 // ETH orders get unwrapped into WETH by the driver before being passed to the
66 // solver.
67 let sell_token = if quote.order.sell_token == "ETH" {
68 "WETH"
69 } else {
70 quote.order.sell_token
71 };
72 let buy_token = if quote.order.buy_token == "ETH" {
73 "WETH"
74 } else {
75 quote.order.buy_token
76 };
77 let sell_amount = match quote.order.side {
78 order::Side::Buy if config.quote => {
79 "22300745198530623141535718272648361505980416".to_owned()
80 }
81 order::Side::Buy => {
82 let mut current_sell_amount = quote.sell_amount();
83 for fee_policy in &quote.order.fee_policy {
84 match fee_policy {
85 // If the fees are handled in the driver, for volume based fee, we
86 // artificially reduce the limit sell amount
87 // for buy orders before sending to solvers. This
88 // allows driver to withhold volume based fee and not violate original
89 // limit prices.
90 fee::Policy::Volume { factor }
91 if config.fee_handler == FeeHandler::Driver =>
92 {
93 current_sell_amount = eth::TokenAmount(current_sell_amount)
94 .apply_factor(1.0 / (1.0 + factor))
95 .unwrap()
96 .0;
97 }
98 _ => {}
99 }
100 }
101 // Make-room for the haircut: the driver subtracts a haircut
102 // post-hoc from buy_amount() (sell orders) / adds it to
103 // sell_amount() (buy orders). Tightening the auction limits
104 // here ensures solvers bid with enough headroom.
105 if config.haircut_bps > 0 {
106 let factor = f64::from(config.haircut_bps) / 10_000.0;
107 current_sell_amount = eth::TokenAmount(current_sell_amount)
108 .apply_factor(1.0 / (1.0 + factor))
109 .unwrap()
110 .0;
111 }
112 current_sell_amount.to_string()
113 }
114 _ => quote.sell_amount().to_string(),
115 };
116 let buy_amount = match quote.order.side {
117 order::Side::Sell if config.quote => "1".to_owned(),
118 order::Side::Sell => {

Callers

nothing calls this directly

Calls 15

adjustmentsFunction · 0.85
postFunction · 0.85
check_solve_requestFunction · 0.85
unwrapMethod · 0.80
apply_factorMethod · 0.80
to_stringMethod · 0.80
collectMethod · 0.80
to_json_valueMethod · 0.80
extendMethod · 0.80
get_token_wrappedMethod · 0.80
order_uidMethod · 0.80
routeMethod · 0.80

Tested by

no test coverage detected