Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/merge-prs' into feat/routin…
Browse files Browse the repository at this point in the history
…g-indexer
  • Loading branch information
ankurdubey521 committed Jun 19, 2024
2 parents 31e7cbd + fd7ae8f commit 56b96c8
Show file tree
Hide file tree
Showing 39 changed files with 1,478 additions and 105 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
name: Test Suite
on: [ pull_request, push ]
on: [pull_request, push]

jobs:
test:
name: cargo test
runs-on: ubuntu-latest

services:
mongodb:
image: mongo:6
ports:
- 27017:27017
options: >-
--health-cmd="mongosh --eval 'db.adminCommand({ ping: 1 })'"
--health-interval=30s
--health-timeout=10s
--health-retries=10
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --all-features

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable

env:
BUNGEE_API_KEY: ${{ secrets.BUNGEE_API_KEY }}
environment: Testing
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

members = [
"crates/config",
"crates/routing_engine",
"crates/routing-engine",
"crates/api",
"crates/storage",
"crates/account_aggregation",
"crates/account-aggregation",
"bin/reflux"
]

[workspace.dependencies]
api = { path = "crates/api" }
config = { path = "crates/config" }
storage = { path = "crates/storage" }
routing-engine = { path = "crates/routing-engine" }
account-aggregation = { path = "crates/account-aggregation" }
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# reflux
## reflux

Backend of solver which helps in seamless cross-chain asset consolidation. It aggregates user balances, automates routing, and suggests optimal transactions.

#### Installation

To setup the project locally

```bash
# cp ./config.yaml.example ./config.yaml
cargo build
cargo run
```

#### Usage

Once build is copleted, just run the server and test with the endpoints

### Dependencies graph

![image](./graph.png)
11 changes: 11 additions & 0 deletions bin/reflux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.38.0", features = ["full"] }
tower-http = { version = "0.5.2", features = ["cors"] }
axum = "0.7.5"
log = "0.4.21"

# workspace dependencies
account-aggregation = { workspace = true }
storage = { workspace = true }
config = { workspace = true }
routing-engine = { workspace = true }
api = { workspace = true }
87 changes: 85 additions & 2 deletions bin/reflux/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,86 @@
fn main() {
println!("Hello, world!");
use account_aggregation::service::AccountAggregationService;
use api::service_controller::ServiceController;
use axum::http::Method;
use config::Config;
use log::info;
use routing_engine::engine::RoutingEngine;
use storage::mongodb_provider::MongoDBProvider;
use tokio;
use tokio::signal;
use tower_http::cors::{Any, CorsLayer};

#[tokio::main]
async fn main() {
// Load configuration from yaml
let config = Config::from_file("config.yaml").expect("Failed to load config file");
let mongodb_uri = config.infra.mongo_url;
let (app_host, app_port) = (config.server.host, config.server.port);

// Instance of MongoDBProvider for users and account mappings
let user_db_provider =
MongoDBProvider::new(&mongodb_uri, "reflux".to_string(), "users".to_string(), true)
.await
.expect("Failed to create MongoDB provider for users");
let account_mapping_db_provider = MongoDBProvider::new(
&mongodb_uri,
"reflux".to_string(),
"account_mappings".to_string(),
false,
)
.await
.expect("Failed to create MongoDB provider for account mappings");

let (covalent_base_url, covalent_api_key) = (config.covalent.base_url, config.covalent.api_key);

// Initialize account aggregation service for api
let account_service = AccountAggregationService::new(
user_db_provider.clone(),
account_mapping_db_provider.clone(),
covalent_base_url,
covalent_api_key,
);

// Initialize routing engine
let routing_engine = RoutingEngine::new(account_service.clone());

// API service controller
let service_controller = ServiceController::new(account_service, routing_engine);

let cors = CorsLayer::new().allow_origin(Any).allow_methods([
Method::GET,
Method::POST,
Method::PATCH,
]);

let app = service_controller.router().layer(cors);

let listener = tokio::net::TcpListener::bind(format!("{}:{}", app_host, app_port))
.await
.expect("Failed to bind port");
axum::serve(listener, app.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await
.unwrap();

info!("Server stopped.");
}

async fn shutdown_signal() {
let ctrl_c = async {
signal::ctrl_c().await.expect("Unable to handle ctrl+c");
};
#[cfg(unix)]
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("Failed to install signal handler")
.recv()
.await;
};
#[cfg(not(unix))]
let terminate = std::future::pending::<()>();
tokio::select! {
_ = ctrl_c => {},
_ = terminate => {},
}
info!("signal received, starting graceful shutdown");
}
17 changes: 17 additions & 0 deletions crates/account-aggregation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "account-aggregation"
version = "0.1.0"
edition = "2021"

[dependencies]
mongodb = "2.8.2"
reqwest = { version = "0.12.4", features = ["json"] }
tokio = "1.38.0"
serde = { version = "1.0.203", features = ["derive"] }
futures = "0.3.30"
log = "0.4.21"
derive_more = { version = "1.0.0-beta.6", features = ["from", "into", "display"] }

# workspace dependencies
storage = { workspace = true }
uuid = "1.8.0"
2 changes: 2 additions & 0 deletions crates/account-aggregation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod service;
pub mod types;
Loading

0 comments on commit 56b96c8

Please sign in to comment.