Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
51626eb
feat(sep40): add the SEP-40 types and trait
hpmaxi Nov 5, 2026
bb0dd35
feat(bindings): add the vault view the feed reads
hpmaxi Nov 5, 2026
d302210
feat(feed): convert a WAD NAV to 14 decimals
hpmaxi Nov 5, 2026
82b986a
feat(feed): follow a vault from the constructor
hpmaxi Nov 6, 2026
5cd7a57
feat(feed): quote the share through SEP-40
hpmaxi Nov 6, 2026
be6934c
fix(feed): share one oracle read between quotes and docs
hpmaxi Nov 6, 2026
a9925f4
test(feed): read a kit vault and its oracle
hpmaxi Nov 10, 2026
e06962d
feat(feed): upgrade only through the timelock
hpmaxi Nov 10, 2026
8b006ce
fix(feed): cover pause eta, hand-over apply, name the wind-down guard
hpmaxi Nov 10, 2026
cbaa6fd
test(feed): upgrade the built feed Wasm
hpmaxi Nov 10, 2026
914bc00
feat(harness): deploy the SEP-40 feed
hpmaxi Nov 10, 2026
8a87b56
docs: record the SEP-40 feed decisions
hpmaxi Nov 10, 2026
c297f21
docs: describe the SEP-40 feed
hpmaxi Nov 10, 2026
30aef73
chore: add the SEP-40 feed to the testnet set
hpmaxi Nov 10, 2026
2ae9150
docs: fix sep40-feed documentation accuracy
hpmaxi Nov 10, 2026
a366dbf
fix(harness): verify the feed's vault and record its own commit
hpmaxi Nov 10, 2026
19bd2e2
docs(harness): rebuild a later feed at its own commit
hpmaxi Nov 10, 2026
9d9c6d0
refactor(feed): fix price scales at compile time
hpmaxi Nov 13, 2026
cafcefd
docs: keep the SEP-40 decisions in the design doc
hpmaxi Nov 13, 2026
e05e4ef
docs(feed): explain the zero resolution and base
hpmaxi Nov 13, 2026
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
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ jobs:
set -o pipefail
stellar contract build --package share-token
stellar contract build --package nav-oracle
stellar contract build --package sep40-feed
CARGO_TARGET_DIR=target/upgrade-probe stellar contract build --package share-token --features upgrade_probe
CARGO_TARGET_DIR=target/upgrade-probe stellar contract build --package nav-oracle --features upgrade_probe
CARGO_TARGET_DIR=target/upgrade-probe stellar contract build --package async-vault --features upgrade_probe
cargo test --locked -p async-vault -p nav-oracle --features upgrade_wasm with_wasm 2>&1 | tee upgrade-tests.log
scripts/ci/check-tests-ran.sh upgrade-tests.log test::upgrade::with_wasm test::governance::with_wasm
CARGO_TARGET_DIR=target/upgrade-probe stellar contract build --package sep40-feed --features upgrade_probe
cargo test --locked -p async-vault -p nav-oracle -p sep40-feed --features upgrade_wasm with_wasm 2>&1 | tee upgrade-tests.log
scripts/ci/check-tests-ran.sh upgrade-tests.log test::upgrade::with_wasm test::governance::with_wasm test::timelock::with_wasm

network:
needs: changes
Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ contracts. The addresses emitted by the deploy script are authoritative.

- **Crate names.** Shared crates in `crates/` start with `strata-`
(`strata-timelock`, `strata-storage`, `strata-bindings`), so a path such as
`strata_timelock::DAY_DURATION` reads as the kit's own code.
`strata_timelock::DAY_DURATION` reads as the kit's own code. `crates/sep40`
keeps the standard's name, without the `strata-` prefix, because it holds a
Stellar standard and no kit code.
- **Addresses in entrypoints.** In an entrypoint the kit defines, `caller` is
the account that must sign the call, and `holder` is the account whose
position, request or balance the call is about. When one account is both, the
Expand Down
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ than its pending deposits, and once a wind-down is proposed.
- [Grant differences](./docs/GRANT_DIFFERENCES.md) — where the built kit
differs from the SCF grant proposal, what is not built yet, and the limits an
adopter should know.
- [Architecture decisions](./docs/adr/) — the hard-to-reverse choices behind
each component, and why.

## Status

