In a flashloan health checks of a marginfi account are done once at the end of the transaction.
This gives the user much more flexiblity in how to use the marginfi.
This works throug 2 mechanisms.
One mechanism is diabling health checks on the marignfi account during the flashloan,
and the other mechanism is ensuring that the health check is performed by the end of the flashloan.
This achieved with two instructions:
Flashloan Start: This instruction sets a flag on the marginfi account to disable health checks, and the verifies that a valid corresponding Flashloan End instruction exists in the same transaction.
Flashloan End: Sets a flag to enable health checks on a marginfi account, and perfoms an intialization health check.
The Flashloan Start additionally checks that the marginfi account isn't already in a flashloan and the Flashloan End checks that the account is in a flashloan,
I'm not aware of any attack vectors this is covering, its mostly there as a sanity check, and will prevent multiple flashloans overlapping.
Assumptions enforced by this check
There exists a flashloan end instruction (FE) in the transaction.
The FE is for the same program.
The FE is positioned after the current instruction (flashloan start - FS) in the transaction.
The FE is matched by the FE instruction discriminator.
The FE and FS are for the same marginfi account, the FE ix has the marginfi account positioned at the IXS_SYSVAR_MARGINFI_ACCOUNT_INDEX (1) in the account metas.
Flashloans
Flashloan security model
In a flashloan health checks of a marginfi account are done once at the end of the transaction. This gives the user much more flexiblity in how to use the marginfi.
This works throug 2 mechanisms. One mechanism is diabling health checks on the marignfi account during the flashloan, and the other mechanism is ensuring that the health check is performed by the end of the flashloan.
This achieved with two instructions:
The Flashloan Start additionally checks that the marginfi account isn't already in a flashloan and the Flashloan End checks that the account is in a flashloan, I'm not aware of any attack vectors this is covering, its mostly there as a sanity check, and will prevent multiple flashloans overlapping.
Assumptions enforced by this check