state.proto 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. syntax = "proto3";
  2. package pyth_lazer;
  3. import "google/protobuf/duration.proto";
  4. import "google/protobuf/timestamp.proto";
  5. import "google/protobuf/empty.proto";
  6. import "dynamic_value.proto";
  7. // All optional fields should always be set unless documented otherwise.
  8. message Channel {
  9. oneof kind {
  10. google.protobuf.Duration rate = 1;
  11. google.protobuf.Empty real_time = 2;
  12. }
  13. }
  14. // State of a Pyth Lazer shard.
  15. //
  16. // The state is shared across all Pyth Lazer aggregators that process this shard.
  17. // All aggregators should observe the same state at any `last_sequence_no`.
  18. // The state contains all the information necessary for processing the updates.
  19. // The aggregators cannot rely on any external data, except the state and the update sequence.
  20. // A snapshot of the state includes the serialized `State` value as the payload.
  21. message State {
  22. // [required] ID of this shard. Each state value only accounts for data of a particular shard.
  23. optional uint32 shard_id = 1;
  24. // [required] sequence_no of the last update applied to the state.
  25. optional uint64 last_sequence_no = 2;
  26. // [required] Timestamp of the last update provided by Kafka/Nats.
  27. // If no updates were applied, contains the timestamp of genesis snapshot creation time.
  28. optional google.protobuf.Timestamp last_timestamp = 3;
  29. // [required] Shard name. Must be unique. Used for governance instruction targeting and
  30. // for logs, metrics, etc. Example: "shard1.tokyo.staging.pyth-lazer"
  31. optional string shard_name = 4;
  32. // [required] Shard group name. Used for governance instruction targeting.
  33. // Example: "tokyo.staging.pyth-lazer"
  34. optional string shard_group = 5;
  35. // [required] Minimal aggregation rate allowed in this shard.
  36. optional google.protobuf.Duration min_rate = 6;
  37. // List of feeds.
  38. repeated Feed feeds = 7;
  39. // List of publishers.
  40. repeated Publisher publishers = 8;
  41. // List of governance sources.
  42. repeated GovernanceSourceState governance_sources = 9;
  43. // Currently active feature flags. Feature flags influence the aggregator's behavior.
  44. repeated string feature_flags = 10;
  45. }
  46. // An item of the state describing a publisher.
  47. message Publisher {
  48. // [required] Publisher ID. Restricted to uint16.
  49. optional uint32 publisher_id = 1;
  50. // [required] Publisher name (only for debug/monitoring/management purposes). Must be unique.
  51. optional string name = 2;
  52. // Public keys used to sign publisher update transactions.
  53. repeated bytes public_keys = 3;
  54. // [required] If true, the publisher is active, i.e. it's allowed to publish updates.
  55. optional bool is_active = 4;
  56. // IDs of the feeds for which the publisher's price will be included in the aggregate.
  57. repeated uint32 allowed_feed_ids = 5;
  58. }
  59. enum FeedState {
  60. // Default value. Feeds in this state are not available to consumers.
  61. // `COMING_SOON` feeds are expected to become stable in the future.
  62. COMING_SOON = 0;
  63. // A fully available feed.
  64. STABLE = 1;
  65. // Inactive feeds are not available to consumers.
  66. // `INACTIVE` feeds are not expected to become stable again.
  67. INACTIVE = 2;
  68. }
  69. // Feed kind determines the set of data fields available in the feed.
  70. // It also determines the kind of data accepted from publishers for this feed
  71. // (`PriceUpdate` or `FundingRateUpdate`).
  72. enum FeedKind {
  73. // Fields: price, best_bid_price, best_ask_price
  74. PRICE = 0;
  75. // Fields: price, rate.
  76. FUNDING_RATE = 1;
  77. }
  78. // An item of the state describing a feed.
  79. message Feed {
  80. // [required] ID of the feed.
  81. optional uint32 feed_id = 1;
  82. // Additional state per publisher.
  83. // If an eligible publisher is not listed here, the corresponding state should be considered empty.
  84. repeated FeedPublisherState per_publisher = 2;
  85. // [required] Additional metadata values. These values will be exposed in the APIs, but
  86. // are not directly used in the aggregator.
  87. optional DynamicValue.Map metadata = 3;
  88. // [required] A readable feed name. It must be unique across all feeds in the shard.
  89. // Used for logs, metrics, feed search API, TradingView API.
  90. optional string name = 101;
  91. // [required] Exponent applied to all price and rate values for this feed.
  92. // Actual value is `mantissa * 10 ^ exponent`.
  93. // Restricted to int16.
  94. optional sint32 exponent = 102;
  95. // [required] Minimal number of publisher prices required to produce an aggregate.
  96. optional uint32 min_publishers = 103;
  97. // [required] Minimal channel of aggregation performed by the aggregator for this feed.
  98. // Cannot be lower than the shard's top level `State.min_rate`.
  99. optional Channel min_channel = 104;
  100. // [required] Time after which the publisher update is discarded.
  101. optional google.protobuf.Duration expiry_time = 105;
  102. // [required] Market schedule in Pythnet format.
  103. optional string market_schedule = 106;
  104. // [required] Feed state.
  105. optional FeedState state = 107;
  106. // [required] Feed kind.
  107. optional FeedKind kind = 108;
  108. // [required] Current aggregated data of the feed.
  109. optional FeedDataFields aggregated_data = 109;
  110. // [required] Feed status in the current shard. Disabled feeds will not be visible in
  111. // the consumer API for the current shard. This setting should only be used
  112. // to migrate a feed from one shard to another.
  113. //
  114. // If a feed is present in
  115. // multiple shards, it must only be active in one of them at each time.
  116. // To enforce this, `enable_in_shard_timestamp` and `disable_in_shard_timestamp` fields
  117. // can be used to deactivate a feed in one shard and activate it in another shard
  118. // at the same instant.
  119. optional bool is_enabled_in_shard = 201;
  120. // [optional] If present, the aggregator will enable the feed in the current shard
  121. // at the specified instant.
  122. optional google.protobuf.Timestamp enable_in_shard_timestamp = 202;
  123. // [optional] If present, the aggregator will disable the feed in the current shard
  124. // at the specified instant.
  125. optional google.protobuf.Timestamp disable_in_shard_timestamp = 203;
  126. // TODO: list of permissioned publisher IDs.
  127. }
  128. // A part of the feed state related to a particular publisher.
  129. message FeedPublisherState {
  130. // [required] Publisher ID. Restricted to uint16.
  131. optional uint32 publisher_id = 1;
  132. // [optional] Timestamp of the last update received from this publisher to this feed.
  133. // This timestamp is provided by Nats/Kafka, not by publisher.
  134. // Can be absent if no update was ever received or if the last update was deemed no longer relevant.
  135. optional google.protobuf.Timestamp last_update_timestamp = 2;
  136. // [optional] Publisher timestamp of the last update received from this publisher to this feed.
  137. // This timestamp is provided by publisher.
  138. // Can be absent if no update was ever received or if the last update was deemed no longer relevant.
  139. optional google.protobuf.Timestamp last_publisher_timestamp = 3;
  140. // [optional] Data of the last update received from this publisher to this feed.
  141. // Can be absent if no update was ever received or if the last update was deemed no longer relevant.
  142. optional FeedData last_feed_data = 4;
  143. }
  144. // Data provided by a publisher for a certain feed.
  145. message FeedData {
  146. // [required] Timestamp provided by the source of data that the publisher uses (e.g. an exchange).
  147. // If no such timestamp is available, it should be set to the same value as `publisher_timestamp`.
  148. optional google.protobuf.Timestamp source_timestamp = 1;
  149. // [required] Timestamp of the publisher.
  150. optional google.protobuf.Timestamp publisher_timestamp = 2;
  151. // [required] Values of the data fields.
  152. optional FeedDataFields fields = 3;
  153. }
  154. message FeedDataFields {
  155. // [optional] Best executable price. Can be absent if no data is available. Never present for funding rate feeds.
  156. optional int64 price = 1;
  157. // [optional] Best bid price. Can be absent if no data is available. Never present for funding rate feeds.
  158. optional int64 best_bid_price = 2;
  159. // [optional] Best ask price. Can be absent if no data is available. Never present for funding rate feeds.
  160. optional int64 best_ask_price = 3;
  161. // [optional] Funding rate. Can be absent if no data is available. Can only be present for funding rate feeds.
  162. optional int64 funding_rate = 4;
  163. // [optional] Funding rate interval. Can be absent if no data is available. Can only be present for funding rate feeds.
  164. optional google.protobuf.Duration funding_rate_interval = 5;
  165. }
  166. // State associated with a governance source.
  167. message GovernanceSourceState {
  168. // [required]
  169. optional GovernanceSource source = 1;
  170. // [required]
  171. optional Permissions permissions = 2;
  172. // [required]
  173. optional uint64 last_sequence_no = 3;
  174. }
  175. // Permissions granted to a governance source.
  176. // bool fields in this message are optional and default to false (no permission).
  177. message Permissions {
  178. enum ShardAction {
  179. // Required by protobuf. Instruction will be rejected if this value is encountered.
  180. SHARD_ACTION_UNSPECIFIED = 0;
  181. // All operations, including operations added in the future.
  182. ALL_ACTIONS = 1;
  183. CREATE_SHARD = 101;
  184. ADD_GOVERNANCE_SOURCE = 102;
  185. // All operations under `UpdateGovernanceSource`,
  186. // including operations added in the future.
  187. UPDATE_GOVERNANCE_SOURCE = 103;
  188. SET_SHARD_NAME = 105;
  189. SET_SHARD_GROUP = 106;
  190. RESET_LAST_SEQUENCE_NO = 107;
  191. ADD_PUBLISHER = 108;
  192. // All operations under `UpdatePublisher`,
  193. // including operations added in the future.
  194. UPDATE_PUBLISHER = 109;
  195. REMOVE_PUBLISHER = 110;
  196. ADD_FEED = 111;
  197. // All operations under `UpdateFeed`,
  198. // including operations added in the future.
  199. UPDATE_FEED = 112;
  200. REMOVE_FEED = 113;
  201. ADD_FEATURE_FLAG = 114;
  202. REMOVE_FEATURE_FLAG = 115;
  203. }
  204. enum UpdateGovernanceSourceAction {
  205. // Required by protobuf. Instruction will be rejected if this value is encountered.
  206. UPDATE_GOVERNANCE_SOURCE_ACTION_UNSPECIFIED = 0;
  207. SET_GOVERNANCE_SOURCE_PERMISSIONS = 101;
  208. }
  209. enum UpdatePublisherAction {
  210. // Required by protobuf. Instruction will be rejected if this value is encountered.
  211. UPDATE_PUBLISHER_ACTION_UNSPECIFIED = 0;
  212. SET_PUBLISHER_NAME = 101;
  213. ADD_PUBLISHER_PUBLIC_KEYS = 102;
  214. REMOVE_PUBLISHER_PUBLIC_KEYS = 103;
  215. SET_PUBLISHER_PUBLIC_KEYS = 104;
  216. SET_PUBLISHER_ACTIVE = 105;
  217. ADD_PUBLISHER_ALLOWED_FEED_IDS = 106;
  218. REMOVE_PUBLISHER_ALLOWED_FEED_IDS = 107;
  219. SET_PUBLISHER_ALLOWED_FEED_IDS = 108;
  220. }
  221. enum UpdateFeedAction {
  222. // Required by protobuf. Instruction will be rejected if this value is encountered.
  223. UPDATE_FEED_ACTION_UNSPECIFIED = 0;
  224. UPDATE_FEED_PROPERTIES = 101;
  225. UPDATE_FEED_METADATA = 102;
  226. ENABLE_FEED_IN_SHARD = 103;
  227. DISABLE_FEED_IN_SHARD = 104;
  228. }
  229. repeated ShardAction actions = 1;
  230. repeated UpdateGovernanceSourceAction update_governance_source_actions = 2;
  231. repeated UpdatePublisherAction update_publisher_actions = 3;
  232. repeated UpdateFeedAction update_feed_actions = 4;
  233. }
  234. // Specifies the way governance transactions are signed and verified.
  235. // Note that once added, a governance source cannot be removed.
  236. // The last sequence number associated with this source
  237. // will be retained in the state indefinitely to prevent repeated execution of instructions.
  238. message GovernanceSource {
  239. // Governance transactions are signed by a single Ed25519 signature.
  240. // This will generally be used in development and testing groups.
  241. message SingleEd25519 {
  242. // [required] Ed25519 public key that signs governance transactions.
  243. optional bytes public_key = 1;
  244. }
  245. message WormholeEmitter {
  246. // [required] Wormhole emitter address.
  247. optional bytes address = 1;
  248. // [required] Wormhole emitter chain ID. Restricted to uint16.
  249. optional uint32 chain_id = 2;
  250. }
  251. // [required]
  252. oneof source {
  253. SingleEd25519 single_ed25519 = 1;
  254. WormholeEmitter wormhole_emitter = 2;
  255. }
  256. }