Skip to content

feat: release the agent with multi-rpc and lazer support #160

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

Merged
merged 11 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-agent"
version = "2.12.3"
version = "3.0.0"
edition = "2024"

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM rust:slim-bookworm as builder

RUN apt update && apt install -y curl libssl-dev pkg-config && apt clean all
RUN apt update && apt install -y curl libssl-dev pkg-config build-essential && apt clean all

ADD . /agent
WORKDIR /agent
Expand Down
2 changes: 1 addition & 1 deletion config/config.sample.pythnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rpc_urls = ["https://api2.pythnet.pyth.network"]

# WS(S) endpoint of the RRC node. This is used to subscribe to account changes on the network.
# This can be omitted when oracle.subscriber_enabled is set to false.
wss_url = "wss://api2.pythnet.pyth.network"
wss_urls = ["wss://api2.pythnet.pyth.network"]

# Path to your publishing keypair.
key_store.publish_keypair_path = "/path/to/keypair.json"
Expand Down
2 changes: 1 addition & 1 deletion config/config.sample.pythtest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rpc_urls = ["https://api.pythtest.pyth.network"]
# WS(S) endpoint of the RRC node. This is used to subscribe to account changes
# on the network. This can be omitted when oracle.subscriber_enabled is set to
# false.
wss_url = "wss://api.pythtest.pyth.network"
wss_urls = ["wss://api.pythtest.pyth.network"]

# Path to your publishing keypair.
key_store.publish_keypair_path = "/path/to/keypair.json"
Expand Down
23 changes: 22 additions & 1 deletion config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rpc_urls = ["https://api.pythtest.pyth.network"]

# WS(S) endpoint of the RRC node. This is used to subscribe to account changes on the network.
# This can be omitted when oracle.subscriber_enabled is set to false.
wss_url = "wss://api.pythtest.pyth.network"
wss_urls = ["wss://api.pythtest.pyth.network"]

# Path to the keypair used to publish price updates. If set to a
# non-existent file path, the system expects a keypair to be loaded
Expand Down Expand Up @@ -218,3 +218,24 @@ exporter_timeout_duration = "3s"

# Endpoint URL for the OpenTelemetry exporter
exporter_endpoint = "http://127.0.0.1:4317"

## Configuration for Pyth Lazer ##

# [pyth_lazer]
# URL for the history service
# history_url = "https://pyth-lazer-staging.dourolabs.app"

# URLs for the Lazer relayers to connect to
# relayer_urls = ["wss://pyth-lazer-staging.dourolabs.app"]

# Unique identifier for this publisher
# publisher_id = 1

# Authorization token for connecting to relayers
# authorization_token = "your-auth-token"

# Path to the publisher's secret key file
# publish_keypair_path = "/path/to/publisher-key.json"

# Duration between price updates (defaults to 200ms if not specified)
# publish_interval_duration = "200ms"
2 changes: 1 addition & 1 deletion integration-tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ENV PATH="${PATH}:/root/.local/bin"
RUN poetry config virtualenvs.in-project true

# Install Solana Tool Suite
RUN sh -c "$(curl -sSfL https://release.solana.com/v1.14.17/install)"
RUN sh -c "$(curl -sSfL https://release.anza.xyz/v2.2.1/install)"
ENV PATH="${PATH}:/root/.local/share/solana/install/active_release/bin"

ADD . /agent
Expand Down
32 changes: 26 additions & 6 deletions src/agent/services/lazer_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use {
reqwest::Client,
serde::Deserialize,
std::{
path::PathBuf,
sync::Arc,
time::Duration,
},
Expand Down Expand Up @@ -48,7 +49,7 @@ pub struct Config {
pub relayer_urls: Vec<Url>,
pub publisher_id: u32,
pub authorization_token: String,
publisher_secret_key: PublisherSecretKey,
pub publish_keypair_path: PathBuf,
#[serde(with = "humantime_serde", default = "default_publish_interval")]
pub publish_interval_duration: Duration,
}
Expand All @@ -62,7 +63,7 @@ impl std::fmt::Debug for PublisherSecretKey {
}

fn default_publish_interval() -> Duration {
Duration::from_millis(10)
Duration::from_millis(200)
}

struct RelayerSender {
Expand All @@ -85,13 +86,14 @@ impl RelayerSender {
}

async fn connect_to_relayer(
url: &Url,
mut url: Url,
token: &str,
) -> Result<(
SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, TungsteniteMessage>,
SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
)> {
tracing::info!("connecting to the relayer at {}", url);
url.set_path("/v1/transaction");
let mut req = url.clone().into_client_request()?;
let headers = req.headers_mut();
headers.insert(
Expand All @@ -112,7 +114,7 @@ async fn connect_to_relayers(
let mut relayer_receivers = Vec::new();
for url in config.relayer_urls.clone() {
let (relayer_sender, relayer_receiver) =
connect_to_relayer(&url, &config.authorization_token).await?;
connect_to_relayer(url, &config.authorization_token).await?;
relayer_senders.push(relayer_sender);
relayer_receivers.push(relayer_receiver);
}
Expand Down Expand Up @@ -172,7 +174,10 @@ mod lazer_exporter {
},
state::local::LocalStore,
},
anyhow::bail,
anyhow::{
Context,
bail,
},
ed25519_dalek::{
Signer,
SigningKey,
Expand All @@ -197,6 +202,7 @@ mod lazer_exporter {
lazer_transaction::Payload,
},
},
solana_sdk::signer::keypair,
std::{
collections::HashMap,
sync::Arc,
Expand Down Expand Up @@ -259,7 +265,21 @@ mod lazer_exporter {
stream_map.insert(config.relayer_urls[i].clone(), receiver);
}

let signing_key = SigningKey::from_bytes(&config.publisher_secret_key.0);
// Read the keypair from the file using Solana SDK because it's the same key used by the Pythnet publisher
let publish_keypair = match keypair::read_keypair_file(&config.publish_keypair_path) {
Ok(k) => k,
Err(e) => {
tracing::error!(
error = ?e,
publish_keypair_path = config.publish_keypair_path.display().to_string(),
"Reading publish keypair returned an error. ",
);
bail!("Reading publish keypair returned an error. ");
}
};

let signing_key = SigningKey::from_keypair_bytes(&publish_keypair.to_bytes())
.context("Failed to create signing key from keypair")?;
let mut publish_interval = tokio::time::interval(config.publish_interval_duration);

loop {
Expand Down
Loading