Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: read proxy URL from config file (priority: --proxy flag > POLYM…
…ARKET_PROXY env > config file)
  • Loading branch information
croll83 committed Feb 25, 2026
commit 5acf9f772c077a11af188136b4d2eba72d97f1dc
21 changes: 21 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ use serde::{Deserialize, Serialize};

const ENV_VAR: &str = "POLYMARKET_PRIVATE_KEY";
const SIG_TYPE_ENV_VAR: &str = "POLYMARKET_SIGNATURE_TYPE";
const PROXY_ENV_VAR: &str = "POLYMARKET_PROXY";
pub const DEFAULT_SIGNATURE_TYPE: &str = "proxy";

pub const NO_WALLET_MSG: &str =
"No wallet configured. Run `polymarket wallet create` or `polymarket wallet import <key>`";

#[derive(Serialize, Deserialize)]
pub struct Config {
#[serde(default)]
pub private_key: String,
pub chain_id: u64,
#[serde(default = "default_signature_type")]
pub signature_type: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub proxy: Option<String>,
}

fn default_signature_type() -> String {
Expand Down Expand Up @@ -98,6 +102,7 @@ pub fn save_wallet(key: &str, chain_id: u64, signature_type: &str) -> Result<()>
private_key: key.to_string(),
chain_id,
signature_type: signature_type.to_string(),
proxy: None,
};
let json = serde_json::to_string_pretty(&config)?;
let path = config_path()?;
Expand Down Expand Up @@ -125,6 +130,22 @@ pub fn save_wallet(key: &str, chain_id: u64, signature_type: &str) -> Result<()>
Ok(())
}


/// Priority: CLI flag > env var > config file.
pub fn resolve_proxy(cli_flag: Option<&str>) -> Option<String> {
if let Some(url) = cli_flag {
return Some(url.to_string());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty proxy string not filtered from CLI flag

Low Severity

resolve_proxy filters empty strings for the POLYMARKET_PROXY env var path (via !url.is_empty()) but does not apply the same check to the CLI flag path or the config file path. An empty --proxy "" value or an empty proxy string in the config file would result in setting HTTPS_PROXY and HTTP_PROXY to empty strings, likely causing confusing request failures.

Fix in Cursor Fix in Web

}
if let Ok(url) = std::env::var(PROXY_ENV_VAR)
&& !url.is_empty()
{
return Some(url);
}
if let Some(config) = load_config() {
return config.proxy;
}
None
}
/// Priority: CLI flag > env var > config file.
pub fn resolve_key(cli_flag: Option<&str>) -> (Option<String>, KeySource) {
if let Some(key) = cli_flag {
Expand Down
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,8 @@ async fn main() -> ExitCode {
let cli = Cli::parse();
let output = cli.output;

// Apply proxy: --proxy flag > POLYMARKET_PROXY > ALL_PROXY (already set by user)
let proxy_url = cli.proxy
.as_deref()
.map(String::from)
.or_else(|| std::env::var("POLYMARKET_PROXY").ok());
if let Some(ref url) = proxy_url {
// Apply proxy: --proxy flag > POLYMARKET_PROXY env > config file proxy field
if let Some(ref url) = config::resolve_proxy(cli.proxy.as_deref()) {
// SAFETY: called before any threads are spawned by the async runtime
unsafe { std::env::set_var("HTTPS_PROXY", url); }
unsafe { std::env::set_var("HTTP_PROXY", url); }
Expand Down