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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
//! This module implements the `CexDexQuotesInspector`, a specialized inspector
//! designed to detect arbitrage opportunities between centralized
//! exchanges (CEXs) and decentralized exchanges (DEXs).
//!
//! ## Overview
//!
//! A Cex-Dex arbitrage occurs when a trader exploits the price difference
//! between a CEX and a DEX. The trader buys an undervalued asset on the DEX and
//! sells it on the CEX.
//!
//!
//! ## Methodology
//!
//! The `CexDexQuotesInspector` systematically identifies arbitrage
//! opportunities between CEXs and DEXs by analyzing transactions containing
//! swap actions.
//!
//! ### Step 1: Collect Transactions
//! All transactions containing swap actions are collected from the block tree
//! using `collect_all`.
//!
//! ### Step 2: Detect Arbitrage Opportunities
//! For each transaction with swaps, the inspector:
//!   - Retrieves CEX quotes for the swapped tokens for each exchange with
//!     `cex_quotes_for_swap`.
//!   - Calculates PnL post Cex & Dex fee and identifies arbitrage legs with
//!     `detect_cex_dex_opportunity`, considering both direct and intermediary
//!     token quotes.
//!   - Assembles `PossibleCexDexLeg` instances, for each swap, containing the
//!     swap action and the potential arbitrage legs i.e the different
//!     arbitrages that can be done for each exchange.
//!
//! ### Step 3: Profit Calculation and Gas Accounting
//! The inspector filters for the most profitable arbitrage path per swap i.e
//! for a given swap it gets the exchange with the highest profit
//! through `filter_most_profitable_leg`. It then gets the total potential
//! profit, and accounts for gas costs with `gas_accounting` to calculate the
//! transactions final PnL.
//!
//! ### Step 4: Validation and Bundle Construction
//! Arbitrage opportunities are validated and false positives minimized in
//! `filter_possible_cex_dex`. Valid opportunities are bundled into
//! `BundleData::CexDex` instances.
use std::{
    cmp::{max, min},
    sync::Arc,
};

use alloy_primitives::Address;
use brontes_database::libmdbx::LibmdbxReader;
use brontes_metrics::inspectors::OutlierMetrics;
use brontes_types::{
    db::cex::{quotes::FeeAdjustedQuote, CexExchange},
    display::utils::format_etherscan_url,
    mev::{Bundle, BundleData, MevType},
    normalized_actions::{accounting::ActionAccounting, Action, NormalizedSwap},
    pair::Pair,
    tree::{BlockTree, GasDetails},
    BlockData, FastHashMap, MultiBlockData, ToFloatNearest, TreeCollector, TreeSearchBuilder,
    TxInfo,
};
use malachite::{
    num::{arithmetic::traits::Reciprocal, basic::traits::Zero},
    Rational,
};
use tracing::{debug, trace};

use super::types::{
    log_cex_dex_quote_delta, CexDexProcessing, ExchangeLeg, ExchangeLegCexPrice, PossibleCexDex,
};

pub const FILTER_THRESHOLD: u64 = 20;

use itertools::Itertools;

use crate::{shared_utils::SharedInspectorUtils, Inspector, Metadata};
pub struct CexDexQuotesInspector<'db, DB: LibmdbxReader> {
    utils:                SharedInspectorUtils<'db, DB>,
    _quotes_fetch_offset: u64,
    _cex_exchanges:       Vec<CexExchange>,
}

impl<'db, DB: LibmdbxReader> CexDexQuotesInspector<'db, DB> {
    /// Constructs a new `CexDexQuotesInspector`.
    ///
    /// # Arguments
    ///
    /// * `quote` - The address of the quote asset
    /// * `db` - Database reader to our local libmdbx database
    /// * `cex_exchanges` - List of centralized exchanges to consider for
    ///   arbitrage.
    pub fn new(
        quote: Address,
        db: &'db DB,
        cex_exchanges: &[CexExchange],
        quotes_fetch_offset: u64,
        metrics: Option<OutlierMetrics>,
    ) -> Self {
        Self {
            utils:                SharedInspectorUtils::new(quote, db, metrics),
            _quotes_fetch_offset: quotes_fetch_offset,
            _cex_exchanges:       cex_exchanges.to_owned(),
        }
    }
}

