state.proto 14 KB

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