pub struct CentralContext {
pub markets: RwLock<HashMap<Pubkey, HashMap<Pubkey, Arc<RwLock<Vec<Arc<RwLock<dyn PoolTrait>>>>>>>>,
pub json_rpc_client: RpcClient,
pub json_rpc_client_async: RpcClient,
pub raydium_cpmm_fee_rates_lp: HashMap<Pubkey, u64>,
pub meteora_vault_cache: Mutex<HashMap<Pubkey, Arc<RwLock<MeteoraVault>>>>,
pub pf_bonding_curves: Mutex<HashMap<Pubkey, Arc<RwLock<PfBondingCurve>>>>,
pub raydium_launchpads: Mutex<HashMap<Pubkey, Arc<RwLock<RaydiumLaunchpad>>>>,
pub legit_tokens: Mutex<HashMap<Pubkey, bool>>,
pub legit_update_authorities: HashSet<Pubkey>,
pub pools_map: RwLock<HashMap<Pubkey, Arc<RwLock<dyn PoolTrait>>>>,
pub current_slot: RwLock<u64>,
pub latest_blockhash: RwLock<Hash>,
}Expand description
Central context for managing DEX liquidity pools, markets, and RPC clients
This structure serves as the shared state across all pool operations, providing thread-safe access to:
- Market graphs with bidirectional token pair mappings (markets[“wsol”][“usdc”] will give you the same thread safe access as if you did markets[“usdc”][“wsol”])
- Protocol-specific pools and vaults
- JSON RPC clients for on-chain data fetching
- Token validation and legitimacy tracking
- Current network state (slot, blockhash)
Fields§
§markets: RwLock<HashMap<Pubkey, HashMap<Pubkey, Arc<RwLock<Vec<Arc<RwLock<dyn PoolTrait>>>>>>>>Bidirectional market graph: token A -> token B -> list of pools
Markets are stored bidirectionally so pools can be looked up by either token in the pair. Each pool is wrapped in Arc<RwLock<>> for shared ownership and thread-safe access.
- RwLock on both layers of the hash map for mutability
- Arc on the vector for bidirectional reference
- RwLock on the vector for mutability and adding new markets in
- RwLock on the pool traits to modify the pools states
json_rpc_client: RpcClientSynchronous JSON RPC client for Solana network requests
json_rpc_client_async: RpcClientAsynchronous JSON RPC client for concurrent network requests
raydium_cpmm_fee_rates_lp: HashMap<Pubkey, u64>Fee rates for Raydium CPMM pools, keyed by config account address
Stored in lamports (10^9 = 1 SOL) for high precision. Can be loaded during initialization via the load_cpmm_pool_configs function and available throughout the process lifetime.
meteora_vault_cache: Mutex<HashMap<Pubkey, Arc<RwLock<MeteoraVault>>>>Cache of Meteora Ammv1 vaults keyed by token address
Protected by Mutex to ensure only one vault instance exists per token, preventing race conditions. Multiple pools should reference the same token vault as only one per token. Avoid creating multiple vaults per token.
pf_bonding_curves: Mutex<HashMap<Pubkey, Arc<RwLock<PfBondingCurve>>>>Cache of Pumpfun bonding curves keyed by bonding curve address
Protected by Mutex for thread-safe read-check-write operations when creating new bonding curve instances.
raydium_launchpads: Mutex<HashMap<Pubkey, Arc<RwLock<RaydiumLaunchpad>>>>Cache of Raydium launchpads keyed by launchpad/market address
Protected by Mutex for thread-safe read-check-write operations when creating new bonding curve instances.
legit_tokens: Mutex<HashMap<Pubkey, bool>>Cache of token legitimacy flags keyed by token address
A token is considered legit if it has Metaplex metadata and the update authority matches a reputable launchpad (Raydium Launchpad or Pumpfun Bonding Curve). Mutex for lookup and then store if not in cache (write based on read)
Set of legitimate update authorities used to validate tokens
Contains update authorities from known reputable launchpads (Raydium Launchpad and Pumpfun Bonding Curve only for now)
pools_map: RwLock<HashMap<Pubkey, Arc<RwLock<dyn PoolTrait>>>>Map of account addresses to pools for efficient pool lookup
A pool can be looked up by its pool address, token A vault address, or token B vault address.
Updated automatically when pools are inserted via insert_pool.
current_slot: RwLock<u64>Current slot being produced by the Solana network
latest_blockhash: RwLock<Hash>Most recent blockhash produced by the network
Typically the blockhash of slot (current_slot - 1).
Implementations§
Source§impl CentralContext
impl CentralContext
Sourcepub fn fetch_current_slot_blockhash(&self)
pub fn fetch_current_slot_blockhash(&self)
Refresh current slot and latest blockhash from JSON RPC
Updates the current_slot and latest_blockhash fields in the context.
Note: In production, these values are typically updated via gRPC streams rather than polling.
Source§impl CentralContext
impl CentralContext
Sourcepub fn insert_pool(&self, pool: Arc<RwLock<dyn PoolTrait>>)
pub fn insert_pool(&self, pool: Arc<RwLock<dyn PoolTrait>>)
Insert a pool into the central context
Adds the pool to both the bidirectional market graph and the pools map. Pools can then be queried by token pairs or by account addresses (pool address or vault addresses). Invalid pools (with system program addresses or duplicate tokens) are silently ignored.
Source§impl CentralContext
impl CentralContext
Sourcepub fn load_cpmm_pool_configs(&mut self)
pub fn load_cpmm_pool_configs(&mut self)
Load Raydium CPMM pool configurations from on-chain data
Fetches all Raydium CPMM pool config accounts and populates the raydium_cpmm_fee_rates_lp
map with fee rates. This should be called during initialization before processing pools.
Auto Trait Implementations§
impl !Freeze for CentralContext
impl !RefUnwindSafe for CentralContext
impl Send for CentralContext
impl Sync for CentralContext
impl Unpin for CentralContext
impl !UnwindSafe for CentralContext
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more