Skip to content

[contracts] CharonLiquidator: Aave flashLoanSimple + Venus liquidate + PancakeSwap V3 swap #13

@obchain

Description

@obchain

Context

Core atomic execution. Inside one transaction: flash-borrow the debt token from Aave V3 → call VToken.liquidateBorrow → swap seized collateral → repay the flash loan → forward profit. If anything fails, the whole transaction reverts — zero capital risk.

Scope

  • executeLiquidation(LiquidationParams params) — external entry point, onlyOwner
  • Invokes AavePool.flashLoanSimple(address(this), debtToken, amount, data, 0)
  • executeOperation callback:
    1. Approve VToken to pull debtToken
    2. Call VToken.liquidateBorrow(borrower, repayAmount, collateralVToken)
    3. Redeem seized collateralVToken for underlying
    4. Swap underlying → debt token via PancakeSwap V3 exactInputSingle
    5. Approve Aave to pull principal + premium
    6. Transfer profit remainder to owner()
  • Slippage guard on the swap (minAmountOut parameter)
  • Revert reasons for every failure mode (documented)

Acceptance criteria

  • forge build passes
  • Unit test: full flow on a forked BSC block with a real underwater position
  • Gas usage documented (target: < 600k gas per liquidation)
  • Slippage exceeded → tx reverts atomically, no state change
  • Owner receives profit > 0 for a profitable fork scenario

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions