Use casesHow it worksDocsLaunch app

Blog · November 4, 2026

Why the borrow has to see the repay

There is no callback here, so a flash loan is two instructions — and the first one has to prove the second exists.

Most flash loans elsewhere are callbacks: the lender sends funds, calls your code, and checks its balance when your code returns. Here a program cannot be re-entered mid-chain, and cross-program invocation stops at depth 4. There is no place to hang a callback.

So Wedesak splits the loan into two top-level instructions. The borrow runs first and, before it moves a lamport, reads the Instructions sysvar to find a repay later in the same transaction for the same reserve, mint and borrower. If it is not there, the borrow fails and the runtime rolls everything back.

Two details matter more than they look. The borrow must reject being called through CPI — otherwise a wrapper program could satisfy the check in ways the lender never sees. And the match must be on accounts, not on an absolute instruction index, or a second loan in the same transaction can borrow the first loan's repay.

← All posts