Morpho Blue flash loans require the caller to approve repayment
Morpho Blue flash loans complete only when the calling contract can return the borrowed tokens through an approved repayment pull. The protocol transfers tokens to that contract, runs its callback, and then collects the original amount. Before the callback returns, the contract must hold enough of the same token and give the Blue contract sufficient ERC-20 allowance. A balance or approval in your wallet does not cover repayment from the calling contract. All of this happens within one transaction.
The contract balance and the approved spender
The repayment allowance belongs to a specific token, owner, and spender. Each address must match the pending flash-loan execution.
The balance owner
An ERC-20 balance belongs to an address. During a Blue flash loan, the recipient is the contract that invokes
flashLoan. Its callback executes with the borrowed tokens available at that address.
Blue collects repayment from the contract that called
flashLoan.
Funding an external wallet does not increase that contract's balance. If callback operations move tokens elsewhere, the original caller still needs the repayment amount when control returns. Allowance authorizes spending; it cannot supply missing tokens.
The approved spender
The calling contract grants allowance on the borrowed token to the configured Blue contract. Approving a router or another contract grants a different permission. An approval from your wallet covers that wallet's tokens, even if your wallet started the transaction. Existing allowance can satisfy the requirement if it remains sufficient at the repayment pull.
What happens after Blue transfers the borrowed tokens?
Blue calls
onMorphoFlashLoan(assets, data)
on the same contract that received the tokens, then attempts repayment after that callback returns. The callback runs inside the original execution; there is no later repayment transaction.
Callback inputs
The callback receives the requested amount and arbitrary bytes that the calling contract supplied. The token address is an input to
flashLoan, but not a separate callback argument. The implementation therefore needs a reliable association between its callback data and the selected token. It can retain that address in contract state or encode it in the callback data.
Return to the repayment pull
Callback logic can call other contracts or combine lending operations while the temporary funds remain available. Before returning, it must leave enough of the borrowed token and keep the required allowance in place. An approval can exist before the loan or be established during the callback; repayment depends on its final usable value.
A repayment failure reverts the flash-loan call and its nested operations. An uncaught failure also reverts the enclosing transaction.
Sending tokens back and granting repayment permission
A direct token transfer to Blue does not replace the approval that the repayment pull uses. After a successful callback, the core function attempts
transferFrom
regardless of any earlier token transfer. Sending the principal to Blue during that callback reduces the caller's available balance, while leaving the automatic collection unchanged. If the caller cannot also cover that collection, the call fails.
The relevant comparisons are caller balance versus
assets
and caller-to-Blue allowance versus
assets, using the same token contract. An unlimited approval is not required by the flash-loan interface. An allowance that covers the requested principal suffices for the repayment transfer, provided the token follows the expected transfer rules. Other callback operations can consume balance or allowance, so their effects matter at that boundary.
How much can Blue lend in a flash loan?
Blue can flash-lend up to the selected token's balance at its own contract address when the outgoing transfer executes. This is the aggregate balance of the singleton contract, which holds assets for multiple markets. The available flash-loan balance includes deposited collateral, unborrowed lending assets, and donated tokens of the selected type. A particular market's liquidity figure therefore does not describe the entire flash-loan capacity.
Token balances can change between a preliminary read and execution. The requested amount has to fit the balance at the transfer itself. Borrowing those tokens also temporarily reduces the assets that other callback operations can draw from Blue. A withdrawal inside the same callback can fail if the remaining actual token balance cannot cover it.
Flash loans and collateralized borrowing
A flash loan supplies temporary execution funds without creating a Blue market debt position. Its caller must return the principal in the same transaction. A collateralized market borrow creates debt under that market's collateral and health rules, and the debt can remain after execution. Vault deposits follow a separate share-based allocation model. Neither a market position nor vault shares substitute for the token balance required by the flash-loan pull.
Blue charges no protocol fee for its flash loans. The amount that the core flash-loan function collects equals the requested principal. Transaction gas and fees from external callback operations remain separate costs. A failed transaction can still consume gas. Returning the principal therefore establishes repayment, while any gain or loss depends on the callback's actual asset flows and execution costs.
Callback permissions and token transfer behavior
The borrower contract controls callback access and token handling. Blue's repayment mechanism cannot make an unsafe callback implementation safe.
Authenticate the callback
The callback should reject a sender other than the configured Blue contract. That check authenticates the protocol call; the wrapper's entrypoint still needs its own rules for who may initiate operations and supply instructions. Blue's callback signature contains no separate initiator argument. Retained balances can fund later calls, so arbitrary entrypoint access combined with arbitrary callback instructions can expose those balances to unintended spending.
Handle token return values
Blue's transfer helper accepts successful token calls that return either no data or a true boolean. It rejects calls that revert or return false. This handling covers return-value differences, not every token behavior. The protocol assumes that transfers move the exact specified amount; tokens that deduct transfer fees violate that assumption. A callback's approval handling must also match the selected token's behavior and detect approval failure.
A repayment check before transaction submission
Simulation tests the proposed flash-loan call without committing changes on-chain. Use the intended token, requested
assets, and callback data together, through the actual contract entrypoint. Continue only when the simulation completes the repayment pull and the enclosing call without reverting. A successful simulation applies to the state it used; execution may encounter a different balance or allowance.
- Inspect the simulated callback's ending token balance and the caller's allowance to Blue. Both must cover the requested principal.
- Confirm the callback accepts only the configured Blue sender and the entrypoint restricts instructions as intended.
- Submit the signed transaction only after confirming that its token, amount, callback actions, and spending permissions match the call you simulated.
-
Record a successful transaction receipt with the matching
FlashLoanevent from Blue and the repayment token transfer. - Read the calling contract's remaining token balance and residual allowance after execution, including any funds left available to future calls.
A transaction hash alone establishes no repayment. A confirmed repayment transfer records execution without implying that the callback produced a profit.
Common questions, answered
Can a Blue flash loan request zero assets?
Blue rejects a flash-loan request with zero assets. The check happens before the outgoing transfer and callback. This makes the core flash-loan entrypoint unsuitable as a zero-value callback trigger; contract logic that only needs a callback should not assume this function will run one without a positive amount.
Does empty callback data skip the Blue flash-loan callback?
Empty data does not skip Blue's flash-loan callback. The core function invokes onMorphoFlashLoan for a valid flash loan regardless of the byte array's length. Your callback can still reject empty data if its own decoding logic needs fields. That is a borrower-contract requirement, separate from the protocol's decision to invoke the callback.
Is the Blue flash-loan interface compatible with ERC-3156?
Blue's native flash-loan interface is not ERC-3156 compliant. It uses onMorphoFlashLoan(assets, data) and sends the tokens to its caller. ERC-3156 uses a different callback signature and permits a separately specified receiver. A compatible adapter must translate those interfaces and preserve the repayment approval from whichever contract calls Blue.
What does onMorphoFlashLoan need to return?
The Blue callback has no required return value. Its interface declares onMorphoFlashLoan without a returns clause, and the core contract does not check a success hash. The callback must finish without reverting and leave the repayment pull able to execute. Returning a value cannot compensate for an unusable balance or allowance.
Will setAuthorization create the token allowance for a flash loan?
setAuthorization does not grant the ERC-20 allowance needed for flash-loan repayment. It changes permission to manage positions inside Blue. Token allowance lives on the token contract and identifies a token owner and spender. A workflow that combines a flash loan with position management may need both permissions because they authorize different actions.
Do token decimals change the amount that Blue pulls back?
Token decimals do not change the integer amount that Blue pulls back. The assets parameter uses the token's base units, and the repayment uses that same integer. Displaying an amount in whole tokens requires a separate decimal conversion. An incorrect conversion changes the requested loan size; Blue does not infer the intended display amount.
Why can replacing an existing repayment allowance fail?
Some tokens require an existing allowance to be reset to zero before setting a new nonzero allowance. An approval routine that assumes every token accepts a direct replacement can therefore fail. Apply the selected token's approval semantics within the caller contract, and ensure the resulting allowance exists before the repayment pull. Blue does not perform that approval on your contract's behalf.
Can a later revert cancel a flash loan that has already returned?
A later revert in the enclosing transaction also rolls back an earlier successful flash-loan call. The return from flashLoan shows that the function finished, but subsequent contract logic can still fail. In that case, the enclosing revert discards the loan's token transfers and logs along with its other execution changes. Gas already consumed remains chargeable.