Skip to content

Commit

Permalink
feat(mint-options): add lightweight option minter cron
Browse files Browse the repository at this point in the history
  • Loading branch information
raghav-rama committed Nov 17, 2024
1 parent cec5872 commit 4de334c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/context/app_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum AppContextError {
ConnectionError(String),
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct AppContext {
pub db_client: Client,
}
Expand Down
31 changes: 31 additions & 0 deletions src/handlers/mint_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::context::app_context::AppContext;
use crate::models::{MintOptionsBody, MintOptionsResponse};
use axum::{extract::State, http::StatusCode, Json};
use std::sync::Arc;

pub async fn mint_options(
State(app_context): State<Arc<AppContext>>,
Json(payload): Json<MintOptionsBody>,
) -> (StatusCode, Json<MintOptionsResponse>) {
// Spawn a new task to handle minting in the background
tokio::spawn(async move {
// Your minting logic goes here
process_mint_options(app_context, payload).await;
});

(
StatusCode::ACCEPTED,
Json(MintOptionsResponse {
message: "Minting process started in the background".to_string(),
}),
)
}

async fn process_mint_options(app_context: Arc<AppContext>, payload: MintOptionsBody) {
loop {
println!("{payload:?} {app_context:?}");
// Implement your actual minting logic here
// This will run in the background
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
}
2 changes: 2 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod health;
pub mod mint_options;
pub mod trades;

pub use health::*;
pub use mint_options::*;
pub use trades::*;
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use std::sync::Arc;
use context::AppContext;
mod app;
mod context;
mod errors;
mod handlers;
mod models;
mod pdas;
mod routes;

#[tokio::main]
Expand Down
14 changes: 14 additions & 0 deletions src/models/mint_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
pub struct MintOptionsBody {
pub strike_price: u64,
pub price_decimals: u8,
pub underlying_amount_per_contract: u64,
pub expiration_timestamp: i64,
}

#[derive(Debug, Serialize)]
pub struct MintOptionsResponse {
pub message: String,
}
3 changes: 3 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub mod health;
pub mod mint_options;
pub mod program_types;
pub mod trades;

pub use health::*;
pub use mint_options::*;
pub use trades::*;
2 changes: 2 additions & 0 deletions src/models/program_types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod euro_meta;
pub mod expiration_data;
10 changes: 10 additions & 0 deletions src/routes/bot_actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::context::app_context::AppContext;
use crate::handlers::mint_options;
use axum::{routing::post, Router};
use std::sync::Arc;

pub fn bot_actions_route(app_context: Arc<AppContext>) -> Router {
Router::new()
.route("/mint-options", post(mint_options))
.with_state(app_context)
}
5 changes: 4 additions & 1 deletion src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod base_router;
mod bot_actions;
mod health;
mod trades;

use axum::Router;
use base_router::base_router;
pub use bot_actions::*;
pub use health::*;
use std::sync::Arc;
pub use trades::*;
Expand All @@ -13,5 +15,6 @@ use crate::context::app_context::AppContext;
pub fn build_routes(app_context: Arc<AppContext>) -> Router {
base_router(app_context.clone())
.merge(health_route())
.merge(trades_route(app_context))
.merge(trades_route(app_context.clone()))
.merge(bot_actions_route(app_context.clone()))
}

0 comments on commit 4de334c

Please sign in to comment.