-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feat/merge-prs' into feat/routin…
…g-indexer
- Loading branch information
Showing
39 changed files
with
1,478 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod service; | ||
pub mod types; |
Oops, something went wrong.