Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Fix/always permission per #90

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/brockelmore/forge-std
path = lib/forge-std
url = https://github.com/brockelmore/forge-std
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/rari-capital/solmate
[submodule "lib/fuse-flywheel"]
path = lib/fuse-flywheel
url = https://github.com/fei-protocol/fuse-flywheel
path = lib/solmate
url = https://github.com/rari-capital/solmate
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/pyth-sdk-solidity"]
path = lib/pyth-sdk-solidity
url = https://github.com/pyth-network/pyth-sdk-solidity
path = lib/pyth-sdk-solidity
url = https://github.com/pyth-network/pyth-sdk-solidity
[submodule "lib/solidity-bytes-utils"]
path = lib/solidity-bytes-utils
url = https://github.com/GNSPS/solidity-bytes-utils
path = lib/solidity-bytes-utils
url = https://github.com/GNSPS/solidity-bytes-utils
[submodule "lib/ops"]
path = lib/ops
url = https://github.com/gelatodigital/ops
path = lib/ops
url = https://github.com/gelatodigital/ops
[submodule "lib/adrastia-periphery"]
path = lib/adrastia-periphery
url = https://github.com/adrastia-oracle/adrastia-periphery
[submodule "lib/flywheel-v2"]
path = lib/flywheel-v2
url = https://github.com/ionicprotocol/flywheel-v2
path = lib/adrastia-periphery
url = https://github.com/adrastia-oracle/adrastia-periphery
3 changes: 1 addition & 2 deletions chainDeploy/helpers/liquidators/ionicLiquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export const deployIonicUniV3Liquidator = async ({
args: [deployConfig.wtoken, deployConfig.uniswap.uniswapV3Quoter]
}
},
proxyContract: "OpenZeppelinTransparentProxy",
owner: multisig
proxyContract: "OpenZeppelinTransparentProxy"
}
});
if (uniV3Liquidator.transactionHash)
Expand Down
33 changes: 26 additions & 7 deletions contracts/IonicLiquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee, I
*/
uint256 public healthFactorThreshold;

