From 195eaa84562fc8d7f6dbadb1ba40c3560e30a0ab Mon Sep 17 00:00:00 2001 From: Samyak Jain Date: Thu, 20 Jun 2019 22:45:02 +0530 Subject: [PATCH] maker to compound max --- contracts/bridges/MakerCompound.sol | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/contracts/bridges/MakerCompound.sol b/contracts/bridges/MakerCompound.sol index 7bef29f..0e85a61 100644 --- a/contracts/bridges/MakerCompound.sol +++ b/contracts/bridges/MakerCompound.sol @@ -360,9 +360,19 @@ contract MakerResolver is CompoundResolver { } } - function wipeAndFree(uint cdpNum, uint jam, uint _wad) internal returns (uint daiAmt) { - daiAmt = wipe(cdpNum, _wad); - free(cdpNum, jam); + function getCDPStats(bytes32 cup) internal returns (uint ethCol, uint daiDebt) { + TubInterface tub = TubInterface(sai); + ethCol = rmul(tub.ink(cup), tub.per()); // get ETH col from PETH col + daiDebt = tub.tab(cup); + } + + function wipeAndFree(uint cdpNum, uint jam, uint _wad) internal returns (uint ethAmt, uint daiAmt) { + (uint ethCol, uint daiDebt) = getCDPStats(bytes32(cdpNum)); + daiDebt = _wad < daiDebt ? _wad : daiDebt; // if DAI amount > max debt. Set max debt + ethCol = jam < ethCol ? jam : ethCol; // if ETH amount > max Col. Set max col + daiAmt = wipe(cdpNum, daiDebt); + ethAmt = ethCol; + free(cdpNum, ethCol); } function lockAndDraw(uint cdpNum, uint jam, uint _wad) internal { @@ -472,8 +482,9 @@ contract Bridge is LiquidityProvider { * @dev MakerDAO to Compound */ function makerToCompound(uint cdpId, uint ethCol, uint daiDebt) public payable isUserWallet returns (uint daiAmt) { - daiAmt = wipeAndFree(cdpId, ethCol, daiDebt); - mintCETH(ethCol); + uint ethAmt = ethCol; + (ethAmt, daiAmt) = wipeAndFree(cdpId, ethCol, daiDebt); + mintCETH(ethAmt); give(cdpId, msg.sender); }