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

flash loans #95

Merged
merged 27 commits into from
Aug 31, 2022
Merged

flash loans #95

merged 27 commits into from
Aug 31, 2022

Conversation

0xripleys
Copy link

@0xripleys 0xripleys commented Jul 22, 2022

Port of #70 + some tweaks

Quick Summary: You can now flash borrow funds from a reserve in instruction i as long as you flash repay the funds + fees in instruction j where i < j.

Couple of things to note:

  1. I deprecated the old flash loan instruction. I don't think there's an exploit, but better to be safe than sorry.
  2. There can only be 1 flash borrow/repay per transaction. This constraint might be relaxed later.
  3. the flash repay instruction needs to know the index of the flash borrow instruction. this is to prevent lone flash repays in a transaction
  4. I am also considering adding the requirement flash_borrow.destination_liquidity_info == flash_repay.source_liquidity_info, for extra safety.

@codecov-commenter
Copy link

codecov-commenter commented Jul 25, 2022

Codecov Report

Attention: Patch coverage is 86.80445% with 166 lines in your changes missing coverage. Please review.

Project coverage is 81.37%. Comparing base (1feaffc) to head (c108e99).
Report is 31 commits behind head on upcoming.

Files with missing lines Patch % Lines
token-lending/program/tests/flash_borrow_repay.rs 88.72% 91 Missing ⚠️
token-lending/program/src/processor.rs 78.59% 55 Missing ⚠️
...-lending/program/tests/helpers/flash_loan_proxy.rs 89.85% 14 Missing ⚠️
token-lending/program/src/instruction.rs 90.19% 5 Missing ⚠️
token-lending/program/src/state/reserve.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           upcoming      #95      +/-   ##
============================================
- Coverage     81.85%   81.37%   -0.48%     
============================================
  Files            32       33       +1     
  Lines          7681     8633     +952     
============================================
+ Hits           6287     7025     +738     
- Misses         1394     1608     +214     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@0xripleys 0xripleys changed the title (WIP) flash loans flash loans Jul 27, 2022
@0xripleys 0xripleys requested a review from nope-finance August 1, 2022 17:43
msg!("Instruction: Flash Loan");
process_flash_loan(program_id, amount, accounts)
msg!("This instruction has been deprecated. Use FlashBorrowReserveLiquidity instead");
Err(LendingError::DeprecatedInstruction.into())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess will change other place to do like this too

@nope-finance nope-finance merged commit aeedc87 into upcoming Aug 31, 2022
@nope-finance nope-finance deleted the 0xripleys_flash_loan branch August 31, 2022 00:47
@nope-finance nope-finance mentioned this pull request Sep 1, 2022
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.

3 participants