Skip to main content
This example demonstrates a flash loan implementation - a key DeFi primitive that allows uncollateralized borrowing within a single transaction.

Flash Loan Implementation

From examples/move/flash_lender/sources/example.move:

Key Concepts

Hot Potato Pattern

The Receipt struct has no abilities, so it cannot be:
  • Dropped (drop)
  • Stored (store)
  • Copied (copy)
  • Transferred (key)
The ONLY way to get rid of it is to call repay(), forcing loan repayment:

Shared Object for Lending

Makes the lender accessible to everyone.

Admin Capability Pattern

Using Flash Loans

Simple arbitrage example

Testing Flash Loans

From the source code tests:

Deploying Flash Lender

Advanced DeFi Patterns

Liquidity pools

Automated market makers

Best Practices

1. Use hot potato for forced actions

2. Validate repayments

3. Separate concerns with capabilities

4. Emit events for tracking

Next Steps