Flash Loan
Borrow and repay within one Sui transaction using lending_core::lending.
The four functions below are in lending_core::lending. Choose the pair for the transaction sender or the pair for an AccountCap. Borrowing returns a balance and a receipt. Repayment consumes that receipt in the same transaction and returns any balance left after principal and fees.
The Move source aliases lending_core::flash_loan::Config as FlashLoanConfig and lending_core::flash_loan::Receipt as FlashLoanReceipt.
flash_loan_with_ctx_v2
Borrow for the transaction sender.
public fun flash_loan_with_ctx_v2<CoinType>(
config: &FlashLoanConfig,
pool: &mut Pool<CoinType>,
amount: u64,
system_state: &mut SuiSystemState,
ctx: &mut TxContext,
): (Balance<CoinType>, FlashLoanReceipt<CoinType>)flash_repay_with_ctx
Pass the receipt, the repayment balance and the same sender's transaction context.
public fun flash_repay_with_ctx<CoinType>(
clock: &Clock,
storage: &mut Storage,
pool: &mut Pool<CoinType>,
receipt: FlashLoanReceipt<CoinType>,
repay_balance: Balance<CoinType>,
ctx: &mut TxContext,
): Balance<CoinType>flash_loan_with_account_cap_v2
Borrow on behalf of the account represented by the cap. Keep the receipt for the matching repayment.
public fun flash_loan_with_account_cap_v2<CoinType>(
config: &FlashLoanConfig,
pool: &mut Pool<CoinType>,
amount: u64,
account_cap: &AccountCap,
system_state: &mut SuiSystemState,
ctx: &mut TxContext,
): (Balance<CoinType>, FlashLoanReceipt<CoinType>)flash_repay_with_account_cap
Repay using the same cap and pool. Use or transfer the returned surplus balance.
public fun flash_repay_with_account_cap<CoinType>(
clock: &Clock,
storage: &mut Storage,
pool: &mut Pool<CoinType>,
receipt: FlashLoanReceipt<CoinType>,
repay_balance: Balance<CoinType>,
account_cap: &AccountCap,
): Balance<CoinType>