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

Function analyze_simulation

crates/shared/src/order_creation_simulation.rs:157–200  ·  view source on GitHub ↗

Runs the simulation, handles errors caused by fundamental limitations of the simulation approach and returns a comprehensive report in case of an error.

(
    order: &Order,
    inputs: EthCallInputs,
)

Source from the content-addressed store, hash-verified

155/// the simulation approach and returns a comprehensive report in case of an
156/// error.
157async fn analyze_simulation(
158 order: &Order,
159 inputs: EthCallInputs,
160) -> Result<SimulationSuccess, OrderSimulationError> {
161 let report = inputs
162 .simulation_report()
163 .await
164 .map_err(|err| OrderSimulationError::Infra(anyhow!(err).context("simulate")))?;
165
166 let revert_reason = match extract_critical_revert(
167 order,
168 inputs.simulator.settlement_address(),
169 &inputs.failed_state_overrides,
170 &report,
171 ) {
172 Some(revert) => revert,
173 None => {
174 let gas = if matches!(order.signature, Signature::Eip1271(_)) {
175 report
176 .eip1271_gas_cost(&order.metadata.owner)
177 .map_err(OrderSimulationError::Infra)?
178 } else {
179 0
180 };
181
182 return Ok(SimulationSuccess {
183 eip1271_signature_verification_gas: gas,
184 });
185 }
186 };
187
188 let tenderly = inputs.simulator.tenderly();
189 let tenderly_request = inputs.to_tenderly_request().ok();
190 let tenderly_url = match (tenderly, tenderly_request.as_ref()) {
191 (Some(api), Some(req)) => api.simulate_and_share(req.clone()).await.ok(),
192 _ => None,
193 };
194 Err(OrderSimulationError::Reverted {
195 reason: revert_reason,
196 summary: report.events,
197 tenderly_url,
198 tenderly_request: tenderly_request.map(Box::new),
199 })
200}
201
202/// Analyzes the simulation and only surfaces a revert if it was critical
203/// (as opposed to being caused by limitations of the simulation

Callers 1

simulateMethod · 0.85

Calls 10

extract_critical_revertFunction · 0.85
simulation_reportMethod · 0.80
contextMethod · 0.80
eip1271_gas_costMethod · 0.80
okMethod · 0.80
to_tenderly_requestMethod · 0.80
simulate_and_shareMethod · 0.80
settlement_addressMethod · 0.45
tenderlyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected