From bc66c2452dd99f929b2e9d67c19b71c1e810acbb Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Mon, 29 Oct 2018 19:23:35 +0530 Subject: [PATCH] Implemented SafeMath. --- contracts/protocols/MoatKyber.sol | 4 ++-- contracts/protocols/MoatMaker.sol | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/protocols/MoatKyber.sol b/contracts/protocols/MoatKyber.sol index 9a59d27..4b0f337 100644 --- a/contracts/protocols/MoatKyber.sol +++ b/contracts/protocols/MoatKyber.sol @@ -76,8 +76,8 @@ contract Trade is Registry { uint ethQty; uint feecut; if (fees > 0) { - feecut = srcAmt / fees; - sellQty = srcAmt - feecut; + feecut = div(srcAmt, fees); + sellQty = sub(srcAmt, feecut); } // fetch token & deduct fees diff --git a/contracts/protocols/MoatMaker.sol b/contracts/protocols/MoatMaker.sol index c5eaac1..ff54860 100644 --- a/contracts/protocols/MoatMaker.sol +++ b/contracts/protocols/MoatMaker.sol @@ -79,7 +79,7 @@ contract IssueLoan is GlobalVar { event OpenedNewCDP(address borrower, bytes32 cdpBytes); function pethPEReth(uint ethNum) public view returns (uint rPETH) { - rPETH = ethNum * (10 ** 27) / loanMaster.per(); + rPETH = div(mul(ethNum, 10 ** 27), loanMaster.per()); } function borrow(uint daiDraw) public payable { @@ -105,13 +105,13 @@ contract IssueLoan is GlobalVar { loanMaster.draw(cdps[msg.sender], daiDraw); uint feecut = deductFees(daiDraw); IERC20 daiTkn = IERC20(getAddress("dai")); - daiTkn.transfer(msg.sender, daiDraw - feecut); + daiTkn.transfer(msg.sender, sub(daiDraw, feecut)); emit LoanedDAI(msg.sender, daiDraw, feecut); } function deductFees(uint volume) internal returns(uint brokerage) { if (fees > 0) { - brokerage = volume / fees; + brokerage = div(volume, fees); IERC20 daiTkn = IERC20(getAddress("dai")); daiTkn.transfer(getAddress("admin"), brokerage); } @@ -174,7 +174,7 @@ contract BorrowTasks is RepayLoan { PriceInterface ethRate = PriceInterface(getAddress("price")); bytes32 ethrate; (ethrate, ) = ethRate.peek(); - return (uint(ethrate) / 10**18); + return div(uint(ethrate), 10**18); } function getCDPID(address borrower) public view returns (uint) {