-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
177 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// Gearbox Protocol. Generalized leverage for DeFi protocols | ||
// (c) Gearbox Foundation, 2024 | ||
pragma solidity ^0.8.10; | ||
|
||
import {AbstractLiquidator, LiquidationResult, IntermediateData} from "./AbstractLiquidator.sol"; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeERC20} from "@1inch/solidity-utils/contracts/libraries/SafeERC20.sol"; | ||
|
||
import {AaveFLTaker} from "./AaveFLTaker.sol"; | ||
|
||
contract AaveLiquidator is AbstractLiquidator { | ||
using SafeERC20 for IERC20; | ||
|
||
address public immutable aavePool; | ||
address public immutable aaveFLTaker; | ||
|
||
modifier onlyAave() { | ||
if (msg.sender != aavePool) revert("Caller not Aave pool"); | ||
_; | ||
} | ||
|
||
constructor(address _router, address _plb, address _aavePool, address _aaveFLTaker) | ||
AbstractLiquidator(_router, _plb) | ||
{ | ||
aavePool = _aavePool; | ||
aaveFLTaker = _aaveFLTaker; | ||
} | ||
|
||
function _takeFlashLoan(address underlying, uint256 amount, bytes memory data) internal virtual override { | ||
AaveFLTaker(aaveFLTaker).takeFlashLoan(underlying, amount, data); | ||
} | ||
|
||
function executeOperation( | ||
address[] memory assets, | ||
uint256[] memory amounts, | ||
uint256[] memory premiums, | ||
address initiator, | ||
bytes calldata params | ||
) external onlyAave returns (bool) { | ||
if (initiator != aaveFLTaker) revert("Flash loan initiator is not FLTaker"); | ||
|
||
IntermediateData memory intData = abi.decode(params, (IntermediateData)); | ||
|
||
_processFlashLoan(assets[0], amounts[0], premiums[0], intData); | ||
|
||
IERC20(assets[0]).forceApprove(aavePool, amounts[0] + premiums[0]); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pragma solidity ^0.8.17; | ||
|
||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import {IGhoFlashMinter} from "./interfaces/IGhoFlashMinter.sol"; | ||
|
||
contract GhoFMTaker is Ownable { | ||
event SetAllowedFMReceiver(address indexed consumer, bool status); | ||
|
||
error CallerNotAllowedReceiverException(); | ||
|
||
address public immutable ghoFlashMinter; | ||
address public immutable gho; | ||
|
||
mapping(address => bool) public allowedFMReceiver; | ||
|
||
modifier onlyAllowedFMReceiver() { | ||
if (!allowedFMReceiver[msg.sender]) revert CallerNotAllowedReceiverException(); | ||
_; | ||
} | ||
|
||
constructor(address _ghoFlashMinter, address _gho) { | ||
ghoFlashMinter = _ghoFlashMinter; | ||
gho = _gho; | ||
} | ||
|
||
function takeFlashMint(uint256 amount, bytes memory data) external onlyAllowedFMReceiver { | ||
IGhoFlashMinter(ghoFlashMinter).flashLoan(msg.sender, gho, amount, data); | ||
} | ||
|
||
function setAllowedFMReceiver(address receiver, bool status) external onlyOwner { | ||
if (allowedFMReceiver[receiver] == status) return; | ||
allowedFMReceiver[receiver] = status; | ||
emit SetAllowedFMReceiver(receiver, status); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// Gearbox Protocol. Generalized leverage for DeFi protocols | ||
// (c) Gearbox Foundation, 2024 | ||
pragma solidity ^0.8.10; | ||
|
||
import {AbstractLiquidator, LiquidationResult, IntermediateData} from "./AbstractLiquidator.sol"; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeERC20} from "@1inch/solidity-utils/contracts/libraries/SafeERC20.sol"; | ||
|
||
import {GhoFMTaker} from "./GhoFMTaker.sol"; | ||
|
||
contract GhoLiquidator is AbstractLiquidator { | ||
using SafeERC20 for IERC20; | ||
|
||
bytes32 public constant CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan"); | ||
|
||
address public immutable ghoFlashMinter; | ||
address public immutable ghoFMTaker; | ||
address public immutable gho; | ||
|
||
modifier onlyGhoFlashMinter() { | ||
if (msg.sender != ghoFlashMinter) revert("Caller not GHO flash minter"); | ||
_; | ||
} | ||
|
||
constructor(address _router, address _plb, address _ghoFlashMinter, address _ghoFMTaker, address _gho) | ||
AbstractLiquidator(_router, _plb) | ||
{ | ||
ghoFlashMinter = _ghoFlashMinter; | ||
ghoFMTaker = _ghoFMTaker; | ||
gho = _gho; | ||
} | ||
|
||
function _takeFlashLoan(address, uint256 amount, bytes memory data) internal virtual override { | ||
GhoFMTaker(ghoFMTaker).takeFlashMint(amount, data); | ||
} | ||
|
||
function onFlashLoan(address initiator, address token, uint256 amount, uint256 fee, bytes calldata data) | ||
external | ||
onlyGhoFlashMinter | ||
returns (bytes32) | ||
{ | ||
if (initiator != ghoFMTaker) revert("Flash loan initiator is not FMTaker"); | ||
|
||
IntermediateData memory intData = abi.decode(data, (IntermediateData)); | ||
|
||
_processFlashLoan(token, amount, fee, intData); | ||
|
||
IERC20(token).forceApprove(ghoFlashMinter, amount + fee); | ||
|
||
return CALLBACK_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// Gearbox Protocol. Generalized leverage for DeFi protocols | ||
// (c) Gearbox Foundation, 2024 | ||
pragma solidity ^0.8.10; | ||
|
||
interface IGhoFlashMinter { | ||
function flashLoan(address receiver, address token, uint256 amount, bytes calldata data) external returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters