This document describes the canonical naming scheme for storage keys in Credence Soroban contracts. Following this convention ensures consistency across the codebase and helps reviewers verify behavior against documented intent.
Storage key enums and their variants must follow these rules:
- Enum names: Use
snake_case(e.g.,DataKey,SlashStorageKey,EmergencyDataKey) - Variant names: Use
snake_casewith singular nouns (e.g.,Admin,Token,Bond,AttestationCounter) - Parameterized variants: Use descriptive singular names with type parameters (e.g.,
Bond(Address),Attestation(u64),SlashRecord(Address, u32))
#[contracttype]
#[derive(Clone)]
pub enum DataKey {
/// Contract administrator
Admin,
/// Token address for bond deposits
Token,
/// Bond data for a specific identity
Bond(Address),
/// Individual attestation record
Attestation(u64),
/// Monotonic counter for attestation IDs
AttestationCounter,
}#[contracttype]
#[derive(Clone)]
pub enum SlashStorageKey {
/// Number of slashes for an identity
SlashCount(Address),
/// Individual slash record by (identity, index)
SlashRecord(Address, u32),
}#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum EmergencyDataKey {
/// Emergency record by ID
Record(u64),
/// State transition record by ID
Transition(u64),
/// Monotonic sequence counter
RecordSeq,
}- Singular nouns:
BondnotBonds,AdminnotAdmins. This matches the conceptual model where each key represents a single storage entry or namespace. - snake_case: Consistent with Rust naming conventions for enum variants in this codebase.
- Descriptive parameterized variants:
Bond(Address)clearly indicates the key is indexed by address, making the storage layout self-documenting.
- Datakey Fingerprint - Storage key stability and migration considerations
- Storage TTL - Time-to-live configuration for storage entries