2ī¸Flash Loan

An uncollateralized loan in NAVI that must be repaid within the same Sui transaction.

The following functions provide users the ability to take out and repay flash loans from a specified pool. A flash loan allows users to borrow assets with the condition that the loan must be repaid within the same Sui transaction. If the loan is not fully repaid, the transaction reverts, ensuring that no loss occurs for the pool.

flashloan_with_ctx

This function allows a user to take out a flash loan of a specified amount of a certain coin type from a pool. The loan must be repaid within the same transaction. A FlashLoanReceipt is generated to keep track of the loan details.

public fun flash_loan_with_ctx<CoinType>(
    config: &FlashLoanConfig, 
    pool: &mut Pool<CoinType>, 
    amount: u64, 
    ctx: &mut TxContext
): (Balance<CoinType>, FlashLoanReceipt<CoinType>)

example:

https://suivision.xyz/txblock/8LfrMrZL5msEvYWtayX8ELXZJRnXGnzZJSBgTjfsah5Y

repay_with_ctx

This function handles the repayment of a flash loan. It takes in the loan receipt, the repayment balance object, and updates the pool's balance accordingly. If the loan is not repaid in full, the transaction will revert. The rest will be returned as a balance object.

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>

example:

https://suivision.xyz/txblock/8LfrMrZL5msEvYWtayX8ELXZJRnXGnzZJSBgTjfsah5Y

flashloan_with_account_cap

This function facilitates the repayment of a flash loan while leveraging an AccountCap. It adjusts the pool’s balance and ensures the loan is settled. If the loan is not fully repaid, the transaction will revert. The rest will be returned as a balance object.

public fun flash_loan_with_account_cap<CoinType>(
    config: &FlashLoanConfig, 
    pool: &mut Pool<CoinType>, 
    amount: u64, 
    account_cap: &AccountCap
): (Balance<CoinType>, FlashLoanReceipt<CoinType>)

example:

https://suivision.xyz/txblock/8LfrMrZL5msEvYWtayX8ELXZJRnXGnzZJSBgTjfsah5Y

repay_with_account_cap

This function allows a user to take out a flash loan while utilizing an AccountCap. The AccountCap serves as an agent layer during the loan process. The function returns both the loan balance and the receipt for tracking the loan.

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
)

example:

https://suivision.xyz/txblock/8LfrMrZL5msEvYWtayX8ELXZJRnXGnzZJSBgTjfsah5Y

Last updated