stablebond_sdk/
lib.rs

1#[cfg(feature = "sdk")]
2pub mod sdk;
3
4use generated::types::PaymentFeedType;
5use solana_program::pubkey;
6use solana_program::pubkey::Pubkey;
7
8#[allow(unused)]
9#[allow(clippy::identity_op)]
10mod generated;
11
12pub use generated::programs::STABLEBOND_ID;
13pub use generated::programs::STABLEBOND_ID as ID;
14pub use generated::*;
15
16impl AsRef<[u8]> for PaymentFeedType {
17    fn as_ref(&self) -> &[u8] {
18        match self {
19            Self::UsdcUsd => b"usdc_usd",
20            Self::UsdcMxn => b"usdc_mxn",
21            Self::SwitchboardUsdcUsd => b"switchboard_usdc_usd",
22            Self::SwitchboardUsdcMxn => b"switchboard_usdc_mxn",
23            Self::Stub => b"stub",
24            Self::SwitchboardUsdcBrl => b"switchboard_usdc_brl",
25            Self::SwitchboardUsdcEur => b"switchboard_usdc_eur",
26            Self::SwitchboardUsdcGbp => b"switchboard_usdc_gbp",
27            Self::SwitchboardOnDemandUsdcMxn => b"switchboard_on_demand_usdc_mxn",
28            Self::SwitchboardOnDemandUsdcBrl => b"switchboard_on_demand_usdc_brl",
29            Self::SwitchboardOnDemandUsdcEur => b"switchboard_on_demand_usdc_eur",
30            Self::SwitchboardOnDemandUsdcGbp => b"switchboard_on_demand_usdc_gbp",
31            Self::SwitchboardOnDemandUsdcUsd => b"switchboard_on_demand_usdc_usd",
32        }
33    }
34}
35
36pub fn find_config_pda() -> (Pubkey, u8) {
37    Pubkey::find_program_address(&["config".to_string().as_ref()], &crate::ID)
38}
39
40pub fn find_delegate_pda(delegate_wallet: Pubkey) -> (Pubkey, u8) {
41    Pubkey::find_program_address(
42        &["delegate".to_string().as_ref(), delegate_wallet.as_ref()],
43        &crate::ID,
44    )
45}
46
47pub fn find_bond_pda(mint: Pubkey) -> (Pubkey, u8) {
48    Pubkey::find_program_address(&["bond".to_string().as_ref(), mint.as_ref()], &crate::ID)
49}
50
51pub fn find_issuance_pda(bond: Pubkey, issuance_number: u64) -> (Pubkey, u8) {
52    Pubkey::find_program_address(
53        &[
54            "issuance".to_string().as_ref(),
55            bond.as_ref(),
56            &issuance_number.to_le_bytes(),
57        ],
58        &crate::ID,
59    )
60}
61
62pub fn find_payment_pda(issuance: Pubkey) -> (Pubkey, u8) {
63    Pubkey::find_program_address(
64        &["payment".to_string().as_ref(), issuance.as_ref()],
65        &crate::ID,
66    )
67}
68
69pub fn find_payout_pda(issuance: Pubkey) -> (Pubkey, u8) {
70    Pubkey::find_program_address(
71        &["payout".to_string().as_ref(), issuance.as_ref()],
72        &crate::ID,
73    )
74}
75
76pub fn find_payment_feed_pda(payment_feed_type: PaymentFeedType) -> (Pubkey, u8) {
77    Pubkey::find_program_address(
78        &[
79            "payment_feed".to_string().as_ref(),
80            payment_feed_type.as_ref(),
81        ],
82        &crate::ID,
83    )
84}
85
86pub fn find_nft_issuance_vault_pda(nft_mint: Pubkey) -> (Pubkey, u8) {
87    Pubkey::find_program_address(
88        &["nft_issuance_vault".to_string().as_ref(), nft_mint.as_ref()],
89        &crate::ID,
90    )
91}
92
93pub fn find_access_pass_pda(user_wallet: Pubkey) -> (Pubkey, u8) {
94    Pubkey::find_program_address(
95        &["access_pass".to_string().as_ref(), user_wallet.as_ref()],
96        &crate::ID,
97    )
98}
99
100pub fn find_purchase_order_pda(nft_mint: Pubkey) -> (Pubkey, u8) {
101    Pubkey::find_program_address(
102        &["purchase_order".to_string().as_ref(), nft_mint.as_ref()],
103        &crate::ID,
104    )
105}
106
107pub fn find_kyc_pda(user_wallet: Pubkey) -> (Pubkey, u8) {
108    Pubkey::find_program_address(
109        &["kyc".to_string().as_ref(), user_wallet.as_ref()],
110        &crate::ID,
111    )
112}
113
114pub fn find_sell_liquidity_pda(bond: Pubkey) -> (Pubkey, u8) {
115    Pubkey::find_program_address(
116        &["sell_liquidity".to_string().as_ref(), bond.as_ref()],
117        &crate::ID,
118    )
119}
120
121pub fn find_offramp_pda(external_identifier: &[u8; 16]) -> (Pubkey, u8) {
122    Pubkey::find_program_address(
123        &["offramp".to_string().as_ref(), external_identifier.as_ref()],
124        &crate::ID,
125    )
126}
127
128pub fn find_onramp_pda(external_identifier: &[u8; 16]) -> (Pubkey, u8) {
129    Pubkey::find_program_address(
130        &["onramp".to_string().as_ref(), external_identifier.as_ref()],
131        &crate::ID,
132    )
133}
134
135cfg_if::cfg_if! {
136    if #[cfg(feature = "mainnet-beta")] {
137        pub const PYTH_PROGRAM: Pubkey = pubkey!("FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH");
138    } else {
139        pub const PYTH_PROGRAM: Pubkey = pubkey!("gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s");
140    }
141}
142
143cfg_if::cfg_if! {
144    if #[cfg(feature = "mainnet-beta")] {
145        pub const PYTH_USDC: Pubkey = pubkey!("Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD");
146    } else {
147        pub const PYTH_USDC: Pubkey = pubkey!("5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7");
148    }
149}
150
151cfg_if::cfg_if! {
152    if #[cfg(feature = "mainnet-beta")] {
153        pub const PROGRAM_OWNER: Pubkey = pubkey!("owNEred9E1jEEFsS2E3LRMNtAnUf6XBseqBnyKc33Pz");
154    } else {
155        pub const PROGRAM_OWNER: Pubkey = pubkey!("9Qx7RaqE56rHz4k1bM3Bta2dmqYGd8nLQxonde26MukW");
156    }
157}