← Contract Hero · WorkLearnPlugins
acc-deepbook-course
All lessons Lesson 3 · DeepBook track

Flash-Loan Arbitrage

Borrow DEEP from a DeepBook pool with no collateral and repay it in the same transaction. Write the Move module that consumes the FlashLoan hot potato, assemble the borrow-use-return PTB, and prove the loan is risk-free: a short repayment reverts everything.

borrowBaseAsset pool::return_flashloan_base arb_executor::execute_base Move package
What you'll learn

A loan the type system makes safe

  • ›The hot-potato pattern: a value with no abilities that the compiler forces you to consume before the transaction ends.
  • ›Atomic borrow and repay in a single PTB, so the pool's liquidity providers bear no risk.
  • ›Publishing a Move package to the sandbox and wiring it into a TypeScript transaction.
Walkthrough

Six sections, end to end

  1. Connect & fund

    Stand up a client and a BalanceManager, and seed the pool vault so the borrow has liquidity to draw.

    src/sandbox.ts
  2. The hot potato

    Meet the FlashLoan value with no drop, store, or key: the compiler will not let you discard it.

    contracts/sources/arb_executor.move
  3. Consume it

    execute_base merges the loan with a top-up, repays the exact principal, and settles the remainder.

    contracts/sources/arb_executor.move
  4. Publish

    Stage the package into the sandbox so its deps resolve, publish it, and write the package id to deployment.json.

    contracts/scripts/deploy.sh · deployment.json
  5. Assemble the PTB

    Borrow the base asset and call your module in one transaction, so borrow and repay are indivisible.

    src/flashLoan.ts
  6. Drive it & prove atomicity

    The live gate asserts a short repayment reverts inside your module, not at the borrow step.

    src/App.tsx · src/main.tsx
Run it

Start this lesson

claude code
/acc-deepbook-course:start
# then pick "Flash-Loan Arbitrage"

Already installed? Run the start command and choose this lesson from the catalog.

New here? Follow the install steps first. The course brings up a local sandbox and gates each section with pnpm vitest run.