Skip to content
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

Flashloans #121

Merged
merged 48 commits into from
Jan 3, 2024
Merged

Flashloans #121

merged 48 commits into from
Jan 3, 2024

Conversation

jkbpvsc
Copy link
Member

@jkbpvsc jkbpvsc commented Jul 15, 2023

Flashloans

  • Flashloans only work for accounts that have a flag manually set for them by a group admin

How they work

Flashloans work by deferring health checks for an account to the end of the flashloan. This is achieved with two new instructions. flashloan_start and flashloan_end.

  • flashloan_start - performs a number of security checks, set the IN_FLASHLOAN_FLAG
  • flashloan_end - checks the account health, and clears the IN_FLASHLOAN_FLAG

Security checklist

  1. end_flashloan ix index is after start_flashloan ix index
  2. Ixs has an end_flashloan ix present
  3. end_flashloan ix is for the marginfi program
  4. end_flashloan ix is for the same marginfi account
  5. Account is not disabled
  6. Account is not already in a flashloan

Considerations

  • What happens if you flashloan multiple accounts in a single tx?
  • Can you corrupt bank parameters by artificially changing the utilization rate in a bank.

@jkbpvsc
Copy link
Member Author

jkbpvsc commented Sep 10, 2023

One consideration I'm having is if we should have all the borrows and repays happen in the fl_start and fl_end ixs, to prevent any unexpected combinations of flashloan ixs and bank state updates.
Thoughts @losman0s?

@jkbpvsc jkbpvsc merged commit 14fac27 into main Jan 3, 2024
4 checks passed
jkbpvsc added a commit that referenced this pull request Oct 15, 2024
* feat: flashloans

* fix: RiskEngine constructor

* fix: clippy fix

* fix: test setup, set account flags ixs

* fix: flashloans test

* fix: more tests

* fix: even more tests

* fix: fmt + anchor lint

* fix: fmt

* fix: cli imports

* feat: reworked risk engine value calculations

* fix: update imports, correct log name

* fix: fix indexer

* fix: use correct oracle type for price bands

* fix: format

* fix: again with cyrills unreasonable demands

* fix: check start and end flashloan ixs are not in CPI

* fix: add tests

* fix: fmt

* fix: update indexer, and cli

* fix: fuzz tests

* fix: fuzzer generation

* fix: fuzz github action

* fix: action

* fix: actions

* fix: temp disabled manual actions

* fix: install cargo fuzz

* fix: gha

* fix: assert start and end fl ix are not in CPI

* fix: nit

---------

Co-authored-by: j <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant