Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

program: cleanup some vault protocol things #59

Merged
merged 8 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions programs/drift_vaults/src/state/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ impl Vault {
self.last_fee_update_ts = now;
}

validate!(
self.total_shares >= self.user_shares,
ErrorCode::InvalidVaultSharesDetected,
"total_shares must be >= user_shares"
)?;

// this will underflow if there is an issue with protocol fee calc
self.get_manager_shares(vault_protocol)?;

Ok(VaultFee {
management_fee_payment: management_fee_payment.cast::<i64>()?,
management_fee_shares: management_fee_shares.cast::<i64>()?,
Expand Down Expand Up @@ -801,6 +810,13 @@ impl Vault {
ErrorCode::InvalidVaultWithdrawSize,
"Requested n_shares = 0"
)?;
validate!(
protocol_shares_before >= n_shares,
ErrorCode::InvalidVaultWithdrawSize,
"Requested n_shares={} > protocol shares={}",
n_shares,
protocol_shares_before,
)?;

let total_vault_shares_before = self.total_shares;
let user_vault_shares_before = self.user_shares;
Expand Down
4 changes: 0 additions & 4 deletions programs/drift_vaults/src/state/vault_depositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ impl VaultDepositor {
} = vault.apply_fee(vault_protocol, vault_equity, now)?;
let (manager_profit_share, protocol_profit_share) =
self.apply_profit_share(vault_equity, vault, vault_protocol)?;
msg!("manager_profit_share: {}", manager_profit_share);
msg!("protocol_profit_share: {}", protocol_profit_share);

let (withdraw_value, n_shares) = withdraw_unit.get_withdraw_value_and_shares(
withdraw_amount,
Expand Down Expand Up @@ -772,8 +770,6 @@ impl VaultDepositor {
)?;
let withdraw_amount = self.last_withdraw_request.value.min(shares_value);

msg!("withdraw amount: {}", withdraw_amount);

let mut spot_market = spot_market_map.get_ref_mut(&vault.spot_market_index)?;

// Save relevant data before updating balances
Expand Down
Loading