mirror of
				https://github.com/Instadapp/smart-contract.git
				synced 2024-07-29 22:08:07 +00:00 
			
		
		
		
	comment and code clean up
This commit is contained in:
		
							parent
							
								
									c9acfc00c5
								
							
						
					
					
						commit
						e60fbc3033
					
				| 
						 | 
					@ -263,6 +263,12 @@ contract MakerHelper is Helper {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function isCupOwner(bytes32 cup) internal view returns(bool isOwner) {
 | 
				
			||||||
 | 
					        TubInterface tub = TubInterface(getSaiTubAddress());
 | 
				
			||||||
 | 
					        (address lad,,,) = tub.cups(cup);
 | 
				
			||||||
 | 
					        isOwner = lad == address(this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function getCDPStats(bytes32 cup) public view returns (uint ethCol, uint daiDebt) {
 | 
					    function getCDPStats(bytes32 cup) public view returns (uint ethCol, uint daiDebt) {
 | 
				
			||||||
        TubInterface tub = TubInterface(getSaiTubAddress());
 | 
					        TubInterface tub = TubInterface(getSaiTubAddress());
 | 
				
			||||||
        (, uint pethCol, uint debt,) = tub.cups(cup);
 | 
					        (, uint pethCol, uint debt,) = tub.cups(cup);
 | 
				
			||||||
| 
						 | 
					@ -270,6 +276,11 @@ contract MakerHelper is Helper {
 | 
				
			||||||
        daiDebt = debt;
 | 
					        daiDebt = debt;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @dev get final Ratio of Maker CDP
 | 
				
			||||||
 | 
					     * @param ethCol amount of ETH Col to add in existing Col
 | 
				
			||||||
 | 
					     * @param daiDebt amount of DAI Debt to add in existing Debt
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    function getMakerRatio(bytes32 cup, uint ethCol, uint daiDebt) public view returns (uint ratio) {
 | 
					    function getMakerRatio(bytes32 cup, uint ethCol, uint daiDebt) public view returns (uint ratio) {
 | 
				
			||||||
        (uint makerCol, uint makerDebt) = getCDPStats(cup);
 | 
					        (uint makerCol, uint makerDebt) = getCDPStats(cup);
 | 
				
			||||||
        makerCol += ethCol;
 | 
					        makerCol += ethCol;
 | 
				
			||||||
| 
						 | 
					@ -284,6 +295,26 @@ contract MakerHelper is Helper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
contract CompoundHelper is MakerHelper {
 | 
					contract CompoundHelper is MakerHelper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    event LogMint(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
				
			||||||
 | 
					    event LogRedeem(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
				
			||||||
 | 
					    event LogBorrow(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
				
			||||||
 | 
					    event LogRepay(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function isCompoundOk(bytes32 cup, uint ethCol, uint daiAmt) internal returns (bool isOk) {
 | 
				
			||||||
 | 
					        uint daiCompOracle = CompOracleInterface(getCompOracleAddress()).getUnderlyingPrice(getCDAIAddress()); // DAI in ETH
 | 
				
			||||||
 | 
					        uint debtInEth = wmul(daiAmt, daiCompOracle);
 | 
				
			||||||
 | 
					        if (ethCol == 0) {
 | 
				
			||||||
 | 
					            (ethCol,) = getCDPStats(cup);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        (, uint totalBorrow, uint maxBorrow,) = getCompRatio(address(this));
 | 
				
			||||||
 | 
					        totalBorrow += debtInEth;
 | 
				
			||||||
 | 
					        maxBorrow += wmul(ethCol, 750000000000000000);
 | 
				
			||||||
 | 
					        isOk = totalBorrow < maxBorrow;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @dev get users overall details for Compound
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    function getCompRatio(address user) public returns (uint totalSupply, uint totalBorrow, uint maxBorrow, uint ratio) {
 | 
					    function getCompRatio(address user) public returns (uint totalSupply, uint totalBorrow, uint maxBorrow, uint ratio) {
 | 
				
			||||||
        BridgeInterface bridgeContract = BridgeInterface(getBridgeAddress());
 | 
					        BridgeInterface bridgeContract = BridgeInterface(getBridgeAddress());
 | 
				
			||||||
        uint arrLength = bridgeContract.cArrLength();
 | 
					        uint arrLength = bridgeContract.cArrLength();
 | 
				
			||||||
| 
						 | 
					@ -304,11 +335,9 @@ contract CompoundHelper is MakerHelper {
 | 
				
			||||||
        ratio = wdiv(totalBorrow, totalSupply);
 | 
					        ratio = wdiv(totalBorrow, totalSupply);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    event LogMint(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
					    /**
 | 
				
			||||||
    event LogRedeem(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
					     * @dev get users overall and basic stats for Compound
 | 
				
			||||||
    event LogBorrow(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
					     */
 | 
				
			||||||
    event LogRepay(address erc20, address cErc20, uint tokenAmt, address owner);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    function getCompoundStats(address user) public returns (uint ethColFree, uint daiDebt, uint totalSupply, uint totalBorrow, uint maxBorrow, uint daiInEth) {
 | 
					    function getCompoundStats(address user) public returns (uint ethColFree, uint daiDebt, uint totalSupply, uint totalBorrow, uint maxBorrow, uint daiInEth) {
 | 
				
			||||||
        CTokenInterface cEthContract = CTokenInterface(getCETHAddress());
 | 
					        CTokenInterface cEthContract = CTokenInterface(getCETHAddress());
 | 
				
			||||||
        CERC20Interface cDaiContract = CERC20Interface(getCDAIAddress());
 | 
					        CERC20Interface cDaiContract = CERC20Interface(getCDAIAddress());
 | 
				
			||||||
| 
						 | 
					@ -362,9 +391,6 @@ contract MakerResolver is CompoundHelper {
 | 
				
			||||||
            TokenInterface weth = tub.gem();
 | 
					            TokenInterface weth = tub.gem();
 | 
				
			||||||
            TokenInterface peth = tub.skr();
 | 
					            TokenInterface peth = tub.skr();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            (address lad,,,) = tub.cups(cup);
 | 
					 | 
				
			||||||
            require(lad == address(this), "cup-not-owned");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            weth.deposit.value(ethAmt)();
 | 
					            weth.deposit.value(ethAmt)();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            uint ink = rdiv(ethAmt, tub.per());
 | 
					            uint ink = rdiv(ethAmt, tub.per());
 | 
				
			||||||
| 
						 | 
					@ -433,9 +459,6 @@ contract MakerResolver is CompoundHelper {
 | 
				
			||||||
            TokenInterface dai = tub.sai();
 | 
					            TokenInterface dai = tub.sai();
 | 
				
			||||||
            TokenInterface mkr = tub.gov();
 | 
					            TokenInterface mkr = tub.gov();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            (address lad,,,) = tub.cups(cup);
 | 
					 | 
				
			||||||
            require(lad == address(this), "cup-not-owned");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            setMakerAllowance(dai, getSaiTubAddress());
 | 
					            setMakerAllowance(dai, getSaiTubAddress());
 | 
				
			||||||
            setMakerAllowance(mkr, getSaiTubAddress());
 | 
					            setMakerAllowance(mkr, getSaiTubAddress());
 | 
				
			||||||
            setMakerAllowance(dai, getUniswapDAIExchange());
 | 
					            setMakerAllowance(dai, getUniswapDAIExchange());
 | 
				
			||||||
| 
						 | 
					@ -448,16 +471,7 @@ contract MakerResolver is CompoundHelper {
 | 
				
			||||||
            uint daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
 | 
					            uint daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
 | 
				
			||||||
            daiAmt = add(_wad, daiFeeAmt);
 | 
					            daiAmt = add(_wad, daiFeeAmt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // compound final status and get DAI from bridge
 | 
					            require(isCompoundOk(cup, ethCol, daiAmt), "Compound Will Liquidate");
 | 
				
			||||||
            uint daiCompOracle = CompOracleInterface(getCompOracleAddress()).getUnderlyingPrice(getCDAIAddress()); // DAI in ETH
 | 
					 | 
				
			||||||
            uint debtInEth = wmul(daiAmt, daiCompOracle);
 | 
					 | 
				
			||||||
            if (ethCol == 0) {
 | 
					 | 
				
			||||||
                (ethCol,) = getCDPStats(cup);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            (, uint totalBorrow, uint maxBorrow,) = getCompRatio(address(this));
 | 
					 | 
				
			||||||
            totalBorrow += debtInEth;
 | 
					 | 
				
			||||||
            maxBorrow += wmul(ethCol, 750000000000000000);
 | 
					 | 
				
			||||||
            require(totalBorrow < maxBorrow, "Compound will liquidate");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            BridgeInterface(getBridgeAddress()).transferDAI(daiAmt);
 | 
					            BridgeInterface(getBridgeAddress()).transferDAI(daiAmt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -520,7 +534,7 @@ contract CompoundResolver is MakerResolver {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @dev borrow ETH/ERC20
 | 
					     * @dev borrow DAI
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    function borrowDAIComp(uint tokenAmt) internal {
 | 
					    function borrowDAIComp(uint tokenAmt) internal {
 | 
				
			||||||
        enterMarket(getCDAIAddress());
 | 
					        enterMarket(getCDAIAddress());
 | 
				
			||||||
| 
						 | 
					@ -536,7 +550,7 @@ contract CompoundResolver is MakerResolver {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @dev Pay Debt ERC20
 | 
					     * @dev Pay DAI Debt
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    function repayToken(uint tokenAmt) internal {
 | 
					    function repayToken(uint tokenAmt) internal {
 | 
				
			||||||
        CERC20Interface cToken = CERC20Interface(getCDAIAddress());
 | 
					        CERC20Interface cToken = CERC20Interface(getCDAIAddress());
 | 
				
			||||||
| 
						 | 
					@ -552,7 +566,7 @@ contract CompoundResolver is MakerResolver {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @dev Redeem ETH/ERC20 and mint Compound Tokens
 | 
					     * @dev Redeem ETH and mint Compound Tokens
 | 
				
			||||||
     * @param tokenAmt Amount of token To Redeem
 | 
					     * @param tokenAmt Amount of token To Redeem
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    function redeemUnderlying(uint tokenAmt) internal {
 | 
					    function redeemUnderlying(uint tokenAmt) internal {
 | 
				
			||||||
| 
						 | 
					@ -578,6 +592,7 @@ contract Bridge is CompoundResolver {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    function makerToCompound(uint cdpId, uint toConvert) public {
 | 
					    function makerToCompound(uint cdpId, uint toConvert) public {
 | 
				
			||||||
        bytes32 cup = bytes32(cdpId);
 | 
					        bytes32 cup = bytes32(cdpId);
 | 
				
			||||||
 | 
					        isCupOwner(cup);
 | 
				
			||||||
        (uint ethCol, uint daiDebt) = getCDPStats(cup);
 | 
					        (uint ethCol, uint daiDebt) = getCDPStats(cup);
 | 
				
			||||||
        uint ethFree = ethCol;
 | 
					        uint ethFree = ethCol;
 | 
				
			||||||
        uint daiAmt = daiDebt;
 | 
					        uint daiAmt = daiDebt;
 | 
				
			||||||
| 
						 | 
					@ -603,9 +618,7 @@ contract Bridge is CompoundResolver {
 | 
				
			||||||
        if (cdpId == 0) {
 | 
					        if (cdpId == 0) {
 | 
				
			||||||
            cup = open();
 | 
					            cup = open();
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            TubInterface tub = TubInterface(getSaiTubAddress());
 | 
					            require(isCupOwner(cup), "Not CDP Owner");
 | 
				
			||||||
            (address lad,,,) = tub.cups(cup);
 | 
					 | 
				
			||||||
            require(lad == address(this), "cup-not-owned");
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        (uint ethCol, uint daiDebt,, uint totalBorrow, uint maxBorrow, uint daiInEth) = getCompoundStats(address(this));
 | 
					        (uint ethCol, uint daiDebt,, uint totalBorrow, uint maxBorrow, uint daiInEth) = getCompoundStats(address(this));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user