Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-lazer-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: install extra tools
run: |
cargo install --locked [email protected]
sudo apt-get install -y protobuf-compiler
sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Install Solana Cli
run: |
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-rust-lazer-publisher-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- run: cargo publish --token ${CARGO_REGISTRY_TOKEN}
- run: publish.sh
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
working-directory: "lazer/publisher_sdk/rust"
3 changes: 2 additions & 1 deletion lazer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions lazer/publisher_sdk/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[package]
name = "pyth-lazer-publisher-sdk"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "Pyth Lazer Publisher SDK types."
license = "Apache-2.0"
repository = "https://github.com/pyth-network/pyth-crosschain"
build = "build.rs"

[dependencies]
protobuf = "3.7.2"
Expand Down
38 changes: 38 additions & 0 deletions lazer/publisher_sdk/rust/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -e

PACKAGE_DIR="."

echo "building package to generate type files"
OUT_DIR=$(cargo build --message-format=json | jq -r 'select(.reason == "build-script-executed") | .out_dir' | grep "pyth-lazer-publisher-sdk")

echo "using output directory: ${OUT_DIR}"

echo "copying files from protobuf output to package directory"
cp -r "${OUT_DIR}/protobuf" "${PACKAGE_DIR}/src/"

echo "deleting build.rs file"
rm -f "${PACKAGE_DIR}/build.rs"

echo "updating lib.rs to export local protobuf files"
python3 -c "
import re

def replace_mod_protobuf(file_path):
with open(file_path, 'r') as f:
content = f.read()

pattern = re.compile(r'mod\s+protobuf\s*\{.*?\}', re.DOTALL)

replacement = 'mod protobuf;'

new_content = pattern.sub(replacement, content)

with open(file_path, 'w') as f:
f.write(new_content)

replace_mod_protobuf('${PACKAGE_DIR}/src/lib.rs')
"

echo "publishing package"
cargo publish --token ${CARGO_REGISTRY_TOKEN}
4 changes: 4 additions & 0 deletions lazer/publisher_sdk/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ pub mod transaction {
pub use crate::protobuf::pyth_lazer_transaction::*;
}

pub mod publisher_update {
pub use crate::protobuf::publisher_update::*;
}

mod protobuf {
include!(concat!(env!("OUT_DIR"), "/protobuf/mod.rs"));
}
1 change: 1 addition & 0 deletions lazer/sdk/rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ derive_more = { version = "1.0.0", features = ["from"] }
itertools = "0.13.0"
rust_decimal = "1.36.0"
base64 = "0.22.1"
protobuf = "3.7.2"

[dev-dependencies]
bincode = "1.3.3"
Expand Down
11 changes: 11 additions & 0 deletions lazer/sdk/rust/protocol/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
crate::payload::AggregatedPriceFeedData,
anyhow::{bail, Context},
itertools::Itertools,
protobuf::well_known_types::timestamp::Timestamp,
rust_decimal::{prelude::FromPrimitive, Decimal},
serde::{de::Error, Deserialize, Serialize},
std::{
Expand All @@ -26,6 +27,16 @@ pub struct ChannelId(pub u8);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct TimestampUs(pub u64);

impl TryFrom<&Timestamp> for TimestampUs {
type Error = anyhow::Error;

fn try_from(timestamp: &Timestamp) -> anyhow::Result<Self> {
let seconds_in_micros: u64 = (timestamp.seconds * 1_000_000).try_into()?;
let nanos_in_micros: u64 = (timestamp.nanos / 1_000).try_into()?;
Ok(TimestampUs(seconds_in_micros + nanos_in_micros))
}
}

impl TimestampUs {
pub fn now() -> Self {
let value = SystemTime::now()
Expand Down
Loading