use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[repr(u8)]
pub enum SignatureType {
Eoa = 0,
PolyProxy = 1,
PolyGnosisSafe = 2,
}
impl SignatureType {
pub fn as_u8(self) -> u8 {
self as u8
}
pub fn from_u8(v: u8) -> Option<Self> {
match v {
0 => Some(Self::Eoa),
1 => Some(Self::PolyProxy),
2 => Some(Self::PolyGnosisSafe),
_ => None,
}
}
}
impl Default for SignatureType {
fn default() -> Self {
Self::PolyGnosisSafe
}
}
impl std::fmt::Display for SignatureType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Eoa => write!(f, "EOA"),
Self::PolyProxy => write!(f, "POLY_PROXY"),
Self::PolyGnosisSafe => write!(f, "POLY_GNOSIS_SAFE"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuilderCredentials {
pub key: String,
pub secret: String,
pub passphrase: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ExchangeVersion {
V1,
V2,
}
impl Default for ExchangeVersion {
fn default() -> Self {
Self::V1
}
}
impl std::fmt::Display for ExchangeVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::V1 => write!(f, "v1"),
Self::V2 => write!(f, "v2"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FeeConfig {
pub fee_bps: u16,
pub affiliate: Option<String>,
pub affiliate_share_bps: Option<u16>,
}
#[derive(Debug, Clone)]
pub struct TraderConfig {
pub polynode_key: String,
pub db_path: String,
pub cosigner_url: String,
pub fallback_direct: bool,
pub default_signature_type: SignatureType,
pub rpc_url: String,
pub builder_credentials: Option<BuilderCredentials>,
pub exchange_version: ExchangeVersion,
pub fee_config: Option<FeeConfig>,
}
impl Default for TraderConfig {
fn default() -> Self {
Self {
polynode_key: String::new(),
db_path: "./polynode-trading.db".into(),
cosigner_url: super::constants::DEFAULT_COSIGNER.into(),
fallback_direct: true,
default_signature_type: SignatureType::PolyGnosisSafe,
rpc_url: super::constants::DEFAULT_RPC.into(),
builder_credentials: None,
exchange_version: ExchangeVersion::V1,
fee_config: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClobCredentials {
pub api_key: String,
pub api_secret: String,
pub api_passphrase: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct ReadyStatus {
pub wallet: String,
pub funder_address: String,
pub signature_type: SignatureType,
pub safe_deployed: bool,
pub approvals_set: bool,
pub credentials_stored: bool,
pub credentials: ClobCredentials,
pub actions: Vec<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct LinkResult {
pub wallet: String,
pub funder_address: String,
pub signature_type: SignatureType,
pub credentials: ClobCredentials,
}
#[derive(Debug, Clone, Serialize)]
pub struct WalletInfo {
pub wallet: String,
pub funder_address: String,
pub signature_type: SignatureType,
pub credentials: ClobCredentials,
pub created_at: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WalletExport {
pub wallet: String,
pub funder_address: String,
pub signature_type: SignatureType,
pub credentials: ClobCredentials,
pub safe_deployed: bool,
pub approvals_set: bool,
pub created_at: f64,
}
#[derive(Debug, Clone, Serialize)]
pub struct UsdcApprovals {
pub ctf_exchange: bool,
pub neg_risk_ctf_exchange: bool,
pub neg_risk_adapter: bool,
pub fee_escrow: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct CtfApprovals {
pub ctf_exchange: bool,
pub neg_risk_ctf_exchange: bool,
pub neg_risk_adapter: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct ApprovalStatus {
pub funder_address: String,
pub usdc: UsdcApprovals,
pub ctf: CtfApprovals,
pub all_approved: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct BalanceInfo {
pub funder_address: String,
pub usdc: String,
pub usdc_raw: String,
pub matic: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderSide {
#[serde(rename = "BUY")]
Buy,
#[serde(rename = "SELL")]
Sell,
}
impl std::fmt::Display for OrderSide {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Buy => write!(f, "BUY"),
Self::Sell => write!(f, "SELL"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderType {
GTC,
GTD,
FOK,
FAK,
}
impl Default for OrderType {
fn default() -> Self {
Self::GTC
}
}
impl std::fmt::Display for OrderType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::GTC => write!(f, "GTC"),
Self::GTD => write!(f, "GTD"),
Self::FOK => write!(f, "FOK"),
Self::FAK => write!(f, "FAK"),
}
}
}
#[derive(Debug, Clone)]
pub struct OrderParams {
pub token_id: String,
pub side: OrderSide,
pub price: f64,
pub size: f64,
pub order_type: OrderType,
pub expiration: Option<u64>,
pub post_only: bool,
pub fee_config: Option<FeeConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderResult {
pub success: bool,
pub order_id: Option<String>,
pub status: Option<String>,
pub error: Option<String>,
pub making_amount: Option<String>,
pub taking_amount: Option<String>,
pub fee_escrow_tx_hash: Option<String>,
pub fee_amount: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CancelResult {
pub canceled: Vec<String>,
pub not_canceled: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpenOrder {
pub id: String,
pub market: String,
#[serde(rename = "assetId")]
pub asset_id: String,
pub side: String,
pub price: String,
#[serde(rename = "originalSize")]
pub original_size: String,
#[serde(rename = "sizeMatched")]
pub size_matched: String,
pub status: String,
#[serde(rename = "createdAt")]
pub created_at: String,
#[serde(rename = "orderType")]
pub order_type: String,
}
#[derive(Debug, Clone)]
pub struct SplitParams {
pub condition_id: String,
pub amount: f64,
}
#[derive(Debug, Clone)]
pub struct MergeParams {
pub condition_id: String,
pub amount: f64,
}
#[derive(Debug, Clone)]
pub struct ConvertParams {
pub market_id: String,
pub outcome_indices: Vec<u32>,
pub amount: f64,
}
#[derive(Debug, Clone, Serialize)]
pub struct TransactionRequest {
pub to: String,
pub data: String,
pub value: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PositionResult {
pub success: bool,
pub tx_hash: Option<String>,
pub error: Option<String>,
}
#[derive(Debug, Clone)]
pub struct MarketMeta {
pub token_id: String,
pub tick_size: String,
pub fee_rate_bps: i32,
pub neg_risk: bool,
pub fetched_at: f64,
}
#[derive(Debug, Clone, Serialize)]
pub struct OrderHistoryRow {
pub id: i64,
pub wallet_address: String,
pub order_id: Option<String>,
pub token_id: String,
pub side: String,
pub price: f64,
pub size: f64,
pub order_type: String,
pub status: String,
pub error_msg: Option<String>,
pub response_json: Option<String>,
pub created_at: f64,
pub fee_amount_raw: Option<String>,
pub escrow_order_id: Option<String>,
pub fee_escrow_tx_hash: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct HistoryParams {
pub limit: Option<u32>,
pub offset: Option<u32>,
pub token_id: Option<String>,
pub side: Option<OrderSide>,
}
#[derive(Debug, Clone)]
pub struct StoredCredentials {
pub wallet_address: String,
pub funder_address: Option<String>,
pub api_key: String,
pub api_secret: String,
pub api_passphrase: String,
pub signature_type: SignatureType,
pub safe_deployed: bool,
pub approvals_set: bool,
pub created_at: f64,
pub updated_at: f64,
}
#[derive(Debug, Clone, Serialize)]
pub struct CosignerRequest {
pub method: String,
pub path: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub body: Option<String>,
pub headers: std::collections::HashMap<String, String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub builder_credentials: Option<BuilderCredentials>,
#[serde(skip_serializing_if = "Option::is_none")]
pub fee_auth: Option<FeeAuthRequest>,
#[serde(skip)]
pub clob_host: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct FeeAuthRequest {
pub escrow_order_id: String,
pub payer: String,
pub signer: String,
pub fee_amount: String,
pub deadline: u64,
pub nonce: u64,
pub signature: String,
pub affiliate: String,
pub affiliate_share_bps: u16,
}
#[derive(Debug, Clone, Serialize)]
pub struct Eip712Payload {
pub domain: serde_json::Value,
pub types: serde_json::Value,
pub primary_type: String,
pub message: serde_json::Value,
}