Skip to content

Commit

Permalink
cli restructure and adding deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
hardyjosh committed Jan 7, 2024
1 parent 38db479 commit 5d45b34
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 39 deletions.
34 changes: 0 additions & 34 deletions crates/cli/src/cli/mod.rs

This file was deleted.

20 changes: 16 additions & 4 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
mod cli;
use clap::Parser;
use anyhow::Result;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
cli::main().await
mod orderbook;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
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
}
19 changes: 19 additions & 0 deletions crates/cli/src/orderbook/deposit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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(())
}
20 changes: 20 additions & 0 deletions crates/cli/src/orderbook/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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,
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Subcommand;
use anyhow::Result;

#[derive(Subcommand)]
#[command(about = "Interact with an order(s) onchain and offchain.")]
Expand All @@ -7,8 +8,14 @@ pub enum Order {
Ls,
}

pub async fn dispatch(order: Order) -> Result<()> {
match order {
Order::Ls => ls().await,
}
}

pub async fn ls() -> anyhow::Result<()> {
let orders = rain_orderbook_subgraph_queries::orders::query().await?;
dbg!(orders);
Ok(())
}
}

0 comments on commit 5d45b34

Please sign in to comment.