Skip to content
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

Update price service to use helium-lib #832

Merged
merged 5 commits into from
Jun 25, 2024
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,163 changes: 1,512 additions & 651 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ license = "Apache-2.0"
edition = "2021"

[workspace.dependencies]
anchor-client = "0.29.0"
anchor-client = { version = "0.30.0", features = ["async"] }
anyhow = { version = "1", features = ["backtrace"] }
bs58 = { version = "0.4", features = ["check"] }
thiserror = "1"
Expand Down Expand Up @@ -66,15 +66,16 @@ sqlx = { version = "0", features = [
] }
helium-anchor-gen = { git = "https://github.com/helium/helium-anchor-gen.git" }
helium-crypto = { version = "0.8.4", features = ["sqlx-postgres", "multisig"] }
helium-lib = { git = "https://github.com/helium/helium-wallet-rs.git", branch = "master" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time to extract helium-lib out of wallet? maybe push into helium-program-library?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not? The whole point is that compiling all of HPL is very brittle and complicated.. helium-lib only relies on the IDLs for the HPL defined programs

hextree = { git = "https://github.com/jaykickliter/HexTree", branch = "main", features = [
"disktree",
] }
helium-proto = { git = "https://github.com/helium/proto", branch = "master", features = [
"services",
] }
solana-client = "1.16"
solana-sdk = "1.16"
solana-program = "1.16"
solana-client = "1.18"
solana-sdk = "1.18"
solana-program = "1.18"
spl-token = "3.5.0"
reqwest = { version = "0", default-features = false, features = [
"gzip",
Expand Down Expand Up @@ -102,7 +103,6 @@ triggered = "0"
futures = "*"
futures-util = "*"
prost = "*"
pyth-solana-receiver-sdk = "0"
once_cell = "1"
lazy_static = "1"
config = { version = "0", default-features = false, features = ["toml"] }
Expand Down
4 changes: 3 additions & 1 deletion price/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ tokio = { workspace = true }
tokio-util = { workspace = true }
chrono = { workspace = true }
helium-anchor-gen = { workspace = true }
helium-lib = { workspace = true }
helium-proto = { workspace = true }
file-store = { path = "../file_store" }
poc-metrics = { path = "../metrics" }
pyth-solana-receiver-sdk = { workspace = true }
rust_decimal = { workspace = true }
rust_decimal_macros = { workspace = true }
triggered = { workspace = true }
solana-client = { workspace = true }
solana-sdk = { workspace = true }
Expand Down
36 changes: 17 additions & 19 deletions price/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use clap::Parser;
use file_store::{file_sink, file_upload, FileType};
use helium_proto::BlockchainTokenTypeV1;
use price::{cli::check, PriceGenerator, Settings};
use std::{
path::{self, PathBuf},
Expand Down Expand Up @@ -92,24 +91,23 @@ impl Server {
.create()
.await?;

// price generators
let hnt_price_generator =
PriceGenerator::new(settings, BlockchainTokenTypeV1::Hnt, price_sink.clone()).await?;
let mobile_price_generator =
PriceGenerator::new(settings, BlockchainTokenTypeV1::Mobile, price_sink.clone())
.await?;
let iot_price_generator =
PriceGenerator::new(settings, BlockchainTokenTypeV1::Iot, price_sink.clone()).await?;

TaskManager::builder()
.add_task(file_upload_server)
.add_task(price_sink_server)
.add_task(hnt_price_generator)
.add_task(mobile_price_generator)
.add_task(iot_price_generator)
.build()
.start()
.await
let mut task_manager = TaskManager::new();
task_manager.add(file_upload_server);
task_manager.add(price_sink_server);

for token_setting in settings.tokens.iter() {
task_manager.add(
PriceGenerator::new(
settings,
token_setting.token,
token_setting.default_price,
price_sink.clone(),
)
.await?,
);
}

task_manager.start().await
}
}

Expand Down
16 changes: 8 additions & 8 deletions price/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use helium_proto::BlockchainTokenTypeV1;
use helium_lib::token::Token;

const PRICE_GAUGE: &str = concat!(env!("CARGO_PKG_NAME"), "_", "price_gauge");

pub struct Metrics;

impl Metrics {
pub fn update(counter: String, token_type: BlockchainTokenTypeV1, price: f64) {
increment_counter(counter, token_type);
set_gauge(token_type, price)
pub fn update(counter: String, token: Token, price: f64) {
increment_counter(counter, token);
set_gauge(token, price)
}
}

fn increment_counter(counter: String, token_type: BlockchainTokenTypeV1) {
metrics::counter!(counter, "token_type" => token_type.as_str_name()).increment(1);
fn increment_counter(counter: String, token: Token) {
metrics::counter!(counter, "token_type" => token.to_string()).increment(1);
}

fn set_gauge(token_type: BlockchainTokenTypeV1, value: f64) {
metrics::gauge!(PRICE_GAUGE, "token_type" => token_type.as_str_name()).set(value);
fn set_gauge(token: Token, value: f64) {
metrics::gauge!(PRICE_GAUGE, "token_type" => token.to_string()).set(value);
}
Loading