carrot_sdk/
lib.rs

1use borsh::{BorshDeserialize, BorshSerialize};
2use solana_sdk::pubkey::Pubkey;
3
4pub mod accounts;
5pub mod error;
6pub mod instructions;
7pub mod client;
8
9pub use error::CarrotError;
10pub use client::{deposit_usdc, withdraw_crt, CarrotClient};
11
12/// Carrot Protocol Program ID
13pub const CARROT_PROGRAM_ID: Pubkey = solana_sdk::pubkey!("CarrotwivhMpDnm27EHmRLeQ683Z1PufuqEmBZvD282s");
14
15/// CRT Token Mint
16pub const CRT_MINT: Pubkey = solana_sdk::pubkey!("CRTx1JouZhzSU6XytsE42UQraoGqiHgxabocVfARTy2s");
17
18/// USDC Token Mint
19pub const USDC_MINT: Pubkey = solana_sdk::pubkey!("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
20
21/// USDT Token Mint
22pub const USDT_MINT: Pubkey = solana_sdk::pubkey!("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB");
23
24/// pyUSD Token Mint
25pub const PYUSD_MINT: Pubkey = solana_sdk::pubkey!("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo");
26
27/// Log Program ID (used by Carrot for logging)
28pub const LOG_PROGRAM_ID: Pubkey = solana_sdk::pubkey!("7Mc3vSdRWoThArpni6t5W4XjvQf4BuMny1uC8b6VBn48");
29
30/// Main vault address on mainnet
31pub const VAULT_ADDRESS: Pubkey = solana_sdk::pubkey!("FfCRL34rkJiMiX5emNDrYp3MdWH2mES3FvDQyFppqgpJ");
32
33/// Fee structure within vault
34#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
35pub struct Fee {
36    pub redemption_fee_bps: u16,
37    pub redemption_fee_accumulated: u64,
38    pub management_fee_bps: u16,
39    pub management_fee_last_update: i64,
40    pub management_fee_accumulated: u64,
41    pub performance_fee_bps: u16,
42}
43
44/// Asset data structure within vault
45#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
46pub struct Asset {
47    /// Asset ID
48    pub asset_id: u16,
49    /// Token mint address
50    pub mint: Pubkey,
51    /// Decimals for the token
52    pub decimals: u8,
53    /// Associated token account for vault
54    pub ata: Pubkey,
55    /// Price oracle address
56    pub oracle: Pubkey,
57}
58
59/// Strategy record within vault
60#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
61pub struct StrategyRecord {
62    pub strategy_id: u16,
63    pub asset_id: u16,
64    pub balance: u64,
65    pub net_earnings: i64,
66}
67
68/// Vault account structure (matches on-chain IDL)
69#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
70pub struct Vault {
71    /// Vault authority
72    pub authority: Pubkey,
73    /// Share token mint (CRT)
74    pub shares: Pubkey,
75    /// Fee configuration
76    pub fee: Fee,
77    /// Whether vault is paused
78    pub paused: bool,
79    /// Current asset index
80    pub asset_index: u16,
81    /// Current strategy index
82    pub strategy_index: u16,
83    /// List of assets (USDC, USDT, pyUSD)
84    pub assets: Vec<Asset>,
85    /// List of strategy records
86    pub strategies: Vec<StrategyRecord>,
87}
88
89impl Vault {
90    /// Get all asset ATAs and oracles as remaining accounts
91    pub fn get_remaining_accounts(&self) -> Vec<Pubkey> {
92        self.assets
93            .iter()
94            .flat_map(|asset| vec![asset.ata, asset.oracle])
95            .collect()
96    }
97}
98
99/// Arguments for issue (deposit) instruction
100#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
101pub struct IssueArgs {
102    pub amount: u64,
103}
104
105/// Arguments for redeem (withdrawal) instruction
106#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
107pub struct RedeemArgs {
108    pub amount: u64,
109}