Skip to content

Commit

Permalink
compliance: compliance-server: Define initial compliance api
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Jun 29, 2024
1 parent a48b2ae commit 1a68366
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 14 deletions.
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[workspace]
members = [
"compliance/compliance-server",
"compliance/compliance-api",
"dealer/renegade-dealer",
"dealer/renegade-dealer-api",
"fee-sweeper",
Expand All @@ -14,3 +16,16 @@ debug = true
[profile.release]
opt-level = 3 # Full optimizations
lto = true

[workspace.dependencies]
# === Renegade Dependencies === #
arbitrum-client = { git = "https://github.com/renegade-fi/renegade.git", features = [
"rand",
] }
renegade-api = { package = "external-api", git = "https://github.com/renegade-fi/renegade.git" }
renegade-common = { package = "common", git = "https://github.com/renegade-fi/renegade.git" }
renegade-constants = { package = "constants", git = "https://github.com/renegade-fi/renegade.git" }
renegade-circuits = { package = "circuits", git = "https://github.com/renegade-fi/renegade.git" }
renegade-circuit-types = { package = "circuit-types", git = "https://github.com/renegade-fi/renegade.git" }
renegade-crypto = { git = "https://github.com/renegade-fi/renegade.git" }
renegade-util = { package = "util", git = "https://github.com/renegade-fi/renegade.git" }
8 changes: 8 additions & 0 deletions compliance/compliance-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "compliance-api"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
17 changes: 17 additions & 0 deletions compliance/compliance-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use serde::{Deserialize, Serialize};

/// The response type for a compliance check
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComplianceCheckResponse {
/// The compliance status of the wallet
pub compliance_status: ComplianceStatus,
}

/// The status on compliance for a wallet
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ComplianceStatus {
/// The wallet is compliant
Compliant,
/// The wallet is not compliant
NotCompliant,
}

Check failure on line 17 in compliance/compliance-api/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for the crate

error: missing documentation for the crate --> compliance/compliance-api/src/lib.rs:1:1 | 1 | / use serde::{Deserialize, Serialize}; 2 | | 3 | | /// The response type for a compliance check 4 | | #[derive(Debug, Clone, Serialize, Deserialize)] ... | 16 | | NotCompliant, 17 | | } | |_^ | = note: requested on the command line with `-D missing-docs`

Check failure on line 17 in compliance/compliance-api/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for the crate

error: missing documentation for the crate --> compliance/compliance-api/src/lib.rs:1:1 | 1 | / use serde::{Deserialize, Serialize}; 2 | | 3 | | /// The response type for a compliance check 4 | | #[derive(Debug, Clone, Serialize, Deserialize)] ... | 16 | | NotCompliant, 17 | | } | |_^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items = note: requested on the command line with `-D clippy::missing-docs-in-private-items`
17 changes: 17 additions & 0 deletions compliance/compliance-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "compliance-server"
version = "0.1.0"
edition = "2021"

[dependencies]
# === HTTP Server === #
http-body-util = "0.1.0"
warp = "0.3"
compliance-api = { path = "../compliance-api" }

# === Renegade Dependencies === #
renegade-util = { workspace = true }

# === Misc === #
clap = { version = "4.5", features = ["derive"] }
tokio = { version = "1.37", features = ["full"] }
17 changes: 17 additions & 0 deletions compliance/compliance-server/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Error types for the compliance server

use std::{error::Error, fmt::Display};

use warp::reject::Reject;

/// The error type emitted by the compliance server
#[derive(Debug, Clone)]
pub enum ComplianceServerError {}

impl Display for ComplianceServerError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ComplianceServerError")
}
}
impl Error for ComplianceServerError {}
impl Reject for ComplianceServerError {}
68 changes: 68 additions & 0 deletions compliance/compliance-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use clap::Parser;
use compliance_api::{ComplianceCheckResponse, ComplianceStatus};
use error::ComplianceServerError;
use renegade_util::telemetry::{setup_system_logger, LevelFilter};
use warp::{reply::Json, Filter};

pub mod error;

/// The CLI for the compliance server
#[derive(Debug, Clone, Parser)]
#[command(about = "The CLI for the compliance server")]
struct Cli {
/// The port to listen on
#[arg(short, long)]
port: u16,
/// The Chainalysis API key
#[arg(long)]
chainalysis_api_key: String,
}

