diff --git a/crates/cli/src/commands/deposit.rs b/crates/cli/src/commands/deposit.rs new file mode 100644 index 000000000..ed192bb21 --- /dev/null +++ b/crates/cli/src/commands/deposit.rs @@ -0,0 +1,33 @@ +use clap::Parser; +use anyhow::Result; +use clap::Args; + +#[derive(Parser)] +pub struct Deposit { + #[clap(flatten)] + deposit_args: DepositArgs +} + +impl Deposit { + pub async fn execute(self) -> Result<()> { + let DepositArgs { + token, + amount, + vault_id, + } = &self.deposit_args; + println!("Token: {}, Amount: {}, Vault ID: {}", token, amount, vault_id); + Ok(()) + } +} + +#[derive(Args)] +pub struct DepositArgs { + #[arg(short, long, help = "The token address in hex format")] + token: String, + + #[arg(short, long, help = "The amount to deposit")] + amount: u64, + + #[arg(short, long, help = "The ID of the vault")] + vault_id: u64, +} \ No newline at end of file diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs new file mode 100644 index 000000000..c201cc0e1 --- /dev/null +++ b/crates/cli/src/commands/mod.rs @@ -0,0 +1,4 @@ +mod order; +mod deposit; + +pub use self::{order::*, deposit::*}; \ No newline at end of file diff --git a/crates/cli/src/orderbook/order/mod.rs b/crates/cli/src/commands/order.rs similarity index 62% rename from crates/cli/src/orderbook/order/mod.rs rename to crates/cli/src/commands/order.rs index df83ec113..8d5c0cf2e 100644 --- a/crates/cli/src/orderbook/order/mod.rs +++ b/crates/cli/src/commands/order.rs @@ -1,16 +1,17 @@ -use clap::Subcommand; +use clap::Parser; use anyhow::Result; -#[derive(Subcommand)] -#[command(about = "Interact with an order(s) onchain and offchain.")] +#[derive(Parser)] pub enum Order { #[command(about = "List all orders from the subgraph.")] Ls, } -pub async fn dispatch(order: Order) -> Result<()> { - match order { +impl Order { + pub async fn execute(self) -> Result<()> { + match self { Order::Ls => ls().await, + } } } diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs new file mode 100644 index 000000000..b7548a671 --- /dev/null +++ b/crates/cli/src/lib.rs @@ -0,0 +1,22 @@ +use anyhow::Result; +use clap::Subcommand; + +use crate::commands::{Order, Deposit}; + +mod commands; + +#[derive(Subcommand)] +pub enum Orderbook { + #[command(subcommand)] + Order(Order), + Deposit(Deposit), +} + +impl Orderbook { + pub async fn execute(self) -> Result<()> { + match self { + Orderbook::Order(order) => order.execute().await, + Orderbook::Deposit(deposit) => deposit.execute().await, + } + } +} \ No newline at end of file diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index a6ea1bbb7..26ea48d14 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,18 +1,17 @@ use clap::Parser; use anyhow::Result; - -mod orderbook; +use rain_orderbook_cli::Orderbook; #[derive(Parser)] #[command(author, version, about, long_about = None)] struct Cli { #[command(subcommand)] - orderbook: orderbook::Orderbook, + orderbook: Orderbook, } #[tokio::main] async fn main() -> Result<()> { tracing::subscriber::set_global_default(tracing_subscriber::fmt::Subscriber::new())?; let cli = Cli::parse(); - orderbook::dispatch(cli.orderbook).await + cli.orderbook.execute().await } \ No newline at end of file diff --git a/crates/cli/src/orderbook/deposit.rs b/crates/cli/src/orderbook/deposit.rs deleted file mode 100644 index a2118f699..000000000 --- a/crates/cli/src/orderbook/deposit.rs +++ /dev/null @@ -1,19 +0,0 @@ -use clap::Args; -use anyhow::Result; - -#[derive(Args)] -pub struct DepositArgs { - #[arg(help = "The token address in hex format")] - token: String, - - #[arg(help = "The amount to deposit")] - amount: u64, - - #[arg(help = "The ID of the vault")] - vault_id: u64, -} - -pub async fn deposit(args: DepositArgs) -> Result<()> { - println!("Token: {}, Amount: {}, Vault ID: {}", args.token, args.amount, args.vault_id); - Ok(()) -} \ No newline at end of file diff --git a/crates/cli/src/orderbook/mod.rs b/crates/cli/src/orderbook/mod.rs deleted file mode 100644 index bfe5b8c21..000000000 --- a/crates/cli/src/orderbook/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -use anyhow::Result; -use clap::Subcommand; - -mod order; -mod deposit; - -#[derive(Subcommand)] -pub enum Orderbook { - #[command(subcommand)] - Order(order::Order), - #[command(about = "Deposit funds into a vault.")] - Deposit(deposit::DepositArgs) -} - -pub async fn dispatch(orderbook: Orderbook) -> Result<()> { - match orderbook { - Orderbook::Order(order) => order::dispatch(order).await, - Orderbook::Deposit(args) => deposit::deposit(args).await, - } -} \ No newline at end of file