mercurial_vault/
lib.rs

1pub mod context;
2pub mod seed;
3pub mod state;
4pub mod strategy;
5pub mod utils;
6
7use crate::strategy::base::StrategyType;
8use anchor_lang::prelude::*;
9use context::*;
10use std::convert::TryFrom;
11use std::str::FromStr;
12
13#[cfg(feature = "staging")]
14declare_id!("6YRZW57XsrT2DxSNLXHHQd4QmiqBode4d6btASkRqcFo");
15
16#[cfg(not(feature = "staging"))]
17declare_id!("24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi");
18
19// Performance fee when rebalancing
20pub const PERFORMANCE_FEE_NUMERATOR: u128 = 500u128; // 5%
21pub const PERFORMANCE_FEE_DENOMINATOR: u128 = 10000u128;
22
23// get vault address from base key and token mint
24// let (vault, _vault_bump) = Pubkey::find_program_address(
25//     &[b"vault".as_ref(), token_mint.as_ref(), get_base_key().as_ref()],
26//     &program_client.id(),
27// );
28pub fn get_base_key() -> Pubkey {
29    Pubkey::from_str("HWzXGcGHy4tcpYfaRDCyLNzXqBTv3E6BttpCH2vJxArv").unwrap()
30}
31
32/// Treasury address
33pub fn get_treasury_address() -> Pubkey {
34    Pubkey::from_str("9kZeN47U2dubGbbzMrzzoRAUvpuxVLRcjW9XiFpYjUo4").unwrap()
35}
36
37pub fn get_base_address_for_idle_vault() -> Pubkey {
38    Pubkey::default()
39}
40
41#[program]
42pub mod vault {
43    use super::*;
44
45    #[allow(unused_variables)]
46    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
47        Ok(())
48    }
49
50    #[allow(unused_variables)]
51    pub fn initialize_idle_vault(ctx: Context<InitializeIdleVault>) -> Result<()> {
52        Ok(())
53    }
54
55    #[allow(unused_variables)]
56    pub fn deposit(
57        ctx: Context<DepositWithdrawLiquidity>,
58        token_amount: u64,
59        minimum_lp_token_amount: u64,
60    ) -> Result<()> {
61        Ok(())
62    }
63
64    #[allow(unused_variables)]
65    pub fn withdraw(
66        ctx: Context<DepositWithdrawLiquidity>,
67        unmint_amount: u64,
68        min_out_amount: u64,
69    ) -> Result<()> {
70        Ok(())
71    }
72
73    #[allow(unused_variables)]
74    pub fn withdraw_directly_from_strategy<'a, 'b, 'c, 'info>(
75        ctx: Context<'a, 'b, 'c, 'info, WithdrawDirectlyFromStrategy<'info>>,
76        unmint_amount: u64,
77        min_out_amount: u64,
78    ) -> Result<()> {
79        Ok(())
80    }
81
82    // simulate function to get unlocked amount
83    pub fn get_unlocked_amount(ctx: Context<GetUnlockedAmount>) -> Result<()> {
84        let vault = &ctx.accounts.vault;
85        let current_time = u64::try_from(Clock::get()?.unix_timestamp)
86            .ok()
87            .ok_or(VaultError::MathOverflow)?;
88        let total_amount = vault
89            .get_unlocked_amount(current_time)
90            .ok_or(VaultError::MathOverflow)?;
91
92        emit!(TotalAmount { total_amount });
93
94        Ok(())
95    }
96
97    #[allow(unused_variables)]
98    pub fn deposit_strategy<'a, 'b, 'c, 'info>(
99        ctx: Context<'a, 'b, 'c, 'info, RebalanceStrategy<'info>>,
100        amount: u64,
101    ) -> Result<()> {
102        Ok(())
103    }
104
105    #[allow(unused_variables)]
106    pub fn withdraw_strategy<'a, 'b, 'c, 'info>(
107        ctx: Context<'a, 'b, 'c, 'info, RebalanceStrategy<'info>>,
108        amount: u64,
109    ) -> Result<()> {
110        Ok(())
111    }
112}
113
114#[error_code]
115pub enum VaultError {
116    #[msg("Vault is disabled")]
117    VaultIsDisabled,
118
119    #[msg("Exceeded slippage tolerance")]
120    ExceededSlippage,
121
122    #[msg("Strategy is not existed")]
123    StrategyIsNotExisted,
124
125    #[msg("UnAuthorized")]
126    UnAuthorized,
127
128    #[msg("Math operation overflow")]
129    MathOverflow,
130
131    #[msg("Protocol is not supported")]
132    ProtocolIsNotSupported,
133
134    #[msg("Reserve does not support token mint")]
135    UnMatchReserve,
136
137    #[msg("lockedProfitDegradation is invalid")]
138    InvalidLockedProfitDegradation,
139
140    #[msg("Maximum number of strategies have been reached")]
141    MaxStrategyReached,
142
143    #[msg("Strategy existed")]
144    StrategyExisted,
145
146    #[msg("Invalid unmint amount")]
147    InvalidUnmintAmount,
148
149    #[msg("Invalid accounts for strategy")]
150    InvalidAccountsForStrategy,
151
152    #[msg("Invalid bump")]
153    InvalidBump,
154
155    #[msg("Amount must be greater than 0")]
156    AmountMustGreaterThanZero,
157
158    #[msg("Mango is not supported anymore")]
159    MangoIsNotSupportedAnymore,
160
161    #[msg("Strategy is not supported")]
162    StrategyIsNotSupported,
163
164    #[msg("Pay amount is exceeded")]
165    PayAmountIsExeeced,
166}
167
168#[event]
169pub struct AddLiquidity {
170    pub lp_mint_amount: u64,
171    pub token_amount: u64,
172}
173
174#[event]
175pub struct RemoveLiquidity {
176    pub lpunmint_amount: u64,
177    pub token_amount: u64,
178}
179#[event]
180pub struct StrategyDeposit {
181    pub strategy_type: StrategyType,
182    pub token_amount: u64,
183}
184
185#[event]
186pub struct StrategyWithdraw {
187    pub strategy_type: StrategyType,
188    pub collateral_amount: u64,
189    pub estimated_token_amount: u64,
190}
191
192#[event]
193pub struct StakingReward {
194    pub strategy_type: StrategyType,
195    pub token_amount: u64,
196    pub mint_account: Pubkey,
197}
198
199#[event]
200pub struct PerformanceFee {
201    pub lp_mint_more: u64,
202}
203
204#[event]
205pub struct ReportLoss {
206    pub strategy: Pubkey,
207    pub loss: u64,
208}
209
210#[event]
211pub struct TotalAmount {
212    pub total_amount: u64,
213}