diff --git a/contracts/ProxyLogics/InstaMaker.sol b/contracts/ProxyLogics/InstaMaker.sol index 688151a..133ed75 100644 --- a/contracts/ProxyLogics/InstaMaker.sol +++ b/contracts/ProxyLogics/InstaMaker.sol @@ -141,9 +141,6 @@ contract CDPResolver is Helpers { TokenInterface weth = tub.gem(); TokenInterface peth = tub.skr(); - (address lad,,,) = tub.cups(cup); - require(lad == address(this), "cup-not-owned"); - weth.deposit.value(msg.value)(); uint ink = rdiv(msg.value, tub.per()); @@ -181,28 +178,28 @@ contract CDPResolver is Helpers { } } - function draw(uint cdpNum, uint wad) public { + function draw(uint cdpNum, uint _wad) public { bytes32 cup = bytes32(cdpNum); - if (wad > 0) { + if (_wad > 0) { TubInterface tub = TubInterface(getSaiTubAddress()); - (address lad,,,) = tub.cups(cup); - require(lad == address(this), "cup-not-owned"); - - tub.draw(cup, wad); - tub.sai().transfer(msg.sender, wad); + tub.draw(cup, _wad); + tub.sai().transfer(msg.sender, _wad); } } - function wipe(uint cdpNum, uint wad) public { - require(wad > 0, "no-wipe-no-dai"); + function wipe( + uint cdpNum, + uint _wad + ) public + { + require(_wad > 0, "no-wipe-no-dai"); TubInterface tub = TubInterface(getSaiTubAddress()); UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange()); UniswapExchange mkrEx = UniswapExchange(getUniswapMKRExchange()); TokenInterface dai = tub.sai(); TokenInterface mkr = tub.gov(); - PepInterface pep = tub.pep(); bytes32 cup = bytes32(cdpNum); @@ -210,15 +207,13 @@ contract CDPResolver is Helpers { setAllowance(mkr, getSaiTubAddress()); setAllowance(dai, getUniswapDAIExchange()); - (bytes32 val, bool ok) = pep.peek(); + (bytes32 val, bool ok) = tub.pep().peek(); // MKR required for wipe = Stability fees accrued in Dai / MKRUSD value - uint mkrFee = wdiv(rmul(wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val)); + uint mkrFee = wdiv(rmul(_wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val)); - uint ethAmt = mkrEx.getEthToTokenOutputPrice(mkrFee); - uint daiAmt = daiEx.getTokenToEthOutputPrice(ethAmt); - - daiAmt = add(wad, daiAmt); + uint daiAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee)); + daiAmt = add(_wad, daiAmt); require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet"); if (ok && val != 0) { @@ -231,7 +226,7 @@ contract CDPResolver is Helpers { ); } - tub.wipe(cup, wad); + tub.wipe(cup, _wad); } function setAllowance(TokenInterface token_, address spender_) private { @@ -245,8 +240,8 @@ contract CDPResolver is Helpers { contract CDPCluster is CDPResolver { - function wipeAndFree(uint cdpNum, uint jam, uint wad) public payable { - wipe(cdpNum, wad); + function wipeAndFree(uint cdpNum, uint jam, uint _wad) public payable { + wipe(cdpNum, _wad); free(cdpNum, jam); } diff --git a/contracts/ProxyLogics/WipeProxy.sol b/contracts/ProxyLogics/WipeProxy.sol index 18130e7..1f94814 100644 --- a/contracts/ProxyLogics/WipeProxy.sol +++ b/contracts/ProxyLogics/WipeProxy.sol @@ -1,16 +1,16 @@ pragma solidity ^0.5.0; -interface TubLike { +interface TubInterface { function wipe(bytes32, uint) external; - function gov() external view returns (TokenLike); - function sai() external view returns (TokenLike); + function gov() external view returns (TokenInterface); + function sai() external view returns (TokenInterface); function tab(bytes32) external returns (uint); function rap(bytes32) external returns (uint); - function pep() external view returns (PepLike); + function pep() external view returns (PepInterface); } -interface TokenLike { +interface TokenInterface { function allowance(address, address) external view returns (uint); function balanceOf(address) external view returns (uint); function approve(address, uint) external; @@ -18,11 +18,11 @@ interface TokenLike { function transferFrom(address, address, uint) external returns (bool); } -interface PepLike { +interface PepInterface { function peek() external returns (bytes32, bool); } -interface UniswapExchangeLike { +interface UniswapExchange { function getEthToTokenOutputPrice(uint256 tokensBought) external view returns (uint256 ethSold); function getTokenToEthOutputPrice(uint256 ethBought) external view returns (uint256 tokensSold); function tokenToTokenSwapOutput( @@ -65,38 +65,44 @@ contract DSMath { contract WipeProxy is DSMath { - function wipeWithDai( - address _tub, - address _daiEx, - address _mkrEx, - uint cupid, - uint wad + function getSaiTubAddress() public pure returns (address sai) { + sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3; + } + + function getUniswapMKRExchange() public pure returns (address ume) { + ume = 0x2C4Bd064b998838076fa341A83d007FC2FA50957; + } + + function getUniswapDAIExchange() public pure returns (address ude) { + ude = 0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14; + } + + function wipe( + uint cdpNum, + uint _wad ) public { - require(wad > 0, "no-wipe-no-dai"); + require(_wad > 0, "no-wipe-no-dai"); - TubLike tub = TubLike(_tub); - UniswapExchangeLike daiEx = UniswapExchangeLike(_daiEx); - UniswapExchangeLike mkrEx = UniswapExchangeLike(_mkrEx); - TokenLike dai = tub.sai(); - TokenLike mkr = tub.gov(); - PepLike pep = tub.pep(); + TubInterface tub = TubInterface(getSaiTubAddress()); + UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange()); + UniswapExchange mkrEx = UniswapExchange(getUniswapMKRExchange()); + TokenInterface dai = tub.sai(); + TokenInterface mkr = tub.gov(); - bytes32 cup = bytes32(cupid); + bytes32 cup = bytes32(cdpNum); - setAllowance(dai, _tub); - setAllowance(mkr, _tub); - setAllowance(dai, _daiEx); + setAllowance(dai, getSaiTubAddress()); + setAllowance(mkr, getSaiTubAddress()); + setAllowance(dai, getUniswapDAIExchange()); - (bytes32 val, bool ok) = pep.peek(); + (bytes32 val, bool ok) = tub.pep().peek(); // MKR required for wipe = Stability fees accrued in Dai / MKRUSD value - uint mkrFee = wdiv(rmul(wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val)); + uint mkrFee = wdiv(rmul(_wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val)); - uint ethAmt = mkrEx.getEthToTokenOutputPrice(mkrFee); - uint daiAmt = daiEx.getTokenToEthOutputPrice(ethAmt); - - daiAmt = add(wad, daiAmt); + uint daiAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee)); + daiAmt = add(_wad, daiAmt); require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet"); if (ok && val != 0) { @@ -109,10 +115,10 @@ contract WipeProxy is DSMath { ); } - tub.wipe(cup, wad); + tub.wipe(cup, _wad); } - function setAllowance(TokenLike token_, address spender_) private { + function setAllowance(TokenInterface token_, address spender_) private { if (token_.allowance(address(this), spender_) != uint(-1)) { token_.approve(spender_, uint(-1)); }