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,
)
| 155 | /// the simulation approach and returns a comprehensive report in case of an |
| 156 | /// error. |
| 157 | async 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 |
no test coverage detected