@@ -5,11 +5,27 @@ use anyhow::{Context, Result, bail};
55use clap:: { Args , Subcommand } ;
66use polymarket_client_sdk:: auth:: LocalSigner ;
77use 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
1010use crate :: config;
1111use 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 ) ]
1430pub 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