mirror of
				https://github.com/Instadapp/smart-contract.git
				synced 2024-07-29 22:08:07 +00:00 
			
		
		
		
	added max to compound to maker
This commit is contained in:
		
							parent
							
								
									195eaa8456
								
							
						
					
					
						commit
						0d1d08ff95
					
				|  | @ -74,6 +74,7 @@ interface CETHInterface { | ||||||
| interface CDAIInterface { | interface CDAIInterface { | ||||||
|     function mint(uint mintAmount) external returns (uint); // For ERC20 |     function mint(uint mintAmount) external returns (uint); // For ERC20 | ||||||
|     function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint); |     function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint); | ||||||
|  |     function borrowBalanceCurrent(address account) external returns (uint); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -207,11 +208,30 @@ contract CompoundResolver is Helper { | ||||||
|             CTokenInterface cToken = CTokenInterface(cEth); |             CTokenInterface cToken = CTokenInterface(cEth); | ||||||
|             uint cTokenAmt = wdiv(ethAmt, cToken.exchangeRateCurrent()); |             uint cTokenAmt = wdiv(ethAmt, cToken.exchangeRateCurrent()); | ||||||
|             uint cEthBal = cToken.balanceOf(msg.sender); |             uint cEthBal = cToken.balanceOf(msg.sender); | ||||||
|             cTokenAmt = cEthBal > cTokenAmt ? cTokenAmt : cTokenAmt - 1; |             cTokenAmt = cEthBal >= cTokenAmt ? cTokenAmt : cTokenAmt - 1; | ||||||
|             require(ERC20Interface(cEth).transferFrom(msg.sender, address(this), cTokenAmt), "Contract Approved?"); |             require(ERC20Interface(cEth).transferFrom(msg.sender, address(this), cTokenAmt), "Contract Approved?"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * @dev If col/debt > user's balance/borrow. Then set max | ||||||
|  |      */ | ||||||
|  |     function checkCompound(uint ethAmt, uint daiAmt) internal returns (uint ethCol, uint daiDebt) { | ||||||
|  |         CTokenInterface cEthContract = CTokenInterface(cEth); | ||||||
|  |         uint cEthBal = cEthContract.balanceOf(address(this)); | ||||||
|  |         uint ethExchangeRate = cEthContract.exchangeRateCurrent(); | ||||||
|  |         ethCol = wmul(cEthBal, ethExchangeRate); | ||||||
|  |         ethCol = wdiv(ethCol, ethExchangeRate) <= cEthBal ? ethCol : ethCol - 1; | ||||||
|  |         if (ethCol > ethAmt) { | ||||||
|  |             ethCol = ethAmt; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         daiDebt = CDAIInterface(cDai).borrowBalanceCurrent(msg.sender); | ||||||
|  |         if (daiDebt > daiAmt) { | ||||||
|  |             daiDebt = daiAmt; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -482,7 +502,7 @@ contract Bridge is LiquidityProvider { | ||||||
|      * @dev MakerDAO to Compound |      * @dev MakerDAO to Compound | ||||||
|      */ |      */ | ||||||
|     function makerToCompound(uint cdpId, uint ethCol, uint daiDebt) public payable isUserWallet returns (uint daiAmt) { |     function makerToCompound(uint cdpId, uint ethCol, uint daiDebt) public payable isUserWallet returns (uint daiAmt) { | ||||||
|         uint ethAmt = ethCol; |         uint ethAmt; | ||||||
|         (ethAmt, daiAmt) = wipeAndFree(cdpId, ethCol, daiDebt); |         (ethAmt, daiAmt) = wipeAndFree(cdpId, ethCol, daiDebt); | ||||||
|         mintCETH(ethAmt); |         mintCETH(ethAmt); | ||||||
|         give(cdpId, msg.sender); |         give(cdpId, msg.sender); | ||||||
|  | @ -492,12 +512,13 @@ contract Bridge is LiquidityProvider { | ||||||
|      * @dev Compound to MakerDAO |      * @dev Compound to MakerDAO | ||||||
|      */ |      */ | ||||||
|     function compoundToMaker(uint cdpId, uint ethCol, uint daiDebt) public payable isUserWallet { |     function compoundToMaker(uint cdpId, uint ethCol, uint daiDebt) public payable isUserWallet { | ||||||
|         payUserDebt(daiDebt); |         (uint ethAmt, uint daiAmt) = checkCompound(ethCol, daiDebt); | ||||||
|         fetchCETH(ethCol); |         payUserDebt(daiAmt); | ||||||
|         redeemUnderlying(cEth, ethCol); |         fetchCETH(ethAmt); | ||||||
|  |         redeemUnderlying(cEth, ethAmt); | ||||||
|         uint cdpNum = cdpId > 0 ? cdpId : open(); |         uint cdpNum = cdpId > 0 ? cdpId : open(); | ||||||
|         lockAndDraw(cdpNum, ethCol, daiDebt); |         lockAndDraw(cdpNum, ethAmt, daiAmt); | ||||||
|         mintCDAI(daiDebt); |         mintCDAI(daiAmt); | ||||||
|         give(cdpNum, msg.sender); |         give(cdpNum, msg.sender); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Samyak Jain
						Samyak Jain