1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use brontes_macros::action_impl;
use brontes_pricing::Protocol;
use brontes_types::{normalized_actions::NormalizedNewPool, structured_trace::CallInfo};

action_impl!(
    Protocol::Dodo,
    crate::DodoDVMFactory::createDODOVendingMachineCall,
    NewPool,
    [NewDVM],
    logs: true,
    |info: CallInfo, log_data: DodoCreateDODOVendingMachineCallLogs, _| {
        let logs = log_data.new_d_v_m_field?;

        Ok(NormalizedNewPool {
            trace_index: info.trace_idx,
            protocol: Protocol::Dodo,
            pool_address: logs.dvm,
            tokens: vec![logs.baseToken, logs.quoteToken],
        })
    }
);

action_impl!(
    Protocol::Dodo,
    crate::DodoDSPFactory::createDODOStablePoolCall,
    NewPool,
    [NewDSP],
    logs: true,
    |info: CallInfo, log_data: DodoCreateDODOStablePoolCallLogs, _| {
        let logs = log_data.new_d_s_p_field?;

        Ok(NormalizedNewPool {
            trace_index: info.trace_idx,
            protocol: Protocol::Dodo,
            pool_address: logs.DSP,
            tokens: vec![logs.baseToken, logs.quoteToken],
        })
    }
);

action_impl!(
    Protocol::Dodo,
    crate::DodoDPPFactory::initDODOPrivatePoolCall,
    NewPool,
    [NewDPP],
    logs: true,
    |info: CallInfo, log_data: DodoInitDODOPrivatePoolCallLogs, _| {
        let logs = log_data.new_d_p_p_field?;

        let base_token = logs.baseToken;
        let quote_token = logs.quoteToken;

        Ok(NormalizedNewPool {
            trace_index: info.trace_idx,
            protocol: Protocol::Dodo,
            pool_address: logs.dpp,
            tokens: vec![base_token, quote_token],
        })
    }
);

#[cfg(test)]
mod tests {
    use alloy_primitives::{hex, Address, B256};
    use brontes_classifier::test_utils::ClassifierTestUtils;
    use brontes_types::{normalized_actions::Action, TreeSearchBuilder};

    use super::*;

    #[brontes_macros::test]
    async fn test_dodo_dvm_discovery() {
        let classifier_utils = ClassifierTestUtils::new().await;
        let tx =
            B256::from(hex!("620f07fc5d7781598214e2524b8c226ae8e475ec422fdad1272ab2775a80bf0a"));

        let new_pool = Action::NewPool(NormalizedNewPool {
            trace_index:  1,
            protocol:     Protocol::Dodo,
            pool_address: Address::new(hex!("0f5814de3581cb1d8ad2b608d6ef2e6409738c36")),
            tokens:       vec![
                Address::new(hex!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")),
                Address::new(hex!("9aFa9999e45484Adf5d8EED8D9Dfe0693BACd838")),
            ],
        });

        classifier_utils
            .contains_action(
                tx,
                0,
                new_pool,
                TreeSearchBuilder::default().with_action(Action::is_new_pool),
            )
            .await
            .unwrap();
    }

    #[brontes_macros::test]
    async fn test_dodo_dsp_discovery() {
        let classifier_utils = ClassifierTestUtils::new().await;
        let tx =
            B256::from(hex!("feb3000cd801ad15204235813eab94004d697ccba75cc9e082dc96c5e63c1529"));

        let new_pool = Action::NewPool(NormalizedNewPool {
            trace_index:  1,
            protocol:     Protocol::Dodo,
            pool_address: Address::new(hex!("ea2c9470aec6251ef10a28d783ab877d17706bc4")),
            tokens:       vec![
                Address::new(hex!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")),
                Address::new(hex!("99ea4dB9EE77ACD40B119BD1dC4E33e1C070b80d")),
            ],
        });

        classifier_utils
            .contains_action(
                tx,
                0,
                new_pool,
                TreeSearchBuilder::default().with_action(Action::is_new_pool),
            )
            .await
            .unwrap();
    }

    #[brontes_macros::test]
    async fn test_dodo_dpp_discovery() {
        let classifier_utils = ClassifierTestUtils::new().await;
        let tx =
            B256::from(hex!("6268fa8c5bf169e319d9e16734adc34199c8b0d7256bd9cec6aa18b7c18f1bcc"));

        let new_pool = Action::NewPool(NormalizedNewPool {
            trace_index:  10,
            protocol:     Protocol::Dodo,
            pool_address: Address::new(hex!("0b16EeAb0f35f07011886F3e72A8cd468a0009ed")),
            tokens:       vec![
                Address::new(hex!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")),
                Address::new(hex!("9d71CE49ab8A0E6D2a1e7BFB89374C9392FD6804")),
            ],
        });

        classifier_utils
            .contains_action(
                tx,
                0,
                new_pool,
                TreeSearchBuilder::default().with_action(Action::is_new_pool),
            )
            .await
            .unwrap();
    }
}