-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathmain.rs
More file actions
148 lines (136 loc) · 5.09 KB
/
main.rs
File metadata and controls
148 lines (136 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
mod auth;
mod commands;
mod config;
mod output;
mod shell;
use std::process::ExitCode;
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
use output::OutputFormat;
#[derive(Parser)]
#[command(name = "polymarket", about = "Polymarket CLI", version)]
pub(crate) struct Cli {
#[command(subcommand)]
command: Commands,
/// Output format: table or json
#[arg(short, long, global = true, default_value = "table")]
pub(crate) output: OutputFormat,
/// Private key (overrides env var and config file)
#[arg(long, global = true)]
private_key: Option<String>,
/// Signature type: eoa, proxy, or gnosis-safe
#[arg(long, global = true)]
signature_type: Option<String>,
}
#[derive(Subcommand)]
enum Commands {
/// Guided first-time setup (wallet, proxy, approvals)
Setup,
/// Launch interactive shell
Shell,
/// Interact with markets
Markets(commands::markets::MarketsArgs),
/// Interact with events
Events(commands::events::EventsArgs),
/// Interact with tags
Tags(commands::tags::TagsArgs),
/// Interact with series
Series(commands::series::SeriesArgs),
/// Interact with comments
Comments(commands::comments::CommentsArgs),
/// Look up public profiles
Profiles(commands::profiles::ProfilesArgs),
/// Sports metadata and teams
Sports(commands::sports::SportsArgs),
/// Check and set contract approvals for trading
Approve(commands::approve::ApproveArgs),
/// Interact with the CLOB (order book, trading, balances)
Clob(commands::clob::ClobArgs),
/// CTF operations: split, merge, redeem positions
Ctf(commands::ctf::CtfArgs),
/// Query on-chain data (positions, trades, leaderboards)
Data(commands::data::DataArgs),
/// Bridge assets from other chains to Polymarket
Bridge(commands::bridge::BridgeArgs),
/// Manage wallet and authentication
Wallet(commands::wallet::WalletArgs),
/// Check API health status
Status,
/// Update to the latest version
Upgrade,
/// Generate shell completions
Completions {
/// Shell to generate completions for
shell: Shell,
},
}
#[tokio::main]
async fn main() -> ExitCode {
let cli = Cli::parse();
let output = cli.output;
if let Err(e) = run(cli).await {
output::print_error(&e, output);
return ExitCode::FAILURE;
}
ExitCode::SUCCESS
}
#[allow(clippy::too_many_lines)]
pub(crate) async fn run(cli: Cli) -> anyhow::Result<()> {
// Lazy-init so we only pay for the client we actually use.
let gamma = std::cell::LazyCell::new(polymarket_client_sdk::gamma::Client::default);
let data = std::cell::LazyCell::new(polymarket_client_sdk::data::Client::default);
let bridge = std::cell::LazyCell::new(polymarket_client_sdk::bridge::Client::default);
match cli.command {
Commands::Setup => commands::setup::execute(),
Commands::Shell => Box::pin(shell::run_shell()).await,
Commands::Markets(args) => commands::markets::execute(&gamma, args, cli.output).await,
Commands::Events(args) => commands::events::execute(&gamma, args, cli.output).await,
Commands::Tags(args) => commands::tags::execute(&gamma, args, cli.output).await,
Commands::Series(args) => commands::series::execute(&gamma, args, cli.output).await,
Commands::Comments(args) => commands::comments::execute(&gamma, args, cli.output).await,
Commands::Profiles(args) => commands::profiles::execute(&gamma, args, cli.output).await,
Commands::Sports(args) => commands::sports::execute(&gamma, args, cli.output).await,
Commands::Approve(args) => {
commands::approve::execute(args, cli.output, cli.private_key.as_deref()).await
}
Commands::Clob(args) => {
commands::clob::execute(
args,
cli.output,
cli.private_key.as_deref(),
cli.signature_type.as_deref(),
)
.await
}
Commands::Ctf(args) => {
commands::ctf::execute(args, cli.output, cli.private_key.as_deref()).await
}
Commands::Data(args) => commands::data::execute(&data, args, cli.output).await,
Commands::Bridge(args) => commands::bridge::execute(&bridge, args, cli.output).await,
Commands::Wallet(args) => {
commands::wallet::execute(args, cli.output, cli.private_key.as_deref())
}
Commands::Upgrade => commands::upgrade::execute(),
Commands::Completions { shell } => {
clap_complete::generate(
shell,
&mut Cli::command(),
"polymarket",
&mut std::io::stdout(),
);
Ok(())
}
Commands::Status => {
let status = gamma.status().await?;
match cli.output {
OutputFormat::Json => {
println!("{}", serde_json::json!({"status": status}));
}
OutputFormat::Table => {
println!("API Status: {status}");
}
}
Ok(())
}
}
}