Skip to content

Commit 489d83e

Browse files
croll83claude
andcommitted
fix: derive trading wallet from signature_type config (gnosis-safe support)
wallet show/create/import now use the configured signature_type to derive the correct trading wallet address: - "proxy" → EIP-1167 minimal proxy (Magic/email wallets) - "gnosis-safe" → Gnosis Safe 1-of-1 (browser/MetaMask wallets) - "eoa" → no derived wallet, use EOA directly Previously all wallet commands hardcoded derive_proxy_wallet(), ignoring the signature_type setting entirely. This caused the CLI to show the wrong deposit address when using gnosis-safe mode (which is what polymarket.com creates for browser wallet users). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 27cb3e4 commit 489d83e

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

src/commands/setup.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::str::FromStr;
55
use anyhow::{Context, Result};
66
use polymarket_client_sdk::auth::{LocalSigner, Signer as _};
77
use polymarket_client_sdk::types::Address;
8-
use polymarket_client_sdk::{POLYGON, derive_proxy_wallet};
8+
use polymarket_client_sdk::POLYGON;
99

10-
use super::wallet::normalize_key;
10+
use super::wallet::{derive_trading_wallet, normalize_key};
1111
use crate::config;
1212

1313
fn print_banner() {
@@ -154,26 +154,26 @@ fn setup_wallet() -> Result<Address> {
154154
fn finish_setup(address: Address) -> Result<()> {
155155
let total = 4;
156156

157-
step_header(2, total, "Proxy Wallet");
157+
step_header(2, total, "Trading Wallet");
158158

159-
let proxy = derive_proxy_wallet(address, POLYGON);
160-
match proxy {
161-
Some(proxy) => {
162-
println!(" ✓ Proxy wallet derived");
163-
println!(" Proxy: {proxy}");
159+
let sig_type = config::resolve_signature_type(None);
160+
let trading = derive_trading_wallet(address, POLYGON, &sig_type);
161+
match trading {
162+
Some(tw) => {
163+
println!(" ✓ Trading wallet derived ({sig_type})");
164+
println!(" Trading wallet: {tw}");
164165
println!(" Deposit USDC to this address to start trading.");
165166
}
166167
None => {
167-
println!(" ✗ Could not derive proxy wallet");
168-
println!(" You may need to use --signature-type eoa");
168+
println!(" ℹ Using EOA directly (signature type: {sig_type})");
169169
}
170170
}
171171

172172
println!();
173173

174174
step_header(3, total, "Fund Wallet");
175175

176-
let deposit_addr = proxy.unwrap_or(address);
176+
let deposit_addr = trading.unwrap_or(address);
177177
println!(" ○ Deposit USDC to your wallet to start trading");
178178
println!(" Run: polymarket bridge deposit {deposit_addr}");
179179
println!(" Or transfer USDC directly on Polygon");

src/commands/wallet.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ use anyhow::{Context, Result, bail};
55
use clap::{Args, Subcommand};
66
use polymarket_client_sdk::auth::LocalSigner;
77
use polymarket_client_sdk::auth::Signer as _;
8-
use polymarket_client_sdk::{POLYGON, derive_proxy_wallet};
8+
use polymarket_client_sdk::{POLYGON, derive_proxy_wallet, derive_safe_wallet};
99

1010
use crate::config;
1111
use crate::output::OutputFormat;
1212

13+
/// Derive the trading wallet address based on the configured signature type.
14+
/// - "proxy" → Polymarket Proxy wallet (Magic/email)
15+
/// - "gnosis-safe" → Gnosis Safe wallet (browser/MetaMask)
16+
/// - anything else (e.g. "eoa") → None (the EOA itself is used)
17+
pub(crate) fn derive_trading_wallet(
18+
address: polymarket_client_sdk::types::Address,
19+
chain_id: u64,
20+
signature_type: &str,
21+
) -> Option<polymarket_client_sdk::types::Address> {
22+
match signature_type {
23+
"proxy" => derive_proxy_wallet(address, chain_id),
24+
"gnosis-safe" => derive_safe_wallet(address, chain_id),
25+
_ => None,
26+
}
27+
}
28+
1329
#[derive(Args)]
1430
pub struct WalletArgs {
1531
#[command(subcommand)]
@@ -103,15 +119,15 @@ fn cmd_create(output: &OutputFormat, force: bool, signature_type: &str) -> Resul
103119

104120
config::save_wallet(&key_hex, POLYGON, signature_type)?;
105121
let config_path = config::config_path()?;
106-
let proxy_addr = derive_proxy_wallet(address, POLYGON);
122+
let trading_addr = derive_trading_wallet(address, POLYGON, signature_type);
107123

108124
match output {
109125
OutputFormat::Json => {
110126
println!(
111127
"{}",
112128
serde_json::json!({
113129
"address": address.to_string(),
114-
"proxy_address": proxy_addr.map(|a| a.to_string()),
130+
"trading_wallet": trading_addr.map(|a| a.to_string()),
115131
"signature_type": signature_type,
116132
"config_path": config_path.display().to_string(),
117133
})
@@ -120,8 +136,8 @@ fn cmd_create(output: &OutputFormat, force: bool, signature_type: &str) -> Resul
120136
OutputFormat::Table => {
121137
println!("Wallet created successfully!");
122138
println!("Address: {address}");
123-
if let Some(proxy) = proxy_addr {
124-
println!("Proxy wallet: {proxy}");
139+
if let Some(tw) = trading_addr {
140+
println!("Trading wallet: {tw}");
125141
}
126142
println!("Signature type: {signature_type}");
127143
println!("Config: {}", config_path.display());
@@ -144,15 +160,15 @@ fn cmd_import(key: &str, output: &OutputFormat, force: bool, signature_type: &st
144160

145161
config::save_wallet(&normalized, POLYGON, signature_type)?;
146162
let config_path = config::config_path()?;
147-
let proxy_addr = derive_proxy_wallet(address, POLYGON);
163+
let trading_addr = derive_trading_wallet(address, POLYGON, signature_type);
148164

149165
match output {
150166
OutputFormat::Json => {
151167
println!(
152168
"{}",
153169
serde_json::json!({
154170
"address": address.to_string(),
155-
"proxy_address": proxy_addr.map(|a| a.to_string()),
171+
"trading_wallet": trading_addr.map(|a| a.to_string()),
156172
"signature_type": signature_type,
157173
"config_path": config_path.display().to_string(),
158174
})
@@ -161,8 +177,8 @@ fn cmd_import(key: &str, output: &OutputFormat, force: bool, signature_type: &st
161177
OutputFormat::Table => {
162178
println!("Wallet imported successfully!");
163179
println!("Address: {address}");
164-
if let Some(proxy) = proxy_addr {
165-
println!("Proxy wallet: {proxy}");
180+
if let Some(tw) = trading_addr {
181+
println!("Trading wallet: {tw}");
166182
}
167183
println!("Signature type: {signature_type}");
168184
println!("Config: {}", config_path.display());
@@ -193,12 +209,13 @@ fn cmd_show(output: &OutputFormat, private_key_flag: Option<&str>) -> Result<()>
193209
let (key, source) = config::resolve_key(private_key_flag);
194210
let signer = key.as_deref().and_then(|k| LocalSigner::from_str(k).ok());
195211
let address = signer.as_ref().map(|s| s.address().to_string());
196-
let proxy_addr = signer
212+
213+
let sig_type = config::resolve_signature_type(None);
214+
let trading_addr = signer
197215
.as_ref()
198-
.and_then(|s| derive_proxy_wallet(s.address(), POLYGON))
216+
.and_then(|s| derive_trading_wallet(s.address(), POLYGON, &sig_type))
199217
.map(|a| a.to_string());
200218

201-
let sig_type = config::resolve_signature_type(None);
202219
let config_path = config::config_path()?;
203220

204221
match output {
@@ -207,7 +224,7 @@ fn cmd_show(output: &OutputFormat, private_key_flag: Option<&str>) -> Result<()>
207224
"{}",
208225
serde_json::json!({
209226
"address": address,
210-
"proxy_address": proxy_addr,
227+
"trading_wallet": trading_addr,
211228
"signature_type": sig_type,
212229
"config_path": config_path.display().to_string(),
213230
"source": source.label(),
@@ -220,8 +237,8 @@ fn cmd_show(output: &OutputFormat, private_key_flag: Option<&str>) -> Result<()>
220237
Some(addr) => println!("Address: {addr}"),
221238
None => println!("Address: (not configured)"),
222239
}
223-
if let Some(proxy) = &proxy_addr {
224-
println!("Proxy wallet: {proxy}");
240+
if let Some(tw) = &trading_addr {
241+
println!("Trading wallet: {tw}");
225242
}
226243
println!("Signature type: {sig_type}");
227244
println!("Config path: {}", config_path.display());

0 commit comments

Comments
 (0)