mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-08-18 06:58:08 +00:00
fix: support V2 proxy wallet funders
This commit is contained in:
@@ -13,6 +13,8 @@ pub struct TestConfig {
|
||||
pub api_key: Option<String>,
|
||||
pub api_secret: Option<String>,
|
||||
pub api_passphrase: Option<String>,
|
||||
pub signature_type: Option<u8>,
|
||||
pub funder: Option<String>,
|
||||
pub test_timeout: Duration,
|
||||
}
|
||||
|
||||
@@ -33,6 +35,12 @@ impl Default for TestConfig {
|
||||
api_passphrase: env::var("POLYMARKET_API_PASSPHRASE")
|
||||
.or_else(|_| env::var("POLYMARKET_PASSPHRASE"))
|
||||
.ok(),
|
||||
signature_type: env::var("POLYMARKET_SIGNATURE_TYPE")
|
||||
.ok()
|
||||
.and_then(|v| v.parse::<u8>().ok()),
|
||||
funder: env::var("POLYMARKET_FUNDER")
|
||||
.or_else(|_| env::var("POLYMARKET_FUNDER_ADDRESS"))
|
||||
.ok(),
|
||||
test_timeout: Duration::from_secs(30),
|
||||
}
|
||||
}
|
||||
@@ -73,6 +81,8 @@ impl TestConfig {
|
||||
base_url: self.host.clone(),
|
||||
chain: self.chain,
|
||||
private_key: Some(private_key.clone()),
|
||||
signature_type: self.signature_type,
|
||||
funder: self.funder.clone(),
|
||||
..ClientConfig::default()
|
||||
})
|
||||
}
|
||||
@@ -84,6 +94,8 @@ impl TestConfig {
|
||||
println!(" Chain ID: {}", self.chain);
|
||||
println!(" Has Auth: {}", self.has_auth());
|
||||
println!(" Has API Creds: {}", self.has_api_creds());
|
||||
println!(" Signature Type: {:?}", self.signature_type);
|
||||
println!(" Has Funder Override: {}", self.funder.is_some());
|
||||
println!(" Timeout: {:?}", self.test_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
+93
-25
@@ -25,11 +25,25 @@ fn load_env_vars() -> (String, Option<String>, Option<String>, Option<String>) {
|
||||
(private_key, api_key, api_secret, api_passphrase)
|
||||
}
|
||||
|
||||
fn env_signature_type() -> Option<u8> {
|
||||
env::var("POLYMARKET_SIGNATURE_TYPE")
|
||||
.ok()
|
||||
.and_then(|value| value.parse::<u8>().ok())
|
||||
}
|
||||
|
||||
fn env_funder() -> Option<String> {
|
||||
env::var("POLYMARKET_FUNDER")
|
||||
.or_else(|_| env::var("POLYMARKET_FUNDER_ADDRESS"))
|
||||
.ok()
|
||||
}
|
||||
|
||||
fn bootstrap_client(private_key: &str) -> ClobClient {
|
||||
ClobClient::from_config(ClientConfig {
|
||||
base_url: HOST.to_string(),
|
||||
chain: CHAIN_ID,
|
||||
private_key: Some(private_key.to_string()),
|
||||
signature_type: env_signature_type(),
|
||||
funder: env_funder(),
|
||||
..ClientConfig::default()
|
||||
})
|
||||
.expect("failed to build bootstrap client")
|
||||
@@ -44,6 +58,8 @@ fn authenticated_client(
|
||||
chain: CHAIN_ID,
|
||||
private_key: Some(private_key),
|
||||
api_credentials: Some(api_credentials),
|
||||
signature_type: env_signature_type(),
|
||||
funder: env_funder(),
|
||||
..ClientConfig::default()
|
||||
})
|
||||
.expect("failed to build authenticated client")
|
||||
@@ -96,39 +112,48 @@ async fn test_real_api_authenticated_order_flow() {
|
||||
.await
|
||||
.expect("Failed to get markets");
|
||||
|
||||
let active_market = markets
|
||||
.data
|
||||
.iter()
|
||||
.find(|m| m.active && !m.closed)
|
||||
.expect("No active markets found");
|
||||
let mut selected_token = None;
|
||||
let mut selected_midpoint = None;
|
||||
for market in markets.data.iter().filter(|m| m.active && !m.closed) {
|
||||
for token in &market.tokens {
|
||||
let midpoint = match client.get_midpoint(&token.token_id).await {
|
||||
Ok(midpoint) => midpoint.mid,
|
||||
Err(_) => continue,
|
||||
};
|
||||
if midpoint > dec!(0.05) {
|
||||
selected_token = Some(token.token_id.clone());
|
||||
selected_midpoint = Some(midpoint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if selected_token.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let token_id = &active_market.tokens[0].token_id;
|
||||
let token_id = selected_token.expect("No active token with midpoint safely above 0.01 found");
|
||||
let midpoint = selected_midpoint.expect("midpoint should be selected with token");
|
||||
println!("PASS: Found active token: {}", token_id);
|
||||
println!("PASS: Current midpoint: {}", midpoint);
|
||||
|
||||
// Step 3: Get current price to place a reasonable order
|
||||
println!("Step 3: Getting current market price...");
|
||||
let midpoint = client
|
||||
.get_midpoint(token_id)
|
||||
// Step 4: Create and post a tiny non-marketable BUY order.
|
||||
// A BUY at 0.01 validates pUSD balance/allowance without requiring outcome-token inventory.
|
||||
let side = Side::BUY;
|
||||
let order_price = dec!(0.01);
|
||||
let order_book = client
|
||||
.get_order_book(&token_id)
|
||||
.await
|
||||
.expect("Failed to get midpoint");
|
||||
println!("PASS: Current midpoint: {}", midpoint.mid);
|
||||
|
||||
// Step 4: Create and post a small order well away from market price (so it won't fill immediately).
|
||||
// IMPORTANT: choose side consistently with the price so we don't accidentally create a marketable order.
|
||||
let (side, order_price) = if midpoint.mid > dec!(0.5) {
|
||||
(Side::BUY, dec!(0.01)) // Very low buy price, won't fill
|
||||
} else {
|
||||
(Side::SELL, dec!(0.99)) // Very high sell price, won't fill
|
||||
};
|
||||
.expect("Failed to get selected order book");
|
||||
let order_size = order_book.min_order_size.max(dec!(5));
|
||||
|
||||
println!(
|
||||
"Step 4: Posting {:?} order at price {}...",
|
||||
side, order_price
|
||||
"Step 4: Posting {:?} order at price {} and size {}...",
|
||||
side, order_price, order_size
|
||||
);
|
||||
let order_args = OrderArgs {
|
||||
token_id: token_id.clone(),
|
||||
token_id,
|
||||
price: order_price,
|
||||
size: dec!(1.0), // Small size (auth is the thing we're testing here)
|
||||
size: order_size,
|
||||
side,
|
||||
expiration: None,
|
||||
builder_code: None,
|
||||
@@ -255,6 +280,50 @@ async fn test_real_api_get_balance_allowance() {
|
||||
|
||||
println!("Testing get_balance_allowance...");
|
||||
|
||||
use polyfill_rs::types::{AssetType, BalanceAllowanceParams};
|
||||
let collateral_update_params = BalanceAllowanceParams {
|
||||
asset_type: Some(AssetType::COLLATERAL),
|
||||
token_id: None,
|
||||
signature_type: None,
|
||||
};
|
||||
let collateral_update = client
|
||||
.update_balance_allowance(Some(collateral_update_params))
|
||||
.await;
|
||||
match collateral_update {
|
||||
Ok(update) => {
|
||||
println!("PASS: Successfully requested collateral balance/allowance update");
|
||||
println!(" Collateral update: {:?}", update);
|
||||
},
|
||||
Err(e) => {
|
||||
let err_str = format!("{:?}", e);
|
||||
if err_str.contains("401") {
|
||||
panic!("FAIL: 401 Unauthorized - authentication failed!");
|
||||
}
|
||||
println!("WARNING: Collateral balance update failed: {:?}", e);
|
||||
},
|
||||
}
|
||||
|
||||
let collateral_params = BalanceAllowanceParams {
|
||||
asset_type: Some(AssetType::COLLATERAL),
|
||||
token_id: None,
|
||||
signature_type: None,
|
||||
};
|
||||
let collateral_result = client.get_balance_allowance(Some(collateral_params)).await;
|
||||
|
||||
match collateral_result {
|
||||
Ok(balance) => {
|
||||
println!("PASS: Successfully fetched collateral balance/allowance");
|
||||
println!(" Collateral: {:?}", balance);
|
||||
},
|
||||
Err(e) => {
|
||||
let err_str = format!("{:?}", e);
|
||||
if err_str.contains("401") {
|
||||
panic!("FAIL: 401 Unauthorized - authentication failed!");
|
||||
}
|
||||
println!("WARNING: Collateral balance check failed: {:?}", e);
|
||||
},
|
||||
}
|
||||
|
||||
// Get a valid token_id first
|
||||
let markets = client
|
||||
.get_sampling_markets(None)
|
||||
@@ -262,7 +331,6 @@ async fn test_real_api_get_balance_allowance() {
|
||||
.expect("Failed to get markets");
|
||||
let token_id = &markets.data[0].tokens[0].token_id;
|
||||
|
||||
use polyfill_rs::types::{AssetType, BalanceAllowanceParams};
|
||||
let params = BalanceAllowanceParams {
|
||||
asset_type: Some(AssetType::CONDITIONAL),
|
||||
token_id: Some(token_id.clone()),
|
||||
|
||||
Reference in New Issue
Block a user