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

post-review fixes #29

Merged
merged 1 commit into from
Nov 12, 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
8 changes: 4 additions & 4 deletions programs/strategy/src/instructions/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ pub fn handle_deposit<'info>(
return Err(ErrorCode::MaxDepositReached.into());
}

strategy.deposit(amount)?;
strategy.save_changes(&mut &mut ctx.accounts.strategy.try_borrow_mut_data()?[8..])?;

transfer(
ctx.accounts.token_program.to_account_info(),
ctx.accounts.vault_token_account.to_account_info(),
ctx.accounts.underlying_token_account.to_account_info(),
ctx.accounts.signer.to_account_info(),
amount
)?;

strategy.deposit(amount)?;
strategy.save_changes(&mut &mut ctx.accounts.strategy.try_borrow_mut_data()?[8..])
)
}
3 changes: 0 additions & 3 deletions programs/tokenized_vault/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ pub enum ErrorCode {
#[msg("Exceed withdraw limit")]
ExceedWithdrawLimit,

#[msg("Invalid strategy / token account pairs")]
InvalidAccountPairs,

#[msg("Loss is too high")]
TooMuchLoss,

Expand Down
10 changes: 6 additions & 4 deletions programs/tokenized_vault/src/instructions/add_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use access_control::{
program::AccessControl,
state::{UserRole, Role}
};
use strategy::program::Strategy;

use crate::errors::ErrorCode;
use crate::constants::STRATEGY_DATA_SEED;
use crate::state::{ StrategyData, Vault};
use crate::utils::strategy;
use crate::utils::strategy as strategy_utils;

#[derive(Accounts)]
pub struct AddStrategy<'info> {
Expand All @@ -29,7 +30,7 @@ pub struct AddStrategy<'info> {
pub vault: AccountLoader<'info, Vault>,

/// CHECK: can be any strategy
#[account()]
#[account(constraint = *strategy.owner == strategy_program.key())]
pub strategy: UncheckedAccount<'info>,

#[account(
Expand All @@ -47,11 +48,12 @@ pub struct AddStrategy<'info> {
pub signer: Signer<'info>,

pub access_control: Program<'info, AccessControl>,
pub system_program: Program<'info, System>
pub system_program: Program<'info, System>,
pub strategy_program: Program<'info, Strategy>,
}

pub fn handle_add_strategy(ctx: Context<AddStrategy>, max_debt: u64) -> Result<()> {
let strategy_vault = strategy::get_vault(&ctx.accounts.strategy.to_account_info())?;
let strategy_vault = strategy_utils::get_vault(&ctx.accounts.strategy.to_account_info())?;

if strategy_vault != *ctx.accounts.vault.to_account_info().key {
return Err(ErrorCode::InvalidStrategyToAdd.into());
Expand Down
8 changes: 4 additions & 4 deletions programs/tokenized_vault/src/instructions/update_debt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ pub fn handle_update_debt<'a, 'b, 'c, 'info>(
) -> Result<()> {
let (total_idle, total_debt, new_debt) = handle_internal(&mut ctx, new_debt)?;

let vaut_mut = &mut ctx.accounts.vault.load_mut()?;
vaut_mut.total_idle = total_idle;
vaut_mut.total_debt = total_debt;
let vault_mut = &mut ctx.accounts.vault.load_mut()?;
vault_mut.total_idle = total_idle;
vault_mut.total_debt = total_debt;

ctx.accounts.strategy_data.update_strategy_current_debt(new_debt)?;

emit!(UpdatedCurrentDebtForStrategyEvent {
vault_key: vaut_mut.key,
vault_key: vault_mut.key,
strategy_key: ctx.accounts.strategy.key(),
total_idle: total_idle,
total_debt: total_debt,
Expand Down
5 changes: 3 additions & 2 deletions programs/tokenized_vault/src/instructions/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pub fn handle_withdraw<'info>(
}
}

ctx.accounts.vault.load_mut()?.handle_withdraw(assets_to_transfer, shares_to_burn);

token::burn(
ctx.accounts.token_program.to_account_info(),
ctx.accounts.shares_mint.to_account_info(),
Expand All @@ -120,8 +122,7 @@ pub fn handle_withdraw<'info>(
&ctx.accounts.vault.load()?.seeds()
)?;

let mut vault = ctx.accounts.vault.load_mut()?;
vault.handle_withdraw(assets_to_transfer, shares_to_burn);
let vault = ctx.accounts.vault.load()?;

emit!(VaultWithdrawlEvent {
vault_key: vault.key,
Expand Down
Loading