From 071cbeeef1fe599aa9d140873d6332073a6c4958 Mon Sep 17 00:00:00 2001 From: IG-ABHINAV Date: Sun, 22 Nov 2026 13:07:14 +0000 Subject: [PATCH] feat(vault): add get_config and get_cycle_claimed_total views Expose the bound admin, oracle and token as Option, and the per-cycle claimed total, as read-only contract methods with no auth and no TTL bump. Fixes #30 --- contracts/vault/src/lib.rs | 21 ++++++++++++++- contracts/vault/src/test.rs | 50 ++++++++++++++++++++++++++++++++++++ contracts/vault/src/types.rs | 15 +++++++++++ docs/SUMMARY.md | 2 +- docs/contract-reference.md | 4 ++- 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/contracts/vault/src/lib.rs b/contracts/vault/src/lib.rs index 1f3bb8a..a0f3e40 100644 --- a/contracts/vault/src/lib.rs +++ b/contracts/vault/src/lib.rs @@ -45,7 +45,7 @@ mod test; use soroban_sdk::{contract, contractimpl, token, Address, BytesN, Env, MuxedAddress, Symbol, Vec}; pub use crate::errors::SplitStreamError; -pub use crate::types::{CycleInfo, SweepRequestData, VestingData}; +pub use crate::types::{CycleInfo, SweepRequestData, VaultConfig, VestingData}; /// The SplitStream payout vault. #[contract] @@ -313,4 +313,23 @@ impl SplitStreamVault { let reserved = storage::get_reserved_total(&env).unwrap_or(i128::MAX); on_hand.saturating_sub(reserved) } + + /// Admin, oracle and token this deployment is bound to, or `None` before + /// `initialize`. Read-only: no auth and no TTL bump. + pub fn get_config(env: Env) -> Option { + if !storage::is_initialized(&env) { + return None; + } + Some(VaultConfig { + admin: storage::get_admin(&env).ok()?, + oracle: storage::get_oracle(&env).ok()?, + token: storage::get_token(&env).ok()?, + }) + } + + /// Cumulative amount claimed against a cycle; `0` if nothing has been + /// claimed. Read-only: no auth and no TTL bump. + pub fn get_cycle_claimed_total(env: Env, cycle_id: u64) -> i128 { + storage::get_cycle_claimed_total(&env, cycle_id) + } } diff --git a/contracts/vault/src/test.rs b/contracts/vault/src/test.rs index e815ac8..bda395f 100644 --- a/contracts/vault/src/test.rs +++ b/contracts/vault/src/test.rs @@ -987,3 +987,53 @@ mod auth { ); } } + +mod readonly_views { + use super::*; + use crate::VaultConfig; + + #[test] + fn get_config_is_none_before_initialize() { + let env = Env::default(); + env.mock_all_auths(); + let contract_id = env.register(SplitStreamVault, ()); + let client = SplitStreamVaultClient::new(&env, &contract_id); + assert_eq!(client.get_config(), None); + } + + #[test] + fn get_config_returns_bound_addresses_after_initialize() { + let t = setup(); + let cfg = t.client().get_config().expect("initialized"); + assert_eq!( + cfg, + VaultConfig { + admin: t.admin, + oracle: t.oracle, + token: t.token, + } + ); + } + + #[test] + fn get_cycle_claimed_total_starts_at_zero_and_increments() { + let t = setup(); + let contributor = Address::generate(&t.env); + let (root, claims) = build_manifest( + &t.env, + &[(t.admin.clone(), 100), (contributor.clone(), 200)], + ); + t.client().post_cycle_root(&1, &root, &300); + + assert_eq!(t.client().get_cycle_claimed_total(&1), 0); + + t.env.ledger().set_timestamp(CHALLENGE_WINDOW_SECS); + t.client() + .credit_claim(&t.admin, &1, &100, proof_for(&claims, &t.admin)); + assert_eq!(t.client().get_cycle_claimed_total(&1), 100); + + t.client() + .credit_claim(&contributor, &1, &200, proof_for(&claims, &contributor)); + assert_eq!(t.client().get_cycle_claimed_total(&1), 300); + } +} diff --git a/contracts/vault/src/types.rs b/contracts/vault/src/types.rs index dafc955..27bfbc5 100644 --- a/contracts/vault/src/types.rs +++ b/contracts/vault/src/types.rs @@ -56,3 +56,18 @@ pub struct SweepRequestData { /// measured from this instant. pub requested_at: u64, } + +/// The addresses this vault deployment is bound to. +/// +/// Returned by the `get_config` view so operators can read admin, oracle and +/// token without relying on off-chain records. `None` before `initialize`. +#[contracttype] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct VaultConfig { + /// Admin address. + pub admin: Address, + /// Oracle (CI relay) address. + pub oracle: Address, + /// SEP-41 token contract address. + pub token: Address, +} diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index a74a2a0..926b144 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -5,7 +5,7 @@ settlement logic itself. Read in this order: 1. [Introduction](introduction.md) — what this repo is, its role in SplitStream, and the problem it solves. 2. [Protocol mechanics](protocol-mechanics.md) — the cycle lifecycle, a worked numeric example, the challenge window, and the three settlement strategies. -3. [Contract reference](contract-reference.md) — all 22 public functions, the full error enum, deployed Testnet addresses, and the storage layout. +3. [Contract reference](contract-reference.md) — all 24 public functions, the full error enum, deployed Testnet addresses, and the storage layout. 4. [For maintainers](for-maintainers.md) — the admin operations: fixed splits, vesting schedules, disputes, and sweeps. 5. [Developer guide](developer-guide.md) — toolchain, build and test commands, and deployment steps. 6. [Contributing](contributing.md) — the cross-repo contract this repo's interface is part of, and how to land changes. diff --git a/docs/contract-reference.md b/docs/contract-reference.md index 3590520..82aa320 100644 --- a/docs/contract-reference.md +++ b/docs/contract-reference.md @@ -6,7 +6,7 @@ renumbered. ## Public functions -22 public functions: 14 state-changing, 8 read-only views. Events are emitted +24 public functions: 14 state-changing, 10 read-only views. Events are emitted through `Events::publish` with a topic tuple and a data payload; the payload is `()` unless noted. @@ -34,6 +34,8 @@ through `Events::publish` with a topic tuple and a data payload; the payload is | `get_total_credited` | none | — → `i128` | Sum of every contributor's outstanding pull-payment balance. | — | | `get_vesting_reserved` | none | — → `i128` | Outstanding vesting liability, `sum(total - claimed)`. | — | | `get_available_funds` | none | — → `i128` | Token balance minus both liabilities, floored at zero. The cap on `execute_sweep`. | — | +| `get_config` | none | — → `Option` | `admin`, `oracle`, `token`. `None` before `initialize`. | — | +| `get_cycle_claimed_total` | none | `cycle_id: u64` → `i128` | Cumulative amount claimed against the cycle; `0` if never claimed. | — | Notes: