Skip to content
Open
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: 2 additions & 0 deletions backend/.env.exemple → backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CONTRACT_ADDRESS="0xbA276291a3EFE899b5B5fB2DFFd513B7347E11D7"
PRIVATE_KEY="your_private_key_here"
COINGECKO_API_KEY="your_coingecko_api_key_here"
GEMINI_API_KEY="your_gemini_api_key_here"
PORT=8080
130 changes: 130 additions & 0 deletions backend/Cargo.lock

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

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dotenvy = "0.15.7"
futures = "0.3.31"
once_cell = "1.21.3"
reqwest = "0.12.24"
rig-core = "0.24.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
tokio = { version = "1.48.0", features = ["sync"] }
Expand Down
45 changes: 44 additions & 1 deletion backend/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use actix_web::{HttpResponse, Responder, get, post, web};

use crate::{state::AppState, types::Pool};
use crate::{
core::{self, coingecko::CoingeckoOhlcvRes},
state::AppState,
strategies,
types::{Pool, RangeSuggestion},
};

#[utoipa::path(
responses(
Expand Down Expand Up @@ -36,3 +41,41 @@ async fn get_pools_service(app_state: web::Data<AppState>) -> impl Responder {
.collect();
HttpResponse::Ok().json(pools)
}

#[utoipa::path(
responses(
(status = 200, description = "Pool", body = CoingeckoOhlcvRes),
)
)]
#[get("/pool/{pool_address}/coingecko/ohlcv")]
async fn get_pool_coingecko_ohlcv_service(pool_address: web::Path<String>) -> impl Responder {
let pool_address = pool_address.into_inner();

let ohlcv_data_result = match core::coingecko::get_pool_ohlcv_data(&pool_address).await {
Ok(data) => data,
Err(err) => {
return HttpResponse::InternalServerError()
.body(format!("Error fetching OHLCV data: {}", err));
}
};

HttpResponse::Ok().json(ohlcv_data_result)
}

#[utoipa::path(
responses(
(status = 200, description = "Suggested liquidity range", body = RangeSuggestion),
)
)]
#[get("/pools/{pool_address}/liquidity/suggest")]
async fn suggest_liquidity_range_service(
app_state: web::Data<AppState>,
path: web::Path<String>,
) -> impl Responder {
let pool_address = path.into_inner();

match strategies::default::suggest_liquidity_range(&app_state, &pool_address).await {
Ok(suggestion) => HttpResponse::Ok().json(suggestion),
Err(err) => HttpResponse::InternalServerError().body(err.to_string()),
}
}
1 change: 1 addition & 0 deletions backend/src/config/bnb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[chain]
rpc_url = "https://bsc-dataseed.binance.org/"
chain_id = 56
coingecko_id = "bsc"

[[pools]]
address = "0xaeaD6bd31dd66Eb3A6216aAF271D0E661585b0b1"
Expand Down
7 changes: 6 additions & 1 deletion backend/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct TomlConfig {
pub struct ChainConfig {
pub rpc_url: String,
pub chain_id: u64,
pub coingecko_id: String,
}

#[derive(Debug, Deserialize, Clone)]
Expand All @@ -28,6 +29,7 @@ pub struct PoolConfig {
pub struct Config {
pub contract_address: String,
pub private_key: String,
pub coingecko_api_key: String,
pub port: u16,
pub toml: TomlConfig,
}
Expand All @@ -37,6 +39,8 @@ impl Config {
let contract_address =
std::env::var("CONTRACT_ADDRESS").expect("CONTRACT_ADDRESS must be set");
let private_key = std::env::var("PRIVATE_KEY").expect("PRIVATE_KEY must be set");
let coingecko_api_key =
std::env::var("COINGECKO_API_KEY").expect("COINGECKO_API_KEY must be set");
let port: u16 = std::env::var("PORT")
.unwrap_or_else(|_| "8080".to_string())
.parse()
Expand All @@ -52,6 +56,7 @@ impl Config {
Self {
contract_address,
private_key,
coingecko_api_key,
port,
toml: config,
}
Expand All @@ -66,4 +71,4 @@ pub const FEE_FACTOR: f64 = 10_000.0;

/// Maximum number of concurrent tasks allowed
/// This prevents overwhelming
pub const MAX_ALLOWED_THREADS: usize = 8;
pub const MAX_ALLOWED_THREADS: usize = 8;
Loading