Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion contracts/vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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<VaultConfig> {
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)
}
}
50 changes: 50 additions & 0 deletions contracts/vault/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
15 changes: 15 additions & 0 deletions contracts/vault/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 3 additions & 1 deletion docs/contract-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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<VaultConfig>` | `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:

Expand Down