Skip to content

Commit

Permalink
Update price service to use helium-lib (#832)
Browse files Browse the repository at this point in the history
* Update price to use helium-lib to retrieve on chain price

* remove unused dep

* remove commented out code

* Add async featur to anchor-client

* remove commented code
  • Loading branch information
bbalser authored Jun 25, 2024
1 parent 6ce7d68 commit d945ad1
Show file tree
Hide file tree
Showing 10 changed files with 1,626 additions and 933 deletions.
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" }
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

0 comments on commit d945ad1

Please sign in to comment.