1use anchor_lang::prelude::*;
7
8pub const POOL_SEED: &[u8] = b"pool";
12pub const POOL_VAULT_SEED: &[u8] = b"pool-vault";
14pub const LP_ENTRY_SEED: &[u8] = b"lp-entry";
16pub const LP_MINT_SEED: &[u8] = b"lp-mint";
18pub const INSURANCE_SEED: &[u8] = b"insurance";
20
21pub const CREDIT_LINE_SEED: &[u8] = b"credit-line";
23pub const CREDIT_VAULT_SEED: &[u8] = b"credit-vault";
25pub const TOLL_VAULT_SEED: &[u8] = b"toll-vault";
27pub const BORROWER_SEED: &[u8] = b"borrower";
29
30pub const POSITION_SEED: &[u8] = b"position";
32pub const COLLATERAL_VAULT_SEED: &[u8] = b"collateral-vault";
34pub const PT_CONFIG_SEED: &[u8] = b"pt-config";
36
37pub const POSITION_TRACKER_PROGRAM_ID: Pubkey =
41 solana_program::pubkey!("6uvr2JcP2iMQooG76RjpCtJLoJ4NuptGyRCiMKuDR1ws");
42pub const ESCROW_PROGRAM_ID: Pubkey =
44 solana_program::pubkey!("2WPb3wsyp4G6zFPx8sTYf3bTDyySxwpo1Ja8H6RCHXCZ");
45pub const CREDIT_LINE_PROGRAM_ID: Pubkey =
50 solana_program::pubkey!("68s4vuWUXAaEFF1EM1RUQpw7SFdYZSV3opvtDqoBCs56");
51pub const NV_USDC_VAULT_PROGRAM_ID: Pubkey =
53 solana_program::pubkey!("CN92hAtnZxbMxPdho8tugi9GDK86UpGwmnbEvk5yzAWC");
54pub const BURN_ENGINE_PROGRAM_ID: Pubkey =
56 solana_program::pubkey!("nFgJEQSrKEi7FdAKC6vz5HsQ6f9QjQLBuQcQqQy45id");
57pub const STAKING_MANAGER_PROGRAM_ID: Pubkey =
59 solana_program::pubkey!("HjxcKV51A7jxE2iqMCDY7EvWFL9XsheuM43DamWGabqb");
60pub const NETTING_ENGINE_PROGRAM_ID: Pubkey =
62 solana_program::pubkey!("68s4vuWUXAaEFF1EM1RUQpw7SFdYZSV3opvtDqoBCs56");
63pub const LIQUIDATION_VAULT_PROGRAM_ID: Pubkey =
65 solana_program::pubkey!("Cwma3FfMKhoLkgfrGYgErVPoFWEtHpx7DNc4wArpRHBz");
66pub const JIT_RISK_PROGRAM_ID: Pubkey =
71 solana_program::pubkey!("JDsM18uSZ1UJEP49XdKSjumdftpuZ8cJbpb8CkBaBiMc");
72pub const GATEWAY_AUCTION_PROGRAM_ID: Pubkey =
74 solana_program::pubkey!("HQ26VTfoBVmGFY1JsFp5HmMT3rjLNoLJH6zurm8TL9xR");
75pub const SOVEREIGN_NETTING_PROGRAM_ID: Pubkey =
80 solana_program::pubkey!("68s4vuWUXAaEFF1EM1RUQpw7SFdYZSV3opvtDqoBCs56");
81
82pub const USDC_MINT: Pubkey =
84 solana_program::pubkey!("Cx2bfKM7hcpnreSZxiDaN8q4Ca9i5ViCLxqRTs12JhS5");
85pub const NVSC_MINT: Pubkey =
87 solana_program::pubkey!("4BXiDT5o9J6aQdJNd36QE1L2YvQqedEKSP1wuQdSgJkg");
88pub const NVSCUSDC_MINT: Pubkey =
90 solana_program::pubkey!("2TmaUey4Hh2om1kFR77Vw1RDh8H69qcW6UAACVidJeVk");
91
92pub const BPS: u64 = 10_000;
96pub const BPS_U128: u128 = 10_000;
98pub const WAD: u128 = 1_000_000_000_000;
100pub const LP_NAV_SPLIT_BPS: u64 = 9_000;
102pub const TREASURY_SPLIT_BPS: u64 = 1_000;
104
105#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
109#[repr(u8)]
110pub enum LpTier {
111 #[default]
113 Retail = 0,
114 Accredited = 1,
116 Institutional = 2,
118}
119
120impl LpTier {
121 pub fn max_deposit_bps(self) -> u64 {
123 match self {
124 LpTier::Retail => 500,
125 LpTier::Accredited => 2_000,
126 LpTier::Institutional => 10_000,
127 }
128 }
129}
130
131#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
133#[repr(u8)]
134pub enum Side {
135 #[default]
136 Long = 0,
137 Short = 1,
138}
139
140#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)]
146pub struct CreditLine {
147 pub authority: Pubkey,
148 pub toll_recipient: Pubkey,
149 pub usdc_mint: Pubkey,
150 pub base_toll_bps: u64,
152 pub max_toll_bps: u64,
154 pub borrower_cap: u64,
156 pub global_outstanding_cap: u64,
158 pub total_outstanding: u64,
160 pub bump: u8,
161 pub credit_vault_bump: u8,
162 pub toll_vault_bump: u8,
163}
164
165impl CreditLine {
166 pub const SPACE: usize = 8 + 32 + 32 + 32 + 8 + 8 + 8 + 8 + 8 + 1 + 1 + 1;
167}
168
169#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)]
173pub struct Borrower {
174 pub owner: Pubkey,
175 pub authorized: bool,
177 pub credit_limit: u64,
179 pub outstanding: u64,
181 pub bump: u8,
182}
183
184impl Borrower {
185 pub const SPACE: usize = 8 + 32 + 1 + 8 + 8 + 1;
186}
187
188#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)]
192pub struct PoolConfig {
193 pub authority: Pubkey,
194 pub label: [u8; 32],
196 pub base_mint: Pubkey,
197 pub quote_mint: Pubkey,
198 pub kyc_required: bool,
200 pub kyc_merkle_root: [u8; 32],
202 pub fee_bps: u64,
204 pub insurance_cut_bps: u64,
206 pub total_shares: u64,
208 pub base_reserve: u64,
210 pub quote_reserve: u64,
212 pub lp_count: u64,
214 pub is_paused: bool,
216 pub bump: u8,
217 pub vault_bump: u8,
218 pub lp_mint_bump: u8,
219 pub insurance_bump: u8,
220}
221
222impl PoolConfig {
223 pub const SPACE: usize = 8
224 + 32 + 32 + 32 + 32 + 1 + 32 + 8 + 8 + 8 + 8 + 8 + 8 + 1 + 1 + 1 + 1 + 1; }
242
243#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)]
247pub struct LpEntry {
248 pub wallet: Pubkey,
249 pub kyc_hash: [u8; 32],
251 pub verified_at: i64,
253 pub expires_at: i64,
255 pub tier: LpTier,
257 pub shares: u64,
259 pub is_active: bool,
261 pub bump: u8,
262}
263
264impl LpEntry {
265 pub const SPACE: usize = 8
266 + 32 + 32 + 8 + 8 + 1 + 8 + 1 + 1; }
275
276#[derive(Debug, Clone, Copy, PartialEq, Eq)]
279pub struct TollResult {
280 pub toll_amount: u64,
282 pub rate_bps: u64,
284 pub utilization_bps: u64,
286 pub lp_share: u64,
288 pub treasury_share: u64,
290}
291
292#[cfg(test)]
293mod tests {
294 use super::*;
295
296 #[test]
297 fn lp_tier_max_deposit_bps() {
298 assert_eq!(LpTier::Retail.max_deposit_bps(), 500);
299 assert_eq!(LpTier::Accredited.max_deposit_bps(), 2_000);
300 assert_eq!(LpTier::Institutional.max_deposit_bps(), 10_000);
301 }
302
303 #[test]
304 fn credit_line_space_matches_constant() {
305 assert_eq!(
306 CreditLine::SPACE,
307 8 + 32 + 32 + 32 + 8 + 8 + 8 + 8 + 8 + 1 + 1 + 1
308 );
309 }
310
311 #[test]
312 fn borrower_space_matches_constant() {
313 assert_eq!(Borrower::SPACE, 8 + 32 + 1 + 8 + 8 + 1);
314 }
315
316 #[test]
317 fn pool_config_space_matches_constant() {
318 assert_eq!(
319 PoolConfig::SPACE,
320 8 + 32 + 32 + 32 + 32 + 1 + 32 + 8 + 8 + 8 + 8 + 8 + 8 + 1 + 1 + 1 + 1 + 1
321 );
322 }
323
324 #[test]
325 fn lp_entry_space_matches_constant() {
326 assert_eq!(LpEntry::SPACE, 8 + 32 + 32 + 8 + 8 + 1 + 8 + 1 + 1);
327 }
328
329 #[test]
330 fn actual_serialized_sizes_sans_discriminator() {
331 assert_eq!(PoolConfig::default().try_to_vec().unwrap().len(), 214);
332 assert_eq!(LpEntry::default().try_to_vec().unwrap().len(), 91);
333 assert_eq!(CreditLine::default().try_to_vec().unwrap().len(), 139);
334 assert_eq!(Borrower::default().try_to_vec().unwrap().len(), 50);
335 }
336}
337
338pub const CAPACITY_SEED: &[u8] = b"capacity";
342pub const CONGESTION_SEED: &[u8] = b"congestion";
344pub const CLIENT_SEED: &[u8] = b"client";
346pub const SLOT_LEDGER_SEED: &[u8] = b"slot-ledger";
348pub const TREASURY_SEED: &[u8] = b"treasury";
350pub const TREASURY_AUTH_SEED: &[u8] = b"treasury-auth";
352
353pub const CAPACITY_PROGRAM_ID: Pubkey =
355 anchor_lang::solana_program::pubkey!("JDsM18uSZ1UJEP49XdKSjumdftpuZ8cJbpb8CkBaBiMc");
356
357#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
359#[repr(u8)]
360pub enum ClientTier {
361 #[default]
362 TierOne = 0,
363 TierTwo = 1,
364}
365
366#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
368pub struct CapacityConfig {
369 pub authority: Pubkey,
370 pub guard_authority: Pubkey,
371 pub usdc_mint: Pubkey,
372 pub kyc_merkle_root: [u8; 32],
373 pub base_premium_bps: u64,
374 pub premium_cap_bps: u64,
375 pub congestion_multiplier_bps: u64,
376 pub min_premium_lamports: u64,
377 pub paused: bool,
378 pub bump: u8,
379}
380
381impl CapacityConfig {
382 pub const SPACE: usize = 8 + 32 + 32 + 32 + 32 + 8 + 8 + 8 + 8 + 1 + 1;
383}
384
385#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
387pub struct CongestionOracle {
388 pub load_ratio_bps: u64,
389 pub cu_consumed: u64,
390 pub cu_capacity: u64,
391 pub updated_slot: u64,
392 pub bump: u8,
393}
394
395impl CongestionOracle {
396 pub const SPACE: usize = 8 + 8 + 8 + 8 + 8 + 1;
397}
398
399#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
401pub struct ClientAccount {
402 pub operator: Pubkey,
403 pub authority: Pubkey,
404 pub tier: ClientTier,
405 pub premium_multiplier_bps: u64,
406 pub credit_limit: u64,
407 pub active_utilization: u64,
408 pub available_balance: u64,
409 pub margin_posted: u64,
410 pub frozen: bool,
411 pub bump: u8,
412}
413
414impl ClientAccount {
415 pub const SPACE: usize = 8 + 32 + 32 + 1 + 8 + 8 + 8 + 8 + 8 + 1 + 1;
416
417 pub fn capacity_budget(&self) -> u64 {
418 self.credit_limit
419 .saturating_add(self.margin_posted)
420 .saturating_sub(self.active_utilization)
421 }
422}
423
424#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
426pub struct SlotLedger {
427 pub client: Pubkey,
428 pub slot: u64,
429 pub capacity_granted: u64,
430 pub utilized: u64,
431 pub premium_paid: u64,
432 pub settled: bool,
433 pub bump: u8,
434}
435
436impl SlotLedger {
437 pub const SPACE: usize = 8 + 32 + 8 + 8 + 8 + 8 + 1 + 1;
438}
439
440pub const ASSET_REGISTRY_SEED: &[u8] = b"asset-registry";
444pub const ASSET_POOL_SEED: &[u8] = b"asset-pool";
446pub const ASSET_VAULT_SEED: &[u8] = b"asset-vault";
448pub const ASSET_FEE_VAULT_SEED: &[u8] = b"asset-fees";
450pub const ASSET_AUTHORITY_SEED: &[u8] = b"asset-authority";
452pub const ASSET_CREDIT_LINE_SEED: &[u8] = b"credit-line";
454pub const DESK_POSITION_SEED: &[u8] = b"desk-position";
456pub const ASSET_LP_MINT_SEED: &[u8] = b"asset-lp-mint";
458pub const ASSET_LP_POSITION_SEED: &[u8] = b"asset-lp-position";
460pub const WINDOW_SLOTS: u64 = 216_000;
462pub const GRACE_SLOTS: u64 = 18_000;
464pub const LATE_FEE_RATE_BPS: u64 = 50;
466pub const LATE_FEE_BASE: u64 = 10_000;
467
468pub const ASSET_ENGINE_PROGRAM_ID: Pubkey =
473 anchor_lang::solana_program::pubkey!("JDsM18uSZ1UJEP49XdKSjumdftpuZ8cJbpb8CkBaBiMc");
474
475pub const WSOL_MINT: Pubkey =
477 anchor_lang::solana_program::pubkey!("So11111111111111111111111111111111111111112");
478
479#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
482pub struct AssetEngineRegistry {
483 pub breaker_authority: Pubkey,
486 pub risk_committee_authority: Pubkey,
489 pub upgrade_authority: Pubkey,
492 pub wsol_mint: Pubkey,
493 pub usdc_mint: Pubkey,
494 pub nvsc_mint: Pubkey,
495 pub supported_count: u8,
496 pub paused: bool,
497 pub bump: u8,
498}
499
500impl AssetEngineRegistry {
501 pub const SPACE: usize = 8 + 32 * 3 + 32 * 3 + 3;
502}
503
504#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
506pub struct AssetPool {
507 pub mint: Pubkey,
508 pub pool_bump: u8,
509 pub vault: Pubkey,
510 pub fee_vault: Pubkey,
511 pub vault_authority: Pubkey,
512 pub decimals: u8,
513 pub supported: bool,
514 pub total_idle_capital: u64,
515 pub active_credit_utilization: u64,
516 pub base_premium_rate_bps: u16,
517 pub premium_cap_bps: u16,
518 pub min_premium_lamports: u64,
519 pub max_capacity: u64,
520 pub lp_mint: Pubkey,
522 pub total_lp_shares: u64,
523 pub lp_yield_split_bps: u16,
524}
525
526impl AssetPool {
527 pub const SPACE: usize =
528 8 + 32 + 1 + 32 + 32 + 32 + 1 + 1 + 8 + 8 + 2 + 2 + 8 + 8 + 32 + 8 + 2;
529}
530
531#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
533pub struct InstitutionalCreditLine {
534 pub institution: Pubkey,
535 pub authority: Pubkey,
536 pub total_credit_limit: u64,
537 pub active_utilization: u64,
538 pub kyc_merkle_root: [u8; 32],
540 pub window_start_slot: u64,
542 pub peak_active_utilization: u64,
544 pub accumulated_premiums: u64,
546 pub last_settlement_timestamp: i64,
548 pub frozen: bool,
549 pub bump: u8,
550}
551
552impl InstitutionalCreditLine {
553 pub const SPACE: usize = 8 + 32 + 32 + 8 + 8 + 32 + 8 + 8 + 8 + 8 + 1 + 1;
554}
555
556#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
558pub struct DeskPosition {
559 pub institution: Pubkey,
560 pub mint: Pubkey,
561 pub active_principal: u64,
563 pub accumulated_premiums: u64,
565 pub settled_invoices: u64,
567 pub bump: u8,
568}
569
570impl DeskPosition {
571 pub const SPACE: usize = 8 + 32 + 32 + 8 + 8 + 8 + 1;
572}
573
574pub const TRANCHES_SEED: &[u8] = b"tranches";
578pub const PROTECTED_VAULT_SEED: &[u8] = b"protected-vault";
580pub const INSTI_VAULT_SEED: &[u8] = b"insti-vault";
582pub const TRANCHE_POSITION_SEED: &[u8] = b"position";
584
585pub const TRANCHE_VAULT_PROGRAM_ID: Pubkey =
587 anchor_lang::solana_program::pubkey!("9Sk1zLo7uprmtrskoZQS6zf1KFSNv4uTCxMsbqGVMCMb");
588
589#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
591#[repr(u8)]
592pub enum Tranche {
593 #[default]
594 Protected = 0,
595 Institutional = 1,
596}
597
598#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
600pub struct TrancheVault {
601 pub tranche: Tranche,
602 pub nav_usdc: u64,
603 pub total_shares: u64,
604 pub last_accrual_ts: i64,
605 pub bump: u8,
606}
607
608impl TrancheVault {
609 pub const SPACE: usize = 8 + 1 + 8 + 8 + 8 + 1;
610}
611
612#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
614pub struct TranchePosition {
615 pub owner: Pubkey,
616 pub tranche: Tranche,
617 pub shares: u64,
618 pub bump: u8,
619}
620
621impl TranchePosition {
622 pub const SPACE: usize = 8 + 32 + 1 + 8 + 1;
623}
624
625#[cfg(test)]
626mod capacity_tests {
627 use super::*;
628
629 #[test]
630 fn capacity_client_space_matches_constant() {
631 assert_eq!(ClientAccount::SPACE, 8 + 32 + 32 + 1 + 8 + 8 + 8 + 8 + 8 + 1 + 1);
632 }
633
634 #[test]
635 fn capacity_budget_accounts_margin() {
636 let c = ClientAccount {
637 credit_limit: 500_000_000,
638 margin_posted: 100_000_000,
639 active_utilization: 200_000_000,
640 ..ClientAccount::default()
641 };
642 assert_eq!(c.capacity_budget(), 400_000_000);
643 }
644}