Skip to content

Commit

Permalink
feat: remove liquidate
Browse files Browse the repository at this point in the history
  • Loading branch information
shriyatyagii committed Jun 4, 2024
1 parent 78aa785 commit 066eff1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 99 deletions.
9 changes: 0 additions & 9 deletions contracts/mainnet/connectors/compound/v2/events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,4 @@ contract Events {
uint256 getId,
uint256 setId
);

event LogLiquidate(
address indexed borrower,
address indexed tokenToPay,
address indexed tokenInReturn,
uint256 tokenAmt,
uint256 getId,
uint256 setId
);
}
90 changes: 0 additions & 90 deletions contracts/mainnet/connectors/compound/v2/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -405,96 +405,6 @@ abstract contract CompoundConnector is Events, Helpers {
(address token, address cToken) = compMapping.getMapping(tokenId);
(_eventName, _eventParam) = withdrawCTokenRaw(token, cToken, cTokenAmt, getId, setId);
}

/**
* @dev Liquidate a position.
* @notice Liquidate a position.
* @param borrower Borrower's Address.
* @param tokenToPay The address of the token to pay for liquidation.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param cTokenPay Corresponding cToken address.
* @param tokenInReturn The address of the token to return for liquidation.
* @param cTokenColl Corresponding cToken address.
* @param amt The token amount to pay for liquidation.
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of paid for liquidation.
*/
function liquidateRaw(
address borrower,
address tokenToPay,
address cTokenPay,
address tokenInReturn,
address cTokenColl,
uint256 amt,
uint256 getId,
uint256 setId
) public payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = getUint(getId, amt);
require(tokenToPay != address(0) && cTokenPay != address(0), "invalid token/ctoken address");
require(tokenInReturn != address(0) && cTokenColl != address(0), "invalid token/ctoken address");

CTokenInterface cTokenContract = CTokenInterface(cTokenPay);

{
(,, uint shortfal) = troller.getAccountLiquidity(borrower);
require(shortfal != 0, "account-cannot-be-liquidated");
_amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(borrower) : _amt;
}

if (tokenToPay == ethAddr) {
require(address(this).balance >= _amt, "not-enought-eth");
CETHInterface(cTokenPay).liquidateBorrow{value: _amt}(borrower, cTokenColl);
} else {
TokenInterface tokenContract = TokenInterface(tokenToPay);
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
approve(tokenContract, cTokenPay, _amt);
require(cTokenContract.liquidateBorrow(borrower, _amt, cTokenColl) == 0, "liquidate-failed");
}

setUint(setId, _amt);

_eventName = "LogLiquidate(address,address,address,uint256,uint256,uint256)";
_eventParam = abi.encode(
address(this),
tokenToPay,
tokenInReturn,
_amt,
getId,
setId
);
}

/**
* @dev Liquidate a position using the mapping.
* @notice Liquidate a position using the mapping.
* @param borrower Borrower's Address.
* @param tokenIdToPay token id of the token to pay for liquidation.(For eg: ETH-A)
* @param tokenIdInReturn token id of the token to return for liquidation.(For eg: USDC-A)
* @param amt token amount to pay for liquidation.
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of paid for liquidation.
*/
function liquidate(
address borrower,
string calldata tokenIdToPay,
string calldata tokenIdInReturn,
uint256 amt,
uint256 getId,
uint256 setId
) external payable returns (string memory _eventName, bytes memory _eventParam) {
(address tokenToPay, address cTokenToPay) = compMapping.getMapping(tokenIdToPay);
(address tokenInReturn, address cTokenColl) = compMapping.getMapping(tokenIdInReturn);

(_eventName, _eventParam) = liquidateRaw(
borrower,
tokenToPay,
cTokenToPay,
tokenInReturn,
cTokenColl,
amt,
getId,
setId
);
}
}

contract ConnectV2Compound is CompoundConnector {
Expand Down

0 comments on commit 066eff1

Please sign in to comment.