syntax = "proto3";
package pyth_lazer;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

// if any fields marked as [required] are missing, feed/publisher update will be rejected

// Publisher update included in transaction
//
// Each publisher update contains a batch of feed updates from publisher.
// The publisher uses Pyth Agent on their side that handles batching.
// Each feed update specifies a single update type (price, funding rate, etc.)
message PublisherUpdate {
    // [required] array of feed updates, each of which target a single feed
    // order of updates are preserved between encoding/decoding
    repeated FeedUpdate updates = 1;

    // [required] timestamp when batch of feed updates was collected
    optional google.protobuf.Timestamp publisher_timestamp = 2;
}

// A single feed update containing one type of update
message FeedUpdate {
    // [required] id of the lazer feed to be updated
    // should match the ids of feeds recognized by pyth lazer
    optional uint32 feed_id = 1;

    // [required] timestamp when this data was first acquired or generated
    optional google.protobuf.Timestamp source_timestamp = 2;

    // [required] one type of update containing specific data
    oneof update {
      PriceUpdate price_update = 3;
      FundingRateUpdate funding_rate_update = 4;
    };
}

// feed update containing data for the core price, bid, and ask prices
message PriceUpdate {
    // [optional] price for the feed as an integer
    // should be produced with a matching exponent to the configured exponent value in pyth lazer
    optional int64 price = 1;

    // [optional] best bid price for the feed as an integer
    // should be produced with a matching exponent to the configured exponent value in pyth lazer
    // may be missing if no data is available
    optional int64 best_bid_price = 2;

    // [optional] best ask price for the feed as an integer
    // should be produced with a matching exponent to the configured exponent value in pyth lazer
    // may be missing if no data is available
    optional int64 best_ask_price = 3;
}

// feed update containing data relating to funding rate
message FundingRateUpdate {
    // [optional] price for which the funding rate applies to
    optional int64 price = 1;

    // [optional] perpetual future funding rate
    optional int64 rate = 2;

    // [optional] funding rate update interval
    optional google.protobuf.Duration funding_rate_interval = 3;
}
