Added withdrawCToken to set tokenAmt instead of ctokenAmt

This commit is contained in:
Thrilok Kumar 2020-11-27 20:18:08 +05:30
parent 09973b9221
commit 1731d63601

View File

@ -190,7 +190,7 @@ contract BasicResolver is CompoundHelpers {
TokenInterface tokenContract = TokenInterface(token); TokenInterface tokenContract = TokenInterface(token);
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
tokenContract.approve(cToken, _amt); tokenContract.approve(cToken, _amt);
require(CTokenInterface(cToken).mint(_amt) == 0, "borrow-failed"); require(CTokenInterface(cToken).mint(_amt) == 0, "deposit-failed");
} }
setUint(setId, _amt); setUint(setId, _amt);
@ -286,7 +286,7 @@ contract BasicResolver is CompoundHelpers {
contract ExtraResolver is BasicResolver { contract ExtraResolver is BasicResolver {
event LogClaimedComp(uint256 compAmt, uint256 setId); event LogClaimedComp(uint256 compAmt, uint256 setId);
event LogDepositCToken(address indexed token, address cToken, uint256 tokenAmt, uint256 cTokenAmt,uint256 getId, uint256 setId); event LogDepositCToken(address indexed token, address cToken, uint256 tokenAmt, uint256 cTokenAmt,uint256 getId, uint256 setId);
event LogWithdrawCToken(address indexed token, address cToken, uint256 cTokenAmt, uint256 getId, uint256 setId); event LogWithdrawCToken(address indexed token, address cToken, uint256 tokenAmt, uint256 cTokenAmt, uint256 getId, uint256 setId);
event LogLiquidate( event LogLiquidate(
address indexed borrower, address indexed borrower,
address indexed tokenToPay, address indexed tokenToPay,
@ -296,26 +296,6 @@ contract ExtraResolver is BasicResolver {
uint256 setId uint256 setId
); );
/**
* @dev Claim Accrued COMP Token.
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
*/
function ClaimComp(uint setId) external payable {
TokenInterface compToken = TokenInterface(getCompTokenAddress());
uint intialBal = compToken.balanceOf(address(this));
ComptrollerInterface(getComptrollerAddress()).claimComp(address(this));
uint finalBal = compToken.balanceOf(address(this));
uint amt = sub(finalBal, intialBal);
setUint(setId, amt);
emit LogClaimedComp(amt, setId);
bytes32 _eventCode = keccak256("LogClaimedComp(uint256,uint256)");
bytes memory _eventParam = abi.encode(amt, setId);
(uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
}
/** /**
* @dev Deposit ETH/ERC20_Token. * @dev Deposit ETH/ERC20_Token.
* @param token token address to depositCToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token token address to depositCToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
@ -357,19 +337,25 @@ contract ExtraResolver is BasicResolver {
* @param token token address to withdraw CToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token token address to withdraw CToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param cTokenAmt ctoken amount to withdrawCToken. * @param cTokenAmt ctoken amount to withdrawCToken.
* @param getId Get ctoken amount at this ID from `InstaMemory` Contract. * @param getId Get ctoken amount at this ID from `InstaMemory` Contract.
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract. * @param setId Set token amount at this ID in `InstaMemory` Contract.
*/ */
function withdrawCToken(address token, uint cTokenAmt, uint getId, uint setId) external payable { function withdrawCToken(address token, uint cTokenAmt, uint getId, uint setId) external payable {
uint _amt = getUint(getId, cTokenAmt); uint _cAmt = getUint(getId, cTokenAmt);
address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token);
CTokenInterface cTokenContract = CTokenInterface(cToken); CTokenInterface cTokenContract = CTokenInterface(cToken);
_amt = _amt == uint(-1) ? cTokenContract.balanceOf(address(this)) : _amt; TokenInterface tokenContract = TokenInterface(token);
require(cTokenContract.redeem(_amt) == 0, "redeem-failed"); _cAmt = _cAmt == uint(-1) ? cTokenContract.balanceOf(address(this)) : _cAmt;
setUint(setId, _amt);
emit LogWithdrawCToken(token, cToken, _amt, getId, setId); uint initialBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
bytes32 _eventCode = keccak256("LogWithdrawCToken(address,address,uint256,uint256,uint256)"); require(cTokenContract.redeem(_cAmt) == 0, "redeem-failed");
bytes memory _eventParam = abi.encode(token, cToken, _amt, getId, setId); uint finalBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
uint withdrawAmt = sub(finalBal, initialBal);
setUint(setId, withdrawAmt);
emit LogWithdrawCToken(token, cToken, withdrawAmt, _cAmt, getId, setId);
bytes32 _eventCode = keccak256("LogWithdrawCToken(address,address,uint256,uint256,uint256,uint256)");
bytes memory _eventParam = abi.encode(token, cToken, withdrawAmt, _cAmt, getId, setId);
(uint _type, uint _id) = connectorID(); (uint _type, uint _id) = connectorID();
EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam); EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam);
@ -438,5 +424,5 @@ contract ExtraResolver is BasicResolver {
contract ConnectCompound is ExtraResolver { contract ConnectCompound is ExtraResolver {
string public name = "Compound-v1.2"; string public name = "Compound-v1.3";
} }