impl<DB: LibmdbxReader> Inspector for CexDexQuotesInspector<'_, DB> {
    type Result = Vec<Bundle>;

    fn get_id(&self) -> &str {
        "CexDex"
    }

    fn get_quote_token(&self) -> Address {
        self.utils.quote
    }

    fn inspect_block(&self, data: MultiBlockData) -> Self::Result {
        let block = data.get_most_recent_block();
        let BlockData { metadata, tree } = block;

        if metadata.cex_quotes.quotes.is_empty() {
            tracing::warn!("no cex quotes for this block");
            return vec![]
        }

        self.utils
            .get_metrics()
            .map(|m| {
                m.run_inspector(MevType::CexDexQuotes, || {
                    self.inspect_block_inner(tree.clone(), metadata.clone())
                })
            })
            .unwrap_or_else(|| self.inspect_block_inner(tree.clone(), metadata.clone()))
    }
}

impl<DB: LibmdbxReader> CexDexQuotesInspector<'_, DB> {
    /// Processes the block tree to find CEX-DEX arbitrage
    /// opportunities. This is the entry point for the inspection process,
    /// identifying transactions that include swap actions.
    ///
    /// # Arguments
    /// * `tree` - A shared reference to the block tree.
    /// * `metadata` - Shared metadata struct containing:
    ///     - `cex_quotes` - CEX quotes
    ///     - `dex_quotes` - DEX quotes
    ///     - `private_flow` - Set of private transactions that were not seen in
    ///       the mempool
    ///     - `relay & p2p_timestamp` - When the block was first sent to a relay
    ///       & when it was first seen in the p2p network
    ///
    ///
    /// # Returns
    /// A vector of `Bundle` instances representing classified CEX-DEX arbitrage
    fn inspect_block_inner(
        &self,
        tree: Arc<BlockTree<Action>>,
        metadata: Arc<Metadata>,
    ) -> Vec<Bundle> {
        tree.clone()
            .collect_all(TreeSearchBuilder::default().with_actions([
                Action::is_swap,
                Action::is_transfer,
                Action::is_eth_transfer,
                Action::is_aggregator,
            ]))
            .filter_map(|(tx, swaps)| {
                let tx_info = tree.get_tx_info(tx, self.utils.db)?;

                // Return early if this is an defi automation contract
                if let Some(contract_type) = tx_info.contract_type.as_ref() {
                    if contract_type.is_defi_automation() {
                        return None
                    }
                }

                let deltas = swaps
                    .clone()
                    .into_iter()
                    .chain(
                        tx_info
                            .get_total_eth_value()
                            .iter()
                            .cloned()
                            .map(Action::from),
                    )
                    .account_for_actions();

                let (mut dex_swaps, rem): (Vec<_>, _) = self
                    .utils
                    .flatten_nested_actions(swaps.into_iter(), &|action| action.is_swap())
                    .split_return_rem(Action::try_swaps_merged);

                let transfers: Vec<_> = rem.into_iter().split_actions(Action::try_transfer);

                // robust way & deduplicate the swaps post
                if dex_swaps.is_empty() {
                    if let Some(extra) = self.utils.cex_try_convert_transfer_to_swap(
                        transfers,
                        &tx_info,
                        MevType::CexDexQuotes,
                    ) {
                        dex_swaps.push(extra);
                    }
                }

                if dex_swaps.is_empty() {
                    trace!(    target: "brontes::cex-dex-quotes",
                "no dex swaps found\n Tx: {}", format_etherscan_url(&tx_info.tx_hash));
                    return None
                }

                if self.is_triangular_arb(&dex_swaps) {
                    trace!(
                        target: "brontes::cex-dex-markout",
                        "Filtered out CexDex because it is a triangular arb\n Tx: {}",
                        format_etherscan_url(&tx_info.tx_hash)
                    );
                    self.utils.get_metrics().inspect(|m| {
                        m.branch_filtering_trigger(MevType::CexDexQuotes, "is_triangular_arb")
                    });

                    return None
                }

                let mut possible_cex_dex: CexDexProcessing =
                    self.detect_cex_dex(dex_swaps, &metadata, &tx_info)?;

                self.gas_accounting(&mut possible_cex_dex, &tx_info.gas_details, metadata.clone());

                let price_map = possible_cex_dex.pnl.trade_prices.clone().into_iter().fold(
                    FastHashMap::default(),
                    |mut acc, x| {
                        acc.insert(x.token0, x.price0);
                        acc.insert(x.token1, x.price1);
                        acc
                    },
                );

                let (profit_usd, cex_dex) =
                    self.filter_possible_cex_dex(possible_cex_dex, &tx_info, &metadata)?;

                let header = self.utils.build_bundle_header(
                    vec![deltas],
                    vec![tx_info.tx_hash],
                    &tx_info,
                    profit_usd,
                    &[tx_info.gas_details],
                    metadata.clone(),
                    MevType::CexDexQuotes,
                    false,
                    |_, token, amount| Some(price_map.get(&token)? * amount),
                );

                Some(Bundle { header, data: cex_dex })
            })
            .collect::<Vec<_>>()
    }

    pub fn detect_cex_dex(
        &self,
        dex_swaps: Vec<NormalizedSwap>,
        metadata: &Metadata,
        tx_info: &TxInfo,
    ) -> Option<CexDexProcessing> {
        //TODO: Add smiths map to query most liquid dex for given pair
        //
        let swaps = SharedInspectorUtils::<DB>::cex_merge_possible_swaps(dex_swaps);

        let quotes = self.cex_quotes_for_swap(&swaps, metadata, 0, None);
        let cex_dex = self.detect_cex_dex_opportunity(&swaps, quotes, metadata, tx_info)?;
        let cex_dex_processing = CexDexProcessing { dex_swaps: swaps, pnl: cex_dex };
        Some(cex_dex_processing)
    }

    /// Detects potential CEX-DEX arbitrage opportunities for a sequence of
    /// swaps
    ///
    /// # Arguments
    ///
    /// * `dex_swaps` - The DEX swaps to analyze.
    /// * `metadata` - Combined metadata for additional context in analysis.
    /// * `cex_prices` - Fee adjusted CEX quotes for the corresponding swaps.
    ///
    /// # Returns
    ///
    /// An option containing a `PossibleCexDex` if an opportunity is found,
    /// otherwise `None`.
    pub fn detect_cex_dex_opportunity(
        &self,
        dex_swaps: &[NormalizedSwap],
        cex_prices: Vec<Option<FeeAdjustedQuote>>,
        metadata: &Metadata,
        tx_info: &TxInfo,
    ) -> Option<PossibleCexDex> {
        PossibleCexDex::from_exchange_legs(
            dex_swaps
                .iter()
                .zip(cex_prices)
                .map(|(dex_swap, quote)| {
                    if let Some(q) = quote {
                        self.profit_classifier(dex_swap, q, metadata, tx_info)
                    } else {
                        None
                    }
                })
                .collect_vec(),
        )
    }

    /// For a given DEX swap & CEX quote, calculates the potential profit from
    /// buying on DEX and selling on CEX.
    fn profit_classifier(
        &self,
        swap: &NormalizedSwap,
        cex_quote: FeeAdjustedQuote,
        metadata: &Metadata,
        tx_info: &TxInfo,
    ) -> Option<(ExchangeLeg, ExchangeLegCexPrice)> {
        let maker_taker_mid = cex_quote.maker_taker_mid();

        let output_of_cex_trade_maker = &maker_taker_mid.0 * &swap.amount_out;

        let smaller = min(&swap.amount_in, &output_of_cex_trade_maker);
        let larger = max(&swap.amount_in, &output_of_cex_trade_maker);

        // A positive amount indicates potential profit from selling the token in on the
        // DEX and buying it on the CEX.
        let maker_token_delta = &output_of_cex_trade_maker - &swap.amount_in;

        let token_price = metadata
            .cex_quotes
            .get_quote_from_most_liquid_exchange(
                &Pair(swap.token_in.address, self.utils.quote),
                metadata.microseconds_block_timestamp(),
                None,
            )?
            .maker_taker_mid()
            .0;

        // Amount * base_to_quote = USDT amount
        let base_to_quote = if token_price == Rational::ZERO {
            trace!("Token price is zero");
            return None
        } else {
            token_price.clone().reciprocal()
        };

        if maker_taker_mid.0 == Rational::ZERO || swap.amount_out == Rational::ZERO {
            return None
        }

        let pairs_price = ExchangeLegCexPrice {
            token0: swap.token_in.address,
            price0: base_to_quote.clone(),
            token1: swap.token_out.address,
            price1: (&token_price * maker_taker_mid.0.clone().reciprocal()).reciprocal(),
        };

        let pnl_mid = &maker_token_delta * &base_to_quote;

        let max_diff = max_arb_delta(tx_info, &pnl_mid);

        if smaller * max_diff < *larger {
            log_cex_dex_quote_delta(
                &tx_info.tx_hash.to_string(),
                swap.token_in_symbol(),
                swap.token_out_symbol(),
                &cex_quote.exchange,
                swap.swap_rate().clone().to_float(),
                cex_quote.price_maker.0.clone().to_float(),
                &swap.token_in.address,
                &swap.token_out.address,
                &swap.amount_in,
                &swap.amount_out,
                &output_of_cex_trade_maker,
            );
            return None
        }

        Some((
            ExchangeLeg {
                pnl:           pnl_mid.to_float(),
                cex_mid_price: maker_taker_mid.0.to_float(),
                exchange:      cex_quote.exchange,
            },
            pairs_price,
        ))
    }

    /// Retrieves CEX quotes for a DEX swap, analyzing both direct and
    /// intermediary token pathways.
    fn cex_quotes_for_swap(
        &self,
        dex_swaps: &[NormalizedSwap],
        metadata: &Metadata,
        time_delta: u64,
        max_time_diff: Option<u64>,
    ) -> Vec<Option<FeeAdjustedQuote>> {
        dex_swaps
            .iter()
            .map(|dex_swap| {
                let pair = Pair(dex_swap.token_in.address, dex_swap.token_out.address);

                metadata
                    .cex_quotes
                    .get_quote_from_most_liquid_exchange(
                        &pair,
                        metadata.microseconds_block_timestamp() + (time_delta * 1_000_000),
                        max_time_diff,
                    )
                    .or_else(|| {
                        debug!(
                            "No CEX quote found for pair: {}-{}",
                            dex_swap.token_in_symbol(),
                            dex_swap.token_out_symbol(),
                        );
                        None
                    })
            })
            .collect()
    }

    /// Accounts for gas costs in the calculation of potential arbitrage
    /// profits. This function calculates the final pnl for the transaction by
    /// subtracting gas costs from the total potential arbitrage profits.
    fn gas_accounting(
        &self,
        cex_dex: &mut CexDexProcessing,
        gas_details: &GasDetails,
        metadata: Arc<Metadata>,
    ) {
        let gas_cost = metadata.get_gas_price_usd(gas_details.gas_paid(), self.utils.quote);

        cex_dex.pnl.adjust_for_gas_cost(gas_cost);
    }

    /// Filters and validates identified CEX-DEX arbitrage opportunities to
    /// minimize false positives.
    ///
    /// # Arguments
    /// * `possible_cex_dex` - The arbitrage opportunity being validated.
    /// * `info` - Transaction info providing additional context for validation.
    ///
    /// # Returns
    /// An option containing `BundleData::CexDex` if a valid opportunity is
    /// identified, otherwise `None`.
    fn filter_possible_cex_dex(
        &self,
        possible_cex_dex: CexDexProcessing,
        info: &TxInfo,
        metadata: &Metadata,
    ) -> Option<(f64, BundleData)> {
        let is_cex_dex_bot_with_significant_activity =
            info.is_searcher_of_type_with_count_threshold(MevType::CexDexQuotes, FILTER_THRESHOLD);
        let is_labelled_cex_dex_bot = info.is_labelled_searcher_of_type(MevType::CexDexQuotes);

        let should_include_based_on_pnl = possible_cex_dex.pnl.aggregate_pnl > 1.5;

        let should_include_if_know_cex_dex = possible_cex_dex.pnl.aggregate_pnl > 0.0;

        let is_cex_dex_based_on_historical_activity = (is_cex_dex_bot_with_significant_activity
            || is_labelled_cex_dex_bot)
            && should_include_if_know_cex_dex;

        if is_cex_dex_based_on_historical_activity || should_include_based_on_pnl {
            let t2 = self
                .cex_quotes_for_swap(&possible_cex_dex.dex_swaps, metadata, 2, None)
                .into_iter()
                .map(|quote_option| {
                    quote_option.map_or(0.0, |quote| quote.maker_taker_mid().0.to_float())
                })
                .collect_vec();

            let t12 = self
                .cex_quotes_for_swap(&possible_cex_dex.dex_swaps, metadata, 12, Some(500_000))
                .into_iter()
                .map(|quote_option| {
                    quote_option.map_or(0.0, |quote| quote.maker_taker_mid().0.to_float())
                })
                .collect_vec();

            let t30 = self
                .cex_quotes_for_swap(&possible_cex_dex.dex_swaps, metadata, 30, Some(2_000_000))
                .into_iter()
                .map(|quote_option| {
                    quote_option.map_or(0.0, |quote| quote.maker_taker_mid().0.to_float())
                })
                .collect_vec();

            let t60 = self
                .cex_quotes_for_swap(&possible_cex_dex.dex_swaps, metadata, 60, Some(4_000_000))
                .into_iter()
                .map(|quote_option| {
                    quote_option.map_or(0.0, |quote| quote.maker_taker_mid().0.to_float())
                })
                .collect_vec();

            let t300 = self
                .cex_quotes_for_swap(&possible_cex_dex.dex_swaps, metadata, 300, Some(15_000_000))
                .into_iter()
                .map(|quote_option| {
                    quote_option.map_or(0.0, |quote| quote.maker_taker_mid().0.to_float())
                })
                .collect_vec();

            possible_cex_dex.into_bundle(info, metadata.block_timestamp, t2, t12, t30, t60, t300)
        } else {
            None
        }
    }

    /// Filters out triangular arbitrage
    pub fn is_triangular_arb(&self, dex_swaps: &[NormalizedSwap]) -> bool {
        // Not enough swaps to form a cycle, thus cannot be an atomic triangular
        // arbitrage.
        if dex_swaps.len() < 2 {
            return false
        }

        let original_token = dex_swaps[0].token_in.address;
        let final_token = dex_swaps.last().unwrap().token_out.address;

        original_token == final_token
    }
}

