sep_40_oracle/
lib.rs

1//! Interface for SEP-40 Oracle Price Feed
2//! https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0040.md
3
4#![no_std]
5
6#[cfg(any(test, feature = "testutils"))]
7pub mod testutils;
8
9use soroban_sdk::{contractclient, contracttype, Address, Env, Symbol, Vec};
10
11/// Price data for an asset at a specific timestamp
12#[contracttype]
13#[derive(Clone)]
14pub struct PriceData {
15    pub price: i128,
16    pub timestamp: u64,
17}
18
19/// Asset type
20#[contracttype]
21#[derive(Clone)]
22pub enum Asset {
23    Stellar(Address),
24    Other(Symbol),
25}
26
27/// Oracle feed interface description
28#[contractclient(name = "PriceFeedClient")]
29pub trait PriceFeedTrait {
30    /// Return the base asset the price is reported in
31    fn base(env: Env) -> Asset;
32
33    /// Return all assets quoted by the price feed
34    fn assets(env: Env) -> Vec<Asset>;
35
36    /// Return the number of decimals for all assets quoted by the oracle
37    fn decimals(env: Env) -> u32;
38
39    /// Return default tick period timeframe (in seconds)
40    fn resolution(env: Env) -> u32;
41
42    /// Get price in base asset at specific timestamp
43    fn price(env: Env, asset: Asset, timestamp: u64) -> Option<PriceData>;
44
45    /// Get last N price records
46    fn prices(env: Env, asset: Asset, records: u32) -> Option<Vec<PriceData>>;
47
48    /// Get the most recent price for an asset
49    fn lastprice(env: Env, asset: Asset) -> Option<PriceData>;
50}