v0.1.0-pre.061
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: kb-lib/src/materializer/token/accounts.rs
|
||||
// version: 4
|
||||
// version: 6
|
||||
|
||||
//! Stable committed SPL Token mutation and ATA lifecycle projections.
|
||||
|
||||
@@ -46,7 +46,7 @@ pub struct MtTokenAccountsMaterializer;
|
||||
|
||||
impl crate::MtMaterializer for crate::MtTokenAccountsMaterializer {
|
||||
fn materializer_name(&self) -> &'static str {
|
||||
return "kb_materializer_token_accounts";
|
||||
return "kb-lib.materializer.token.accounts";
|
||||
}
|
||||
|
||||
fn materializer_version(&self) -> &'static str {
|
||||
@@ -175,8 +175,8 @@ impl crate::MtApiEventMaterializer for crate::MtTokenAccountsMaterializer {
|
||||
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_mutation = token_program && MUTATION_ENTRIES.contains(&event.event_name.0.as_str());
|
||||
let ata = is_ata_event(event);
|
||||
return ACCEPTED_FAMILIES.contains(&event.event_family) && (token_mutation || ata);
|
||||
@@ -316,7 +316,7 @@ fn validate_ata_addresses(
|
||||
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)
|
||||
);
|
||||
if !token_supported || !token_program_exact {
|
||||
return std::result::Result::Err((
|
||||
@@ -394,7 +394,7 @@ fn account_key_for_role(accounts: &serde_json::Value, role: &str) -> serde_json:
|
||||
}
|
||||
|
||||
/// Materialize one already parsed Token-2022 account snapshot without inferring hidden state.
|
||||
pub fn materializer_token_materialize_token2022_state_snapshot(
|
||||
pub fn materializer_token_materialize_token_2022_state_snapshot(
|
||||
account_key: &str,
|
||||
slot: u64,
|
||||
state: &crate::DcToken2022State,
|
||||
@@ -431,16 +431,16 @@ pub fn materializer_token_materialize_token2022_state_snapshot(
|
||||
|| entry.extension_name == "confidential_mint_burn";
|
||||
});
|
||||
return std::result::Result::Ok(crate::MtApiMaterializedOutput {
|
||||
output_key: format!("token2022_state_snapshot:{account_key}:{slot}"),
|
||||
output_key: format!("token_2022_state_snapshot:{account_key}:{slot}"),
|
||||
family: crate::MdMaterializedEventFamily::TokenAccount,
|
||||
payload_json: serde_json::json!({
|
||||
"projectionVersion": crate::MT_TOKEN_ACCOUNTS_PROJECTION_VERSION,
|
||||
"domain": "spl_token2022_account_state",
|
||||
"domain": "spl_token_2022_account_state",
|
||||
"projectionSemantics": "authoritative_bounded_account_snapshot",
|
||||
"idempotenceKey": format!("token2022_state:{account_key}:{slot}"),
|
||||
"idempotenceKey": format!("token_2022_state:{account_key}:{slot}"),
|
||||
"accountKey": account_key,
|
||||
"slot": slot,
|
||||
"programId": kb_program_ids::SPL_TOKEN2022_PROGRAM_ID,
|
||||
"programId": kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID,
|
||||
"stateKind": kind,
|
||||
"baseFields": state.base_fields,
|
||||
"baseHex": state.base_hex,
|
||||
@@ -454,7 +454,7 @@ pub fn materializer_token_materialize_token2022_state_snapshot(
|
||||
"provenance": {
|
||||
"processorName": crate::MT_TOKEN_ACCOUNTS_PROCESSOR_NAME,
|
||||
"processorVersion": env!("CARGO_PKG_VERSION"),
|
||||
"source": "bounded_token2022_state_parser"
|
||||
"source": "bounded_token_2022_state_parser"
|
||||
}
|
||||
}),
|
||||
});
|
||||
@@ -502,18 +502,18 @@ mod tests {
|
||||
};
|
||||
}
|
||||
|
||||
fn token2022_observation(
|
||||
fn token_2022_observation(
|
||||
entry: &str,
|
||||
family: crate::MdEventFamily,
|
||||
failed: bool,
|
||||
) -> crate::DcApiDecodedObservation {
|
||||
let mut observation = observation(entry, family, 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;
|
||||
}
|
||||
|
||||
@@ -535,8 +535,8 @@ mod tests {
|
||||
} else {
|
||||
serde_json::json!({
|
||||
"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
|
||||
},
|
||||
"associatedTokenAccount": {"expected":"ata111","observed":"ata111","valid":valid},
|
||||
@@ -590,9 +590,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn committed_token2022_transfer_has_the_same_single_projection_owner() {
|
||||
fn committed_token_2022_transfer_has_the_same_single_projection_owner() {
|
||||
let observation =
|
||||
token2022_observation("transfer_checked", crate::MdEventFamily::TokenAccount, false);
|
||||
token_2022_observation("transfer_checked", crate::MdEventFamily::TokenAccount, false);
|
||||
let result = crate::MtApiEventMaterializer::materialize(
|
||||
&crate::MtTokenAccountsMaterializer,
|
||||
&observation,
|
||||
@@ -602,7 +602,7 @@ mod tests {
|
||||
assert_eq!(result.outputs[0].payload_json["operation"], "transfer_checked");
|
||||
assert_eq!(
|
||||
result.outputs[0].payload_json["programId"],
|
||||
kb_program_ids::SPL_TOKEN2022_PROGRAM_ID
|
||||
kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID
|
||||
);
|
||||
}
|
||||
|
||||
@@ -636,12 +636,12 @@ mod tests {
|
||||
#[test]
|
||||
fn every_ata_variant_has_one_exact_lifecycle_projection() {
|
||||
for (entry, expected_kind, expected_ata, expected_token_program) in [
|
||||
("create", "ata_created", "ata111", kb_program_ids::SPL_TOKEN2022_PROGRAM_ID),
|
||||
("create", "ata_created", "ata111", kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID),
|
||||
(
|
||||
"create_idempotent",
|
||||
"ata_created_or_reused_idempotently",
|
||||
"ata111",
|
||||
kb_program_ids::SPL_TOKEN2022_PROGRAM_ID,
|
||||
kb_program_ids::SPL_TOKEN_2022_PROGRAM_ID,
|
||||
),
|
||||
(
|
||||
"recover_nested",
|
||||
@@ -779,7 +779,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn token2022_state_snapshot_preserves_base_and_ordered_extensions() {
|
||||
fn token_2022_state_snapshot_preserves_base_and_ordered_extensions() {
|
||||
let state = crate::DcToken2022State {
|
||||
kind: crate::DcToken2022StateKind::Mint,
|
||||
base_fields: serde_json::json!({"supply":"42","decimals":9,"initialized":true}),
|
||||
@@ -800,7 +800,7 @@ mod tests {
|
||||
},
|
||||
],
|
||||
};
|
||||
let output = match crate::materializer_token_materialize_token2022_state_snapshot(
|
||||
let output = match crate::materializer_token_materialize_token_2022_state_snapshot(
|
||||
"mint111", 99, &state,
|
||||
) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
@@ -816,7 +816,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn token2022_state_snapshot_is_idempotent_and_rejects_missing_identity() {
|
||||
fn token_2022_state_snapshot_is_idempotent_and_rejects_missing_identity() {
|
||||
let state = crate::DcToken2022State {
|
||||
kind: crate::DcToken2022StateKind::Account,
|
||||
base_fields: serde_json::json!({"mint":"mint111","owner":"wallet111","amount":"5"}),
|
||||
@@ -824,13 +824,19 @@ mod tests {
|
||||
account_type: std::option::Option::None,
|
||||
extensions: std::vec::Vec::new(),
|
||||
};
|
||||
let first =
|
||||
crate::materializer_token_materialize_token2022_state_snapshot("account111", 7, &state);
|
||||
let second =
|
||||
crate::materializer_token_materialize_token2022_state_snapshot("account111", 7, &state);
|
||||
let first = crate::materializer_token_materialize_token_2022_state_snapshot(
|
||||
"account111",
|
||||
7,
|
||||
&state,
|
||||
);
|
||||
let second = crate::materializer_token_materialize_token_2022_state_snapshot(
|
||||
"account111",
|
||||
7,
|
||||
&state,
|
||||
);
|
||||
assert_eq!(first, second);
|
||||
assert!(
|
||||
crate::materializer_token_materialize_token2022_state_snapshot("", 7, &state).is_err()
|
||||
crate::materializer_token_materialize_token_2022_state_snapshot("", 7, &state).is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: kb-lib/src/materializer/token/metadata_risk.rs
|
||||
// version: 3
|
||||
// version: 4
|
||||
|
||||
//! Reserved token-metadata risk materializer.
|
||||
|
||||
@@ -9,7 +9,7 @@ pub struct MtTokenMetadataRiskMaterializer;
|
||||
|
||||
impl crate::MtMaterializer for crate::MtTokenMetadataRiskMaterializer {
|
||||
fn materializer_name(&self) -> &'static str {
|
||||
return "kb_materializer_token_metadata_risk";
|
||||
return "kb-lib.materializer.token.metadata_risk";
|
||||
}
|
||||
|
||||
fn materializer_version(&self) -> &'static str {
|
||||
@@ -36,7 +36,7 @@ impl crate::MtMaterializer for crate::MtTokenMetadataRiskMaterializer {
|
||||
impl crate::MtApiEventMaterializer for crate::MtTokenMetadataRiskMaterializer {
|
||||
fn identity(&self) -> crate::MtApiMaterializerIdentity {
|
||||
return crate::MtApiMaterializerIdentity {
|
||||
name: "kb_materializer_token_metadata_risk".to_string(),
|
||||
name: "kb-lib.materializer.token.metadata_risk".to_string(),
|
||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user