Skip to content

Commit

Permalink
refactor: engine.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurdubey521 committed Jul 2, 2024
1 parent 71afe92 commit 3ee042e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 171 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## reflux

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

#### Installation

Expand All @@ -18,4 +19,4 @@ Once build is copleted, just run the server and test with the endpoints

### Dependencies graph

![image](./graph.png)
![image](./assets/dependency-graph.png)
File renamed without changes
12 changes: 6 additions & 6 deletions crates/account-aggregation/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::sync::Arc;
use thiserror::Error;

use derive_more::Display;
use mongodb::bson;
use reqwest::Client as ReqwestClient;
use thiserror::Error;
use uuid::Uuid;

use storage::mongodb_client::{DBError, MongoDBClient};
use storage::DBProvider;
use storage::mongodb_client::{DBError, MongoDBClient};

use crate::types::{
Account, AddAccountPayload, ApiResponse, Balance, RegisterAccountPayload, User,
Account, AddAccountPayload, ApiResponse, RegisterAccountPayload, TokenWithBalance, User,
UserAccountMapping, UserAccountMappingQuery, UserQuery,
};

Expand Down Expand Up @@ -217,7 +217,7 @@ impl AccountAggregationService {
pub async fn get_user_accounts_balance(
&self,
account: &String,
) -> Result<Vec<Balance>, AccountAggregationError> {
) -> Result<Vec<TokenWithBalance>, AccountAggregationError> {
let mut accounts: Vec<String> = Vec::new();
let user_id = self.get_user_id(account).await.unwrap_or(None);
if let Some(user_id) = user_id {
Expand Down Expand Up @@ -251,7 +251,7 @@ impl AccountAggregationService {
/// Extract balance data from the API response
fn extract_balance_data(
api_response: ApiResponse,
) -> Result<Vec<Balance>, AccountAggregationError> {
) -> Result<Vec<TokenWithBalance>, AccountAggregationError> {
let chain_id = api_response.data.chain_id.to_string();
let results = api_response
.data
Expand All @@ -273,7 +273,7 @@ fn extract_balance_data(
} else {
let balance = balance_raw / 10f64.powf(item.contract_decimals.unwrap() as f64);

Some(Balance {
Some(TokenWithBalance {
token: token.clone(),
token_address: item.contract_ticker_symbol.clone().unwrap(),
chain_id: chain_id.clone().parse::<u32>().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions crates/account-aggregation/src/service_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_trait::async_trait;

use storage::mongodb_client::MongoDBClient;

use crate::types::{Account, AddAccountPayload, Balance, RegisterAccountPayload};
use crate::types::{Account, AddAccountPayload, RegisterAccountPayload, TokenWithBalance};

#[async_trait]
pub trait AccountAggregationServiceTrait {
Expand All @@ -21,5 +21,5 @@ pub trait AccountAggregationServiceTrait {
account_payload: RegisterAccountPayload,
) -> Result<(), Box<dyn Error>>;
fn add_account(&self, account_payload: AddAccountPayload) -> Result<(), Box<dyn Error>>;
fn get_user_accounts_balance(&self, account: &String) -> Vec<Balance>;
fn get_user_accounts_balance(&self, account: &String) -> Vec<TokenWithBalance>;
}
2 changes: 1 addition & 1 deletion crates/account-aggregation/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct TokenData {
}

#[derive(Deserialize, Serialize, Debug)]
pub struct Balance {
pub struct TokenWithBalance {
pub token: String,
pub token_address: String,
pub chain_id: u32,
Expand Down
Loading

0 comments on commit 3ee042e

Please sign in to comment.