-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add function to deposit reserve liquidity and collateral #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,14 @@ pub fn process_instruction( | |
msg!("Instruction: Flash Loan"); | ||
process_flash_loan(program_id, amount, accounts) | ||
} | ||
LendingInstruction::DepositReserveLiquidityAndObligationCollateral { liquidity_amount } => { | ||
msg!("Instruction Deposit Reserve Liquidity and Obligation Collateral"); | ||
process_deposit_reserve_liquidity_and_obligation_collateral( | ||
program_id, | ||
liquidity_amount, | ||
accounts, | ||
) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -451,7 +459,7 @@ fn process_deposit_reserve_liquidity( | |
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( | ||
_deposit_reserve_liquidity( | ||
program_id, | ||
liquidity_amount, | ||
source_liquidity_info, | ||
|
@@ -469,7 +477,7 @@ fn process_deposit_reserve_liquidity( | |
} | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
fn _process_deposit_reserve_liquidity<'a>( | ||
fn _deposit_reserve_liquidity<'a>( | ||
program_id: &Pubkey, | ||
liquidity_amount: u64, | ||
source_liquidity_info: &AccountInfo<'a>, | ||
|
@@ -970,6 +978,63 @@ fn _deposit_obligation_collateral<'a>( | |
Ok(()) | ||
} | ||
|
||
#[inline(never)] // avoid stack frame limit | ||
fn process_deposit_reserve_liquidity_and_obligation_collateral( | ||
program_id: &Pubkey, | ||
liquidity_amount: u64, | ||
accounts: &[AccountInfo], | ||
) -> ProgramResult { | ||
if liquidity_amount == 0 { | ||
msg!("Liquidity amount provided cannot be zero"); | ||
return Err(LendingError::InvalidAmount.into()); | ||
} | ||
|
||
let account_info_iter = &mut accounts.iter(); | ||
let source_liquidity_info = next_account_info(account_info_iter)?; | ||
let user_collateral_info = next_account_info(account_info_iter)?; | ||
let reserve_info = next_account_info(account_info_iter)?; | ||
let reserve_liquidity_supply_info = next_account_info(account_info_iter)?; | ||
let reserve_collateral_mint_info = next_account_info(account_info_iter)?; | ||
let lending_market_info = next_account_info(account_info_iter)?; | ||
let lending_market_authority_info = next_account_info(account_info_iter)?; | ||
let destination_collateral_info = next_account_info(account_info_iter)?; | ||
let obligation_info = next_account_info(account_info_iter)?; | ||
let obligation_owner_info = next_account_info(account_info_iter)?; | ||
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)?; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are there no extra checks we should do here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured no, since all it's doing is calling two existing endpoints, all which do their own checks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeh kk sounds fine then. the only main thing is the 4 vs 14 |
||
let collateral_amount = _deposit_reserve_liquidity( | ||
program_id, | ||
liquidity_amount, | ||
source_liquidity_info, | ||
user_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, | ||
)?; | ||
_deposit_obligation_collateral( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe there is a check on like collateral amount we should do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The _deposit_obligation_collateral checks for nonzero collateral amount. Anything else? I suupose we can change it to a >0 check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just kidding its unsigned |
||
program_id, | ||
collateral_amount, | ||
user_collateral_info, | ||
destination_collateral_info, | ||
reserve_info, | ||
obligation_info, | ||
lending_market_info, | ||
lending_market_authority_info, | ||
obligation_owner_info, | ||
user_transfer_authority_info, | ||
clock, | ||
token_program_id, | ||
)?; | ||
Ok(()) | ||
} | ||
|
||
#[inline(never)] // avoid stack frame limit | ||
fn process_withdraw_obligation_collateral( | ||
program_id: &Pubkey, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'm not 100% sure what accounts I should be using here and if the ones here are correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhh you should be able to check this in the code side (this is just a comment)
so it looks fine at first glance