Fix flash loan

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-06-23 13:10:15 +02:00
parent 0bd5b8fdf3
commit 54c0306ae7
2 changed files with 4 additions and 4 deletions

View File

@ -54,7 +54,7 @@ struct AllowedVault {
#[derive(AnchorDeserialize, AnchorSerialize, Clone, Copy)]
pub struct FlashLoanWithdraw {
/// Account index of the vault to withdraw from in the target_accounts section.
/// Meaning that the first account after target_program_id would have index 0.
/// Index is counted after health accounts.
pub index: u8,
/// Requested withdraw amount.
pub amount: u64,
@ -119,7 +119,7 @@ pub fn flash_loan<'key, 'accounts, 'remaining, 'info>(
require!(pre_cpi_health >= 0, MangoError::HealthMustBePositive);
msg!("pre_cpi_health {:?}", pre_cpi_health);
let all_cpi_ais = &ctx.remaining_accounts[num_health_accounts + 1..];
let all_cpi_ais = &ctx.remaining_accounts[num_health_accounts..];
let mut all_cpi_ams = all_cpi_ais
.iter()
.flat_map(|item| item.to_account_metas(None))
@ -262,7 +262,7 @@ pub fn flash_loan<'key, 'accounts, 'remaining, 'info>(
cpi_datas[cpi_index + 1].account_start as usize - num_health_accounts
};
let all_cpi_ais_start_index = cpi_account_start - num_health_accounts;
let all_cpi_ais_start_index = cpi_account_start - num_health_accounts + 1;
let cpi_ais = &all_cpi_ais[all_cpi_ais_start_index..all_cpi_ais_end_index];
let cpi_ams = &all_cpi_ams[all_cpi_ais_start_index..all_cpi_ais_end_index];

View File

@ -320,7 +320,7 @@ impl<'keypair> ClientInstruction for FlashLoanInstruction<'keypair> {
let instruction = Self::Instruction {
withdraws: vec![FlashLoanWithdraw {
index: 1,
index: 2,
amount: self.withdraw_amount,
}],
cpi_datas: vec![CpiData {