Description
We previously scaffolded the fee for flash loans, but to actually execute them, we need a standard cross-contract callback interface.
When a borrower requests a flash loan, our contract must send them the tokens, and then immediately call a specific execute_operation function on their smart contract.
If their contract fails to return the principal plus the fee by the end of that specific call, our contract must panic and revert the entire ledger state.
This is complex, synchronous DeFi architecture that requires deep knowledge of Soroban's cross-contract invocation.
Requirements
Description
We previously scaffolded the fee for flash loans, but to actually execute them, we need a standard cross-contract callback interface.
When a borrower requests a flash loan, our contract must send them the tokens, and then immediately call a specific
execute_operationfunction on their smart contract.If their contract fails to return the principal plus the fee by the end of that specific call, our contract must panic and revert the entire ledger state.
This is complex, synchronous DeFi architecture that requires deep knowledge of Soroban's cross-contract invocation.
Requirements
FlashLoanReceivertrait that external borrower contracts must implement.flash_loanfunction to transfer the requested tokens to the borrower's address.env.invoke_contract()to trigger the borrower's callback function.>=the balance before the loan + the flash loan fee.