Skip to main content

kora_lib/
constant.rs

1use solana_program::pubkey;
2use solana_sdk::pubkey::Pubkey;
3
4pub const SOL_MINT: &str = "So11111111111111111111111111111111111111112";
5pub const NATIVE_SOL: &str = "11111111111111111111111111111111";
6pub const LAMPORTS_PER_SIGNATURE: u64 = 5000;
7pub const ESTIMATED_LAMPORTS_FOR_PAYMENT_INSTRUCTION: u64 = 50;
8pub const MIN_BALANCE_FOR_RENT_EXEMPTION: u64 = 2_039_280;
9pub const DEFAULT_INTEREST_MULTIPLIER: u128 = 100 * 24 * 60 * 60 / 10000 / (365 * 24 * 60 * 60);
10pub const MAX_TRANSACTION_SIZE: usize = 1232;
11
12// HTTP Headers
13pub const X_RECAPTCHA_TOKEN: &str = "x-recaptcha-token";
14pub const X_API_KEY: &str = "x-api-key";
15pub const X_HMAC_SIGNATURE: &str = "x-hmac-signature";
16pub const X_TIMESTAMP: &str = "x-timestamp";
17pub const DEFAULT_MAX_TIMESTAMP_AGE: i64 = 300;
18pub const MIN_RECAPTCHA_SCORE: f64 = 0.0;
19pub const MAX_RECAPTCHA_SCORE: f64 = 1.0;
20pub const DEFAULT_RECAPTCHA_SCORE_THRESHOLD: f64 = 0.5;
21pub const DEFAULT_PROTECTED_METHODS: &[&str] =
22    &["signTransaction", "signAndSendTransaction", "signBundle", "signAndSendBundle"];
23
24// External Services
25pub const JUPITER_API_URL: &str = "https://api.jup.ag";
26pub const RECAPTCHA_VERIFY_URL: &str = "https://www.google.com/recaptcha/api/siteverify";
27pub const RECAPTCHA_TIMEOUT_SECS: u64 = 5;
28
29// Lighthouse Program ID
30pub const LIGHTHOUSE_PROGRAM_ID: Pubkey = pubkey!("L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95");
31
32// Metrics
33pub const DEFAULT_METRICS_ENDPOINT: &str = "/metrics";
34pub const DEFAULT_METRICS_PORT: u16 = 8080;
35pub const DEFAULT_METRICS_SCRAPE_INTERVAL: u64 = 60;
36
37// Cache
38pub const DEFAULT_CACHE_DEFAULT_TTL: u64 = 300; // 5 minutes
39pub const DEFAULT_CACHE_ACCOUNT_TTL: u64 = 60; // 1 minute for account data
40pub const DEFAULT_FEE_PAYER_BALANCE_METRICS_EXPIRY_SECONDS: u64 = 30; // 30 seconds
41
42pub const DEFAULT_USAGE_LIMIT_MAX_TRANSACTIONS: u64 = 0; // 0 = unlimited
43pub const DEFAULT_USAGE_LIMIT_FALLBACK_IF_UNAVAILABLE: bool = false;
44
45// Request body size limit
46pub const DEFAULT_MAX_REQUEST_BODY_SIZE: usize = 2 * 1024 * 1024; // 2 MB
47
48// Account Indexes within instructions
49// Instruction indexes for the instructions that we support to parse from the transaction
50pub mod instruction_indexes {
51    pub mod system_create_account {
52        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 1;
53        pub const PAYER_INDEX: usize = 0;
54    }
55
56    pub mod system_transfer {
57        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
58        pub const SENDER_INDEX: usize = 0;
59        pub const RECEIVER_INDEX: usize = 1;
60    }
61
62    pub mod system_transfer_with_seed {
63        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
64        pub const SENDER_INDEX: usize = 1;
65        pub const RECEIVER_INDEX: usize = 2;
66    }
67
68    pub mod system_withdraw_nonce_account {
69        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 5;
70        pub const NONCE_AUTHORITY_INDEX: usize = 4;
71        pub const RECIPIENT_INDEX: usize = 1;
72    }
73
74    pub mod system_assign {
75        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 1;
76        pub const AUTHORITY_INDEX: usize = 0;
77    }
78
79    pub mod system_assign_with_seed {
80        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
81        pub const AUTHORITY_INDEX: usize = 1;
82    }
83
84    pub mod system_allocate {
85        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 1;
86        pub const ACCOUNT_INDEX: usize = 0;
87    }
88
89    pub mod system_allocate_with_seed {
90        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
91        pub const ACCOUNT_INDEX: usize = 1;
92    }
93
94    pub mod system_initialize_nonce_account {
95        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
96        pub const NONCE_ACCOUNT_INDEX: usize = 0;
97        // Authority is in instruction data, not accounts
98    }
99
100    pub mod system_advance_nonce_account {
101        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
102        pub const NONCE_ACCOUNT_INDEX: usize = 0;
103        pub const NONCE_AUTHORITY_INDEX: usize = 2;
104    }
105
106    pub mod system_authorize_nonce_account {
107        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
108        pub const NONCE_ACCOUNT_INDEX: usize = 0;
109        pub const NONCE_AUTHORITY_INDEX: usize = 1;
110    }
111
112    // Note: system_upgrade_nonce_account not included - no authority parameter, cannot validate
113
114    pub mod spl_token_transfer {
115        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
116        pub const OWNER_INDEX: usize = 2;
117        pub const SOURCE_ADDRESS_INDEX: usize = 0;
118        pub const DESTINATION_ADDRESS_INDEX: usize = 1;
119    }
120
121    pub mod spl_token_transfer_checked {
122        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 4;
123        pub const OWNER_INDEX: usize = 3;
124        pub const MINT_INDEX: usize = 1;
125        pub const SOURCE_ADDRESS_INDEX: usize = 0;
126        pub const DESTINATION_ADDRESS_INDEX: usize = 2;
127    }
128
129    pub mod spl_token_burn {
130        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
131        pub const OWNER_INDEX: usize = 2;
132    }
133
134    pub mod spl_token_close_account {
135        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
136        pub const OWNER_INDEX: usize = 2;
137    }
138
139    pub mod spl_token_approve {
140        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
141        pub const OWNER_INDEX: usize = 2;
142    }
143
144    pub mod spl_token_approve_checked {
145        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 4;
146        pub const OWNER_INDEX: usize = 3;
147    }
148
149    pub mod spl_token_revoke {
150        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
151        pub const OWNER_INDEX: usize = 1;
152    }
153
154    pub mod spl_token_set_authority {
155        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
156        pub const CURRENT_AUTHORITY_INDEX: usize = 1;
157    }
158
159    pub mod spl_token_mint_to {
160        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
161        pub const MINT_AUTHORITY_INDEX: usize = 2;
162    }
163
164    pub mod spl_token_mint_to_checked {
165        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
166        pub const MINT_AUTHORITY_INDEX: usize = 2;
167    }
168
169    pub mod spl_token_initialize_mint {
170        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
171        // Authority is in instruction data, not accounts
172    }
173
174    pub mod spl_token_initialize_mint2 {
175        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 1;
176        // Authority is in instruction data, not accounts
177    }
178
179    pub mod spl_token_initialize_account {
180        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 4;
181        // Owner is in account data at index 2
182        pub const OWNER_INDEX: usize = 2;
183    }
184
185    pub mod spl_token_initialize_account2 {
186        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
187        // Owner is in instruction data, not accounts
188    }
189
190    pub mod spl_token_initialize_account3 {
191        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2;
192        // Owner is in instruction data, not accounts
193    }
194
195    pub mod spl_token_initialize_multisig {
196        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 2; // Minimum
197                                                          // Signers are accounts from index 2 onwards (after multisig account and rent sysvar)
198    }
199
200    pub mod spl_token_initialize_multisig2 {
201        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 1; // Minimum
202                                                          // Signers are accounts from index 1 onwards (after multisig account)
203    }
204
205    pub mod spl_token_freeze_account {
206        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
207        pub const FREEZE_AUTHORITY_INDEX: usize = 2;
208    }
209
210    pub mod spl_token_thaw_account {
211        pub const REQUIRED_NUMBER_OF_ACCOUNTS: usize = 3;
212        pub const FREEZE_AUTHORITY_INDEX: usize = 2;
213    }
214
215    // ATA instruction indexes
216    pub mod ata_instruction_indexes {
217        pub const ATA_ADDRESS_INDEX: usize = 1;
218        pub const WALLET_OWNER_INDEX: usize = 2;
219        pub const MINT_INDEX: usize = 3;
220        pub const MIN_ACCOUNTS: usize = 6;
221    }
222
223    pub mod spl_transfer_instruction_indexes {
224        pub const DESTINATION_INDEX: usize = 1;
225        pub const MIN_ACCOUNTS: usize = 3;
226    }
227}