diff --git a/contracts/bridges/MakerCompound.sol b/contracts/bridges/MakerCompound.sol index 0471986..b686ae4 100644 --- a/contracts/bridges/MakerCompound.sol +++ b/contracts/bridges/MakerCompound.sol @@ -64,17 +64,17 @@ contract DSMath { contract Helper is DSMath { - address public adminAdd = 0x7284a8451d9a0e7Dc62B3a71C0593eA2eC5c5638; address public daiAdd = 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359; address public cDaiAdd = 0xF5DCe57282A584D2746FaF1593d3121Fcac444dC; address public registryAdd = 0xF5DCe57282A584D2746FaF1593d3121Fcac444dC; - mapping (address => uint) deposited; // Amount of CToken deposited + mapping (address => uint) public deposited; // Amount of CToken deposited + mapping (address => bool) public isAdmin; /** * @dev setting allowance to compound for the "user proxy" if required */ function setApproval(address erc20, uint srcAmt, address to) public { - require(msg.sender == adminAdd, "Not-Admin"); + require(isAdmin[msg.sender] == true, "Not-Admin"); ERC20Interface erc20Contract = ERC20Interface(erc20); uint tokenAllowance = erc20Contract.allowance(address(this), to); if (srcAmt > tokenAllowance) { @@ -88,11 +88,24 @@ contract Helper is DSMath { contract Bridge is Helper { function depositDAI(uint amt) public { - ERC20Interface tokenContract = ERC20Interface(daiAdd); - uint toDeposit = amt; - tokenContract.transferFrom(msg.sender, address(this), toDeposit); + ERC20Interface(daiAdd).transferFrom(msg.sender, address(this), amt); CTokenInterface cToken = CTokenInterface(cDaiAdd); - assert(cToken.mint(toDeposit) == 0); + assert(cToken.mint(amt) == 0); + uint cDaiAmt = wdiv(amt, cToken.exchangeRateCurrent()); + deposited[msg.sender] += cDaiAmt; + } + + function withdrawDAI(uint amt) public { + CTokenInterface cToken = CTokenInterface(cDaiAdd); + uint withdrawAmt = wdiv(amt, cToken.exchangeRateCurrent()); + uint daiAmt = amt; + if (withdrawAmt > deposited[msg.sender]) { + withdrawAmt = deposited[msg.sender]; + daiAmt = wmul(withdrawAmt, cToken.exchangeRateCurrent()); + } + require(cToken.redeem(withdrawAmt) == 0, "something went wrong"); + ERC20Interface(daiAdd).transfer(msg.sender, daiAmt); + deposited[msg.sender] -= withdrawAmt; } function depositCDAI(uint amt) public { @@ -102,6 +115,7 @@ contract Bridge is Helper { } function withdrawCDAI(uint amt) public { + require(deposited[msg.sender] != 0, "something went wrong"); CTokenInterface cToken = CTokenInterface(cDaiAdd); uint withdrawAmt = amt; if (withdrawAmt > deposited[msg.sender]) { @@ -138,6 +152,8 @@ contract MakerCompBridge is Bridge { * 1...2...3 versioning in each subsequent deployments */ constructor(uint _version) public { + isAdmin[0x7284a8451d9a0e7Dc62B3a71C0593eA2eC5c5638] = true; + isAdmin[0xa7615CD307F323172331865181DC8b80a2834324] = true; version = _version; }