diff --git a/src/auth.rs b/src/auth.rs index 15ad61e..3958b6c 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -13,7 +13,7 @@ pub const RPC_URL: &str = "https://polygon.drpc.org"; fn parse_signature_type(s: &str) -> SignatureType { match s { - config::DEFAULT_SIGNATURE_TYPE => SignatureType::Proxy, + "proxy" => SignatureType::Proxy, "gnosis-safe" => SignatureType::GnosisSafe, _ => SignatureType::Eoa, } diff --git a/src/commands/setup.rs b/src/commands/setup.rs index dd04671..609db36 100644 --- a/src/commands/setup.rs +++ b/src/commands/setup.rs @@ -5,9 +5,9 @@ use std::str::FromStr; use anyhow::{Context, Result}; use polymarket_client_sdk::auth::{LocalSigner, Signer as _}; use polymarket_client_sdk::types::Address; -use polymarket_client_sdk::{POLYGON, derive_proxy_wallet}; +use polymarket_client_sdk::POLYGON; -use super::wallet::normalize_key; +use super::wallet::{derive_wallet_for_type, normalize_key}; use crate::config; fn print_banner() { @@ -95,7 +95,7 @@ pub fn execute() -> Result<()> { println!(); if !prompt_yn(" Reconfigure wallet?", false)? { - finish_setup(addr)?; + finish_setup(addr, &config::resolve_signature_type(None))?; return Ok(()); } println!(); @@ -107,7 +107,7 @@ pub fn execute() -> Result<()> { println!(); - finish_setup(address) + finish_setup(address, &config::resolve_signature_type(None)) } fn setup_wallet() -> Result
{ @@ -151,12 +151,12 @@ fn setup_wallet() -> Result
{ Ok(address) } -fn finish_setup(address: Address) -> Result<()> { +fn finish_setup(address: Address, signature_type: &str) -> Result<()> { let total = 4; step_header(2, total, "Proxy Wallet"); - let proxy = derive_proxy_wallet(address, POLYGON); + let proxy = derive_wallet_for_type(address, POLYGON, signature_type); match proxy { Some(proxy) => { println!(" ✓ Proxy wallet derived"); diff --git a/src/commands/wallet.rs b/src/commands/wallet.rs index ce7597f..9717fe4 100644 --- a/src/commands/wallet.rs +++ b/src/commands/wallet.rs @@ -5,11 +5,29 @@ use anyhow::{Context, Result, bail}; use clap::{Args, Subcommand}; use polymarket_client_sdk::auth::LocalSigner; use polymarket_client_sdk::auth::Signer as _; -use polymarket_client_sdk::{POLYGON, derive_proxy_wallet}; +use polymarket_client_sdk::types::Address; +use polymarket_client_sdk::{POLYGON, derive_proxy_wallet, derive_safe_wallet}; use crate::config; use crate::output::OutputFormat; +/// Derive the appropriate proxy/safe wallet address based on signature type. +/// +/// - `"proxy"` → EIP-1167 proxy wallet +/// - `"gnosis-safe"` → Gnosis Safe wallet +/// - `"eoa"` / other → `None` (no proxy wallet) +pub(crate) fn derive_wallet_for_type( + address: Address, + chain_id: u64, + signature_type: &str, +) -> Option
{ + match signature_type { + "proxy" => derive_proxy_wallet(address, chain_id), + "gnosis-safe" => derive_safe_wallet(address, chain_id), + _ => None, + } +} + #[derive(Args)] pub struct WalletArgs { #[command(subcommand)] @@ -23,8 +41,8 @@ pub enum WalletCommand { /// Overwrite existing wallet #[arg(long)] force: bool, - /// Signature type: eoa, proxy (default), or gnosis-safe - #[arg(long, default_value = "proxy")] + /// Signature type: eoa, proxy, or gnosis-safe (default) + #[arg(long, default_value = "gnosis-safe")] signature_type: String, }, /// Import an existing private key @@ -34,8 +52,8 @@ pub enum WalletCommand { /// Overwrite existing wallet #[arg(long)] force: bool, - /// Signature type: eoa, proxy (default), or gnosis-safe - #[arg(long, default_value = "proxy")] + /// Signature type: eoa, proxy, or gnosis-safe (default) + #[arg(long, default_value = "gnosis-safe")] signature_type: String, }, /// Show the address of the configured wallet @@ -103,7 +121,7 @@ fn cmd_create(output: &OutputFormat, force: bool, signature_type: &str) -> Resul config::save_wallet(&key_hex, POLYGON, signature_type)?; let config_path = config::config_path()?; - let proxy_addr = derive_proxy_wallet(address, POLYGON); + let proxy_addr = derive_wallet_for_type(address, POLYGON, signature_type); match output { OutputFormat::Json => { @@ -144,7 +162,7 @@ fn cmd_import(key: &str, output: &OutputFormat, force: bool, signature_type: &st config::save_wallet(&normalized, POLYGON, signature_type)?; let config_path = config::config_path()?; - let proxy_addr = derive_proxy_wallet(address, POLYGON); + let proxy_addr = derive_wallet_for_type(address, POLYGON, signature_type); match output { OutputFormat::Json => { @@ -193,12 +211,11 @@ fn cmd_show(output: &OutputFormat, private_key_flag: Option<&str>) -> Result<()> let (key, source) = config::resolve_key(private_key_flag); let signer = key.as_deref().and_then(|k| LocalSigner::from_str(k).ok()); let address = signer.as_ref().map(|s| s.address().to_string()); + let sig_type = config::resolve_signature_type(None); let proxy_addr = signer .as_ref() - .and_then(|s| derive_proxy_wallet(s.address(), POLYGON)) + .and_then(|s| derive_wallet_for_type(s.address(), POLYGON, &sig_type)) .map(|a| a.to_string()); - - let sig_type = config::resolve_signature_type(None); let config_path = config::config_path()?; match output { diff --git a/src/config.rs b/src/config.rs index d2f5395..49b3349 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; const ENV_VAR: &str = "POLYMARKET_PRIVATE_KEY"; const SIG_TYPE_ENV_VAR: &str = "POLYMARKET_SIGNATURE_TYPE"; -pub const DEFAULT_SIGNATURE_TYPE: &str = "proxy"; +pub const DEFAULT_SIGNATURE_TYPE: &str = "gnosis-safe"; pub const NO_WALLET_MSG: &str = "No wallet configured. Run `polymarket wallet create` or `polymarket wallet import `";