#[tokio::main]
async fn main() {
setup_system_logger(LevelFilter::INFO);
let cli = Cli::parse();

// Get compliance information for a wallet
let chainalysis_key = cli.chainalysis_api_key.clone();
let compliance_check = warp::get()
.and(warp::path("v0"))
.and(warp::path("compliance-check"))
.and(warp::path::param::<String>()) // wallet_address
.and_then(move |wallet_address| {
let key = chainalysis_key.clone();
async move {
handle_req(wallet_address, &key).await
}
});

// GET /ping
let ping = warp::get()
.and(warp::path("ping"))
.map(|| warp::reply::with_status("PONG", warp::http::StatusCode::OK));

let routes = compliance_check.or(ping);
warp::serve(routes).run(([0, 0, 0, 0], cli.port)).await
}

/// Handle a request for a compliance check
async fn handle_req(
wallet_address: String,
chainalysis_api_key: &str,
) -> Result<Json, warp::Rejection> {
let compliance_status = check_wallet_compliance(wallet_address, chainalysis_api_key).await?;
let resp = ComplianceCheckResponse { compliance_status };
Ok(warp::reply::json(&resp))
}

/// Check the compliance of a wallet
async fn check_wallet_compliance(
wallet_address: String,
chainalysis_api_key: &str,
) -> Result<ComplianceStatus, ComplianceServerError> {
// 1. Check the DB first

// 2. If not present, check the chainalysis API

todo!()
}
18 changes: 8 additions & 10 deletions fee-sweeper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ alloy-sol-types = "0.3.1"
ethers = "2"

# === Renegade Dependencies === #
arbitrum-client = { git = "https://github.com/renegade-fi/renegade.git", features = [
"rand",
] }
renegade-api = { package = "external-api", git = "https://github.com/renegade-fi/renegade.git" }
renegade-common = { package = "common", git = "https://github.com/renegade-fi/renegade.git" }
renegade-constants = { package = "constants", git = "https://github.com/renegade-fi/renegade.git" }
renegade-circuits = { package = "circuits", git = "https://github.com/renegade-fi/renegade.git" }
renegade-circuit-types = { package = "circuit-types", git = "https://github.com/renegade-fi/renegade.git" }
renegade-crypto = { git = "https://github.com/renegade-fi/renegade.git" }
renegade-util = { package = "util", git = "https://github.com/renegade-fi/renegade.git" }
arbitrum-client = { workspace = true, features = ["rand"] }
renegade-api = { package = "external-api", workspace = true }
renegade-common = { package = "common", workspace = true }
renegade-constants = { package = "constants", workspace = true }
renegade-circuits = { package = "circuits", workspace = true }
renegade-circuit-types = { package = "circuit-types", workspace = true }
renegade-crypto = { workspace = true }
renegade-util = { package = "util", workspace = true }

# === Misc Dependencies === #
base64 = "0.22"
Expand Down
3 changes: 2 additions & 1 deletion fee-sweeper/src/indexer/index_fees.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Phase one of the sweeper's execution; index all fees since the last consistent block
//! Phase one of the sweeper's execution; index all fees since the last
//! consistent block

use alloy_sol_types::SolCall;
use arbitrum_client::abi::settleOfflineFeeCall;
Expand Down
4 changes: 2 additions & 2 deletions fee-sweeper/src/indexer/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ impl Indexer {
return Ok(vec![]);
}

// We query the fees table with a transformation that calculates the value of each fee using the prices passed in.
// This query looks something like:
// We query the fees table with a transformation that calculates the value of
// each fee using the prices passed in. This query looks something like:
// SELECT tx_hash, mint, amount,
// CASE
// WHEN mint = '<mint1>' then amount * <price1>
Expand Down
3 changes: 2 additions & 1 deletion fee-sweeper/src/relayer_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ impl RelayerClient {
// Enter a polling loop until the task finishes
let poll_interval = Duration::from_millis(POLL_INTERVAL_MS);
loop {
// For now, we assume that an error is a 404 in which case the task has completed
// For now, we assume that an error is a 404 in which case the task has
// completed
// TODO: Improve this break condition if it proves problematic
if self.get_relayer::<GetTaskStatusResponse>(&path).await.is_err() {
break;
Expand Down

0 comments on commit 1a68366

Please sign in to comment.