-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pyth-lazer-protocol): Implement Protobuf files for Lazer Transactions #2557
base: main
Are you sure you want to change the base?
Changes from all commits
e69e71c
ea14862
72f3dd4
a9dcdca
979f793
aa21d2a
770c987
57cb606
f5ac983
36a34bb
308ea14
1bcbe45
031ea71
a06c2d4
56b5a56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ node_modules/ | |
dist/ | ||
|
||
tsconfig.tsbuildinfo | ||
|
||
# Types generated for .proto files | ||
src/generated/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"$schema": "https://turbo.build/schema.json", | ||
"extends": ["//"], | ||
"tasks": { | ||
"build:proto-codegen": { | ||
"dependsOn": ["//#install:modules"], | ||
"inputs": ["../proto/**"], | ||
"outputs": ["src/generated/**"], | ||
"cache": false | ||
}, | ||
"build": { | ||
"dependsOn": ["build:proto-codegen", "^build"], | ||
"outputs": ["dist/**"] | ||
}, | ||
"build:cjs": { | ||
"dependsOn": ["build:proto-codegen"], | ||
"outputs": ["dist/cjs/**"] | ||
}, | ||
"build:esm": { | ||
"dependsOn": ["build:proto-codegen"], | ||
"outputs": ["dist/esm/**"] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
syntax = "proto3"; | ||
|
||
import "google/protobuf/timestamp.proto"; | ||
|
||
package pyth_lazer_transaction; | ||
darunrs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// PublisherUpdate contains an array of individual updates and a timestamp | ||
message PublisherUpdate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking that publisher ID would be something only Relayer knows about. The ID would map to an access token and a public key. The access token used to connect to Relayer determines what public key is accepted, and that key is used to verify the signature. In that scenario, publishers would not know/care what ID they are, and would not include it in any messages. Only the signature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to use this format in the kafka/nats messages and read them in the aggregator (and add governance instructions as another type of transaction along with PublisherUpdate). Aggregator won't know access tokens so it needs another way to know the publisher id. |
||
// Array of updates, each of which target a single feed | ||
repeated FeedUpdate updates = 1; | ||
|
||
// Timestamp when this message was created | ||
optional google.protobuf.Timestamp publisher_timestamp = 2; | ||
} | ||
|
||
// Update to a feed. May contain different types of data depending on what kind of update it is | ||
message FeedUpdate { | ||
// Feed which the update should be applied to | ||
// Should match a feed id recognized by PythLazer | ||
optional uint32 feed_id = 1; | ||
|
||
// Timestamp when this data was first acquired or generated | ||
optional google.protobuf.Timestamp source_timestamp = 2; | ||
|
||
// one of the valid updates allowed by publishers for a lazer feed | ||
oneof update { | ||
PriceUpdate price_update = 3; | ||
FundingRateUpdate funding_rate_update = 4; | ||
}; | ||
} | ||
|
||
message PriceUpdate { | ||
// Price for the symbol as an integer | ||
// Should be produced with a matching exponent to the configured exponent value in PythLazer | ||
// May be missing if no price data is available | ||
optional int64 price = 1; | ||
|
||
// Best Bid Price for the symbol as an integer | ||
// Should be produced with a matching exponent to the configured exponent value in PythLazer | ||
// May be missing if no data is available | ||
optional int64 best_bid_price = 2; | ||
|
||
// Best Ask Price for the symbol as an integer | ||
// Should be produced with a matching exponent to the configured exponent value in PythLazer | ||
// May be missing if no data is available | ||
optional int64 best_ask_price = 3; | ||
} | ||
|
||
message FundingRateUpdate { | ||
// Price for which the funding rate applies to | ||
optional int64 price = 1; | ||
|
||
// Perpetual Future funding rate | ||
optional int64 rate = 2; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
syntax = "proto3"; | ||
|
||
package pyth_lazer_transaction; | ||
|
||
import "publisher_update.proto"; | ||
|
||
// Types of Signatures allowed for signing Lazer Transactions | ||
enum TransactionSignatureType { | ||
// signature is 64 bytes long | ||
ed25519 = 0; | ||
} | ||
|
||
// Signed lazer transaction payload | ||
// This is what Pyth Lazer expects as input to the system | ||
message SignedLazerTransaction { | ||
// Type and signature should match | ||
optional TransactionSignatureType signature_type = 1; | ||
|
||
// Signature derived by signing payload with private key | ||
optional bytes signature = 2; | ||
|
||
// a LazerTransaction message which is already encoded with protobuf as bytes | ||
// The encoded bytes are what should be signed | ||
optional bytes payload = 3; | ||
} | ||
|
||
// Transaction contianing one of the valid Lazer Transactions | ||
message LazerTransaction { | ||
oneof payload { | ||
// Expected transaction sent by Publishers | ||
// May contain many individual updates to various feeds | ||
PublisherUpdate publisher_update = 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
[package] | ||
name = "pyth-lazer-protocol" | ||
version = "0.7.0" | ||
version = "0.7.1" | ||
edition = "2021" | ||
description = "Pyth Lazer SDK - protocol types." | ||
license = "Apache-2.0" | ||
repository = "https://github.com/pyth-network/pyth-crosschain" | ||
build = "build.rs" | ||
|
||
[dependencies] | ||
byteorder = "1.5.0" | ||
|
@@ -15,6 +16,8 @@ derive_more = { version = "1.0.0", features = ["from"] } | |
itertools = "0.13.0" | ||
rust_decimal = "1.36.0" | ||
base64 = "0.22.1" | ||
prost = "0.13.5" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that's an interesting suggestion. I'll give that a go and compare the generated code. Thanks! |
||
prost-types = "0.13.5" | ||
|
||
[dev-dependencies] | ||
bincode = "1.3.3" | ||
|
@@ -23,3 +26,6 @@ hex = "0.4.3" | |
libsecp256k1 = "0.7.1" | ||
bs58 = "0.5.1" | ||
alloy-primitives = "0.8.19" | ||
|
||
[build-dependencies] | ||
prost-build = "0.13.5" |
darunrs marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::io::Result; | ||
|
||
/// Automatically runs during cargo build. | ||
/// Proto files for Lazer are defined in the lazer sdk folder in the proto/ subdirectory. | ||
/// Both JS and Rust SDKs read the proto files for generating types. | ||
fn main() -> Result<()> { | ||
// Tell cargo to recompile if any .proto files change | ||
println!("cargo:rerun-if-changed=proto/"); | ||
|
||
// Selects proto files to be read for compiling | ||
let proto_files = vec![ | ||
"../../proto/pyth_lazer_transaction.proto", | ||
"../../proto/publisher_update.proto", | ||
]; | ||
|
||
// Compiles protos and generates Rust types | ||
// Generated types are present in the output folder | ||
prost_build::compile_protos(&proto_files, &["../../proto"]) | ||
.expect("Failed to compile protos and generate types"); | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These SDKs are for end-users, so I think it will be confusing to them if we have publisher-related code in the same package. Maybe it's better to create a separate set of packages for publishers under
lazer/publisher_sdk/{js, rust}
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh good point. I will make a new set of packages for them then. The index.ts example for it can include generating a payload, signing it, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it in a separate PR when we are closer to wanting publishers to work with the agent. We have types for Publishers already defined in the rust protocol.