solana_farm_sdk/
lib.rs

1#![forbid(unsafe_code)]
2
3use serde::{Deserialize, Serialize};
4use serde_json::to_string;
5use solana_program::program_error::ProgramError;
6
7pub mod error;
8pub mod farm;
9pub mod fund;
10pub mod id;
11pub mod instruction;
12pub mod log;
13pub mod math;
14pub mod pack;
15pub mod pool;
16pub mod program;
17pub mod refdb;
18pub mod string;
19pub mod token;
20pub mod traits;
21pub mod vault;
22
23#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)]
24pub enum ProgramIDType {
25    System,
26    ProgramsRef,
27    VaultsRef,
28    Vault,
29    FarmsRef,
30    Farm,
31    PoolsRef,
32    Pool,
33    TokensRef,
34    Token,
35    MainRouter,
36    Serum,
37    Raydium,
38    Saber,
39    Orca,
40    FundsRef,
41    Fund,
42}
43
44#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)]
45pub enum Protocol {
46    Raydium,
47    Saber,
48    Orca,
49}
50
51#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
52pub struct ProtocolInfo {
53    pub protocol: Protocol,
54    pub description: String,
55    pub link: String,
56    pub pools: u32,
57    pub farms: u32,
58    pub vaults: u32,
59}
60
61impl std::fmt::Display for ProgramIDType {
62    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
63        match *self {
64            ProgramIDType::System => write!(f, "System"),
65            ProgramIDType::ProgramsRef => write!(f, "ProgramsRef"),
66            ProgramIDType::VaultsRef => write!(f, "VaultsRef"),
67            ProgramIDType::Vault => write!(f, "Vault"),
68            ProgramIDType::FarmsRef => write!(f, "FarmsRef"),
69            ProgramIDType::Farm => write!(f, "Farm"),
70            ProgramIDType::PoolsRef => write!(f, "PoolsRef"),
71            ProgramIDType::Pool => write!(f, "Pool"),
72            ProgramIDType::TokensRef => write!(f, "TokensRef"),
73            ProgramIDType::Token => write!(f, "Token"),
74            ProgramIDType::MainRouter => write!(f, "MainRouter"),
75            ProgramIDType::Serum => write!(f, "Serum"),
76            ProgramIDType::Raydium => write!(f, "Raydium"),
77            ProgramIDType::Saber => write!(f, "Saber"),
78            ProgramIDType::Orca => write!(f, "Orca"),
79            ProgramIDType::FundsRef => write!(f, "FundsRef"),
80            ProgramIDType::Fund => write!(f, "Fund"),
81        }
82    }
83}
84
85impl std::str::FromStr for ProgramIDType {
86    type Err = ProgramError;
87
88    fn from_str(s: &str) -> Result<Self, ProgramError> {
89        match s.to_lowercase().as_str() {
90            "system" => Ok(ProgramIDType::System),
91            "programsref" => Ok(ProgramIDType::ProgramsRef),
92            "vaultsref" => Ok(ProgramIDType::VaultsRef),
93            "vault" => Ok(ProgramIDType::Vault),
94            "farmsref" => Ok(ProgramIDType::FarmsRef),
95            "farm" => Ok(ProgramIDType::Farm),
96            "poolsref" => Ok(ProgramIDType::PoolsRef),
97            "pool" => Ok(ProgramIDType::Pool),
98            "tokensref" => Ok(ProgramIDType::TokensRef),
99            "token" => Ok(ProgramIDType::Token),
100            "mainrouter" => Ok(ProgramIDType::MainRouter),
101            "serum" => Ok(ProgramIDType::Serum),
102            "raydium" => Ok(ProgramIDType::Raydium),
103            "saber" => Ok(ProgramIDType::Saber),
104            "orca" => Ok(ProgramIDType::Orca),
105            "fundsref" => Ok(ProgramIDType::FundsRef),
106            "fund" => Ok(ProgramIDType::Fund),
107            _ => Err(ProgramError::InvalidArgument),
108        }
109    }
110}
111
112impl Protocol {
113    pub fn id(&self) -> &'static str {
114        match *self {
115            Protocol::Raydium => "RDM",
116            Protocol::Saber => "SBR",
117            Protocol::Orca => "ORC",
118        }
119    }
120}
121
122impl std::fmt::Display for Protocol {
123    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
124        match *self {
125            Protocol::Raydium => write!(f, "Raydium"),
126            Protocol::Saber => write!(f, "Saber"),
127            Protocol::Orca => write!(f, "Orca"),
128        }
129    }
130}
131
132impl std::str::FromStr for Protocol {
133    type Err = ProgramError;
134
135    fn from_str(s: &str) -> Result<Self, ProgramError> {
136        match s.to_lowercase().as_str() {
137            "rdm" | "raydium" => Ok(Protocol::Raydium),
138            "sbr" | "saber" => Ok(Protocol::Saber),
139            "orc" | "orca" => Ok(Protocol::Orca),
140            _ => Err(ProgramError::InvalidArgument),
141        }
142    }
143}
144
145impl std::fmt::Display for ProtocolInfo {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        write!(f, "{}", to_string(&self).unwrap())
148    }
149}