Struct CentralContext

Source
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: RpcClient

Synchronous JSON RPC client for Solana network requests

§json_rpc_client_async: RpcClient

Asynchronous 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)

§legit_update_authorities: HashSet<Pubkey>

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

Source

pub fn new() -> Self

Create a new CentralContext instance

Initializes RPC clients, empty caches, and sets up legitimate update authorities from known reputable launchpads. Requires RPC_NODE_URL environment variable to be set.

Source§

impl CentralContext

Source

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

Source

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

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more