mev_engine/amm/jediswap/
factory.rs1use std::{sync::Arc, time::Duration};
2
3use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5use starknet::{
6 core::{
7 types::{BlockId, BlockTag, Felt, FunctionCall, StarknetError},
8
9 },
10 providers::Provider,
11};
12
13use crate::{
14 amm::{
15 factory::AutomatedMarketMakerFactory,
16 pool::{AutomatedMarketMaker, AMM},
17 },
18 errors::AMMError,
19};
20
21use super::{
22 get_data::{get_all_pools, get_pool_info},
23};
24
25
26#[derive(Serialize, Deserialize, Clone, Debug)]
27pub struct JediswapFactory {
28 pub factory_address: Felt,
29}
30
31#[async_trait]
32impl AutomatedMarketMakerFactory for JediswapFactory {
33 fn address(&self) -> Felt {
34 self.factory_address
35 }
36
37 async fn fetch_all_pools<P>(&mut self, provider: Arc<P>) -> Result<Vec<AMM>, AMMError>
38 where
39 P: Provider + Sync + Send,
40 {
41 let pool_addresses = get_all_pools(self, provider.clone()).await.unwrap();
42 let mut all_pools = vec![];
43 let mut first_val = true;
44
45 for pool_address in pool_addresses {
46 if first_val {
47 first_val = false;
48 continue;
49 }
50 let pool = get_pool_info(pool_address, provider.clone()).await.unwrap();
51
52 tokio::time::sleep(Duration::from_millis(200)).await;
53 all_pools.push(AMM::JediswapPool(pool));
54 }
55 Ok(all_pools)
56 }
57
58 async fn populate_amm_data<P>(
59 &self,
60 amms: &mut [AMM],
61 _block_number: Option<u64>,
62 middleware: Arc<P>,
63 ) -> Result<(), AMMError>
64 where
65 P: Provider + Sync + Send,
66 {
67 for amm in amms {
68 get_pool_info(amm.address(), middleware.clone())
69 .await
70 .unwrap();
71 }
72 Ok(())
73 }
74
75 fn amm_created_event_signature(&self) -> Vec<Vec<Felt>> {
76 vec![vec![Felt::ONE]]
77 }
78}
79
80impl JediswapFactory {
81 pub fn new(factory_address: Felt) -> JediswapFactory {
82 JediswapFactory { factory_address }
83 }
84}