deepbookv3-flash-loans
Installation
SKILL.md
DeepBook V3: Flash Loans
Flash loans are uncollateralized loans that must be borrowed and fully repaid within the same Programmable Transaction Block (PTB). Users can borrow the base asset or the quote asset from any DeepBook V3 pool.
1. Key Concepts
Hot-Potato Pattern
- DeepBook V3 utilizes Move's unique safety guarantees via a "hot-potato" struct.
- The
FlashLoanstruct represents the receipt. It has no abilities (nodrop,store,key, orcopy). - Because a struct without
dropcannot be discarded or ignored, the Move compiler and virtual machine enforce that theFlashLoanobject must be consumed by the end of the transaction. The only way to consume it is to pass it to the corresponding repayment function.
Mechanics & Constraints
- Maximum Borrow Amount: You can borrow up to the maximum amount of base/quote assets currently held in the pool's vault.
- Atomicity: The borrow and repayment occur in the same transaction. If any step fails or the repayment is insufficient, the entire transaction is reverted.
- Intra-Pool Trading Conflict: Borrowing from a pool and trading on that same pool within the same PTB can result in transaction failures. Trading requires liquidity movement within the vault; if that liquidity is borrowed, the pool may lack the funds to settle the trade.