kabu_defi_pools/protocols/
uniswapv2.rs1use alloy::primitives::{b256, Address, Bytes, B256};
2use alloy::sol_types::SolCall;
3use kabu_defi_abi::uniswap2::IUniswapV2Pair;
4use kabu_defi_address_book::FactoryAddress;
5
6use crate::protocols::helper::get_uniswap2pool_address;
7use crate::protocols::match_abi;
8use crate::protocols::protocol::Protocol;
9
10pub struct UniswapV2Protocol {}
11
12impl UniswapV2Protocol {
13 pub fn is_code(code: &Bytes) -> bool {
14 match_abi(
15 code,
16 vec![
17 IUniswapV2Pair::swapCall::SELECTOR,
18 IUniswapV2Pair::mintCall::SELECTOR,
19 IUniswapV2Pair::syncCall::SELECTOR,
20 IUniswapV2Pair::token0Call::SELECTOR,
21 IUniswapV2Pair::factoryCall::SELECTOR,
22 ],
23 )
24 }
25
26 pub fn get_pool_address_for_tokens(token0: Address, token1: Address) -> Address {
27 let init_code: B256 = b256!("96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f");
28 get_uniswap2pool_address(token0, token1, FactoryAddress::UNISWAP_V2, init_code)
29 }
30}
31
32impl Protocol for UniswapV2Protocol {
33 fn get_pool_address_vec_for_tokens(token0: Address, token1: Address) -> Vec<Address> {
34 vec![UniswapV2Protocol::get_pool_address_for_tokens(token0, token1)]
35 }
36}