polymarket_client_sdk/
lib.rs1#![cfg_attr(doc, doc = include_str!("../README.md"))]
2
3pub mod auth;
4pub mod clob;
5pub mod error;
6#[cfg(feature = "gamma")]
7pub mod gamma;
8
9use alloy::primitives::{Address, ChainId, address};
10use phf::phf_map;
11
12pub type Result<T> = std::result::Result<T, error::Error>;
13
14pub const POLYGON: ChainId = 137;
16
17pub const AMOY: ChainId = 80002;
19
20pub const PRIVATE_KEY_VAR: &str = "POLYMARKET_PRIVATE_KEY";
21
22pub(crate) type Timestamp = i64;
24
25static CONFIG: phf::Map<ChainId, ContractConfig> = phf_map! {
26 137_u64 => ContractConfig {
27 exchange: address!("0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E"),
28 collateral: address!("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"),
29 conditional_tokens: address!("0x4D97DCd97eC945f40cF65F87097ACe5EA0476045")
30 },
31 80002_u64 => ContractConfig {
32 exchange: address!("0xdFE02Eb6733538f8Ea35D585af8DE5958AD99E40"),
33 collateral: address!("0x9c4e1703476e875070ee25b56a58b008cfb8fa78"),
34 conditional_tokens: address!("0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB"),
35 },
36};
37
38static NEG_RISK_CONFIG: phf::Map<ChainId, ContractConfig> = phf_map! {
39 137_u64 => ContractConfig {
40 exchange: address!("0xC5d563A36AE78145C45a50134d48A1215220f80a"),
41 collateral: address!("0x2791bca1f2de4661ed88a30c99a7a9449aa84174"),
42 conditional_tokens: address!("0x4D97DCd97eC945f40cF65F87097ACe5EA0476045")
43 },
44 80002_u64 => ContractConfig {
45 exchange: address!("0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296"),
46 collateral: address!("0x9c4e1703476e875070ee25b56a58b008cfb8fa78"),
47 conditional_tokens: address!("0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB"),
48 },
49};
50
51#[non_exhaustive]
53#[derive(Debug)]
54pub struct ContractConfig {
55 pub exchange: Address,
56 pub collateral: Address,
57 pub conditional_tokens: Address,
58}
59
60#[must_use]
62pub fn contract_config(chain_id: ChainId, is_neg_risk: bool) -> Option<&'static ContractConfig> {
63 if is_neg_risk {
64 NEG_RISK_CONFIG.get(&chain_id)
65 } else {
66 CONFIG.get(&chain_id)
67 }
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73
74 #[test]
75 fn config_contains_80002() {
76 let cfg = contract_config(AMOY, false).expect("missing config");
77 assert_eq!(
78 cfg.exchange,
79 address!("0xdFE02Eb6733538f8Ea35D585af8DE5958AD99E40")
80 );
81 }
82
83 #[test]
84 fn config_contains_80002_neg() {
85 let cfg = contract_config(AMOY, true).expect("missing config");
86 assert_eq!(
87 cfg.exchange,
88 address!("0xd91e80cf2e7be2e162c6513ced06f1dd0da35296")
89 );
90 }
91}