Expand All @@ -57,6 +59,7 @@ deploy from `environments.toml` → `[staging.contracts]`, which is the record.
| `share_token` | `CDOZT5VNIKSLQSFELF4PHVZRZA3GCJYJEHVDZTUB7O2QMBHBKKOYORQI` |
| `identity_verifier` | `CCGHNGPI66WGVSLLALQVCIRIOZKX73QW23UDZLZ3LMXLGEG7SLVUOULD` |
| `compliance` | `CCQI5NFRWBOO77LYSFY54D6PSU4TVWD5A3CFX2A5AWLEURVR35XISMKG` |
| `sep40_feed` | `CCDNFOV7GFBAZQLXLFBBX6H3T66NYAZG7Z6AWBEHSKLYFNJWRZTPYD2N` |
| `asset` | `CCOHKZLQ5EAD2A3RLHYHH7W4K2TNLNELXUVLWZIZALH45WXHH5H3QV7E` |
<!-- deployed-addresses:end -->

Expand Down
56 changes: 30 additions & 26 deletions contracts/async-vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use stellar_contract_utils::pausable::{self as pausable, Pausable};
use stellar_contract_utils::upgradeable;
use stellar_macros::{only_admin, only_role, when_not_paused};
use stellar_tokens::fungible::FungibleTokenClient;
use strata_bindings::VaultView;
use strata_timelock::{Clock, ClockSource, Refusal, TimelockHost, DAY_DURATION};

use keys::DataKey;
Expand Down Expand Up @@ -167,26 +168,6 @@ impl AsyncVault {
upgradeable::set_schema_version(e, 1);
}

/// The deposit asset's token contract.
pub fn asset(e: &Env) -> Address {
state::get_addr(e, &DataKey::Asset)
}

/// The share token.
pub fn share_token(e: &Env) -> Address {
state::get_addr(e, &DataKey::ShareToken)
}

/// The feed epochs are priced from.
pub fn oracle(e: &Env) -> Address {
state::get_addr(e, &DataKey::Oracle)
}

/// The admin: governance.
pub fn governance(e: &Env) -> Option<Address> {
access_control::get_admin(e)
}

/// The first holder of `manager`, which closes epochs.
pub fn manager(e: &Env) -> Option<Address> {
role_holder(e, &MANAGER_ROLE)
Expand Down Expand Up @@ -396,12 +377,6 @@ impl AsyncVault {
state::min_epoch_duration(e)
}

/// The wind-down once proposed: whether it is proposed or active, the time
/// in seconds it may start, and the rounds finalised.
pub fn wind_down(e: &Env) -> Option<WindDownInfo> {
wind_down::info(e)
}

/// Announces a wind-down, which anyone can start once the delay has run.
/// New deposits stop at once; exits go on.
///
Expand Down Expand Up @@ -1292,6 +1267,35 @@ impl Pausable for AsyncVault {
}
}

#[contractimpl(contracttrait)]
impl VaultView for AsyncVault {
/// The deposit asset's token contract.
fn asset(e: &Env) -> Address {
state::get_addr(e, &DataKey::Asset)
}

/// The share token.
fn share_token(e: &Env) -> Address {
state::get_addr(e, &DataKey::ShareToken)
}

/// The feed epochs are priced from.
fn oracle(e: &Env) -> Address {
state::get_addr(e, &DataKey::Oracle)
}

/// The wind-down once proposed: whether it is proposed or active, the time
/// in seconds it may start, and the rounds finalised.
fn wind_down(e: &Env) -> Option<WindDownInfo> {
wind_down::info(e)
}

/// The admin: governance.
fn governance(e: &Env) -> Option<Address> {
access_control::get_admin(e)
}
}

#[contractimpl(contracttrait)]
impl ClockSource for AsyncVault {
/// The clock the kit's timelocks run on: the upgrade delay and the notice
Expand Down
14 changes: 14 additions & 0 deletions contracts/async-vault/src/test/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ fn compliance_may_not_also_be_the_treasury() {
register_with(&e, roles);
}

fn implements_the_feeds_view<T: strata_bindings::VaultView>() {}

#[test]
fn the_vault_answers_the_view_the_feed_reads() {
implements_the_feeds_view::<AsyncVault>();
let f = setup();
let view = strata_bindings::VaultViewClient::new(&f.e, &f.vault.address);
assert_eq!(view.asset(), f.asset);
assert_eq!(view.share_token(), f.share.address);
assert_eq!(view.oracle(), f.oracle.address);
assert_eq!(view.wind_down(), None);
assert_eq!(view.governance(), Some(f.admin.clone()));
}

#[test]
fn the_guardian_may_be_governance() {
let e = Env::default();
Expand Down
19 changes: 2 additions & 17 deletions contracts/async-vault/src/wind_down.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use soroban_sdk::{contracttype, panic_with_error, token::TokenClient, Address, E
use stellar_contract_utils::math::i128_fixed_point::checked_mul_div_floor;
use stellar_tokens::{fungible::FungibleTokenClient, rwa::RWATokenClient};

pub use strata_bindings::{WindDownInfo, WindDownStatus};

use crate::error::VaultError;
use crate::event::{
WindDownActivated, WindDownClaimed, WindDownDelaySet, WindDownProposalCancelled,
Expand All @@ -25,23 +27,6 @@ pub const MIN_WIND_DOWN_DELAY: u64 = 7 * strata_timelock::DAY_DURATION;
#[cfg(feature = "short_wind_down")]
pub const MIN_WIND_DOWN_DELAY: u64 = 0;

#[contracttype]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum WindDownStatus {
Proposed,
Active,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WindDownInfo {
pub status: WindDownStatus,
/// Ledger time the proposal may be activated.
pub active_at: u64,
/// Rounds finalised so far. Zero means no snapshot has been taken.
pub round: u32,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WindDownPosition {
Expand Down
29 changes: 29 additions & 0 deletions contracts/sep40-feed/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "sep40-feed"
version = "0.1.0"
edition.workspace = true
license.workspace = true
publish = false

[lib]
crate-type = ["lib", "cdylib"]
doctest = false

[dependencies]
soroban-sdk = { workspace = true }
sep40 = { path = "../../crates/sep40" }
strata-bindings = { path = "../../crates/strata-bindings" }
strata-timelock = { path = "../../crates/strata-timelock" }
strata-storage = { path = "../../crates/strata-storage" }
stellar-contract-utils = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
async-vault = { path = "../async-vault" }
nav-oracle = { path = "../nav-oracle" }

[features]
# Builds a stand-in for a later feed version, used only by the upgrade test.
upgrade_probe = []
# Runs the test that upgrades the built feed to its probe build. Build both first.
upgrade_wasm = []
97 changes: 97 additions & 0 deletions contracts/sep40-feed/src/governance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use soroban_sdk::{contracttype, panic_with_error, BytesN, Env, Vec};
use stellar_contract_utils::upgradeable;
use strata_timelock::{queue, Clock, Refusal, TimelockHost};

use crate::guards;
use crate::{ChangeApplied, ChangeCancelled, ChangeProposed, FeedError, Sep40Feed};

/// A privileged change that waits for the vault's timelock before it lands.
/// The feed stores no admin, so the only change it ever proposes is its own
/// upgrade.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FeedChange {
Upgrade(BytesN<32>),
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FeedPendingChange {
pub id: u32,
pub change: FeedChange,
pub eta: u64,
}

/// Maps a timelock refusal onto the feed's own error codes. `SetupOpen`,
/// `SetupClosed`, `AlreadyBound` and `Unbound` arise only in the constructor,
/// which binds the vault and closes setup before any other call can land.
pub(crate) fn refuse(e: &Env, refusal: Refusal) -> ! {
match refusal {
Refusal::WindingDown => panic_with_error!(e, FeedError::WindDownActive),
Refusal::Paused => panic_with_error!(e, FeedError::VaultPaused),
Refusal::NotElapsed => panic_with_error!(e, FeedError::ChangeNotReady),
Refusal::BelowExitWindow => panic_with_error!(e, FeedError::DelayBelowNotice),
Refusal::NotFound => panic_with_error!(e, FeedError::ChangeNotFound),
Refusal::TooMany => panic_with_error!(e, FeedError::UpgradeAlreadyPending),
Refusal::SetupOpen | Refusal::SetupClosed | Refusal::AlreadyBound | Refusal::Unbound => {
panic_with_error!(e, FeedError::NotAVault)
}
}
}

fn vault_clock(e: &Env) -> Clock {
<Sep40Feed as TimelockHost>::clock(e).unwrap_or_else(|r| refuse(e, r))
}

pub(crate) fn propose(e: &Env, change: FeedChange) -> u32 {
guards::vault_not_winding_down(e);
guards::no_upgrade_pending(e);
let id = queue::propose::<Sep40Feed, _>(e, &change).unwrap_or_else(|r| refuse(e, r));
let (_, schedule) =
queue::pending::<FeedChange>(e, id).unwrap_or_else(|| refuse(e, Refusal::NotFound));
// No pause has run since the proposal, so the eta needs no second clock read.
ChangeProposed {
id,
change,
eta: schedule.proposed_at.saturating_add(schedule.delay),
}
.publish(e);
id
}

pub(crate) fn cancel(e: &Env, id: u32) {
queue::cancel(e, id).unwrap_or_else(|r| refuse(e, r));
ChangeCancelled { id }.publish(e);
}

pub(crate) fn apply(e: &Env, id: u32) {
let change: FeedChange =
queue::take_ready::<Sep40Feed, _>(e, id).unwrap_or_else(|r| refuse(e, r));
match &change {
FeedChange::Upgrade(hash) => upgradeable::upgrade(e, hash),
}
ChangeApplied { id, change }.publish(e);
}

/// Every change still waiting, with the moment it may land on the vault's
/// clock as it reads now.
pub(crate) fn pending(e: &Env) -> Vec<FeedPendingChange> {
let mut out = Vec::new(e);
let open = queue::open_ids(e);
if open.is_empty() {
// Skips the vault's clock, which a failed read would turn into a
// refusal even though nothing is waiting.
return out;
}
let clock = vault_clock(e);
for id in open.iter() {
if let Some((change, schedule)) = queue::pending::<FeedChange>(e, id) {
out.push_back(FeedPendingChange {
id,
change,
eta: schedule.eta(&clock),
});
}
}
out
}
55 changes: 55 additions & 0 deletions contracts/sep40-feed/src/guards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use soroban_sdk::{panic_with_error, Address, Env};
use strata_bindings::VaultViewClient;
use strata_timelock::{queue, ClockSourceClient, TimelockHost};

use crate::{bound_vault, governance, FeedChange, FeedError, Sep40Feed};

/// Refuses an address that does not answer every view the feed reads from a
/// vault, so the feed never binds to one it cannot follow.
pub(crate) fn answers_as_vault(e: &Env, vault: &Address) {
if !vault_reports_fully(e, vault) {
panic_with_error!(e, FeedError::NotAVault);
}
}

fn vault_reports_fully(e: &Env, vault: &Address) -> bool {
let view = VaultViewClient::new(e, vault);
matches!(view.try_asset(), Ok(Ok(_)))
&& matches!(view.try_share_token(), Ok(Ok(_)))
&& matches!(view.try_oracle(), Ok(Ok(_)))
&& matches!(view.try_wind_down(), Ok(Ok(_)))
&& matches!(view.try_governance(), Ok(Ok(_)))
&& matches!(
ClockSourceClient::new(e, vault).try_timelock_clock(),
Ok(Ok(_))
)
}

/// The feed stores no admin: every change asks the vault's current governance
/// to sign, read fresh so a hand-over on the vault carries straight over.
pub(crate) fn signed_by_governance(e: &Env) {
match VaultViewClient::new(e, &bound_vault(e)).try_governance() {
Ok(Ok(Some(governance))) => governance.require_auth(),
_ => panic_with_error!(e, FeedError::NoGovernance),
}
}

/// One upgrade at a time, so a standing eta is never quietly replaced.
pub(crate) fn no_upgrade_pending(e: &Env) {
let pending = queue::open_ids(e)
.iter()
.any(|id| queue::pending::<FeedChange>(e, id).is_some());
if pending {
panic_with_error!(e, FeedError::UpgradeAlreadyPending);
}
}

/// A wind-down outranks even the one-upgrade-at-a-time check.
pub(crate) fn vault_not_winding_down(e: &Env) {
if <Sep40Feed as TimelockHost>::clock(e)
.unwrap_or_else(|r| governance::refuse(e, r))
.winding_down
{
panic_with_error!(e, FeedError::WindDownActive);
}
}
Loading
Loading