Skip to content
Merged
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
16 changes: 10 additions & 6 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use polymarket_client_sdk::{POLYGON, clob};

use crate::config;

pub const RPC_URL: &str = "https://polygon.drpc.org";
const DEFAULT_RPC_URL: &str = "https://polygon.drpc.org";

fn rpc_url() -> String {
std::env::var("POLYMARKET_RPC_URL").unwrap_or_else(|_| DEFAULT_RPC_URL.to_string())
}

fn parse_signature_type(s: &str) -> SignatureType {
match s {
Expand All @@ -22,7 +26,7 @@ fn parse_signature_type(s: &str) -> SignatureType {
pub fn resolve_signer(
private_key: Option<&str>,
) -> Result<impl polymarket_client_sdk::auth::Signer> {
let (key, _) = config::resolve_key(private_key);
let (key, _) = config::resolve_key(private_key)?;
let key = key.ok_or_else(|| anyhow::anyhow!("{}", config::NO_WALLET_MSG))?;
LocalSigner::from_str(&key)
.context("Invalid private key")
Expand All @@ -41,7 +45,7 @@ pub async fn authenticate_with_signer(
signer: &(impl polymarket_client_sdk::auth::Signer + Sync),
signature_type_flag: Option<&str>,
) -> Result<clob::Client<Authenticated<Normal>>> {
let sig_type = parse_signature_type(&config::resolve_signature_type(signature_type_flag));
let sig_type = parse_signature_type(&config::resolve_signature_type(signature_type_flag)?);

clob::Client::default()
.authentication_builder(signer)
Expand All @@ -53,22 +57,22 @@ pub async fn authenticate_with_signer(

pub async fn create_readonly_provider() -> Result<impl alloy::providers::Provider + Clone> {
ProviderBuilder::new()
.connect(RPC_URL)
.connect(&rpc_url())
.await
.context("Failed to connect to Polygon RPC")
}

pub async fn create_provider(
private_key: Option<&str>,
) -> Result<impl alloy::providers::Provider + Clone> {
let (key, _) = config::resolve_key(private_key);
let (key, _) = config::resolve_key(private_key)?;
let key = key.ok_or_else(|| anyhow::anyhow!("{}", config::NO_WALLET_MSG))?;
let signer = LocalSigner::from_str(&key)
.context("Invalid private key")?
.with_chain_id(Some(POLYGON));
ProviderBuilder::new()
.wallet(signer)
.connect(RPC_URL)
.connect(&rpc_url())
.await
.context("Failed to connect to Polygon RPC with wallet")
}
Expand Down
9 changes: 5 additions & 4 deletions src/commands/approve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::auth;
use crate::output::OutputFormat;
use crate::output::approve::{ApprovalStatus, print_approval_status, print_tx_result};

/// Polygon USDC (same address as `USDC_ADDRESS_STR`; `address!` requires a literal).
const USDC_ADDRESS: Address = address!("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174");

sol! {
Expand Down Expand Up @@ -39,7 +40,7 @@ pub enum ApproveCommand {
/// Check current contract approvals for a wallet
Check {
/// Wallet address to check (defaults to configured wallet)
address: Option<String>,
address: Option<Address>,
},
/// Approve all required contracts for trading (sends on-chain transactions)
Set,
Expand Down Expand Up @@ -82,18 +83,18 @@ pub async fn execute(
private_key: Option<&str>,
) -> Result<()> {
match args.command {
ApproveCommand::Check { address } => check(address.as_deref(), private_key, output).await,
ApproveCommand::Check { address } => check(address, private_key, output).await,
ApproveCommand::Set => set(private_key, output).await,
}
}

async fn check(
address_arg: Option<&str>,
address_arg: Option<Address>,
private_key: Option<&str>,
output: OutputFormat,
) -> Result<()> {
let owner: Address = if let Some(addr) = address_arg {
super::parse_address(addr)?
addr
} else {
let signer = auth::resolve_signer(private_key)?;
polymarket_client_sdk::auth::Signer::address(&signer)
Expand Down
12 changes: 5 additions & 7 deletions src/commands/bridge.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::parse_address;
use crate::output::OutputFormat;
use crate::output::bridge::{print_deposit, print_status, print_supported_assets};
use anyhow::Result;
use clap::{Args, Subcommand};
use polymarket_client_sdk::bridge::{
self,
types::{DepositRequest, StatusRequest},
};

use crate::output::OutputFormat;
use crate::output::bridge::{print_deposit, print_status, print_supported_assets};

#[derive(Args)]
pub struct BridgeArgs {
#[command(subcommand)]
Expand All @@ -19,7 +19,7 @@ pub enum BridgeCommand {
/// Get deposit addresses for a wallet (EVM, Solana, Bitcoin)
Deposit {
/// Polymarket wallet address (0x...)
address: String,
address: polymarket_client_sdk::types::Address,
},

/// List supported chains and tokens for deposits
Expand All @@ -39,9 +39,7 @@ pub async fn execute(
) -> Result<()> {
match args.command {
BridgeCommand::Deposit { address } => {
let request = DepositRequest::builder()
.address(parse_address(&address)?)
.build();
let request = DepositRequest::builder().address(address).build();

let response = client.deposit(&request).await?;
print_deposit(&response, &output)?;
Expand Down
Loading
Loading