Repository navigation
feat(feed): expose the share price through SEP-40 - #439
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
luchobonatti
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
sep40crate with the standard's types, trait and client, and no kit dependency.VaultViewinterface instrata-bindings; the vault implements it with its existing functions.sep40-feedcontract that stores only the vault and reads its current oracle, asset and share token on every call.deploy:feedadds one to an existing set.Deviations
attested_at + freshness_duration; an earlier reporter expiry still ends it, since every quote needs aValidoracle.price(asset, ts)also refuses atslater than the ledger time.Acceptance criteria
sep40crate with the standard's types, trait and client, and no kit dependencybase,assets,decimals,resolution,price,prices,lastprice) as described abovedocs/kit-spec.md,docs/AUTHORIZATION_MATRIX.md,docs/THREAT_MODEL.mdand 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
cargo test --workspace --locked, clippy with-D warnings,cargo fmt --check: pass.docs/TESTING.mddescribes: the feed's built Wasm upgrades in place, and after a vault governance hand-over the old governance is refused.npm run lint,format:check,typecheck,test, and the harness unit tests: pass.deploy, thentest:happy-pathandtest:wind-down(a feed quote, and no price during a wind-down): pass.Manual verification
CCDNFOV7GFBAZQLXLFBBX6H3T66NYAZG7Z6AWBEHSKLYFNJWRZTPYD2N:decimals()is 14,base()andassets()match the staging vault,resolution()matches its oracle.lastpricereturns 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
Screenshots
None.