Skip to content

feat(feed): expose the share price through SEP-40 - #439

Merged
hpmaxi merged 20 commits into
tranche-3from
feat/236-sep40-feed
Nov 13, 2026
Merged

hpmaxi merged 20 commits into
tranche-3from
feat/236-sep40-feed

Conversation

@hpmaxi

@hpmaxi hpmaxi commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #236

Integrators (lending markets, DEXs, dashboards) read prices through SEP-40. Today the vault's share price is readable only through the oracle's own interface, and a caller that skips state() can read a price the vault would refuse. This adds a SEP-40 feed, one per vault, that answers only while the price is one the vault would accept.

Changes

  • A sep40 crate with the standard's types, trait and client, and no kit dependency.
  • A VaultView interface in strata-bindings; the vault implements it with its existing functions.
  • A sep40-feed contract that stores only the vault and reads its current oracle, asset and share token on every call.
  • Prices in 14 decimals; none while the oracle is stale or paused or a wind-down is active.
  • Upgrades only through the vault's timelock, signed by the vault's current governance.
  • The harness deploys, verifies and extends the feed; deploy:feed adds one to an existing set.
  • The feed on testnet, added to the current set without touching it.
  • The design document records the feed's hard-to-reverse choices, with their reasons and costs; the other docs describe the feed.

Deviations

  • The constructor takes only the vault; governance is read from the vault on each change call.
  • The price window ends at attested_at + freshness_duration; an earlier reporter expiry still ends it, since every quote needs a Valid oracle.
  • price(asset, ts) also refuses a ts later than the ledger time.
  • The issue asks for a separate decision record; those choices are in the design document instead, which is the repository's single source of truth for what the protocol does and why. The epic issue template no longer suggests linking separate decision records.
  • The testnet feed was built before the price scales became compile-time constants. Its prices are the same: the price tests pin every rounding.
  • Two commit subjects exceed 50 characters.

Acceptance criteria

  • A sep40 crate with the standard's types, trait and client, and no kit dependency
  • The feed implements the SEP-40 read interface (base, assets, decimals, resolution, price, prices, lastprice) as described above
  • It reads from the vault and its current oracle on every call and never stores a price; a test swaps the oracle and the feed follows
  • A stale or paused oracle, or an active wind-down, gives no price, never the last good one; a failing read never panics
  • A test fixes the conversion with unequal asset and share decimals
  • Upgrades go only through the timelock, with the same refusals as the kit's other contracts
  • Tests cover valid, stale, paused and wind-down states, unknown assets, and the base asset
  • The harness deploys and extends it on testnet, and the README lists its contract ID
  • docs/kit-spec.md, docs/AUTHORIZATION_MATRIX.md, docs/THREAT_MODEL.md and the design document describe it, and the choices that are hard to reverse are recorded (in the design document; see Deviations)

Test plan

Automated tests

  1. cargo test --workspace --locked, clippy with -D warnings, cargo fmt --check: pass.
  2. The Wasm upgrade tests as docs/TESTING.md describes: the feed's built Wasm upgrades in place, and after a vault governance hand-over the old governance is refused.
  3. Root npm run lint, format:check, typecheck, test, and the harness unit tests: pass.
  4. On a local network: deploy, then test:happy-path and test:wind-down (a feed quote, and no price during a wind-down): pass.

Manual verification

  1. Read-only calls on testnet to CCDNFOV7GFBAZQLXLFBBX6H3T66NYAZG7Z6AWBEHSKLYFNJWRZTPYD2N: decimals() is 14, base() and assets() match the staging vault, resolution() matches its oracle.
  2. lastprice returns no price today: the staging oracle's NAV is stale, and the feed does not answer with an old price.

Breaking changes

None. The vault's exported interface is unchanged.

Checklist

  • Self-reviewed my own diff
  • Tests added or updated
  • Docs updated (if applicable)
  • No unrelated changes bundled in

Screenshots

None.

Close gaps found in the final whole-branch review: pin the feed by
contract ID or vault() rather than base()/assets() alone, name the
decimals-drift residual, name the reviewed commit, correct which views
lack a None fallback, drop the wrong governance-on-every-quote claim,
fix the contract count in three places, and note the attester can set
an earlier expiry than freshness_duration.
verifyFeed now checks the deployed feed's vault() against the vault
it was deployed for, so a feed bound to a lookalike vault fails
deployment instead of passing because its asset and share token match.
withFeed records the feed's own source commit and uncommitted-changes
flag separately from the set's, since deploy-feed.ts can add a feed to
an older set.

Also drops the #[allow(dead_code)] attributes left over in the feed's
test fixtures, none of which clippy -D warnings still needs, and
extracts the ~40-line kit-vault setup the two kit.rs tests repeated
into one helper.
@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
strata-vault-kit-app Ready Ready Preview Nov 13, 2026 2:28pm UTC

Request Review

@hpmaxi
hpmaxi marked this pull request as ready for review November 11, 2026 18:42
@hpmaxi
hpmaxi requested a review from luchobonatti November 13, 2026 00:01

@luchobonatti luchobonatti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. A couple of optional suggestions inline.

pub(crate) fn resolution(e: &Env) -> u32 {
let oracle_address = match ok(VaultViewClient::new(e, &bound_vault(e)).try_oracle()) {
Some(address) => address,
None => return 0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a non-zero fallback here? A consumer applying SEP-40's floor(ts / resolution) would divide by zero on 0. Or a note in the ADR if 0 is intended.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept 0, and documented it in e05e4ef. The oracle refuses a zero freshness_duration, so 0 only ever means the feed cannot read its oracle right now, and then it has no price either; any non-zero value would be made up. The doc comments, the design doc (8.5) and the authorization matrix now say so, including that a consumer must check for 0 before dividing. A test pins resolution() == 0 on a failed read.

#[contractimpl(contracttrait)]
impl PriceFeed for Sep40Feed {
/// The vault's deposit asset: every price is quoted in it.
fn base(e: &Env) -> Asset {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could base() / assets() use try_ like the price reads, so a trapping vault doesn't panic the feed? Fine to keep if intended, maybe worth a line in the ADR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept as is on purpose, now documented in e05e4ef. SEP-40's base() has no way to say "unknown", and a feed whose vault can't name its own asset is broken, so failing the call is the honest answer; assets() follows base() so the two never disagree. The doc comments and the design doc (8.5) explain it.

@hpmaxi
hpmaxi requested a review from luchobonatti November 13, 2026 14:29
@hpmaxi
hpmaxi merged commit 99700e9 into tranche-3 Nov 13, 2026
10 checks passed

This branch was successfully deployed

1 active deployment
Preview — e05e4efa Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants