state.proto 11 KB

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