pub fn max_arb_delta(tx_info: &TxInfo, pnl: &Rational) -> Rational {
    let mut base_diff = 3;

    if tx_info.is_labelled_searcher_of_type(MevType::CexDexQuotes)
        || tx_info.is_labelled_searcher_of_type(MevType::CexDexTrades)
    {
        if pnl < &Rational::from(5) {
            base_diff += 7;
        } else if pnl < &Rational::from(40) {
            base_diff += 5;
        } else if pnl < &Rational::from(100) {
            base_diff += 2;
        }
    } else if tx_info
        .contract_type
        .as_ref()
        .map_or(false, |c| c.is_mev_contract())
    {
        base_diff += 1;
    }

    Rational::from(base_diff)
}

#[cfg(test)]
mod tests {

    use alloy_primitives::hex;
    use brontes_types::constants::{USDT_ADDRESS, WBTC_ADDRESS, WETH_ADDRESS};

    use crate::{
        test_utils::{InspectorTestUtils, InspectorTxRunConfig},
        Inspectors,
    };
    // 0x77d0b50f0da1a77856a44821599aa1cdd06558c4bcdfdb323e14969619be6d2c

    #[brontes_macros::test]
    async fn test_cex_dex() {
        let inspector_util = InspectorTestUtils::new(USDT_ADDRESS, 50.5).await;

        let tx = hex!("21b129d221a4f169de0fc391fe0382dbde797b69300a9a68143487c54d620295").into();

        let config = InspectorTxRunConfig::new(Inspectors::CexDex)
            .with_mev_tx_hashes(vec![tx])
            .with_expected_profit_usd(1931.53)
            .with_gas_paid_usd(78754.85);

        inspector_util.run_inspector(config, None).await.unwrap();
    }

