flash_loan. For a callback that leaves debt on a lending
account, use Flash positions.
Check loan conditions
- The market exists on an active hub and has
is_flashloanable = true. - The protocol is unpaused and the pool has enough cash for the principal.
amountis positive and expressed in token-native units.receiveris a deployed Wasm contract exportingexecute_flash_loan.- No guarded financial operation is already running under the flash-loan guard.
Calculate the fee
The market’sflashloan_fee is in basis points. The fee rounds half-up, with a
one-native-unit minimum when a positive fee would otherwise round to zero.
The maximum configurable rate is 500 BPS (5%).
The pool collects amount + fee and records the fee as protocol revenue.
Read the market parameters before constructing the request, and enforce a
maximum fee in the receiver.
Implement the receiver
The pool transfers the principal, then invokes this callback:amount + fee of the expected asset. Use checked arithmetic for that
total and the allowance expiry. The receiver must hold enough tokens when the
callback returns.
The controller’s FlashLoanOngoing guard blocks reentry into guarded financial
operations, including supply, borrow, withdraw, repay, liquidation, strategies,
and another flash loan. See the security model.
Build and authorize the call
asset selects the market as { hub_id, asset }. data is an opaque payload
forwarded unchanged to the receiver.
@xoxno/sdk-js 1.0.228 for the TypeScript example. caller is the wallet’s
G… public key. The CLI alias caller must resolve to that wallet. CLI
invocation can submit the transaction; use the TypeScript function when your
application needs prepared, unsigned XDR for a wallet.
The example permits no additional caller-authorized receiver calls. If your
receiver needs them, define a narrow StellarAuthPolicy for its exact calls,
recipients, and amount limits. Check every requested signer. Do not disable
validation to accommodate an unexpected authorization tree.
The receiver grants its repayment allowance during the authenticated callback.
Follow Wallet integration to sign the
prepared XDR and persist the original network, signed XDR, and hash before
submission. Resolve an unknown submission outcome by that hash; do not
repeat or replace the loan automatically.
Verify settlement
The controller emitsFlashLoanEvent at ["position", "flash_loan"] with
{ hub_id, asset, receiver, caller, amount, fee }. The pool emits
PoolMarketStateBatchEvent at ["market", "batch_state_update"].
Read the charged fee from FlashLoanEvent. Successful settlement enforces:
Common errors
See the Controller ABI for the public
entrypoint and Pool ABI for pool settlement.

