module pyth_lazer::feed; use pyth_lazer::i16::I16; use pyth_lazer::i64::I64; /// The feed struct is based on the Lazer rust protocol definition defined here: /// https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/sdk/rust/protocol/src/payload.rs /// /// Some fields in Lazer are optional, as in Lazer might return None for them due to some conditions (for example, /// not having enough publishers to calculate the price) and that is why they are represented as Option>. /// The first Option is for the existence of the field within the update data and the second Option is for the /// value of the field. public struct Feed has copy, drop { /// Unique identifier for the price feed (e.g., 1 for BTC/USD, 2 for ETH/USD) feed_id: u32, /// Current aggregate price from all publishers price: Option>, /// Best bid price available across all publishers best_bid_price: Option>, /// Best ask price available across all publishers best_ask_price: Option>, /// Number of publishers contributing to this price feed publisher_count: Option, /// Price exponent (typically negative, e.g., -8 means divide price by 10^8) exponent: Option, /// Confidence interval representing price uncertainty confidence: Option>, /// Funding rate for derivative products (e.g., perpetual futures) funding_rate: Option>, /// Timestamp when the funding rate was last updated funding_timestamp: Option>, /// How often the funding rate and funding payments are calculated, in microseconds funding_rate_interval: Option>, } /// Create a new Feed with the specified parameters public(package) fun new( feed_id: u32, price: Option>, best_bid_price: Option>, best_ask_price: Option>, publisher_count: Option, exponent: Option, confidence: Option>, funding_rate: Option>, funding_timestamp: Option>, funding_rate_interval: Option>, ): Feed { Feed { feed_id, price, best_bid_price, best_ask_price, publisher_count, exponent, confidence, funding_rate, funding_timestamp, funding_rate_interval } } /// Get the feed ID public fun feed_id(feed: &Feed): u32 { feed.feed_id } /// Get the price public fun price(feed: &Feed): Option> { feed.price } /// Get the best bid price public fun best_bid_price(feed: &Feed): Option> { feed.best_bid_price } /// Get the best ask price public fun best_ask_price(feed: &Feed): Option> { feed.best_ask_price } /// Get the publisher count public fun publisher_count(feed: &Feed): Option { feed.publisher_count } /// Get the exponent public fun exponent(feed: &Feed): Option { feed.exponent } /// Get the confidence interval public fun confidence(feed: &Feed): Option> { feed.confidence } /// Get the funding rate public fun funding_rate(feed: &Feed): Option> { feed.funding_rate } /// Get the funding timestamp public fun funding_timestamp(feed: &Feed): Option> { feed.funding_timestamp } /// Get the funding rate interval public fun funding_rate_interval(feed: &Feed): Option> { feed.funding_rate_interval } /// Set the feed ID public(package) fun set_feed_id(feed: &mut Feed, feed_id: u32) { feed.feed_id = feed_id; } /// Set the price public(package) fun set_price(feed: &mut Feed, price: Option>) { feed.price = price; } /// Set the best bid price public(package) fun set_best_bid_price(feed: &mut Feed, best_bid_price: Option>) { feed.best_bid_price = best_bid_price; } /// Set the best ask price public(package) fun set_best_ask_price(feed: &mut Feed, best_ask_price: Option>) { feed.best_ask_price = best_ask_price; } /// Set the publisher count public(package) fun set_publisher_count(feed: &mut Feed, publisher_count: Option) { feed.publisher_count = publisher_count; } /// Set the exponent public(package) fun set_exponent(feed: &mut Feed, exponent: Option) { feed.exponent = exponent; } /// Set the confidence interval public(package) fun set_confidence(feed: &mut Feed, confidence: Option>) { feed.confidence = confidence; } /// Set the funding rate public(package) fun set_funding_rate(feed: &mut Feed, funding_rate: Option>) { feed.funding_rate = funding_rate; } /// Set the funding timestamp public(package) fun set_funding_timestamp(feed: &mut Feed, funding_timestamp: Option>) { feed.funding_timestamp = funding_timestamp; } /// Set the funding rate interval public(package) fun set_funding_rate_interval(feed: &mut Feed, funding_rate_interval: Option>) { feed.funding_rate_interval = funding_rate_interval; }