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

PER Integration Into IonicLiquidator #59

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
"solidity.packageDefaultDependenciesDirectory": "lib"
"solidity.packageDefaultDependenciesDirectory": "lib",
"[solidity]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
35 changes: 33 additions & 2 deletions contracts/IonicLiquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import "./external/uniswap/UniswapV2Library.sol";

import { ICErc20 } from "./compound/CTokenInterfaces.sol";

import "@pythnetwork/express-relay-sdk-solidity/IExpressRelay.sol";
import "@pythnetwork/express-relay-sdk-solidity/IExpressRelayFeeReceiver.sol";

/**
* @title IonicLiquidator
* @author David Lucid <[email protected]> (https://github.com/davidlucid)
* @notice IonicLiquidator safely liquidates unhealthy borrowers (with flashloan support).
* @dev Do not transfer NATIVE or tokens directly to this address. Only send NATIVE here when using a method, and only approve tokens for transfer to here when using a method. Direct NATIVE transfers will be rejected and direct token transfers will be lost.
*/
contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee {
contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee, IExpressRelayFeeReceiver {
using AddressUpgradeable for address payable;
using SafeERC20Upgradeable for IERC20Upgradeable;

Expand Down Expand Up @@ -64,6 +67,23 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee {
*/
uint8 public flashSwapFee;

/**
* @dev Addres of Pyth Express Relay for preventing value leakage in liquidations.
*/
IExpressRelay private expressRelay;

modifier onlyPERPermissioned(
address borrower,
ICErc20 cErc20,
ICErc20 cTokenCollateral
) {
require(
expressRelay.isPermissioned(address(this), abi.encode(borrower, cErc20, cTokenCollateral)),
"invalid liquidation"
);
_;
}

function initialize(
address _wtoken,
address _uniswapV2router,
Expand Down Expand Up @@ -119,7 +139,7 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee {
ICErc20 cErc20,
ICErc20 cTokenCollateral,
uint256 minOutputAmount
) external returns (uint256) {
) external onlyPERPermissioned(borrower, cErc20, cTokenCollateral) 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 Down Expand Up @@ -150,6 +170,7 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee {
*/
function safeLiquidateToTokensWithFlashLoan(LiquidateToTokensWithFlashSwapVars calldata vars)
external
onlyPERPermissioned(vars.borrower, vars.cErc20, vars.cTokenCollateral)
returns (uint256)
{
// Input validation
Expand Down Expand Up @@ -199,6 +220,12 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee {
require(payable(msg.sender).isContract(), "Sender is not a contract.");
}

/**
* @notice receiveAuctionProceedings function - receives native token from the express relay
* You can use permission key to distribute the received funds to users who got liquidated, LPs, etc...
*/
function receiveAuctionProceedings(bytes calldata permissionKey) external payable {}

/**
* @dev Callback function for Uniswap flashloans.
*/
Expand Down Expand Up @@ -419,6 +446,10 @@ contract IonicLiquidator is OwnableUpgradeable, ILiquidator, IUniswapV2Callee {
}
}

function setExpressRelay(IExpressRelay _expressRelay) external onlyOwner {
expressRelay = _expressRelay;
}

/**
* @dev Redeem "special" collateral tokens (before swapping the output for borrowed tokens to be repaid via Uniswap).
* Public visibility because we have to call this function externally if called from a payable IonicLiquidator function (for some reason delegatecall fails when called with msg.value > 0).
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"devDependencies": {
"prettier": "^2.6.2",
"prettier-plugin-solidity": "^1.0.0-beta.19"
},
"dependencies": {
"@pythnetwork/express-relay-sdk-solidity": "^0.2.0"
}
}
3 changes: 2 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
flywheel/=lib/flywheel-v2/src/
solidity-bytes-utils/=lib/solidity-bytes-utils/
@openzeppelin=lib/openzeppelin-contracts/
@pythnetwork/pyth-sdk-solidity/=lib/pyth-sdk-solidity/
@pythnetwork/pyth-sdk-solidity/=lib/pyth-sdk-solidity/
@pythnetwork/express-relay-sdk-solidity/=node_modules/@pythnetwork/express-relay-sdk-solidity
Loading