This commit is contained in:
2026-04-28 17:08:21 +02:00
parent 467e488b36
commit d036b4c79f
6 changed files with 684 additions and 18 deletions

View File

@@ -392,9 +392,9 @@ impl KbDexDecodeService {
event_kind.to_string(),
event.pool_account.clone(),
None,
None,
None,
None,
event.token_a_mint.clone(),
event.token_b_mint.clone(),
event.pool_v2.clone(),
payload_json,
);
let upsert_result = crate::upsert_dex_decoded_event(self.database.as_ref(), &dto).await;
@@ -595,6 +595,60 @@ mod tests {
}
}
async fn seed_projected_pump_swap_transaction(
database: std::sync::Arc<crate::KbDatabase>,
signature: &str,
) {
let service = crate::KbTransactionModelService::new(database);
let resolved_transaction = serde_json::json!({
"slot": 999003,
"blockTime": 1779000003,
"version": 0,
"transaction": {
"message": {
"instructions": [
{
"programId": crate::KB_PUMP_SWAP_PROGRAM_ID,
"program": "pump-amm",
"stackHeight": 1,
"accounts": [
"PumpSwapPool111",
"PumpSwapTokenA111",
"PumpSwapTokenB111",
"PumpSwapPoolV2_111"
],
"parsed": {
"info": {
"pool": "PumpSwapPool111",
"baseMint": "PumpSwapTokenA111",
"quoteMint": "PumpSwapTokenB111",
"poolV2": "PumpSwapPoolV2_111"
}
},
"data": "opaque"
}
]
}
},
"meta": {
"err": null,
"logMessages": [
"Program log: Instruction: Buy"
]
}
});
let persist_result = service
.persist_resolved_transaction(
signature,
Some("helius_primary_http".to_string()),
&resolved_transaction,
)
.await;
if let Err(error) = persist_result {
panic!("projection must succeed: {}", error);
}
}
#[tokio::test]
async fn decode_transaction_by_signature_persists_decoded_raydium_event() {
let database = make_database().await;
@@ -634,4 +688,34 @@ mod tests {
);
assert_eq!(decoded[0].token_a_mint, Some("MintPF111".to_string()));
}
#[tokio::test]
async fn decode_transaction_by_signature_persists_decoded_pump_swap_event() {
let database = make_database().await;
seed_projected_pump_swap_transaction(database.clone(), "sig-dex-decode-pumpswap-1").await;
let service = crate::KbDexDecodeService::new(database.clone());
let decoded_result = service
.decode_transaction_by_signature("sig-dex-decode-pumpswap-1")
.await;
let decoded = match decoded_result {
Ok(decoded) => decoded,
Err(error) => panic!("decode must succeed: {}", error),
};
assert_eq!(decoded.len(), 1);
assert_eq!(decoded[0].protocol_name, "pump_swap");
assert_eq!(decoded[0].event_kind, "pump_swap.buy");
assert_eq!(decoded[0].pool_account, Some("PumpSwapPool111".to_string()));
assert_eq!(
decoded[0].token_a_mint,
Some("PumpSwapTokenA111".to_string())
);
assert_eq!(
decoded[0].token_b_mint,
Some("PumpSwapTokenB111".to_string())
);
assert_eq!(
decoded[0].market_account,
Some("PumpSwapPoolV2_111".to_string())
);
}
}