Skip to content

Commit

Permalink
Refactor some methods before combining
Browse files Browse the repository at this point in the history
  • Loading branch information
DaSichuan authored and nope-finance committed Jun 26, 2021
1 parent ad79d83 commit 4d045c6
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use solana_program::{
use spl_token::solana_program::instruction::AccountMeta;
use spl_token::state::{Account, Mint};
use std::convert::TryInto;
use std::result::Result;

/// Processes an instruction
pub fn process_instruction(
Expand Down Expand Up @@ -449,6 +450,39 @@ fn process_deposit_reserve_liquidity(
let clock = &Clock::from_account_info(next_account_info(account_info_iter)?)?;
let token_program_id = next_account_info(account_info_iter)?;

// We don't care about the return value here, so just ignore it.
_process_deposit_reserve_liquidity(
program_id,
liquidity_amount,
source_liquidity_info,
destination_collateral_info,
reserve_info,
reserve_liquidity_supply_info,
reserve_collateral_mint_info,
lending_market_info,
lending_market_authority_info,
user_transfer_authority_info,
clock,
token_program_id,
)?;
Ok(())
}

#[allow(clippy::too_many_arguments)]
fn _process_deposit_reserve_liquidity<'a>(
program_id: &Pubkey,
liquidity_amount: u64,
source_liquidity_info: &AccountInfo<'a>,
destination_collateral_info: &AccountInfo<'a>,
reserve_info: &AccountInfo<'a>,
reserve_liquidity_supply_info: &AccountInfo<'a>,
reserve_collateral_mint_info: &AccountInfo<'a>,
lending_market_info: &AccountInfo<'a>,
lending_market_authority_info: &AccountInfo<'a>,
user_transfer_authority_info: &AccountInfo<'a>,
clock: &Clock,
token_program_id: &AccountInfo<'a>,
) -> Result<u64, ProgramError> {
let lending_market = LendingMarket::unpack(&lending_market_info.data.borrow())?;
if lending_market_info.owner != program_id {
msg!("Lending market provided is not owned by the lending program");
Expand Down Expand Up @@ -526,7 +560,7 @@ fn process_deposit_reserve_liquidity(
token_program: token_program_id.clone(),
})?;

Ok(())
Ok(collateral_amount)
}

fn process_redeem_reserve_collateral(
Expand Down Expand Up @@ -818,7 +852,37 @@ fn process_deposit_obligation_collateral(
let user_transfer_authority_info = next_account_info(account_info_iter)?;
let clock = &Clock::from_account_info(next_account_info(account_info_iter)?)?;
let token_program_id = next_account_info(account_info_iter)?;
_deposit_obligation_collateral(
program_id,
collateral_amount,
source_collateral_info,
destination_collateral_info,
deposit_reserve_info,
obligation_info,
lending_market_info,
lending_market_authority_info,
obligation_owner_info,
user_transfer_authority_info,
clock,
token_program_id,
)
}

#[allow(clippy::too_many_arguments)]
fn _deposit_obligation_collateral<'a>(
program_id: &Pubkey,
collateral_amount: u64,
source_collateral_info: &AccountInfo<'a>,
destination_collateral_info: &AccountInfo<'a>,
deposit_reserve_info: &AccountInfo<'a>,
obligation_info: &AccountInfo<'a>,
lending_market_info: &AccountInfo<'a>,
lending_market_authority_info: &AccountInfo<'a>,
obligation_owner_info: &AccountInfo<'a>,
user_transfer_authority_info: &AccountInfo<'a>,
clock: &Clock,
token_program_id: &AccountInfo<'a>,
) -> ProgramResult {
let lending_market = LendingMarket::unpack(&lending_market_info.data.borrow())?;
if lending_market_info.owner != program_id {
msg!("Lending market provided is not owned by the lending program");
Expand Down

0 comments on commit 4d045c6

Please sign in to comment.