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
use alloy_primitives::Address;
use futures::Future;

use crate::{
    db::{
        address_metadata::AddressMetadata, block_analysis::BlockAnalysis, builder::BuilderInfo,
        dex::DexQuotes, searcher::SearcherInfo,
    },
    mev::{Bundle, MevBlock},
    normalized_actions::Action,
    structured_trace::TxTrace,
    BlockTree, Protocol,
};

#[auto_impl::auto_impl(&)]
pub trait DBWriter: Send + Unpin + 'static {
    /// allows for writing results to multiple databases
    type Inner: DBWriter;

    fn inner(&self) -> &Self::Inner;

    fn write_block_analysis(
        &self,
        block_analysis: BlockAnalysis,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner().write_block_analysis(block_analysis)
    }

    fn write_dex_quotes(
        &self,
        block_number: u64,
        quotes: Option<DexQuotes>,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner().write_dex_quotes(block_number, quotes)
    }

    fn write_token_info(
        &self,
        address: Address,
        decimals: u8,
        symbol: String,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner().write_token_info(address, decimals, symbol)
    }

    fn save_mev_blocks(
        &self,
        block_number: u64,
        block: MevBlock,
        mev: Vec<Bundle>,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner().save_mev_blocks(block_number, block, mev)
    }

    fn write_searcher_info(
        &self,
        eoa_address: Address,
        contract_address: Option<Address>,
        eoa_info: SearcherInfo,
        contract_info: Option<SearcherInfo>,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner()
            .write_searcher_info(eoa_address, contract_address, eoa_info, contract_info)
    }

    fn write_searcher_eoa_info(
        &self,
        searcher_eoa: Address,
        searcher_info: SearcherInfo,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner()
            .write_searcher_eoa_info(searcher_eoa, searcher_info)
    }

    fn write_searcher_contract_info(
        &self,
        searcher_contract: Address,
        searcher_info: SearcherInfo,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner()
            .write_searcher_contract_info(searcher_contract, searcher_info)
    }

    fn write_builder_info(
        &self,
        builder_address: Address,
        builder_info: BuilderInfo,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner()
            .write_builder_info(builder_address, builder_info)
    }

    fn write_address_meta(
        &self,
        address: Address,
        metadata: AddressMetadata,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner().write_address_meta(address, metadata)
    }

    fn insert_pool(
        &self,
        block: u64,
        address: Address,
        tokens: &[Address],
        curve_lp_token: Option<Address>,
        classifier_name: Protocol,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner()
            .insert_pool(block, address, tokens, curve_lp_token, classifier_name)
    }

    fn insert_tree(
        &self,
        tree: BlockTree<Action>,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner().insert_tree(tree)
    }

    fn save_traces(
        &self,
        block: u64,
        traces: Vec<TxTrace>,
    ) -> impl Future<Output = eyre::Result<()>> + Send {
        self.inner().save_traces(block, traces)
    }
}