From 0961d7f427c73fda5445d29857eaf7bb018bb9c1 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Sun, 28 Oct 2018 22:29:07 +0530 Subject: [PATCH] Restructured Maker Code. --- contracts/MoatAddress.sol | 13 ++++++-- contracts/MoatResolver.sol | 3 +- contracts/protocols/MoatMaker.sol | 52 +++++++++++++++---------------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/contracts/MoatAddress.sol b/contracts/MoatAddress.sol index 819e48b..6020ff5 100644 --- a/contracts/MoatAddress.sol +++ b/contracts/MoatAddress.sol @@ -1,4 +1,5 @@ // addresses name - address, asset, resolver, moatkyber, moatmaker, admin +// I guess, only keep admin and owner pragma solidity ^0.4.24; @@ -24,11 +25,18 @@ contract AddressRegistry { } -contract ManageRegistry is AddressRegistry { +contract ManageGovernors is AddressRegistry { using SafeMath for uint; using SafeMath for uint256; + // set governors function goes here with logics + +} + + +contract ManageRegistry is ManageGovernors { + address public pendingAdmin; uint public pendingTime; @@ -45,6 +53,7 @@ contract ManageRegistry is AddressRegistry { ); pendingAdmin = newAddr; pendingTime = block.timestamp.add(24 * 60 * 60); // adding 24 hours + emit AddressChanged(name, newAddr); } else { require( msg.sender == getAddr("admin"), @@ -88,4 +97,4 @@ contract InitRegistry is ManageResolvers { registry[keccak256(abi.encodePacked("admin"))] = msg.sender; } -} +} \ No newline at end of file diff --git a/contracts/MoatResolver.sol b/contracts/MoatResolver.sol index e85da5c..c8f18a8 100644 --- a/contracts/MoatResolver.sol +++ b/contracts/MoatResolver.sol @@ -33,6 +33,7 @@ contract FeeDetail is Registry { function setFees(uint cut) public onlyAdmin { // 200 means 0.5% fees = cut; } + } @@ -45,7 +46,7 @@ contract MoatResolver is FeeDetail { setFees(cut); } - function collectToken(address tokenAddress, uint amount) public onlyAdmin { + function collectAssets(address tokenAddress, uint amount) public onlyAdmin { if (tokenAddress == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) { msg.sender.transfer(amount); } else { diff --git a/contracts/protocols/MoatMaker.sol b/contracts/protocols/MoatMaker.sol index 2adb7ab..f6c3f78 100644 --- a/contracts/protocols/MoatMaker.sol +++ b/contracts/protocols/MoatMaker.sol @@ -1,10 +1,3 @@ -// mechanism to transfer an existing CDP (2 txn process) -// MKR fee when wiped DAI - buy MRK from OasisDEX onchain maybe -// global variable to freeze operations like stop locking & drawing -// (Think again) -// // store MKR tokens on contract by yourself and charge user 1% instead for now -// // [Best] Instead user should keep MKR & transferFrom & deduct & return the balance back in 1 Txn - pragma solidity 0.4.24; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; @@ -88,6 +81,8 @@ contract GlobalVar is Registry { mapping (address => bytes32) public cdps; // borrower >>> CDP Bytes + bool public freezed; // freeze few important tasks + } @@ -107,12 +102,8 @@ contract IssueLoan is GlobalVar { cdps[borrower] = loanMaster.open(); emit OpenedNewCDP(borrower, cdps[borrower]); } - if (ethLock > 0) { - lockETH(borrower, ethLock); - } - if (daiDraw > 0) { - drawDAI(borrower, daiDraw); - } + if (ethLock > 0) lockETH(borrower, ethLock); + if (daiDraw > 0) drawDAI(borrower, daiDraw); } function lockETH(address borrower, uint ethLock) public payable { @@ -125,6 +116,7 @@ contract IssueLoan is GlobalVar { } function drawDAI(address borrower, uint daiDraw) public onlyUserOrResolver(borrower) { + require(!freezed, "Operation Disabled"); loanMaster.draw(cdps[borrower], daiDraw); uint fees = deductFees(daiDraw); IERC20 tokenFunctions = IERC20(dai); @@ -157,43 +149,48 @@ contract RepayLoan is IssueLoan { function repay( address borrower, uint daiWipe, + uint mkrFees, uint ethFree ) public onlyUserOrResolver(borrower) { - if (daiWipe > 0) { - wipeDAI(borrower, daiWipe); - } - if (ethFree > 0) { - unlockETH(borrower, ethFree); - } + if (daiWipe > 0) wipeDAI(borrower, daiWipe, mkrFees); + if (ethFree > 0) unlockETH(borrower, ethFree); } - function wipeDAI(address borrower, uint daiWipe) public { - IERC20 tokenFunction = IERC20(dai); - tokenFunction.transferFrom(msg.sender, address(this), daiWipe); + function wipeDAI(address borrower, uint daiWipe, uint mkrFees) public { + + // MKR tokens to pay the debt fees + // difference between MKR fees and transferred amount stays with contract + IERC20 mkrToken = IERC20(mkr); + mkrToken.transferFrom(borrower, address(this), mkrFees); + + // DAI to pay the debt + IERC20 daiToken = IERC20(dai); + daiToken.transferFrom(borrower, address(this), daiWipe); loanMaster.wipe(cdps[borrower], daiWipe); + emit WipedDAI(borrower, daiWipe); } function unlockETH(address borrower, uint ethFree) public onlyUserOrResolver(borrower) { + require(!freezed, "Operation Disabled"); uint pethToUnlock = ratioedPETH(ethFree); loanMaster.free(cdps[borrower], pethToUnlock); // CDP to PETH loanMaster.exit(pethToUnlock); // PETH to WETH WETHFace wethFunction = WETHFace(weth); wethFunction.withdraw(ethFree); // WETH to ETH - msg.sender.transfer(ethFree); + borrower.transfer(ethFree); emit UnlockedETH(borrower, ethFree); } - // function freeETH - // free(bytes32 cup, uint wad) - } contract BorrowTasks is RepayLoan { - // transfer existing CDP 2 txn process + function freeze(bool stop) public onlyAdmin { + freezed = stop; + } function claimCDP(address nextOwner) public { require(nextOwner != 0, "Invalid Address."); @@ -210,6 +207,7 @@ contract BorrowTasks is RepayLoan { IERC20 daiTkn = IERC20(dai); daiTkn.approve(cdpAddr, 2**256 - 1); } + }