Skip to content

feat(examples): read the SEP-40 feed from a consumer - #440

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

hpmaxi merged 20 commits into
tranche-3from
feat/237-sep40-consumer

Conversation

@hpmaxi

@hpmaxi hpmaxi commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #237
Refs #433

The SEP-40 feed alone does not show that someone else can read it. This adds a small consumer contract that knows only the SEP-40 interface, reads the feed in one transaction, and emits what it read. It is deployed on testnet, and the transaction that recorded a price is in the README.

Changes

  • examples/sep40-consumer: one entry point, record_price(feed, asset). It reads decimals, resolution and lastprice, and emits PriceRecorded with the price, its timestamp, the decimals and the resolution, or NoPrice. It keeps no state.
  • A missing price, a failing read or an address that is not a contract ends in NoPrice, never a panic.
  • It depends only on the sep40 crate; it lives under examples/, not contracts/.
  • The workspace includes examples/*; the build, the client generation and the doc-size test cover the example.
  • Harness: test:sep40 deploys a new consumer, attests a fresh NAV when the current one is stale, and checks the event in both the simulation and the sent transaction. send() takes force (off by default, used only for record_price, which simulates as a read) and onSent.
  • README: the consumer's testnet contract ID and transactions.

Deviations

None.

Acceptance criteria

  • The consumer depends only on the sep40 crate, not on kit types
  • It reads decimals, resolution and lastprice, and handles a missing price without panicking
  • Tests cover a price, no price, and an unknown asset
  • Deployed to testnet; its contract ID and one transaction hash recorded in the README

Test plan

Automated tests

  1. cargo test --workspace --locked, clippy with -D warnings, cargo fmt --check: pass. The consumer's tests cover a price, no price, an unknown asset, a failing feed, a feed that is an account address, and no stored state.
  2. Root npm run lint, format:check, typecheck, test, and the harness unit tests: pass.
  3. On a local network, in CI order: deploy, test:happy-path, test:sep40: pass. test:sep40 also passes alone on a freshly deployed network with no NAV yet.

Manual verification

  1. Testnet consumer CDKCYZ6IHE2I6KAGATCQPTOYX7GUTTCYRLK26HOQ2JVHEHGXNVA27DOJ, built from this branch, deployed in 5142b57e…4505.
  2. A fresh NAV attested on the staging oracle (the stored value, so the price did not change) in 3478b5b3…2bf2.
  3. record_price against the feed in eb0fd738…fba7: one transaction, a price_recorded event with price 100100000000000 (1.001 at 14 decimals) and the attestation's timestamp.

Breaking changes

None.

Checklist

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

Screenshots

None.

@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 13, 2026 12:26

@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.

Looks good. A few optional suggestions inline.

// The NAV can lapse between simulation and inclusion; re-check the
// event the network actually recorded, not just the simulated one.
const included = decodedEvent(sentEvents(sent ?? {}))
expect(included?.name).toBe("price_recorded")

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 also assert decimals and resolution on included.data, so the recorded payload is covered too?

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.

Done in 0c8e49f: the included event's data is checked for decimals and resolution too.

Comment thread scripts/harness/lib/clients.ts Outdated
getTransactionResponse?: rpc.Api.GetTransactionResponse
}): readonly xdr.DiagnosticEvent[] {
const response = sent.getTransactionResponse
return response && "diagnosticEventsXdr" in response

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.

diagnosticEventsXdr is optional in the SDK types. Would events.contractEventsXdr be a safer source?

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.

Agreed, done in 0c8e49f. sentEvents reads events.contractEventsXdr now, and decodedEvent works on contract events, so the simulated and the included transaction go through the same finder.

//! price to read back from the contract itself.
//! - **Anyone may call it.** `record_price` takes no authorization. The cost:
//! anyone can spend the call's fee to record a price, including a stale or
//! absent one.

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 bullet saying staleness checks are left to callers, so integrators don't copy it as-is?

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.

Done in 6079c4b: a design bullet says the consumer leaves the price's age to the caller, and what that costs if copied as is.

@hpmaxi
hpmaxi requested a review from luchobonatti November 13, 2026 14:29
@hpmaxi
hpmaxi changed the base branch from feat/236-sep40-feed to tranche-3 November 13, 2026 14:43
@hpmaxi
hpmaxi merged commit cd9bf78 into tranche-3 Nov 13, 2026
10 checks passed

This branch was successfully deployed

1 active deployment
Preview — 39be5b2e 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