Skip to content

Commit

Permalink
Feat: Updated AutoSwap service
Browse files Browse the repository at this point in the history
  • Loading branch information
RichoKD committed Dec 17, 2024
1 parent 931e68a commit 2e57b4b
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 233 deletions.
20 changes: 20 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ pub struct Configuration {
pub app_port: u16,
pub db_str: String,
pub db_pool_max_size: u32,
pub rpc_url: String,
pub private_key: String,
pub owner_address: String,
pub autoswap_contract: String,
pub token_address: String,
}

// Environment application is running in.
Expand Down Expand Up @@ -46,13 +51,28 @@ impl Configuration {
// 0.0.0.0 + Port to support containerisation.
let listen_address = SocketAddr::from((Ipv6Addr::UNSPECIFIED, app_port));

let rpc_url = env_var("STARKNET_RPC_URL")
.parse::<String>()
.expect("Unable to parse the value of the STARKNET_RPC_URL environment variable. Please make sure it is a valid string.");

let autoswap_contract = env_var("AUTOSWAP_CONTRACT_ADDRESS")
.parse::<String>()
.expect("Unable to parse the value of the EKUBO_CONTRACT environment variable. Please make sure it is a valid string.");

let token_address = env_var("TOKEN_ADDRESS");

// Configuration values to be safely shared across requests.
Arc::new(Configuration {
env,
listen_address,
app_port,
db_str,
db_pool_max_size,
rpc_url,
private_key: env_var("PRIVATE_KEY"),
owner_address: env_var("OWNER_ADDRESS"),
autoswap_contract,
token_address,
})
}

Expand Down
106 changes: 0 additions & 106 deletions src/http/auto_swap.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ mod subscription;
mod transaction_logs;
mod types;
mod unsubscription;
mod auto_swap;
mod utils;
use crate::AppState;

// Application router.
Expand Down
17 changes: 8 additions & 9 deletions src/http/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,29 @@ pub struct ActivityLogGetResponse {

#[derive(FromRow, Debug, Serialize)]
pub struct SubscriptionData {
pub wallet_address: String,
pub wallet_address: String,
pub to_token: String,
pub is_active: bool
pub is_active: bool,
}

#[derive(FromRow, Debug, Serialize)]
pub struct SwapSubscriptionFromTokenData {
pub wallet_address: String,
pub wallet_address: String,
pub from_token: String,
pub percentage: i16
pub percentage: i16,
}


#[derive(Debug, Serialize, Deserialize)]
pub struct AutoSwapRequest {
pub from : String,
pub to : String,
pub value : i64
pub from: String,
pub to: String,
pub value: i64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AutoSwapResponse {
pub status: String,
pub message: String
pub message: String,
}

#[derive(Debug, Deserialize)]
Expand Down
114 changes: 0 additions & 114 deletions src/http/utils.rs

This file was deleted.

14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use autoswappr_backend::{telemetry, Configuration, Db};
use tokio::net::TcpListener;
use autoswappr_backend::{service::auto_swap::swap, telemetry, Configuration, Db};
use tokio::{net::TcpListener, task};

#[tokio::main]
async fn main() {
Expand All @@ -23,6 +23,16 @@ async fn main() {
tracing::debug!("Running Migrations");
db.migrate().await.expect("Failed to run migrations");

tracing::info!("Running swap service");
task::spawn(async move {
if let Err(e) = swap().await {
tracing::error!("Swap function failed: {}", e);
Err(e) // Return the error
} else {
Ok(()) // Return Ok if no error
}
});

// Listen for requests on specified port.
tracing::info!("Starting server on {}", config.listen_address);
let listener = TcpListener::bind(&config.listen_address)
Expand Down
Loading

0 comments on commit 2e57b4b

Please sign in to comment.