Skip to content

Commit e098914

Browse files
authored
feat(pyth-lazer-publisher-sdk): Add SDK for Publisher Transactions (#2557)
* add proto files * Update proto file and build generated files * Code gen in TS * Update proto file * rename * rename proto fields and re-generate * Update package json scripts and field ids * comment build.rs file * rebase lock file and git ignore generated files * update js generated files * Add turbo build and update proto codegen command * update readme * comment proto file * add prost-types * remove generated files * try using protobuf-codegen * add publisher sdk * remove remaining changes * add pub id * add new pub sdk to workspace * duplicate workspace * remove unnecessary ignores * add caching inputs for turbo * change export of js sdk * remove js publisher sdk * fix publish
1 parent 9e8b00a commit e098914

File tree

10 files changed

+269
-55
lines changed

10 files changed

+269
-55
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish Rust package pyth-lazer-publisher-sdk to crates.io
2+
3+
on:
4+
push:
5+
tags:
6+
- rust-pyth-lazer-publisher-sdk-v*
7+
jobs:
8+
publish-pyth-lazer-publisher-sdk:
9+
name: Publish Rust package pyth-lazer-publisher-sdk to crates.io
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout sources
13+
uses: actions/checkout@v2
14+
15+
- run: cargo publish --token ${CARGO_REGISTRY_TOKEN}
16+
env:
17+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
18+
working-directory: "lazer/publisher-sdk/rust"

lazer/Cargo.lock

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
resolver = "2"
33
members = [
4+
"publisher_sdk/rust",
45
"sdk/rust/protocol",
56
"sdk/rust/client",
67
"contracts/solana/programs/pyth-lazer-solana-contract",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
syntax = "proto3";
2+
3+
import "google/protobuf/timestamp.proto";
4+
5+
package pyth_lazer_transaction;
6+
7+
// PublisherUpdate contains an array of individual updates and a timestamp
8+
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;
15+
16+
// Timestamp when this message was created
17+
optional google.protobuf.Timestamp publisher_timestamp = 3;
18+
}
19+
20+
// Update to a feed. May contain different types of data depending on what kind of update it is
21+
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+
};
34+
}
35+
36+
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;
51+
}
52+
53+
message FundingRateUpdate {
54+
// Price for which the funding rate applies to
55+
optional int64 price = 1;
56+
57+
// Perpetual Future funding rate
58+
optional int64 rate = 2;
59+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
syntax = "proto3";
2+
3+
package pyth_lazer_transaction;
4+
5+
import "publisher_update.proto";
6+
7+
// Types of Signatures allowed for signing Lazer Transactions
8+
enum TransactionSignatureType {
9+
// signature is 64 bytes long
10+
ed25519 = 0;
11+
}
12+
13+
// Signed lazer transaction payload
14+
// This is what Pyth Lazer expects as input to the system
15+
message SignedLazerTransaction {
16+
// Type and signature should match
17+
optional TransactionSignatureType signature_type = 1;
18+
19+
// Signature derived by signing payload with private key
20+
optional bytes signature = 2;
21+
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;
25+
}
26+
27+
// Transaction contianing one of the valid Lazer Transactions
28+
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+
}

lazer/publisher_sdk/rust/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "pyth-lazer-publisher-sdk"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Pyth Lazer Publisher SDK types."
6+
license = "Apache-2.0"
7+
repository = "https://github.com/pyth-network/pyth-crosschain"
8+
build = "build.rs"
9+
10+
[dependencies]
11+
protobuf = "3.7.2"
12+
13+
[build-dependencies]
14+
protobuf-codegen = "3.7.2"

lazer/publisher_sdk/rust/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::io::Result;
2+
3+
/// Automatically runs during cargo build.
4+
/// Proto files for Lazer are defined in the lazer sdk folder in the proto/ subdirectory.
5+
/// Both JS and Rust SDKs read the proto files for generating types.
6+
fn main() -> Result<()> {
7+
// Tell cargo to recompile if any .proto files change
8+
println!("cargo:rerun-if-changed=../proto/");
9+
10+
protobuf_codegen::Codegen::new()
11+
.pure()
12+
.include("../proto")
13+
.input("../proto/publisher_update.proto")
14+
.input("../proto/pyth_lazer_transaction.proto")
15+
.cargo_out_dir("protobuf")
16+
.run_from_script();
17+
18+
Ok(())
19+
}

lazer/publisher_sdk/rust/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub mod transaction {
2+
pub use crate::protobuf::pyth_lazer_transaction::*;
3+
}
4+
5+
mod protobuf {
6+
include!(concat!(env!("OUT_DIR"), "/protobuf/mod.rs"));
7+
}

lazer/sdk/js/turbo.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"],
4+
"tasks": {
5+
"build": {
6+
"dependsOn": ["^build"],
7+
"outputs": ["dist/**"]
8+
},
9+
"build:cjs": {
10+
"dependsOn": ["build"],
11+
"outputs": ["dist/cjs/**"]
12+
},
13+
"build:esm": {
14+
"dependsOn": ["build"],
15+
"outputs": ["dist/esm/**"]
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)