Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
12 changes: 6 additions & 6 deletions src/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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!();
Expand All @@ -107,7 +107,7 @@ pub fn execute() -> Result<()> {

println!();

finish_setup(address)
finish_setup(address, &config::resolve_signature_type(None))
}

fn setup_wallet() -> Result<Address> {
Expand Down Expand Up @@ -151,12 +151,12 @@ fn setup_wallet() -> Result<Address> {
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");
Expand Down
37 changes: 27 additions & 10 deletions src/commands/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address> {
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)]
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <key>`";
Expand Down