use clap::{Parser, Subcommand};
use cow_settlement_client::cow_settlement_interface::Pubkey;
mod cmd;
mod instructions;
mod token;
fn default_keypair_path() -> String {
let home = std::env::var("HOME").expect("`HOME` env not available");
format!("{home}/.config/solana/id.json")
}
#[derive(Parser)]
#[command(name = "cow", about = "CoW Protocol Solana dev/testing CLI")]
struct Cli {
#[arg(
long,
global = true,
env = "RPC_URL",
default_value = "https://api.devnet.solana.com"
)]
rpc_url: String,
#[arg(
long,
global = true,
env = "KEYPAIR",
default_value_t = default_keypair_path()
)]
keypair: String,
#[arg(long, global = true, default_value_t = cow_settlement_client::cow_settlement_interface::ID)]
program_id: Pubkey,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
#[command(about = "Sell a token for another (e.g. `cow sell 1.0 SOL for USDC`)")]
Sell(cmd::create_order::BuyOrSellArgs),
#[command(about = "Buy a token using another (e.g. `cow buy 1.0 SOL with USDC`)")]
Buy(cmd::create_order::BuyOrSellArgs),
#[command(about = "Settle one or more orders")]
Settle(cmd::settle::SettleArgs),
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let ctx = cmd::Context::from_args(&cli)?;
match cli.command {
Commands::Sell(args) => cmd::create_order::run_sell(ctx, args),
Commands::Buy(args) => cmd::create_order::run_buy(ctx, args),
Commands::Settle(args) => cmd::settle::run(ctx, args),
}
}