FlashLoan: Allow mango ix after flash loan end (#681)

This lifts an unnecessary restriction, making it possible to do things
like flash loan and then liquidate with the resulting balances in a
single transaction.

The "no mango ix after FlashLoanEnd" limitation was unnecessary:
After the flash loan ends, the mango accounts are in a valid state
again. And it's impossible to use a two FlashLoanEnd for a single
FlashLoanBegin for the same reason that isolated FlashLoanEnds are
rejected.
This commit is contained in:
Christian Kamm 2023-08-18 15:37:15 +02:00 committed by GitHub
parent a244c27df6
commit cbc96fe79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -146,14 +146,6 @@ pub fn flash_loan_begin<'key, 'accounts, 'remaining, 'info>(
// Check that the mango program key is not used
if ix.program_id == crate::id() {
// must be the last mango ix -- this could possibly be relaxed, but right now
// we need to guard against multiple FlashLoanEnds
require_msg!(
!found_end,
"the transaction must not contain a Mango instruction after FlashLoanEnd"
);
found_end = true;
// must be the FlashLoanEnd instruction
require!(
ix.data[0..8] == crate::instruction::FlashLoanEndV2::discriminator(),
@ -173,6 +165,13 @@ pub fn flash_loan_begin<'key, 'accounts, 'remaining, 'info>(
for (begin_account, end_account) in begin_accounts.iter().zip(end_accounts.iter()) {
require_msg!(*begin_account.key == end_account.pubkey, "the trailing vault, token and group accounts passed to FlashLoanBegin and End must match, found {} on begin and {} on end", begin_account.key, end_account.pubkey);
}
// No need to check any instructions after the end instruction.
// "Duplicate FlashLoanEnd" is guarded against the same way as "End without Begin":
// The End instruction requires at least one bank-vault pair and that bank
// must have flash_loan_token_account_initial set - which only happens in Begin.
found_end = true;
break;
} else {
// ensure no one can cpi into mango either
for meta in ix.accounts.iter() {