mrgnlabs / marginfi-v2

Apache License 2.0
160 stars 67 forks source link

Flashloans #43

Closed jkbpvsc closed 1 year ago

jkbpvsc commented 1 year ago

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

jkbpvsc commented 1 year ago

I should add one or two more tests, where I deposit a different asset as collateral

jkbpvsc commented 1 year ago

Stale