Skip to content

Commit

Permalink
Merge pull request #17 from marinade-finance/a27-has-one
Browse files Browse the repository at this point in the history
seeds = [&state.key().to_bytes(), ...
  • Loading branch information
luciotato authored May 5, 2023
2 parents a38cd81 + b7df9bb commit e69ed89
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 36 deletions.
18 changes: 10 additions & 8 deletions programs/marinade-finance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anchor_spl::{
token::{Mint, TokenAccount, Token},
};
use error::CommonError;
use liq_pool::LiqPool;
use std::{
convert::{TryFrom, TryInto},
fmt::Display,
Expand Down Expand Up @@ -385,7 +386,7 @@ pub struct AddLiquidity<'info> {
// liq_pool_msol_leg to be able to compute current msol value in liq_pool
pub liq_pool_msol_leg: Box<Account<'info, TokenAccount>>,

#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), LiqPool::SOL_LEG_SEED], bump = state.liq_pool.sol_leg_bump_seed)]
// seeds = [&state.to_account_info().key.to_bytes()[..32], LiqPool::SOL_ACCOUNT_SEED], bump = state.liq_pool.sol_account_bump_seed)]
// #[account(owner = "11111111111111111111111111111111")]
pub liq_pool_sol_leg_pda: SystemAccount<'info>,
Expand Down Expand Up @@ -420,7 +421,7 @@ pub struct RemoveLiquidity<'info> {
pub transfer_msol_to: Box<Account<'info, TokenAccount>>,

// legs
#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), LiqPool::SOL_LEG_SEED], bump = state.liq_pool.sol_leg_bump_seed)]
pub liq_pool_sol_leg_pda: SystemAccount<'info>,
#[account(mut)]
pub liq_pool_msol_leg: Box<Account<'info, TokenAccount>>,
Expand All @@ -439,15 +440,15 @@ pub struct Deposit<'info> {
#[account(mut)]
pub msol_mint: Box<Account<'info, Mint>>,

#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), LiqPool::SOL_LEG_SEED], bump = state.liq_pool.sol_leg_bump_seed)]
pub liq_pool_sol_leg_pda: SystemAccount<'info>,

#[account(mut)]
pub liq_pool_msol_leg: Box<Account<'info, TokenAccount>>,
/// CHECK: PDA
pub liq_pool_msol_leg_authority: UncheckedAccount<'info>,

#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), State::RESERVE_SEED], bump = state.reserve_bump_seed)]
pub reserve_pda: SystemAccount<'info>,

#[account(mut)]
Expand Down Expand Up @@ -512,7 +513,7 @@ pub struct LiquidUnstake<'info> {
#[account(mut)]
pub msol_mint: Box<Account<'info, Mint>>,

#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), LiqPool::SOL_LEG_SEED], bump = state.liq_pool.sol_leg_bump_seed)]
pub liq_pool_sol_leg_pda: SystemAccount<'info>,

#[account(mut)]
Expand Down Expand Up @@ -615,7 +616,7 @@ pub struct OrderUnstake<'info> {
pub struct Claim<'info> {
#[account(mut)]
pub state: Account<'info, State>,
#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), State::RESERVE_SEED], bump = state.reserve_bump_seed)]
pub reserve_pda: SystemAccount<'info>,

#[account(mut)]
Expand All @@ -642,7 +643,7 @@ pub struct StakeReserve<'info> {
/// CHECK: CPI
#[account(mut)]
pub validator_vote: UncheckedAccount<'info>,
#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), State::RESERVE_SEED], bump = state.reserve_bump_seed)]
pub reserve_pda: SystemAccount<'info>,
#[account(mut)]
pub stake_account: Box<Account<'info, StakeAccount>>, // must be uninitialized
Expand Down Expand Up @@ -671,7 +672,7 @@ pub struct UpdateCommon<'info> {
pub stake_account: Box<Account<'info, StakeAccount>>,
/// CHECK: PDA
pub stake_withdraw_authority: UncheckedAccount<'info>, // for getting non delegated SOLs
#[account(mut)]
#[account(mut, seeds = [&state.key().to_bytes(), State::RESERVE_SEED], bump = state.reserve_bump_seed)]
pub reserve_pda: SystemAccount<'info>, // all non delegated SOLs (if some attacker transfers it to stake) are sent to reserve_pda

#[account(mut)]
Expand Down Expand Up @@ -776,6 +777,7 @@ pub struct DeactivateStake<'info> {
#[account(mut)]
pub state: Box<Account<'info, State>>,
// Readonly. For stake delta calculation
#[account(seeds = [&state.key().to_bytes(), State::RESERVE_SEED], bump = state.reserve_bump_seed)]
pub reserve_pda: SystemAccount<'info>,
/// CHECK: manual account processing
#[account(mut)]
Expand Down
9 changes: 0 additions & 9 deletions programs/marinade-finance/src/liq_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ pub trait LiqPoolHelpers {
fn liq_pool_msol_leg_authority(&self) -> Pubkey;

fn check_lp_mint_authority(&self, lp_mint_authority: &Pubkey) -> Result<()>;
fn check_liq_pool_sol_leg_pda(&self, liq_pool_sol_leg_pda: &Pubkey) -> Result<()>;
fn check_liq_pool_msol_leg_authority(
&self,
liq_pool_msol_leg_authority: &Pubkey,
Expand Down Expand Up @@ -223,14 +222,6 @@ where
)
}

fn check_liq_pool_sol_leg_pda(&self, liq_pool_sol_leg_pda: &Pubkey) -> Result<()> {
check_address(
liq_pool_sol_leg_pda,
&self.liq_pool_sol_leg_address(),
"liq_pool_sol_leg_pda",
)
}

fn check_liq_pool_msol_leg_authority(
&self,
liq_pool_msol_leg_authority: &Pubkey,
Expand Down
2 changes: 0 additions & 2 deletions programs/marinade-finance/src/liq_pool/add_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ impl<'info> AddLiquidity<'info> {
self.state
.liq_pool
.check_liq_pool_msol_leg(self.liq_pool_msol_leg.to_account_info().key)?;
self.state
.check_liq_pool_sol_leg_pda(self.liq_pool_sol_leg_pda.key)?;
self.check_transfer_from(lamports)?;
self.state
.liq_pool
Expand Down
2 changes: 0 additions & 2 deletions programs/marinade-finance/src/liq_pool/remove_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ impl<'info> RemoveLiquidity<'info> {
.check_lp_mint(self.lp_mint.to_account_info().key)?;
self.check_burn_from(tokens)?;
self.check_transfer_msol_to()?;
self.state
.check_liq_pool_sol_leg_pda(self.liq_pool_sol_leg_pda.key)?;
self.state
.liq_pool
.check_liq_pool_msol_leg(self.liq_pool_msol_leg.to_account_info().key)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use anchor_lang::solana_program::{

use crate::{
checks::{check_address, check_stake_amount_and_validator},
state::StateHelpers,
DeactivateStake,
};

Expand All @@ -21,7 +20,6 @@ impl<'info> DeactivateStake<'info> {
// fn deactivate_stake()
//
pub fn process(&mut self, stake_index: u32, validator_index: u32) -> Result<()> {
self.state.check_reserve_address(self.reserve_pda.key)?;
self.state
.validator_system
.check_validator_list(&self.validator_list)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl<'info> StakeReserve<'info> {
.validator_system
.check_validator_list(&self.validator_list)?;
self.state.stake_system.check_stake_list(&self.stake_list)?;
self.state.check_reserve_address(self.reserve_pda.key)?;
self.check_stake_history()?;
self.state
.check_stake_deposit_authority(self.stake_deposit_authority.key)?;
Expand Down
5 changes: 0 additions & 5 deletions programs/marinade-finance/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ pub trait StateHelpers {
fn reserve_address(&self) -> Pubkey;
fn with_reserve_seeds<R, F: FnOnce(&[&[u8]]) -> R>(&self, f: F) -> R;

fn check_reserve_address(&self, reserve: &Pubkey) -> Result<()>;
fn check_msol_mint_authority(&self, msol_mint_authority: &Pubkey) -> Result<()>;
}

Expand Down Expand Up @@ -318,10 +317,6 @@ where
])
}

fn check_reserve_address(&self, reserve: &Pubkey) -> Result<()> {
check_address(reserve, &self.reserve_address(), "reserve")
}

fn check_msol_mint_authority(&self, msol_mint_authority: &Pubkey) -> Result<()> {
check_address(
msol_mint_authority,
Expand Down
1 change: 0 additions & 1 deletion programs/marinade-finance/src/state/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl<'info> Claim<'info> {
&system_program::ID,
"system_program",
)?;
self.state.check_reserve_address(self.reserve_pda.key)?;
self.check_ticket_account()?;

let lamports = self.ticket_account.lamports_amount;
Expand Down
3 changes: 0 additions & 3 deletions programs/marinade-finance/src/state/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ impl<'info> Deposit<'info> {
// fn deposit_sol()
pub fn process(&mut self, lamports: u64) -> Result<()> {
check_min_amount(lamports, self.state.min_deposit, "deposit SOL")?;
self.state.check_reserve_address(self.reserve_pda.key)?;
self.state
.check_liq_pool_sol_leg_pda(self.liq_pool_sol_leg_pda.key)?;
self.state
.liq_pool
.check_liq_pool_msol_leg(self.liq_pool_msol_leg.to_account_info().key)?;
Expand Down
2 changes: 0 additions & 2 deletions programs/marinade-finance/src/state/liquid_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ impl<'info> LiquidUnstake<'info> {
pub fn process(&mut self, msol_amount: u64) -> Result<()> {
msg!("enter LiquidUnstake");

self.state
.check_liq_pool_sol_leg_pda(self.liq_pool_sol_leg_pda.key)?;
self.state
.liq_pool
.check_liq_pool_msol_leg(self.liq_pool_msol_leg.to_account_info().key)?;
Expand Down
1 change: 0 additions & 1 deletion programs/marinade-finance/src/state/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl<'info> UpdateCommon<'info> {
.check_treasury_msol_account(&self.treasury_msol_account)?;
self.state
.check_stake_withdraw_authority(self.stake_withdraw_authority.key)?;
self.state.check_reserve_address(self.reserve_pda.key)?;
check_address(self.stake_program.key, &stake::program::ID, "stake_program")?;
check_address(self.token_program.key, &spl_token::ID, "token_program")?;

Expand Down

0 comments on commit e69ed89

Please sign in to comment.