-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
programs/drift_vaults/src/instructions/manager_crank_profit_share.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::constraints::{is_manager_for_vault, is_user_for_vault, is_user_stats_for_vault}; | ||
use crate::{Vault, VaultDepositor}; | ||
|
||
use crate::AccountMapProvider; | ||
use anchor_lang::prelude::*; | ||
use drift::instructions::optional_accounts::AccountMaps; | ||
use drift::program::Drift; | ||
use drift::state::user::User; | ||
|
||
pub fn manager_crank_profit_share(ctx: Context<ManagerCrankProfitShare>) -> Result<()> { | ||
let clock = &Clock::get()?; | ||
|
||
let mut vault = ctx.accounts.vault.load_mut()?; | ||
let mut vault_depositor = ctx.accounts.vault_depositor.load_mut()?; | ||
|
||
let user = ctx.accounts.drift_user.load()?; | ||
let spot_market_index = vault.spot_market_index; | ||
|
||
let AccountMaps { | ||
perp_market_map, | ||
spot_market_map, | ||
mut oracle_map, | ||
} = ctx.load_maps(clock.slot, Some(spot_market_index))?; | ||
|
||
let vault_equity = | ||
vault.calculate_equity(&user, &perp_market_map, &spot_market_map, &mut oracle_map)?; | ||
|
||
vault_depositor.apply_profit_share(vault_equity, &mut vault)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct ManagerCrankProfitShare<'info> { | ||
#[account( | ||
mut, | ||
constraint = is_manager_for_vault(&vault, &manager)? | ||
This comment has been minimized.
Sorry, something went wrong. |
||
)] | ||
pub vault: AccountLoader<'info, Vault>, | ||
#[account(mut)] | ||
pub vault_depositor: AccountLoader<'info, VaultDepositor>, | ||
pub manager: Signer<'info>, | ||
#[account( | ||
mut, | ||
constraint = is_user_stats_for_vault(&vault, &drift_user_stats)? | ||
)] | ||
/// CHECK: checked in drift cpi | ||
pub drift_user_stats: AccountInfo<'info>, | ||
#[account( | ||
mut, | ||
constraint = is_user_for_vault(&vault, &drift_user.key())? | ||
)] | ||
/// CHECK: checked in drift cpi | ||
pub drift_user: AccountLoader<'info, User>, | ||
/// CHECK: checked in drift cpi | ||
pub drift_state: AccountInfo<'info>, | ||
/// CHECK: checked in drift cpi | ||
pub drift_signer: AccountInfo<'info>, | ||
pub drift_program: Program<'info, Drift>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
should be allowed to be delegate