    #[brontes_macros::test]
    async fn test_eoa_cex_dex() {
        let inspector_util = InspectorTestUtils::new(USDT_ADDRESS, 50.5).await;

        let tx = hex!("dfe3152caaf92e5a9428827ea94eff2a822ddcb22129499da4d5b6942a7f203e").into();

        let config = InspectorTxRunConfig::new(Inspectors::CexDex)
            .with_mev_tx_hashes(vec![tx])
            .with_expected_profit_usd(8941.5750)
            .with_gas_paid_usd(6267.29);

        inspector_util.run_inspector(config, None).await.unwrap();
    }

    #[brontes_macros::test]
    async fn test_not_triangular_arb_false_positive() {
        let inspector_util = InspectorTestUtils::new(USDT_ADDRESS, 0.5).await;

        let tx = hex!("3329c54fef27a24cef640fbb28f11d3618c63662bccc4a8c5a0d53d13267652f").into();

        let config = InspectorTxRunConfig::new(Inspectors::CexDex)
            .with_mev_tx_hashes(vec![tx])
            .needs_tokens(vec![WETH_ADDRESS, WBTC_ADDRESS]);

        inspector_util.assert_no_mev(config).await.unwrap();
    }

    #[brontes_macros::test]
    async fn test_not_triangular_arb_false_positive_simple() {
        let inspector_util = InspectorTestUtils::new(USDT_ADDRESS, 0.5).await;

        let tx = hex!("31a1572dad67e949cff13d6ede0810678f25a30c6a3c67424453133bb822bd26").into();

        let config = InspectorTxRunConfig::new(Inspectors::CexDex)
            .with_mev_tx_hashes(vec![tx])
            .needs_token(hex!("aa7a9ca87d3694b5755f213b5d04094b8d0f0a6f").into());

        inspector_util.assert_no_mev(config).await.unwrap();
    }
}