modifier onlyPERPermissioned(address borrower, ICErc20 cToken) {
modifier onlyLowHF(address borrower, ICErc20 cToken) {
uint256 currentHealthFactor = lens.getHealthFactor(borrower, cToken.comptroller());
if (currentHealthFactor > healthFactorThreshold) {
require(expressRelay.isPermissioned(address(this), abi.encode(borrower)), "invalid liquidation");
}
require(currentHealthFactor < healthFactorThreshold, "HF not low enough, reserving for PYTH");
_;
}

Expand Down Expand Up @@ -141,13 +139,13 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee, I
* @param cTokenCollateral The cToken collateral to be liquidated.
* @param minOutputAmount The minimum amount of collateral to seize (or the minimum exchange output if applicable) required for execution. Reverts if this condition is not met.
*/
function safeLiquidate(
function _safeLiquidate(
address borrower,
uint256 repayAmount,
ICErc20 cErc20,
ICErc20 cTokenCollateral,
uint256 minOutputAmount
) external onlyPERPermissioned(borrower, cTokenCollateral) returns (uint256) {
) internal returns (uint256) {
// Transfer tokens in, approve to cErc20, and liquidate borrow
require(repayAmount > 0, "Repay amount (transaction value) must be greater than 0.");
IERC20Upgradeable underlying = IERC20Upgradeable(cErc20.underlying());
Expand All @@ -164,6 +162,27 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee, I
return transferSeizedFunds(address(cTokenCollateral.underlying()), minOutputAmount);
}

function safeLiquidate(
address borrower,
uint256 repayAmount,
ICErc20 cErc20,
ICErc20 cTokenCollateral,
uint256 minOutputAmount
) external onlyLowHF(borrower, cTokenCollateral) returns (uint256) {
return _safeLiquidate(borrower, repayAmount, cErc20, cTokenCollateral, minOutputAmount);
}

function safeLiquidatePyth(
address borrower,
uint256 repayAmount,
ICErc20 cErc20,
ICErc20 cTokenCollateral,
uint256 minOutputAmount
) external returns (uint256) {
require(expressRelay.isPermissioned(address(this), abi.encode(borrower)), "invalid liquidation");
return _safeLiquidate(borrower, repayAmount, cErc20, cTokenCollateral, minOutputAmount);
}

/**
* @dev Transfers seized funds to the sender.
* @param erc20Contract The address of the token to transfer.
Expand All @@ -184,7 +203,7 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee, I
*/
function safeLiquidateToTokensWithFlashLoan(LiquidateToTokensWithFlashSwapVars calldata vars)
external
onlyPERPermissioned(vars.borrower, vars.cTokenCollateral)
onlyLowHF(vars.borrower, vars.cTokenCollateral)
returns (uint256)
{
// Input validation
Expand Down
33 changes: 26 additions & 7 deletions contracts/IonicUniV3Liquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ contract IonicUniV3Liquidator is OwnableUpgradeable, ILiquidator, IUniswapV3Flas
*/
uint256 public healthFactorThreshold;

modifier onlyPERPermissioned(address borrower, ICErc20 cToken) {
modifier onlyLowHF(address borrower, ICErc20 cToken) {
uint256 currentHealthFactor = lens.getHealthFactor(borrower, cToken.comptroller());
if (currentHealthFactor > healthFactorThreshold) {
require(expressRelay.isPermissioned(address(this), abi.encode(borrower)), "invalid liquidation");
}
require(currentHealthFactor < healthFactorThreshold, "HF not low enough, reserving for PYTH");
_;
}

Expand All @@ -88,13 +86,13 @@ contract IonicUniV3Liquidator is OwnableUpgradeable, ILiquidator, IUniswapV3Flas
* @param cTokenCollateral The cToken collateral to be liquidated.
* @param minOutputAmount The minimum amount of collateral to seize (or the minimum exchange output if applicable) required for execution. Reverts if this condition is not met.
*/
function safeLiquidate(
function _safeLiquidate(
address borrower,
uint256 repayAmount,
ICErc20 cErc20,
ICErc20 cTokenCollateral,
uint256 minOutputAmount
) external onlyPERPermissioned(borrower, cTokenCollateral) returns (uint256) {
) internal returns (uint256) {
// Transfer tokens in, approve to cErc20, and liquidate borrow
require(repayAmount > 0, "Repay amount (transaction value) must be greater than 0.");
IERC20Upgradeable underlying = IERC20Upgradeable(cErc20.underlying());
Expand All @@ -111,6 +109,27 @@ contract IonicUniV3Liquidator is OwnableUpgradeable, ILiquidator, IUniswapV3Flas
return transferSeizedFunds(address(cTokenCollateral.underlying()), minOutputAmount);
}

function safeLiquidate(
address borrower,
uint256 repayAmount,
ICErc20 cErc20,
ICErc20 cTokenCollateral,
uint256 minOutputAmount
) external onlyLowHF(borrower, cTokenCollateral) returns (uint256) {
return _safeLiquidate(borrower, repayAmount, cErc20, cTokenCollateral, minOutputAmount);
}

function safeLiquidatePyth(
address borrower,
uint256 repayAmount,
ICErc20 cErc20,
ICErc20 cTokenCollateral,
uint256 minOutputAmount
) external returns (uint256) {
require(expressRelay.isPermissioned(address(this), abi.encode(borrower)), "invalid liquidation");
return _safeLiquidate(borrower, repayAmount, cErc20, cTokenCollateral, minOutputAmount);
}

/**
* @dev Transfers seized funds to the sender.
* @param erc20Contract The address of the token to transfer.
Expand All @@ -127,7 +146,7 @@ contract IonicUniV3Liquidator is OwnableUpgradeable, ILiquidator, IUniswapV3Flas

function safeLiquidateToTokensWithFlashLoan(LiquidateToTokensWithFlashSwapVars calldata vars)
external
onlyPERPermissioned(vars.borrower, vars.cTokenCollateral)
onlyLowHF(vars.borrower, vars.cTokenCollateral)
returns (uint256)
{
// Input validation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.10;

import "./IFlywheelBooster.sol";
import {IFlywheelBooster} from "./IFlywheelBooster.sol";
import { ICErc20 } from "../../../compound/CTokenInterfaces.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";

contract LooplessFlywheelBooster is IFlywheelBooster {
string public constant BOOSTER_TYPE = "LooplessFlywheelBooster";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.10;

import "./BaseFlywheelRewards.sol";
import {BaseFlywheelRewards} from "./BaseFlywheelRewards.sol";
import {IonicFlywheelCore} from "../IonicFlywheelCore.sol";
import {SafeTransferLib, ERC20} from "solmate/utils/SafeTransferLib.sol";
import {SafeCastLib} from "solmate/utils/SafeCastLib.sol";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
pragma solidity ^0.8.10;

import {Auth, Authority} from "solmate/auth/Auth.sol";
import "./BaseFlywheelRewards.sol";
import {BaseFlywheelRewards} from "./BaseFlywheelRewards.sol";
import {ERC20} from "solmate/utils/SafeTransferLib.sol";
import {IonicFlywheelCore} from "../IonicFlywheelCore.sol";

/**
@title Flywheel Static Reward Stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ICERC20 {
function plugin() external returns (address);
}

interface IPlugin {
interface IPlugin_FDR {
function claimRewards() external;
}

Expand All @@ -28,7 +28,7 @@ contract IonicFlywheelDynamicRewardsPlugin is FlywheelDynamicRewards {
override
returns (uint192)
{
IPlugin plugin = IPlugin(ICERC20(address(strategy)).plugin());
IPlugin_FDR plugin = IPlugin_FDR(ICERC20(address(strategy)).plugin());
try plugin.claimRewards() {} catch {}

uint256 rewardAmount = rewardToken.balanceOf(address(strategy));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.10;

import { FlywheelDynamicRewards } from "./FlywheelDynamicRewards.sol";
import { BaseFlywheelRewards } from "./BaseFlywheelRewards.sol";
import { IonicFlywheelCore } from "../IonicFlywheelCore.sol";
import { Auth, Authority } from "solmate/auth/Auth.sol";
import { SafeTransferLib, ERC20 } from "solmate/utils/SafeTransferLib.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.10;

import { FlywheelStaticRewards } from "./FlywheelStaticRewards.sol";
import { BaseFlywheelRewards } from "./BaseFlywheelRewards.sol";
import { IonicFlywheelCore } from "../IonicFlywheelCore.sol";
import { Auth, Authority } from "solmate/auth/Auth.sol";
import { SafeTransferLib, ERC20 } from "solmate/utils/SafeTransferLib.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.10;

import { FlywheelStaticRewards } from "./FlywheelStaticRewards.sol";
import { BaseFlywheelRewards } from "./BaseFlywheelRewards.sol";
import { IonicFlywheelCore } from "../IonicFlywheelCore.sol";
import { Auth, Authority } from "solmate/auth/Auth.sol";
import { SafeTransferLib, ERC20 } from "solmate/utils/SafeTransferLib.sol";
Expand Down
1 change: 0 additions & 1 deletion contracts/test/DeployMarkets.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ERC20 } from "solmate/tokens/ERC20.sol";
import { Auth, Authority } from "solmate/auth/Auth.sol";
import { MockERC20 } from "solmate/test/utils/mocks/MockERC20.sol";
import { IonicFlywheelDynamicRewardsPlugin } from "../ionic/strategies/flywheel/rewards/IonicFlywheelDynamicRewardsPlugin.sol";
import { FlywheelCore } from "flywheel/FlywheelCore.sol";
import { IFlywheelBooster } from "../ionic/strategies/flywheel/IFlywheelBooster.sol";
import { IFlywheelRewards } from "../ionic/strategies/flywheel/rewards/IFlywheelRewards.sol";
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
Expand Down
Loading
Loading