v0.1.0-pre.061

This commit is contained in:
2026-07-28 18:41:30 +02:00
parent c7bad46f50
commit f40fb78817
527 changed files with 4598 additions and 4114 deletions

View File

@@ -1,5 +1,5 @@
// file: kb-lib/src/materializer/risk/core.rs
// version: 3
// version: 5
//! Stable fact-only risk projections for committed SPL Token and ATA observations.
@@ -42,7 +42,7 @@ pub struct MtRiskMaterializer;
impl crate::MtMaterializer for crate::MtRiskMaterializer {
fn materializer_name(&self) -> &'static str {
return "kb_materializer_risk";
return "kb-lib.materializer.risk";
}
fn materializer_version(&self) -> &'static str {
return env!("CARGO_PKG_VERSION");
@@ -169,8 +169,8 @@ impl crate::MtApiEventMaterializer for crate::MtRiskMaterializer {
fn accepts_event(event: &crate::MdDecodedProtocolEvent) -> bool {
let token_program = (event.program_id.0 == kb_program_ids::SPL_TOKEN_PROGRAM_ID
&& event.surface_code.0 == "spl_token")
|| (event.program_id.0 == kb_program_ids::SPL_TOKEN2022_PROGRAM_ID
&& event.surface_code.0 == "spl_token2022");
|| (event.program_id.0 == kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID
&& event.surface_code.0 == "spl_token_2022");
let token_risk = token_program && RISK_ENTRIES.contains(&event.event_name.0.as_str());
return ACCEPTED_FAMILIES.contains(&event.event_family)
&& (token_risk || is_ata_recovery(event));
@@ -200,7 +200,7 @@ fn ata_addresses_valid(payload: &serde_json::Value) -> bool {
let token_program_exact = matches!(
token_program_id,
std::option::Option::Some(kb_program_ids::SPL_TOKEN_PROGRAM_ID)
| std::option::Option::Some(kb_program_ids::SPL_TOKEN2022_PROGRAM_ID)
| std::option::Option::Some(kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID)
);
return token_supported
&& token_program_exact
@@ -332,7 +332,7 @@ mod tests {
};
}
fn token2022_observation(
fn token_2022_observation(
entry: &str,
family: crate::MdEventFamily,
parameters: serde_json::Value,
@@ -340,11 +340,11 @@ mod tests {
) -> crate::DcApiDecodedObservation {
let mut observation = observation(entry, family, parameters, failed);
observation.event.program_id =
crate::MdProgramId(kb_program_ids::SPL_TOKEN2022_PROGRAM_ID.to_string());
observation.event.protocol_code = crate::MdProtocolCode("spl_token2022".to_string());
observation.event.surface_code = crate::MdSurfaceCode("spl_token2022".to_string());
observation.event.event_code = crate::MdEventCode(format!("spl_token2022.{entry}"));
observation.event_key = format!("token2022:{entry}:0");
crate::MdProgramId(kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID.to_string());
observation.event.protocol_code = crate::MdProtocolCode("spl_token_2022".to_string());
observation.event.surface_code = crate::MdSurfaceCode("spl_token_2022".to_string());
observation.event.event_code = crate::MdEventCode(format!("spl_token_2022.{entry}"));
observation.event_key = format!("token_2022:{entry}:0");
return observation;
}
@@ -371,8 +371,8 @@ mod tests {
payload_json: serde_json::json!({
"addresses": {
"tokenProgram": {
"programId": kb_program_ids::SPL_TOKEN2022_PROGRAM_ID,
"kind": "token2022",
"programId": kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID,
"kind": "token_2022",
"supported": true
},
"ownerAssociatedTokenAccount": {"observed":"ownerAta","valid":valid},
@@ -417,8 +417,8 @@ mod tests {
}
#[test]
fn token2022_revocation_is_owned_once_without_an_invented_score() {
let observation = token2022_observation(
fn token_2022_revocation_is_owned_once_without_an_invented_score() {
let observation = token_2022_observation(
"set_authority",
crate::MdEventFamily::Admin,
serde_json::json!({"newAuthority":null}),
@@ -536,7 +536,7 @@ mod tests {
}
#[test]
fn token2022_compliance_toggles_are_projected_as_fact_only_risk_rows() {
fn token_2022_compliance_toggles_are_projected_as_fact_only_risk_rows() {
for (entry, expected) in [
("initialize_default_account_state", "default_account_state_configured"),
("enable_required_transfer_memos", "required_transfer_memos_enabled"),
@@ -546,7 +546,7 @@ mod tests {
] {
let result = crate::MtApiEventMaterializer::materialize(
&crate::MtRiskMaterializer,
&token2022_observation(
&token_2022_observation(
entry,
crate::MdEventFamily::Audit,
serde_json::json!({}),
@@ -561,7 +561,7 @@ mod tests {
}
#[test]
fn token2022_restriction_and_pause_facts_have_unique_stable_kinds() {
fn token_2022_restriction_and_pause_facts_have_unique_stable_kinds() {
for (entry, family, expected) in [
(
"initialize_non_transferable_mint",
@@ -583,7 +583,7 @@ mod tests {
] {
let result = crate::MtApiEventMaterializer::materialize(
&crate::MtRiskMaterializer,
&token2022_observation(entry, family, serde_json::json!({}), false),
&token_2022_observation(entry, family, serde_json::json!({}), false),
);
assert_eq!(result.outputs[0].payload_json["riskKind"], expected);
}
@@ -618,7 +618,7 @@ mod tests {
] {
let result = crate::MtApiEventMaterializer::materialize(
&crate::MtRiskMaterializer,
&token2022_observation(
&token_2022_observation(
entry,
crate::MdEventFamily::TokenAccount,
serde_json::json!({