For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Flash Loan

A flash loan lets you borrow assets from a lending pool without collateral, as long as the loan plus the fee is returned within the same transaction. If the loan is not repaid, the whole transaction fails.

Common use cases are arbitrage, refinancing a position and self-liquidation.

Check the Flash Loan Fee

The fee is returned as a decimal rate (e.g. 0.0005 is 0.05%). The amount you repay must cover the loan amount plus this fee.

import { ScallopQuery } from '@scallop-io/sui-scallop-sdk';

const scallopQuery = new ScallopQuery({
  addressId: '695fcdc084f790c04eb068dc',
  fullnodeUrl: 'https://fullnode.mainnet.sui.io:443',
  walletAddress: '0x...',
});

await scallopQuery.init();

const amount = 10 * 1e9; // 10 SUI
const fees = await scallopQuery.getFlashLoanFees(['sui']);
const fee = amount * fees.sui;

Borrow and Repay a Flash Loan

Using ScallopClient

The callback receives the transaction block and the borrowed coin. It must return the coin that is used to repay, which must contain the loan amount plus the fee.

Using ScallopBuilder

borrowFlashLoan returns the borrowed coin and a loan receipt. The receipt must be passed to repayFlashLoan in the same transaction.

Was this helpful?