This commit is contained in:
2026-06-05 14:53:16 +02:00
parent 27e25d5bf4
commit f81e0f3bea
66 changed files with 7655 additions and 214 deletions

View File

@@ -214,6 +214,9 @@ fn infer_expected_db_target_for_entry(
if decoder_code == "raydium_cpmm" && entry_name == "swap_event" {
return Some(crate::DexEventCoverageEntryDto::DB_TARGET_DECODED_EVENTS_ONLY.to_string());
}
if decoder_code == "raydium_clmm" && entry_name == "initialize_reward" {
return Some(crate::DexEventCoverageEntryDto::DB_TARGET_REWARD_EVENTS.to_string());
}
return infer_expected_db_target(event_family, entry_kind);
}
@@ -238,8 +241,8 @@ fn infer_expected_db_target(
"liquidity" => crate::DexEventCoverageEntryDto::DB_TARGET_LIQUIDITY_EVENTS,
"liquidity_add" => crate::DexEventCoverageEntryDto::DB_TARGET_LIQUIDITY_EVENTS,
"liquidity_remove" => crate::DexEventCoverageEntryDto::DB_TARGET_LIQUIDITY_EVENTS,
"position_open" => crate::DexEventCoverageEntryDto::DB_TARGET_POOL_LIFECYCLE_EVENTS,
"position_close" => crate::DexEventCoverageEntryDto::DB_TARGET_POOL_LIFECYCLE_EVENTS,
"position_open" => crate::DexEventCoverageEntryDto::DB_TARGET_LIQUIDITY_EVENTS,
"position_close" => crate::DexEventCoverageEntryDto::DB_TARGET_LIQUIDITY_EVENTS,
"fee" => crate::DexEventCoverageEntryDto::DB_TARGET_FEE_EVENTS,
"reward" => crate::DexEventCoverageEntryDto::DB_TARGET_REWARD_EVENTS,
"admin_config" => crate::DexEventCoverageEntryDto::DB_TARGET_POOL_ADMIN_EVENTS,
@@ -283,6 +286,7 @@ fn infer_event_family(
return Some("swap".to_string());
}
if contains_any(normalized.as_str(), &["create_pool", "initialize_pool", "initialize2"])
|| normalized == "create_customizable_pool"
|| normalized == "initialize"
|| normalized.starts_with("initialize_")
{
@@ -306,11 +310,13 @@ fn infer_event_family(
}
if contains_any(normalized.as_str(), &["close_position", "position_close"])
|| normalized.contains("close_position_if_empty")
|| normalized == "close_protocol_position"
{
return Some("position_close".to_string());
}
if contains_any(normalized.as_str(), &["fee", "collect", "claim_fee"])
&& !normalized.contains("reward")
&& !normalized.contains("config")
{
return Some("fee".to_string());
}
@@ -323,6 +329,9 @@ fn infer_event_family(
) {
return Some("admin_config".to_string());
}
if normalized == "create_support_mint_associated" {
return Some("account_create".to_string());
}
if normalized.contains("mint") {
return Some("mint".to_string());
}
@@ -335,21 +344,24 @@ fn infer_event_family(
if contains_any(normalized.as_str(), &["create_ata", "init_account", "open_orders_create"]) {
return Some("account_create".to_string());
}
if contains_any(normalized.as_str(), &["close_account", "close_open_orders"])
|| normalized.starts_with("close_")
{
return Some("account_close".to_string());
}
if normalized.contains("wrap_sol") {
return Some("wrap_sol".to_string());
}
if normalized.contains("unwrap_sol") {
return Some("unwrap_sol".to_string());
}
if normalized.contains("place_order") || normalized.contains("post_order") {
if normalized.contains("place_order")
|| normalized.contains("post_order")
|| normalized == "open_limit_order"
|| normalized == "increase_limit_order"
{
return Some("order_place".to_string());
}
if normalized.contains("cancel_order") || normalized.contains("cancel_all") {
if normalized.contains("cancel_order")
|| normalized.contains("cancel_all")
|| normalized == "close_limit_order"
|| normalized == "decrease_limit_order"
{
return Some("order_cancel".to_string());
}
if normalized.contains("fill") {
@@ -358,9 +370,14 @@ fn infer_event_family(
if normalized.contains("consume_events") {
return Some("consume_events".to_string());
}
if normalized.contains("settle_funds") {
if normalized.contains("settle_funds") || normalized == "settle_limit_order" {
return Some("settle_funds".to_string());
}
if contains_any(normalized.as_str(), &["close_account", "close_open_orders"])
|| normalized.starts_with("close_")
{
return Some("account_close".to_string());
}
if normalized.contains("vault") && normalized.contains("deposit") {
return Some("vault_deposit".to_string());
}
@@ -399,7 +416,7 @@ fn contains_any(value: &str, needles: &[&str]) -> bool {
return false;
}
fn known_local_event_kind(
pub(crate) fn known_local_event_kind(
decoder_code: &str,
entry_name: &str,
) -> std::option::Option<std::string::String> {
@@ -444,19 +461,98 @@ fn known_local_event_kind(
return Some("raydium_cpmm.update_pool_status".to_string());
},
("raydium_cpmm", "withdraw") => return Some("raydium_cpmm.withdraw".to_string()),
("raydium_clmm", "swap") => return Some("raydium_clmm.swap".to_string()),
("raydium_clmm", "swap_v2") => return Some("raydium_clmm.swap_v2".to_string()),
("raydium_clmm", "increase_liquidity_v2") => {
return Some("raydium_clmm.increase_liquidity_v2".to_string());
("raydium_clmm", "close_limit_order") => {
return Some("raydium_clmm.close_limit_order".to_string());
},
("raydium_clmm", "open_limit_order") => {
return Some("raydium_clmm.open_limit_order".to_string());
},
("raydium_clmm", "increase_limit_order") => {
return Some("raydium_clmm.increase_limit_order".to_string());
},
("raydium_clmm", "decrease_limit_order") => {
return Some("raydium_clmm.decrease_limit_order".to_string());
},
("raydium_clmm", "close_position") => {
return Some("raydium_clmm.close_position".to_string());
},
("raydium_clmm", "close_protocol_position") => {
return Some("raydium_clmm.close_protocol_position".to_string());
},
("raydium_clmm", "collect_fund_fee") => {
return Some("raydium_clmm.collect_fund_fee".to_string());
},
("raydium_clmm", "collect_protocol_fee") => {
return Some("raydium_clmm.collect_protocol_fee".to_string());
},
("raydium_clmm", "collect_remaining_rewards") => {
return Some("raydium_clmm.collect_remaining_rewards".to_string());
},
("raydium_clmm", "create_amm_config") => {
return Some("raydium_clmm.create_amm_config".to_string());
},
("raydium_clmm", "create_customizable_pool") => {
return Some("raydium_clmm.create_customizable_pool".to_string());
},
("raydium_clmm", "create_dynamic_fee_config") => {
return Some("raydium_clmm.create_dynamic_fee_config".to_string());
},
("raydium_clmm", "create_operation_account") => {
return Some("raydium_clmm.create_operation_account".to_string());
},
("raydium_clmm", "create_pool") => return Some("raydium_clmm.create_pool".to_string()),
("raydium_clmm", "create_support_mint_associated") => {
return Some("raydium_clmm.create_support_mint_associated".to_string());
},
("raydium_clmm", "decrease_liquidity") => {
return Some("raydium_clmm.decrease_liquidity".to_string());
},
("raydium_clmm", "decrease_liquidity_v2") => {
return Some("raydium_clmm.decrease_liquidity_v2".to_string());
},
("raydium_clmm", "increase_liquidity") => {
return Some("raydium_clmm.increase_liquidity".to_string());
},
("raydium_clmm", "increase_liquidity_v2") => {
return Some("raydium_clmm.increase_liquidity_v2".to_string());
},
("raydium_clmm", "initialize_reward") => {
return Some("raydium_clmm.initialize_reward".to_string());
},
("raydium_clmm", "open_position") => {
return Some("raydium_clmm.open_position".to_string());
},
("raydium_clmm", "open_position_v2") => {
return Some("raydium_clmm.open_position_v2".to_string());
},
("raydium_clmm", "open_position_with_token22_nft") => {
return Some("raydium_clmm.open_position_with_token22_nft".to_string());
},
("raydium_clmm", "close_position") => {
return Some("raydium_clmm.close_position".to_string());
("raydium_clmm", "set_reward_params") => {
return Some("raydium_clmm.set_reward_params".to_string());
},
("raydium_clmm", "settle_limit_order") => {
return Some("raydium_clmm.settle_limit_order".to_string());
},
("raydium_clmm", "swap") => return Some("raydium_clmm.swap".to_string()),
("raydium_clmm", "swap_router_base_in") => {
return Some("raydium_clmm.swap_router_base_in".to_string());
},
("raydium_clmm", "swap_v2") => return Some("raydium_clmm.swap_v2".to_string()),
("raydium_clmm", "transfer_reward_owner") => {
return Some("raydium_clmm.transfer_reward_owner".to_string());
},
("raydium_clmm", "update_amm_config") => {
return Some("raydium_clmm.update_amm_config".to_string());
},
("raydium_clmm", "update_operation_account") => {
return Some("raydium_clmm.update_operation_account".to_string());
},
("raydium_clmm", "update_pool_status") => {
return Some("raydium_clmm.update_pool_status".to_string());
},
("raydium_clmm", "update_reward_infos") => {
return Some("raydium_clmm.update_reward_infos".to_string());
},
_ => return None,
}
@@ -511,6 +607,77 @@ mod tests {
);
}
#[test]
fn event_family_inference_covers_raydium_clmm_idl_entries() {
assert_eq!(
super::infer_event_family("create_customizable_pool", crate::ENTRY_KIND_INSTRUCTION),
Some("pool_create".to_string())
);
assert_eq!(
super::infer_event_family("create_dynamic_fee_config", crate::ENTRY_KIND_INSTRUCTION),
Some("admin_config".to_string())
);
assert_eq!(
super::infer_event_family(
"create_support_mint_associated",
crate::ENTRY_KIND_INSTRUCTION,
),
Some("account_create".to_string())
);
assert_eq!(
super::infer_event_family("close_limit_order", crate::ENTRY_KIND_INSTRUCTION),
Some("order_cancel".to_string())
);
assert_eq!(
super::infer_event_family("open_limit_order", crate::ENTRY_KIND_INSTRUCTION),
Some("order_place".to_string())
);
assert_eq!(
super::infer_event_family("increase_limit_order", crate::ENTRY_KIND_INSTRUCTION),
Some("order_place".to_string())
);
assert_eq!(
super::infer_event_family("decrease_limit_order", crate::ENTRY_KIND_INSTRUCTION),
Some("order_cancel".to_string())
);
assert_eq!(
super::infer_event_family("close_protocol_position", crate::ENTRY_KIND_INSTRUCTION),
Some("position_close".to_string())
);
assert_eq!(
super::infer_event_family("settle_limit_order", crate::ENTRY_KIND_INSTRUCTION),
Some("settle_funds".to_string())
);
assert_eq!(
super::infer_expected_db_target(Some("position_open"), crate::ENTRY_KIND_INSTRUCTION),
Some(crate::DexEventCoverageEntryDto::DB_TARGET_LIQUIDITY_EVENTS.to_string())
);
assert_eq!(
super::infer_expected_db_target(Some("position_close"), crate::ENTRY_KIND_INSTRUCTION),
Some(crate::DexEventCoverageEntryDto::DB_TARGET_LIQUIDITY_EVENTS.to_string())
);
assert_eq!(
super::known_local_event_kind("raydium_clmm", "create_pool"),
Some("raydium_clmm.create_pool".to_string())
);
assert_eq!(
super::known_local_event_kind("raydium_clmm", "collect_protocol_fee"),
Some("raydium_clmm.collect_protocol_fee".to_string())
);
assert_eq!(
super::known_local_event_kind("raydium_clmm", "open_limit_order"),
Some("raydium_clmm.open_limit_order".to_string())
);
assert_eq!(
super::known_local_event_kind("raydium_clmm", "increase_limit_order"),
Some("raydium_clmm.increase_limit_order".to_string())
);
assert_eq!(
super::known_local_event_kind("raydium_clmm", "decrease_limit_order"),
Some("raydium_clmm.decrease_limit_order".to_string())
);
}
#[tokio::test]
async fn sync_upstream_registry_persists_raydium_cpmm_coverage_rows() {
let database = make_database().await;