This commit is contained in:
2026-05-11 11:02:47 +02:00
parent d66afede28
commit 7f130dba6b
49 changed files with 10301 additions and 8481 deletions

View File

@@ -23,10 +23,22 @@ mod db;
mod detect;
/// DEX-specific transaction decoders.
mod dex;
/// Internal known DEX catalog.
mod dex_catalog;
/// Persistence-oriented DEX decoding service.
mod dex_decode;
/// Transaction context loading for DEX decoding.
mod dex_decode_context;
/// Decoded DEX event materialization helpers.
mod dex_decoded_event_materialization;
/// Business-level detection built from decoded DEX events.
mod dex_detect;
/// Decoded DEX event to business-detection routing.
mod dex_detection_route;
/// Shared DEX event classification and decoded-payload enrichment helpers.
mod dex_event_classification;
/// Shared DEX pool materialization helpers.
mod dex_pool_materialization;
/// Shared error type for `kb_lib`.
mod error;
/// Generic asynchronous HTTP JSON-RPC client.
@@ -55,6 +67,8 @@ mod pair_candle_query;
mod pair_symbol;
/// Cross-DEX pool-origin recording service.
mod pool_origin;
/// Protocol candidate recording.
mod protocol_candidate_recording;
/// Typed Solana WebSocket PubSub helpers built on top of the generic JSON-RPC transport.
mod solana_pubsub_ws;
/// Historical token backfill service.
@@ -65,6 +79,22 @@ mod token_metadata;
mod tracing;
/// Cross-DEX trade aggregation service.
mod trade_aggregation;
/// Database context loading for trade aggregation.
mod trade_aggregation_context;
/// Trade amount resolution orchestration.
mod trade_amount_resolution;
/// Trade-event materialization.
mod trade_event_materialization;
/// Trade metric update and pricing helpers.
mod trade_metric_update;
/// PumpSwap trade amount recovery helpers.
mod trade_pump_swap_amounts;
/// Trade-side resolution helpers.
mod trade_side_resolution;
/// Solana transaction/meta trade amount extraction helpers.
mod trade_solana_amounts;
/// Transaction classification service.
mod transaction_classification;
/// Projection of resolved transactions into normalized internal DB tables.
mod tx_model;
/// Transaction resolution pipeline.
@@ -104,46 +134,143 @@ pub use config::SolanaConfig;
pub use config::SqliteDatabaseConfig;
/// WebSocket endpoint configuration.
pub use config::WsEndpointConfig;
/// Address Lookup Table program identifier. ("AddressLookupTab1e1111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::address_lookup_table::ID
pub use constants::ADDRESS_LOOKUP_TABLE_PROGRAM_ID;
/// Arbitrage Bot (6MWVT) / Arbitrage or Sandwich Bot. ("6MWVTis8rmmk6Vt9zmAJJbmb3VuLpzoQ1aHH4N6wQEGh").
pub use constants::ARBITRAGE_BOT_6MWVT_PROGRAM_ID;
/// Associated Token Account program identifier. ("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL").
/// @see solana_sdk::pubkey::Pubkey = spl_associated_token_account_interface::program::ID
pub use constants::ASSOCIATED_TOKEN_PROGRAM_ID;
/// BPF Loader program identifier. ("BPFLoader1111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::bpf_loader_deprecated::ID
pub use constants::BPF_LOADER_DEPRECATED_PROGRAM_ID;
/// BPF Loader program identifier. ("BPFLoaderUpgradeab1e11111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::bpf_loader_upgradeable::ID
pub use constants::BPF_LOADER_UPGRADEABLE_PROGRAM_ID;
/// Compute Budget program identifier. ("ComputeBudget111111111111111111111111111111").
/// @see solana_sdk_ids::compute_budget::ID
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::compute_budget::ID
pub use constants::COMPUTE_BUDGET_PROGRAM_ID;
/// Config program identifier. ("Config1111111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::config::ID
pub use constants::CONFIG_PROGRAM_ID;
/// DexLab Swap/Pool program id. ("DSwpgjMvXhtGn6BsbqmacdBZyfLj6jSWf3HJpdJtmg6N").
pub use constants::DEXLAB_PROGRAM_ID;
/// ED25519 program identifier. ("Ed25519SigVerify111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::ed25519_program::ID
pub use constants::ED25519_PROGRAM_ID;
/// Feature program identifier. ("Feature111111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::feature::ID
pub use constants::FEATURE_PROGRAM_ID;
/// FluxBeam program id. ("FLUXubRmkEi2q6K3Y9kBPg9248ggaZVsoSFhtJHSrm1X").
pub use constants::FLUXBEAM_PROGRAM_ID;
/// Incinerator program identifier. ("1nc1nerator11111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::incinerator::ID
pub use constants::INCINERATOR_PROGRAM_ID;
/// Loader V4 program identifier. ("LoaderV411111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::loader_v4::ID
pub use constants::LOADER_V4_PROGRAM_ID;
/// Meteora DAMM v1 program id. ("Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB").
pub use constants::METEORA_DAMM_V1_PROGRAM_ID;
/// Meteora DAMM v2 program id. ("cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG").
pub use constants::METEORA_DAMM_V2_PROGRAM_ID;
/// Meteora DBC program id. ("dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN").
pub use constants::METEORA_DBC_PROGRAM_ID;
/// Meteora DLMM program id. ("LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo").
pub use constants::METEORA_DLMM_PROGRAM_ID;
/// Native Loader program identifier. ("NativeLoader1111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::native_loader::ID
pub use constants::NATIVE_LOADER_PROGRAM_ID;
/// Orca Whirlpools program id. ("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc").
pub use constants::ORCA_WHIRLPOOLS_PROGRAM_ID;
/// Pump.fun program id. ("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P").
pub use constants::PUMP_FUN_PROGRAM_ID;
/// PumpSwap / PumpAMM program id. ("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA").
pub use constants::PUMP_SWAP_PROGRAM_ID;
/// Raydium AMM routing program id. ("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS").
pub use constants::RAYDIUM_AMM_ROUTING_PROGRAM_ID;
/// Raydium AmmV4 program id. ("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8").
pub use constants::RAYDIUM_AMM_V4_PROGRAM_ID;
/// Raydium CLMM program id. ("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK").
pub use constants::RAYDIUM_CLMM_PROGRAM_ID;
/// Raydium CPMM mainnet program id. ("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C").
pub use constants::RAYDIUM_CPMM_PROGRAM_ID;
/// Raydium LaunchLab program id. ("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj").
pub use constants::RAYDIUM_LAUNCHLAB_PROGRAM_ID;
/// Raydium Stable Swap AMM program id, deprecated. ("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h").
pub use constants::RAYDIUM_STABLE_SWAP_AMM_PROGRAM_ID;
/// Secp256k1 program identifier. ("KeccakSecp256k11111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::secp256k1_program::ID
pub use constants::SECP256K1_PROGRAM_ID;
/// Secp256r1 program identifier. ("Secp256r1SigVerify1111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::secp256r1_program::ID
pub use constants::SECP256R1_PROGRAM_ID;
/// SPL Token-2022 program identifier. ("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb").
/// @see solana_sdk::pubkey::Pubkey = spl_token_2022_interface::ID
pub use constants::SPL_TOKEN_2022_PROGRAM_ID;
/// SPL Token program identifier. ("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").
/// @see solana_sdk::pubkey::Pubkey = spl_token_interface::ID
pub use constants::SPL_TOKEN_PROGRAM_ID;
/// Stake Config program identifier. ("StakeConfig11111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::stake::config::ID
pub use constants::STAKE_CONFIG_PROGRAM_ID;
/// Stake program identifier. ("Stake11111111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::stake::ID
pub use constants::STAKE_PROGRAM_ID;
/// System program identifier. ("11111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::system_program::ID
pub use constants::SYSTEM_PROGRAM_ID;
/// Sysvar Clock program identifier. ("SysvarC1ock11111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::clock::ID
pub use constants::SYSVAR_CLOCK_PROGRAM_ID;
/// Sysvar Epoch Rewards program identifier. ("SysvarEpochRewards1111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::epoch_rewards::ID
pub use constants::SYSVAR_EPOCH_REWARDS_PROGRAM_ID;
/// Sysvar Epoch Schedule program identifier. ("SysvarEpochSchedu1e111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::epoch_schedule::ID
pub use constants::SYSVAR_EPOCH_SCHEDULE_PROGRAM_ID;
/// Sysvar Fees program identifier. ("SysvarFees111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::fees::ID
pub use constants::SYSVAR_FEES_PROGRAM_ID;
/// Sysvar Instructions program identifier. ("Sysvar1nstructions1111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::instructions::ID
pub use constants::SYSVAR_INSTRUCTIONS_PROGRAM_ID;
/// Sysvar Last Restart Slot program identifier. ("SysvarLastRestartS1ot1111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::last_restart_slot::ID
pub use constants::SYSVAR_LAST_RESTART_SLOT_PROGRAM_ID;
/// Sysvar program identifier. ("Sysvar1111111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::ID
pub use constants::SYSVAR_PROGRAM_ID;
/// Sysvar Recent Blockhashes program identifier. ("SysvarRecentB1ockHashes11111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::recent_blockhashes::ID
pub use constants::SYSVAR_RECENT_BLOCKHASHES_PROGRAM_ID;
/// Sysvar Rent program identifier. ("SysvarRent111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::rent::ID
pub use constants::SYSVAR_RENT_PROGRAM_ID;
/// Sysvar Rewards program identifier. ("SysvarRewards111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::rewards::ID
pub use constants::SYSVAR_REWARDS_PROGRAM_ID;
/// Sysvar Slot Hashes program identifier. ("SysvarS1otHashes111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::slot_hashes::ID
pub use constants::SYSVAR_SLOT_HASHES_PROGRAM_ID;
/// Sysvar Slot History program identifier. ("SysvarS1otHistory11111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::slot_history::ID
pub use constants::SYSVAR_SLOT_HISTORY_PROGRAM_ID;
/// Sysvar Stake History program identifier. ("SysvarStakeHistory1111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::sysvar::stake_history::ID
pub use constants::SYSVAR_STAKE_HISTORY_PROGRAM_ID;
/// Vote program identifier. ("Vote111111111111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::vote::ID
pub use constants::VOTE_PROGRAM_ID;
/// Wrapped SOL mint identifier. ("So11111111111111111111111111111111111111112").
/// @see solana_sdk::pubkey::Pubkey = spl_token_interface::native_mint::ID
pub use constants::WSOL_MINT_ID;
/// Zk El Gamal Proof program identifier. ("ZkE1Gama1Proof11111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::zk_elgamal_proof_program::ID
pub use constants::ZK_ELGAMAL_PROOF_PROGRAM_ID;
/// Zk Token Proof program identifier. ("ZkTokenProof1111111111111111111111111111111").
/// @see solana_sdk::pubkey::Pubkey = solana_sdk_ids::zk_token_proof_program::ID
pub use constants::ZK_TOKEN_PROOF_PROGRAM_ID;
/// Application-facing analysis signal DTO.
pub use db::AnalysisSignalDto;
/// Persisted analysis signal row.
@@ -284,6 +411,18 @@ pub use db::PoolTokenDto;
pub use db::PoolTokenEntity;
/// Role of one token inside a normalized pool.
pub use db::PoolTokenRole;
/// Application-facing protocol candidate DTO.
///
/// A protocol candidate records a program/instruction that should be inspected
/// later because it may correspond to an unsupported DEX, launch surface,
/// migration path or protocol-specific non-trade event.
pub use db::ProtocolCandidateDto;
/// Persisted protocol candidate row.
pub use db::ProtocolCandidateEntity;
/// Aggregated protocol candidate diagnostic row.
pub use db::ProtocolCandidateSummaryDto;
/// Aggregated protocol candidate diagnostic row.
pub use db::ProtocolCandidateSummaryEntity;
/// Application-facing normalized swap DTO.
pub use db::SwapDto;
/// Persisted normalized swap row.
@@ -306,6 +445,10 @@ pub use db::TokenMintEventEntity;
pub use db::TradeEventDto;
/// Persisted trade-event row.
pub use db::TradeEventEntity;
/// Application-facing transaction classification DTO.
pub use db::TransactionClassificationDto;
/// Persisted transaction classification row.
pub use db::TransactionClassificationEntity;
/// Application-facing wallet DTO.
pub use db::WalletDto;
/// Persisted wallet row.
@@ -482,6 +625,20 @@ pub use db::query_pools_get_by_address;
pub use db::query_pools_list;
/// Inserts or updates one normalized pool row by address.
pub use db::query_pools_upsert;
/// Lists protocol candidate summaries ordered by investigation priority.
pub use db::query_protocol_candidate_summaries_list_by_priority;
/// Deletes protocol candidates for one transaction.
///
/// This is useful before recomputing candidates for a replayed transaction.
pub use db::query_protocol_candidates_delete_by_transaction_id;
/// Inserts one protocol candidate row.
pub use db::query_protocol_candidates_insert;
/// Lists protocol candidates for one program id.
pub use db::query_protocol_candidates_list_by_program_id;
/// Lists protocol candidates for one transaction.
pub use db::query_protocol_candidates_list_by_transaction_id;
/// Lists recent protocol candidates ordered from newest to oldest.
pub use db::query_protocol_candidates_list_recent;
/// Lists recent swaps ordered from newest to oldest.
pub use db::query_swaps_list_recent;
/// Inserts or updates one normalized swap row.
@@ -512,6 +669,14 @@ pub use db::query_trade_events_list_by_pair_id;
pub use db::query_trade_events_list_by_transaction_id;
/// Inserts or updates one trade-event row and returns its stable internal id.
pub use db::query_trade_events_upsert;
/// Reads one transaction classification by signature.
pub use db::query_transaction_classifications_get_by_signature;
/// Reads one transaction classification by transaction id.
pub use db::query_transaction_classifications_get_by_transaction_id;
/// Lists recent transaction classifications ordered from newest to oldest.
pub use db::query_transaction_classifications_list_recent;
/// Inserts or updates one transaction classification row.
pub use db::query_transaction_classifications_upsert;
/// Returns one wallet-holding row identified by `(wallet_id, token_id)`, if it exists.
pub use db::query_wallet_holdings_get_by_wallet_and_token;
/// Lists wallet-holding rows for one wallet id.
@@ -644,6 +809,36 @@ pub use dex_decode::DexDecodeService;
pub use dex_detect::DexDetectService;
/// Result of one business-level DEX pool detection.
pub use dex_detect::DexPoolDetectionResult;
/// Stable DEX event business category.
pub use dex_event_classification::DexEventCategory;
/// Classifies a DEX event kind into a stable category.
pub use dex_event_classification::classify_dex_event_category;
/// Classifies a DEX event kind and returns its persisted category code.
pub use dex_event_classification::classify_dex_event_category_code;
/// Enriches and serializes a decoded DEX payload.
pub use dex_event_classification::enrich_and_serialize_dex_decoded_payload;
/// Enriches a decoded DEX payload with classification metadata.
pub use dex_event_classification::enrich_dex_decoded_payload;
/// Parses, enriches and serializes a decoded DEX payload.
pub use dex_event_classification::enrich_serialized_dex_decoded_payload;
/// Returns true when a decoded payload is a candle candidate.
pub use dex_event_classification::is_decoded_event_candle_candidate;
/// Returns true when a decoded payload is a trade candidate.
pub use dex_event_classification::is_decoded_event_trade_candidate;
/// Returns true for admin/config/permission DEX events.
pub use dex_event_classification::is_dex_admin_event_kind;
/// Returns true when a DEX event kind can directly feed candle materialization.
pub use dex_event_classification::is_dex_candle_candidate_event_kind;
/// Returns true for fee collection DEX events.
pub use dex_event_classification::is_dex_fee_event_kind;
/// Returns true for liquidity lifecycle DEX events.
pub use dex_event_classification::is_dex_liquidity_event_kind;
/// Returns true for pool lifecycle DEX events.
pub use dex_event_classification::is_dex_pool_lifecycle_event_kind;
/// Returns true for reward or emission DEX events.
pub use dex_event_classification::is_dex_reward_event_kind;
/// Returns true for swap-like DEX events.
pub use dex_event_classification::is_dex_trade_event_kind;
/// Global error type used by the `kb_lib` crate.
///
/// The project intentionally avoids `anyhow` and `thiserror`, so this
@@ -793,6 +988,8 @@ pub use tracing::init_tracing;
pub use trade_aggregation::TradeAggregationResult;
/// Trade-aggregation service.
pub use trade_aggregation::TradeAggregationService;
/// Service used to classify projected Solana transactions.
pub use transaction_classification::TransactionClassificationService;
/// Service projecting resolved transaction JSON into internal chain tables.
pub use tx_model::TransactionModelService;
/// Result of one transaction resolution pass.