- Points: 200
- Labels: contract, observability, read-api, devops
Background
Keeper bots and monitoring systems have no single endpoint to verify that the contract is in a healthy, operational state before submitting transactions. They must check is_contract_paused, verify the token address is set, and confirm the admin key is present — three separate RPC calls. A health degradation (e.g., instance storage TTL near expiry, contract paused, no token configured) should be detectable in a single read so automated systems can alert before failures occur. This is especially important for keeper infrastructure running against mainnet where failed transactions have real costs.
Task
Define #[contracttype] pub struct HealthReport with fields: is_healthy: bool, contract_paused: bool, token_configured: bool, admin_configured: bool, instance_ttl_ledgers: u32, active_subscription_count: u64, schema_version: u32. Add contract_health_check(env: Env) -> HealthReport as a public no-auth function. Set is_healthy = !contract_paused && token_configured && admin_configured && instance_ttl_ledgers > 17_280 (more than 1 day of TTL remaining). No storage writes.
Key Files
contract/src/lib.rs — define HealthReport; implement contract_health_check reading from storage::get_token, storage::get_admin_optional, subscription_count::get_active_count, migration::get_schema_version, env.storage().instance().get_ttl()
contract/src/test.rs — test: freshly initialized contract returns is_healthy = true; test: after pause_contract, is_healthy = false and contract_paused = true; test: before initialize, token_configured = false and is_healthy = false
Edge Cases
storage::get_admin_optional already returns Option<Address> — use is_some() for admin_configured
env.storage().instance().get_ttl() returns u32 in the soroban-sdk test environment; confirm the method signature before use
- The
instance_ttl_ledgers > 17_280 threshold for is_healthy is an opinionated default — document it in a code comment as "at least 1 day of TTL remaining"
contract_health_check must be callable even before initialize (when most keys are absent) — all field reads must use unwrap_or defaults, never expect or unwrap
Acceptance Criteria
Background
Keeper bots and monitoring systems have no single endpoint to verify that the contract is in a healthy, operational state before submitting transactions. They must check
is_contract_paused, verify the token address is set, and confirm the admin key is present — three separate RPC calls. A health degradation (e.g., instance storage TTL near expiry, contract paused, no token configured) should be detectable in a single read so automated systems can alert before failures occur. This is especially important for keeper infrastructure running against mainnet where failed transactions have real costs.Task
Define
#[contracttype] pub struct HealthReportwith fields:is_healthy: bool,contract_paused: bool,token_configured: bool,admin_configured: bool,instance_ttl_ledgers: u32,active_subscription_count: u64,schema_version: u32. Addcontract_health_check(env: Env) -> HealthReportas a public no-auth function. Setis_healthy = !contract_paused && token_configured && admin_configured && instance_ttl_ledgers > 17_280(more than 1 day of TTL remaining). No storage writes.Key Files
contract/src/lib.rs— defineHealthReport; implementcontract_health_checkreading fromstorage::get_token,storage::get_admin_optional,subscription_count::get_active_count,migration::get_schema_version,env.storage().instance().get_ttl()contract/src/test.rs— test: freshly initialized contract returnsis_healthy = true; test: afterpause_contract,is_healthy = falseandcontract_paused = true; test: before initialize,token_configured = falseandis_healthy = falseEdge Cases
storage::get_admin_optionalalready returnsOption<Address>— useis_some()foradmin_configuredenv.storage().instance().get_ttl()returnsu32in the soroban-sdk test environment; confirm the method signature before useinstance_ttl_ledgers > 17_280threshold foris_healthyis an opinionated default — document it in a code comment as "at least 1 day of TTL remaining"contract_health_checkmust be callable even beforeinitialize(when most keys are absent) — all field reads must useunwrap_ordefaults, neverexpectorunwrapAcceptance Criteria
HealthReportis a#[contracttype]struct with all 7 fieldsis_healthycomputed as the conjunction of 4 conditions including TTL thresholdis_healthy = trueis_healthy = false,contract_paused = truetoken_configured = false,is_healthy = falsecargo testpasses with no regressions