defuse/
simulation_output.rs

1use defuse_core::{
2    Deadline, Result, Salt,
3    accounts::{AccountEvent, NonceEvent},
4    engine::deltas::InvariantViolated,
5    fees::Pips,
6    intents::IntentEvent,
7};
8
9// #[cfg_attr(
10//     all(feature = "abi", not(target_arch = "wasm32")),
11//     serde_as(schemars = true)
12// )]
13use near_sdk::near;
14// use serde_with::serde_as;
15
16#[near(serializers = [json])]
17#[derive(Debug, Clone)]
18pub struct SimulationReport {
19    pub intents_executed: Vec<IntentEvent<AccountEvent<'static, NonceEvent>>>,
20    pub logs: Vec<String>,
21    pub min_deadline: Deadline,
22}
23
24#[near(serializers = [json])]
25#[derive(Debug, Clone)]
26pub struct SimulationOutput {
27    #[serde(flatten)]
28    pub report: SimulationReport,
29
30    /// Unmatched token deltas needed to keep the invariant.
31    /// If not empty, can be used along with fee to calculate `token_diff` closure.
32    #[serde(default, skip_serializing_if = "Option::is_none")]
33    pub invariant_violated: Option<InvariantViolated>,
34
35    /// Additional info about current state
36    pub state: StateOutput,
37}
38
39impl SimulationOutput {
40    pub fn into_result(self) -> Result<(), InvariantViolated> {
41        if let Some(unmatched_deltas) = self.invariant_violated {
42            return Err(unmatched_deltas);
43        }
44        Ok(())
45    }
46}
47
48#[near(serializers = [json])]
49#[derive(Debug, Clone)]
50pub struct StateOutput {
51    pub fee: Pips,
52
53    pub current_salt: Salt,
54}