Skip to main content

predict_sdk/
constants.rs

1use crate::types::ChainId;
2use once_cell::sync::Lazy;
3use std::collections::HashMap;
4
5/// Maximum salt value for order entropy
6pub const MAX_SALT: u64 = 2_147_483_648;
7
8/// Five minutes in seconds
9pub const FIVE_MINUTES_SECONDS: u64 = 60 * 5;
10
11/// Protocol name for EIP-712 domain
12pub const PROTOCOL_NAME: &str = "predict.fun CTF Exchange";
13
14/// Protocol version for EIP-712 domain
15pub const PROTOCOL_VERSION: &str = "1";
16
17/// Contract addresses for BNB Mainnet
18pub mod mainnet {
19    pub const YIELD_BEARING_CTF_EXCHANGE: &str = "0x6bEb5a40C032AFc305961162d8204CDA16DECFa5";
20    pub const YIELD_BEARING_NEG_RISK_CTF_EXCHANGE: &str = "0x8A289d458f5a134bA40015085A8F50Ffb681B41d";
21    pub const YIELD_BEARING_NEG_RISK_ADAPTER: &str = "0x41dCe1A4B8FB5e6327701750aF6231B7CD0B2A40";
22    pub const YIELD_BEARING_CONDITIONAL_TOKENS: &str = "0x9400F8Ad57e9e0F352345935d6D3175975eb1d9F";
23    pub const YIELD_BEARING_NEG_RISK_CONDITIONAL_TOKENS: &str = "0xF64b0b318AAf83BD9071110af24D24445719A07F";
24
25    pub const CTF_EXCHANGE: &str = "0x8BC070BEdAB741406F4B1Eb65A72bee27894B689";
26    pub const NEG_RISK_CTF_EXCHANGE: &str = "0x365fb81bd4A24D6303cd2F19c349dE6894D8d58A";
27    pub const NEG_RISK_ADAPTER: &str = "0xc3Cf7c252f65E0d8D88537dF96569AE94a7F1A6E";
28    pub const CONDITIONAL_TOKENS: &str = "0x22DA1810B194ca018378464a58f6Ac2B10C9d244";
29    pub const NEG_RISK_CONDITIONAL_TOKENS: &str = "0x22DA1810B194ca018378464a58f6Ac2B10C9d244";
30
31    pub const USDT: &str = "0x55d398326f99059fF775485246999027B3197955";
32    pub const KERNEL: &str = "0xBAC849bB641841b44E965fB01A4Bf5F074f84b4D";
33    pub const ECDSA_VALIDATOR: &str = "0x845ADb2C711129d4f3966735eD98a9F09fC4cE57";
34}
35
36/// Contract addresses for BNB Testnet
37pub mod testnet {
38    pub const YIELD_BEARING_CTF_EXCHANGE: &str = "0x8a6B4Fa700A1e310b106E7a48bAFa29111f66e89";
39    pub const YIELD_BEARING_NEG_RISK_CTF_EXCHANGE: &str = "0x95D5113bc50eD201e319101bbca3e0E250662fCC";
40    pub const YIELD_BEARING_NEG_RISK_ADAPTER: &str = "0xb74aea04bdeBE912Aa425bC9173F9668e6f11F99";
41    pub const YIELD_BEARING_CONDITIONAL_TOKENS: &str = "0x38BF1cbD66d174bb5F3037d7068E708861D68D7f";
42    pub const YIELD_BEARING_NEG_RISK_CONDITIONAL_TOKENS: &str = "0x26e865CbaAe99b62fbF9D18B55c25B5E079A93D5";
43
44    pub const CTF_EXCHANGE: &str = "0x2A6413639BD3d73a20ed8C95F634Ce198ABbd2d7";
45    pub const NEG_RISK_CTF_EXCHANGE: &str = "0xd690b2bd441bE36431F6F6639D7Ad351e7B29680";
46    pub const NEG_RISK_ADAPTER: &str = "0x285c1B939380B130D7EBd09467b93faD4BA623Ed";
47    pub const CONDITIONAL_TOKENS: &str = "0x2827AAef52D71910E8FBad2FfeBC1B6C2DA37743";
48    pub const NEG_RISK_CONDITIONAL_TOKENS: &str = "0x2827AAef52D71910E8FBad2FfeBC1B6C2DA37743";
49
50    pub const USDT: &str = "0xB32171ecD878607FFc4F8FC0bCcE6852BB3149E0";
51    pub const KERNEL: &str = "0xBAC849bB641841b44E965fB01A4Bf5F074f84b4D";
52    pub const ECDSA_VALIDATOR: &str = "0x845ADb2C711129d4f3966735eD98a9F09fC4cE57";
53}
54
55/// All contract addresses organized by contract type and chain
56#[derive(Debug, Clone)]
57pub struct Addresses {
58    pub yield_bearing_ctf_exchange: &'static str,
59    pub yield_bearing_neg_risk_ctf_exchange: &'static str,
60    pub yield_bearing_neg_risk_adapter: &'static str,
61    pub yield_bearing_conditional_tokens: &'static str,
62    pub yield_bearing_neg_risk_conditional_tokens: &'static str,
63
64    pub ctf_exchange: &'static str,
65    pub neg_risk_ctf_exchange: &'static str,
66    pub neg_risk_adapter: &'static str,
67    pub conditional_tokens: &'static str,
68    pub neg_risk_conditional_tokens: &'static str,
69
70    pub usdt: &'static str,
71    pub kernel: &'static str,
72    pub ecdsa_validator: &'static str,
73}
74
75impl Addresses {
76    pub fn for_chain(chain_id: ChainId) -> Self {
77        match chain_id {
78            ChainId::BnbMainnet => Self {
79                yield_bearing_ctf_exchange: mainnet::YIELD_BEARING_CTF_EXCHANGE,
80                yield_bearing_neg_risk_ctf_exchange: mainnet::YIELD_BEARING_NEG_RISK_CTF_EXCHANGE,
81                yield_bearing_neg_risk_adapter: mainnet::YIELD_BEARING_NEG_RISK_ADAPTER,
82                yield_bearing_conditional_tokens: mainnet::YIELD_BEARING_CONDITIONAL_TOKENS,
83                yield_bearing_neg_risk_conditional_tokens: mainnet::YIELD_BEARING_NEG_RISK_CONDITIONAL_TOKENS,
84
85                ctf_exchange: mainnet::CTF_EXCHANGE,
86                neg_risk_ctf_exchange: mainnet::NEG_RISK_CTF_EXCHANGE,
87                neg_risk_adapter: mainnet::NEG_RISK_ADAPTER,
88                conditional_tokens: mainnet::CONDITIONAL_TOKENS,
89                neg_risk_conditional_tokens: mainnet::NEG_RISK_CONDITIONAL_TOKENS,
90
91                usdt: mainnet::USDT,
92                kernel: mainnet::KERNEL,
93                ecdsa_validator: mainnet::ECDSA_VALIDATOR,
94            },
95            ChainId::BnbTestnet => Self {
96                yield_bearing_ctf_exchange: testnet::YIELD_BEARING_CTF_EXCHANGE,
97                yield_bearing_neg_risk_ctf_exchange: testnet::YIELD_BEARING_NEG_RISK_CTF_EXCHANGE,
98                yield_bearing_neg_risk_adapter: testnet::YIELD_BEARING_NEG_RISK_ADAPTER,
99                yield_bearing_conditional_tokens: testnet::YIELD_BEARING_CONDITIONAL_TOKENS,
100                yield_bearing_neg_risk_conditional_tokens: testnet::YIELD_BEARING_NEG_RISK_CONDITIONAL_TOKENS,
101
102                ctf_exchange: testnet::CTF_EXCHANGE,
103                neg_risk_ctf_exchange: testnet::NEG_RISK_CTF_EXCHANGE,
104                neg_risk_adapter: testnet::NEG_RISK_ADAPTER,
105                conditional_tokens: testnet::CONDITIONAL_TOKENS,
106                neg_risk_conditional_tokens: testnet::NEG_RISK_CONDITIONAL_TOKENS,
107
108                usdt: testnet::USDT,
109                kernel: testnet::KERNEL,
110                ecdsa_validator: testnet::ECDSA_VALIDATOR,
111            },
112        }
113    }
114
115    /// Get the CTF Exchange address based on market type
116    pub fn get_ctf_exchange(&self, is_yield_bearing: bool, is_neg_risk: bool) -> &'static str {
117        match (is_yield_bearing, is_neg_risk) {
118            (true, true) => self.yield_bearing_neg_risk_ctf_exchange,
119            (true, false) => self.yield_bearing_ctf_exchange,
120            (false, true) => self.neg_risk_ctf_exchange,
121            (false, false) => self.ctf_exchange,
122        }
123    }
124
125    /// Get the Conditional Tokens address based on market type
126    pub fn get_conditional_tokens(&self, is_yield_bearing: bool, is_neg_risk: bool) -> &'static str {
127        match (is_yield_bearing, is_neg_risk) {
128            (true, true) => self.yield_bearing_neg_risk_conditional_tokens,
129            (true, false) => self.yield_bearing_conditional_tokens,
130            (false, true) => self.neg_risk_conditional_tokens,
131            (false, false) => self.conditional_tokens,
132        }
133    }
134}
135
136/// RPC URLs by chain
137pub static RPC_URLS: Lazy<HashMap<ChainId, &'static str>> = Lazy::new(|| {
138    let mut map = HashMap::new();
139    map.insert(ChainId::BnbMainnet, "https://bsc-dataseed.bnbchain.org/");
140    map.insert(ChainId::BnbTestnet, "https://bsc-testnet-dataseed.bnbchain.org/");
141    map
142});
143
144/// EIP-712 Order structure definition
145pub const ORDER_STRUCTURE: &[(&str, &str)] = &[
146    ("salt", "uint256"),
147    ("maker", "address"),
148    ("signer", "address"),
149    ("taker", "address"),
150    ("tokenId", "uint256"),
151    ("makerAmount", "uint256"),
152    ("takerAmount", "uint256"),
153    ("expiration", "uint256"),
154    ("nonce", "uint256"),
155    ("feeRateBps", "uint256"),
156    ("side", "uint8"),
157    ("signatureType", "uint8"),
158];
159
160/// Zero address constant
161pub const ZERO_ADDRESS: &str = "0x0000000000000000000000000000000000000000";