From 69ff3e1146811f34cf4e2b8ed43191226d958f86 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Wed, 28 Nov 2018 01:26:22 +0530 Subject: [PATCH 1/5] Added feature - lock ETH in CDP without being the owner. --- contracts/protocols/InstaMaker.sol | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/contracts/protocols/InstaMaker.sol b/contracts/protocols/InstaMaker.sol index b5bfffc..89cdad6 100644 --- a/contracts/protocols/InstaMaker.sol +++ b/contracts/protocols/InstaMaker.sol @@ -113,13 +113,14 @@ contract IssueLoan is GlobalVar { } function borrow(uint daiDraw) public payable { - if (msg.value > 0) {lockETH();} + if (msg.value > 0) {lockETH(msg.sender);} if (daiDraw > 0) {drawDAI(daiDraw);} } - function lockETH() public payable { + function lockETH(address borrower) public payable { MakerCDP loanMaster = MakerCDP(cdpAddr); - if (cdps[msg.sender] == blankCDP) { + if (cdps[borrower] == blankCDP) { + require(msg.sender == borrower, "Creating CDP for others is not permitted at the moment."); cdps[msg.sender] = loanMaster.open(); emit NewCDP(msg.sender, cdps[msg.sender]); } @@ -127,9 +128,9 @@ contract IssueLoan is GlobalVar { wethTkn.deposit.value(msg.value)(); // ETH to WETH uint pethToLock = pethPEReth(msg.value); loanMaster.join(pethToLock); // WETH to PETH - loanMaster.lock(cdps[msg.sender], pethToLock); // PETH to CDP + loanMaster.lock(cdps[borrower], pethToLock); // PETH to CDP emit LockedETH( - msg.sender, msg.value, pethToLock, msg.sender + borrower, msg.value, pethToLock, msg.sender ); } From 054f069baaef504555f4ee42c853a88164037e2a Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Wed, 28 Nov 2018 01:41:04 +0530 Subject: [PATCH 2/5] Added feature - wipe CDP DAI without being the owner. --- contracts/protocols/InstaMaker.sol | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contracts/protocols/InstaMaker.sol b/contracts/protocols/InstaMaker.sol index 89cdad6..e7513b2 100644 --- a/contracts/protocols/InstaMaker.sol +++ b/contracts/protocols/InstaMaker.sol @@ -148,15 +148,15 @@ contract IssueLoan is GlobalVar { contract RepayLoan is IssueLoan { - event WipedDAI(address borrower, uint daiWipe, uint mkrCharged); + event WipedDAI(address borrower, uint daiWipe, uint mkrCharged, address wipedBy); event UnlockedETH(address borrower, uint ethFree); function repay(uint daiWipe, uint ethFree) public payable { - if (daiWipe > 0) {wipeDAI(daiWipe);} + if (daiWipe > 0) {wipeDAI(daiWipe, msg.sender);} if (ethFree > 0) {unlockETH(ethFree);} } - function wipeDAI(uint daiWipe) public payable { + function wipeDAI(uint daiWipe, address borrower) public payable { address dai = getAddress("dai"); address mkr = getAddress("mkr"); address eth = getAddress("eth"); @@ -167,7 +167,7 @@ contract RepayLoan is IssueLoan { uint contractMKR = mkrTkn.balanceOf(address(this)); // contract MKR balance before wiping daiTkn.transferFrom(msg.sender, address(this), daiWipe); // get DAI to pay the debt MakerCDP loanMaster = MakerCDP(cdpAddr); - loanMaster.wipe(cdps[msg.sender], daiWipe); // wipe DAI + loanMaster.wipe(cdps[borrower], daiWipe); // wipe DAI uint mkrCharged = contractMKR - mkrTkn.balanceOf(address(this)); // MKR fee = before wiping bal - after wiping bal // claiming paid MKR back @@ -179,7 +179,9 @@ contract RepayLoan is IssueLoan { mkrTkn.transferFrom(msg.sender, address(this), mkrCharged); // user paying MKR fees } - emit WipedDAI(msg.sender, daiWipe, mkrCharged); + emit WipedDAI( + borrower, daiWipe, mkrCharged, msg.sender + ); } function unlockETH(uint ethFree) public { From a6b326be90842905a3847c2f22d22d2bc9632212 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Wed, 28 Nov 2018 03:32:53 +0530 Subject: [PATCH 3/5] Returning bytes32 of CDP with getCDPID. --- contracts/protocols/InstaMaker.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/protocols/InstaMaker.sol b/contracts/protocols/InstaMaker.sol index e7513b2..779bd67 100644 --- a/contracts/protocols/InstaMaker.sol +++ b/contracts/protocols/InstaMaker.sol @@ -237,8 +237,8 @@ contract BorrowTasks is RepayLoan { return uint(ethrate).div(10**18); } - function getCDPID(address borrower) public view returns (uint) { - return uint(cdps[borrower]); + function getCDPID(address borrower) public view returns (uint, bytes32) { + return (uint(cdps[borrower]), cdps[borrower]); } function approveERC20() public { From ddbd6ec836e28eb56fc8847ef32d99602334dad9 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Wed, 28 Nov 2018 03:36:53 +0530 Subject: [PATCH 4/5] Minor change. --- contracts/protocols/InstaMaker.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/protocols/InstaMaker.sol b/contracts/protocols/InstaMaker.sol index 779bd67..2db77d1 100644 --- a/contracts/protocols/InstaMaker.sol +++ b/contracts/protocols/InstaMaker.sol @@ -95,7 +95,7 @@ contract GlobalVar is Registry { bytes32 public blankCDP = 0x0000000000000000000000000000000000000000000000000000000000000000; address cdpAddr; // cups - mapping (address => bytes32) public cdps; // borrower >>> CDP Bytes + mapping (address => bytes32) cdps; // borrower >>> CDP Bytes bool public freezed; } @@ -237,7 +237,7 @@ contract BorrowTasks is RepayLoan { return uint(ethrate).div(10**18); } - function getCDPID(address borrower) public view returns (uint, bytes32) { + function getCDP(address borrower) public view returns (uint, bytes32) { return (uint(cdps[borrower]), cdps[borrower]); } From 8982df94824b536698a3e3d303ed971062a4de56 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Wed, 28 Nov 2018 03:40:14 +0530 Subject: [PATCH 5/5] Made blackCDP bytes32 non-public. --- contracts/protocols/InstaMaker.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/protocols/InstaMaker.sol b/contracts/protocols/InstaMaker.sol index 2db77d1..d8f0d4d 100644 --- a/contracts/protocols/InstaMaker.sol +++ b/contracts/protocols/InstaMaker.sol @@ -93,7 +93,7 @@ contract GlobalVar is Registry { using SafeMath for uint; using SafeMath for uint256; - bytes32 public blankCDP = 0x0000000000000000000000000000000000000000000000000000000000000000; + bytes32 blankCDP = 0x0000000000000000000000000000000000000000000000000000000000000000; address cdpAddr; // cups mapping (address => bytes32) cdps; // borrower >>> CDP Bytes bool public freezed;