state.proto 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. syntax = "proto3";
  2. package pyth_lazer;
  3. import "google/protobuf/duration.proto";
  4. import "google/protobuf/timestamp.proto";
  5. import "dynamic_value.proto";
  6. // All optional fields should always be set unless documented otherwise.
  7. // State of a Pyth Lazer shard.
  8. //
  9. // The state is shared across all Pyth Lazer aggregators that process this shard.
  10. // All aggregators should observe the same state at any `last_sequence_no`.
  11. // The state contains all the information necessary for processing the updates.
  12. // The aggregators cannot rely on any external data, except the state and the update sequence.
  13. // A snapshot of the state includes the serialized `State` value as the payload.
  14. message State {
  15. // [required] ID of this shard. Each state value only accounts for data of a particular shard.
  16. optional uint32 shard_id = 1;
  17. // [required] sequence_no of the last update applied to the state.
  18. optional uint64 last_sequence_no = 2;
  19. // [required] Timestamp of the last update provided by Kafka/Nats.
  20. // If no updates were applied, contains the timestamp of genesis snapshot creation time.
  21. optional google.protobuf.Timestamp last_timestamp = 3;
  22. // [required] Shard name. Must be unique. Used for governance instruction targeting and
  23. // for logs, metrics, etc. Example: "shard1.tokyo.staging.pyth-lazer"
  24. optional string shard_name = 4;
  25. // [required] Shard group name. Used for governance instruction targeting.
  26. // Example: "tokyo.staging.pyth-lazer"
  27. optional string shard_group = 5;
  28. // [required] Minimal aggregation rate allowed in this shard.
  29. optional google.protobuf.Duration min_rate = 6;
  30. // List of feeds.
  31. repeated Feed feeds = 7;
  32. // List of publishers.
  33. repeated Publisher publishers = 8;
  34. // TODO: governance state (pubkey, last sequence no)
  35. }
  36. // An item of the state describing a publisher.
  37. message Publisher {
  38. // [required] Publisher ID. Restricted to uint16.
  39. optional uint32 publisher_id = 1;
  40. // [required] Publisher name (only for debug/monitoring/management purposes). Must be unique.
  41. optional string name = 2;
  42. // Public keys used to sign publisher update transactions.
  43. repeated bytes public_keys = 3;
  44. // [required] If true, the publisher is active, i.e. it's allowed to publish updates.
  45. optional bool is_active = 4;
  46. }
  47. enum FeedState {
  48. // Default value. Feeds in this state are not available to consumers.
  49. // `COMING_SOON` feeds are expected to become stable in the future.
  50. COMING_SOON = 0;
  51. // A fully available feed.
  52. STABLE = 1;
  53. // Inactive feeds are not available to consumers.
  54. // `INACTIVE` feeds are not expected to become stable again.
  55. INACTIVE = 2;
  56. }
  57. // Feed kind determines the set of data fields available in the feed.
  58. // It also determines the kind of data accepted from publishers for this feed
  59. // (`PriceUpdate` or `FundingRateUpdate`).
  60. enum FeedKind {
  61. // Fields: price, best_bid_price, best_ask_price
  62. PRICE = 0;
  63. // Fields: price, rate.
  64. FUNDING_RATE = 1;
  65. }
  66. // An item of the state describing a feed.
  67. message Feed {
  68. // [required] ID of the feed.
  69. optional uint32 feed_id = 1;
  70. // Additional state per publisher.
  71. // If an eligible publisher is not listed here, the corresponding state should be considered empty.
  72. repeated FeedPublisherState per_publisher = 2;
  73. // [required] Additional metadata values. These values will be exposed in the APIs, but
  74. // are not directly used in the aggregator.
  75. optional DynamicValue.Map metadata = 3;
  76. // [required] A readable feed name. It must be unique across all feeds in the shard.
  77. // Used for logs, metrics, feed search API, TradingView API.
  78. optional string name = 101;
  79. // [required] Exponent applied to all price and rate values for this feed.
  80. // Actual value is `mantissa * 10 ^ exponent`.
  81. // Restricted to int16.
  82. optional sint32 exponent = 102;
  83. // [required] Minimal number of publisher prices required to produce an aggregate.
  84. optional uint32 min_publishers = 103;
  85. // [required] Minimal rate of aggregation performed by the aggregator for this feed.
  86. // Cannot be lower than the shard's top level `State.min_rate`.
  87. optional google.protobuf.Duration min_rate = 104;
  88. // [required] Time after which the publisher update is discarded.
  89. optional google.protobuf.Duration expiry_time = 105;
  90. // [required] Market schedule in Pythnet format.
  91. optional string market_schedule = 106;
  92. // [required] Feed state.
  93. optional FeedState state = 107;
  94. // [required] Feed kind.
  95. optional FeedKind kind = 108;
  96. // [required] Feed status in the current shard. Disabled feeds will not be visible in
  97. // the consumer API for the current shard. This setting should only be used
  98. // to migrate a feed from one shard to another.
  99. //
  100. // If a feed is present in
  101. // multiple shards, it must only be active in one of them at each time.
  102. // To enforce this, `enable_in_shard_timestamp` and `disable_in_shard_timestamp` fields
  103. // can be used to deactivate a feed in one shard and activate it in another shard
  104. // at the same instant.
  105. optional bool is_enabled_in_shard = 201;
  106. // [optional] If present, the aggregator will enable the feed in the current shard
  107. // at the specified instant.
  108. optional google.protobuf.Timestamp enable_in_shard_timestamp = 202;
  109. // [optional] If present, the aggregator will disable the feed in the current shard
  110. // at the specified instant.
  111. optional google.protobuf.Timestamp disable_in_shard_timestamp = 203;
  112. // TODO: list of permissioned publisher IDs.
  113. }
  114. // A part of the feed state related to a particular publisher.
  115. message FeedPublisherState {
  116. // [required] Publisher ID. Restricted to uint16.
  117. optional uint32 publisher_id = 1;
  118. // [optional] Timestamp of the last update received from this publisher to this feed.
  119. // This timestamp is provided by Nats/Kafka, not by publisher.
  120. // Can be absent if no update was ever received or if the last update was deemed no longer relevant.
  121. optional google.protobuf.Timestamp last_update_timestamp = 2;
  122. // [optional] Publisher timestamp of the last update received from this publisher to this feed.
  123. // This timestamp is provided by publisher.
  124. // Can be absent if no update was ever received or if the last update was deemed no longer relevant.
  125. optional google.protobuf.Timestamp last_publisher_timestamp = 3;
  126. // [optional] Data of the last update received from this publisher to this feed.
  127. // Can be absent if no update was ever received or if the last update was deemed no longer relevant.
  128. optional FeedData last_feed_data = 4;
  129. }
  130. // Data provided by a publisher for a certain feed.
  131. message FeedData {
  132. // [required] Timestamp provided by the source of data that the publisher uses (e.g. an exchange).
  133. // If no such timestamp is available, it should be set to the same value as `publisher_timestamp`.
  134. optional google.protobuf.Timestamp source_timestamp = 1;
  135. // [required] Timestamp of the publisher.
  136. optional google.protobuf.Timestamp publisher_timestamp = 2;
  137. // [optional] Best executable price. Can be absent if no data is available. Never present for funding rate feeds.
  138. optional int64 price = 3;
  139. // [optional] Best bid price. Can be absent if no data is available. Never present for funding rate feeds.
  140. optional int64 best_bid_price = 4;
  141. // [optional] Best ask price. Can be absent if no data is available. Never present for funding rate feeds.
  142. optional int64 best_ask_price = 5;
  143. // [optional] Funding rate. Can be absent if no data is available. Can only be present for funding rate feeds.
  144. optional int64 funding_rate = 6;
  145. // [optional] Funding rate interval. Can be absent if no data is available. Can only be present for funding rate feeds.
  146. optional google.protobuf.Duration funding_rate_interval = 7;
  147. }