Skip to content

Commit 157c756

Browse files
authored
feat(pyth-lazer/publisher-sdk): Move Transaction Envelope Definitions to SDK (#2623)
* remove publisher id from internal publisher update * add envelope proto * expose envelope * bump protocol version * Improve comments and remove index for feed update context * generate docs for rust types * minor change to build.rs * reduce protocol version * minor comments * move publisher id inside publisher update context * add public key todo comment
1 parent f01d4bd commit 157c756

File tree

8 files changed

+149
-64
lines changed

8 files changed

+149
-64
lines changed

.github/workflows/publish-rust-lazer-publisher-sdk.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ jobs:
1212
steps:
1313
- name: Checkout sources
1414
uses: actions/checkout@v2
15+
- name: Install Protoc
16+
uses: arduino/setup-protoc@v3
17+
with:
18+
version: "30.2"
1519

1620
- run: ./publish.sh
1721
env:

lazer/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
syntax = "proto3";
2+
package pyth_lazer_transaction;
23

34
import "google/protobuf/timestamp.proto";
45

5-
package pyth_lazer_transaction;
6+
// if any fields marked as [required] are missing, feed/publisher update will be rejected
67

7-
// PublisherUpdate contains an array of individual updates and a timestamp
8+
// Publisher update included in transaction
9+
//
10+
// Each publisher update contains a batch of feed updates from publisher.
11+
// The publisher uses Pyth Agent on their side that handles batching.
12+
// Each feed update specifies a single update type (price, funding rate, etc.)
813
message PublisherUpdate {
9-
// Array of updates, each of which target a single feed
10-
repeated FeedUpdate updates = 1;
11-
12-
// ID of the Publisher that is sending the update
13-
// Should match ID stored in Pyth Lazer
14-
optional uint32 publisher_id = 2;
14+
// [required] array of feed updates, each of which target a single feed
15+
// order of updates are preserved between encoding/decoding
16+
repeated FeedUpdate updates = 1;
1517

16-
// Timestamp when this message was created
17-
optional google.protobuf.Timestamp publisher_timestamp = 3;
18+
// [required] timestamp when batch of feed updates was collected
19+
optional google.protobuf.Timestamp publisher_timestamp = 2;
1820
}
1921

20-
// Update to a feed. May contain different types of data depending on what kind of update it is
22+
// A single feed update containing one type of update
2123
message FeedUpdate {
22-
// Feed which the update should be applied to
23-
// Should match a feed id recognized by PythLazer
24-
optional uint32 feed_id = 1;
25-
26-
// Timestamp when this data was first acquired or generated
27-
optional google.protobuf.Timestamp source_timestamp = 2;
28-
29-
// one of the valid updates allowed by publishers for a lazer feed
30-
oneof update {
31-
PriceUpdate price_update = 3;
32-
FundingRateUpdate funding_rate_update = 4;
33-
};
24+
// [required] id of the lazer feed to be updated
25+
// should match the ids of feeds recognized by pyth lazer
26+
optional uint32 feed_id = 1;
27+
28+
// [required] timestamp when this data was first acquired or generated
29+
optional google.protobuf.Timestamp source_timestamp = 2;
30+
31+
// [required] one type of update containing specific data
32+
oneof update {
33+
PriceUpdate price_update = 3;
34+
FundingRateUpdate funding_rate_update = 4;
35+
};
3436
}
3537

38+
// feed update containing data for the core price, bid, and ask prices
3639
message PriceUpdate {
37-
// Price for the symbol as an integer
38-
// Should be produced with a matching exponent to the configured exponent value in PythLazer
39-
// May be missing if no price data is available
40-
optional int64 price = 1;
41-
42-
// Best Bid Price for the symbol as an integer
43-
// Should be produced with a matching exponent to the configured exponent value in PythLazer
44-
// May be missing if no data is available
45-
optional int64 best_bid_price = 2;
46-
47-
// Best Ask Price for the symbol as an integer
48-
// Should be produced with a matching exponent to the configured exponent value in PythLazer
49-
// May be missing if no data is available
50-
optional int64 best_ask_price = 3;
40+
// [optional] price for the feed as an integer
41+
// should be produced with a matching exponent to the configured exponent value in pyth lazer
42+
optional int64 price = 1;
43+
44+
// [optional] best bid price for the feed as an integer
45+
// should be produced with a matching exponent to the configured exponent value in pyth lazer
46+
// may be missing if no data is available
47+
optional int64 best_bid_price = 2;
48+
49+
// [optional] best ask price for the feed as an integer
50+
// should be produced with a matching exponent to the configured exponent value in pyth lazer
51+
// may be missing if no data is available
52+
optional int64 best_ask_price = 3;
5153
}
5254

55+
// feed update containing data relating to funding rate
5356
message FundingRateUpdate {
54-
// Price for which the funding rate applies to
55-
optional int64 price = 1;
57+
// [optional] price for which the funding rate applies to
58+
optional int64 price = 1;
5659

57-
// Perpetual Future funding rate
58-
optional int64 rate = 2;
60+
// [optional] perpetual future funding rate
61+
optional int64 rate = 2;
5962
}
Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
syntax = "proto3";
2-
32
package pyth_lazer_transaction;
43

54
import "publisher_update.proto";
65

7-
// Types of Signatures allowed for signing Lazer Transactions
8-
enum TransactionSignatureType {
9-
// signature is 64 bytes long
10-
ed25519 = 0;
11-
}
6+
// if any fields marked as [required] are missing, transaction will be rejected
7+
// if signature does not match payload bytes, transaction will be rejected
128

13-
// Signed lazer transaction payload
14-
// This is what Pyth Lazer expects as input to the system
9+
// Signed transaction for lazer
10+
// Payload should be created on the publisher side and encoded as bytes.
11+
// Resulting bytes should then be signed with the signature scheme specified.
12+
// The signed lazer transaction is encoded as bytes and sent to Pyth Lazer Relayer.
1513
message SignedLazerTransaction {
16-
// Type and signature should match
17-
optional TransactionSignatureType signature_type = 1;
14+
// [required] specifies the type of signature used to sign the payload
15+
optional TransactionSignatureType signature_type = 1;
1816

19-
// Signature derived by signing payload with private key
20-
optional bytes signature = 2;
17+
// [required] signature derived from signing payload bytes
18+
optional bytes signature = 2;
2119

22-
// a LazerTransaction message which is already encoded with protobuf as bytes
23-
// The encoded bytes are what should be signed
24-
optional bytes payload = 3;
20+
// [required] lazer transaction encoded as bytes through protobuf
21+
optional bytes payload = 3;
22+
23+
// TODO: Add public key
24+
}
25+
26+
// Types of signatures supported by Pyth Lazer
27+
enum TransactionSignatureType {
28+
// signature is 64 bytes long
29+
ed25519 = 0;
2530
}
2631

2732
// Transaction contianing one of the valid Lazer Transactions
2833
message LazerTransaction {
29-
oneof payload {
30-
// Expected transaction sent by Publishers
31-
// May contain many individual updates to various feeds
32-
PublisherUpdate publisher_update = 1;
33-
}
34+
// [required] valid transaction types supported by pyth lazer
35+
oneof payload {
36+
// updates to feeds, sent by authorized publishers
37+
PublisherUpdate publisher_update = 1;
38+
}
3439
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
syntax = "proto3";
2+
package pyth_lazer_transaction;
3+
4+
import "google/protobuf/timestamp.proto";
5+
import "pyth_lazer_transaction.proto";
6+
7+
// Envelope containing signed transaction and context attached by Pyth Lazer.
8+
// Created by Pyth Lazer Relayers, which also generate and attach the context.
9+
message TransactionEnvelope {
10+
// [required] signed transaction encoded with protobuf
11+
optional SignedLazerTransaction signed_transaction = 1;
12+
13+
// [required] context attached by pyth lazer relayer
14+
optional PayloadContext payload_context = 2;
15+
}
16+
17+
// Context attached by Pyth Lazer Relayer containing information necessary for processing transaction.
18+
// Has different context data depending on the type of transaction.
19+
// Submitted over Message Queue to be read by rest of Pyth Lazer service.
20+
message PayloadContext {
21+
// [required] timestamp wwhen relayer received the signed transaction
22+
optional google.protobuf.Timestamp relayer_receive_timestamp = 1;
23+
24+
// [required] context set based on type of transaction
25+
oneof context {
26+
PublisherUpdateContext publisher_update_context = 2;
27+
}
28+
}
29+
30+
// Context contains status of each feed update found in transaction
31+
message PublisherUpdateContext {
32+
// [required] ID of publisher based on the access token used to connect
33+
optional uint32 publisher_id = 1;
34+
35+
// [required] context for each feed update
36+
// must exactly match length and order of feed updates
37+
// order of updates are preserved between encoding/decoding
38+
repeated FeedUpdateContext feed_update_context = 2;
39+
}
40+
41+
// State for each feed update.
42+
// Each feed update is validated and may be marked as rejected by Relayer.
43+
message FeedUpdateContext {
44+
// [required] status of feed update
45+
oneof status {
46+
Accepted accepted = 1;
47+
Rejected rejected = 2;
48+
}
49+
}
50+
51+
// Accepted publisher update
52+
message Accepted {}
53+
54+
// Rejected publisher update and its reason for being rejected
55+
message Rejected {
56+
// [required] reason for rejection
57+
RejectReason reject_reason = 1;
58+
}
59+
60+
// The reasons that a publisher update might be rejected for
61+
enum RejectReason {
62+
InvalidTimestamp = 0;
63+
PriceDeviation = 1;
64+
PriceOverflow = 2;
65+
InvalidFeedId = 3;
66+
MissingFields = 4;
67+
}

lazer/publisher_sdk/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-lazer-publisher-sdk"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
description = "Pyth Lazer Publisher SDK types."
66
license = "Apache-2.0"

lazer/publisher_sdk/rust/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ fn main() -> Result<()> {
88
println!("cargo:rerun-if-changed=../proto/");
99

1010
protobuf_codegen::Codegen::new()
11-
.pure()
11+
.protoc()
12+
.protoc_extra_arg("--include_source_info")
1213
.include("../proto")
1314
.input("../proto/publisher_update.proto")
1415
.input("../proto/pyth_lazer_transaction.proto")
16+
.input("../proto/transaction_envelope.proto")
1517
.cargo_out_dir("protobuf")
1618
.run_from_script();
1719

lazer/publisher_sdk/rust/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
pub mod transaction_envelope {
2+
pub use crate::protobuf::transaction_envelope::*;
3+
}
4+
15
pub mod transaction {
26
pub use crate::protobuf::pyth_lazer_transaction::*;
37
}

0 commit comments

Comments
 (0)