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.
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.
Six sections, end to end
-
Connect & fund
Stand up a client and a BalanceManager, and seed the pool vault so the borrow has liquidity to draw.
src/sandbox.ts -
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 -
Consume it
execute_base merges the loan with a top-up, repays the exact principal, and settles the remainder.
contracts/sources/arb_executor.move -
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 -
Assemble the PTB
Borrow the base asset and call your module in one transaction, so borrow and repay are indivisible.
src/flashLoan.ts -
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
Start this lesson
/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.