mirror of
				https://github.com/Instadapp/yield-contract.git
				synced 2024-07-29 21:47:29 +00:00 
			
		
		
		
	Merge branch 'logics' of https://github.com/InstaDApp/yield-contract into logics
This commit is contained in:
		
						commit
						1d2da806b4
					
				
							
								
								
									
										95
									
								
								contracts/logics/settle/dai/crvMining.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								contracts/logics/settle/dai/crvMining.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,95 @@ | |||
| // SPDX-License-Identifier: MIT | ||||
| pragma solidity ^0.6.8; | ||||
| pragma experimental ABIEncoderV2; | ||||
| 
 | ||||
| import { DSMath } from "../../../libs/safeMath.sol"; | ||||
| 
 | ||||
| interface DSAInterface { | ||||
|     function cast(address[] calldata _targets, bytes[] calldata _data, address _origin) external payable; | ||||
| } | ||||
| 
 | ||||
| contract LogicOne { | ||||
| 
 | ||||
|     function getDaiAddress() private pure returns(address) { | ||||
|         return 0x6B175474E89094C44Da98b954EedeAC495271d0F; | ||||
|     } | ||||
| 
 | ||||
|     function getCrvAddress() private pure returns(address) { | ||||
|         return 0xD533a949740bb3306d119CC777fa900bA034cd52; | ||||
|     } | ||||
| 
 | ||||
|     function getOriginAddress() private pure returns(address) { | ||||
|         return 0xB7fA44c2E964B6EB24893f7082Ecc08c8d0c0F87; | ||||
|     } | ||||
| 
 | ||||
|     function getDsaAddress() private pure returns(address) { | ||||
|         return address(0); // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getGuageAddress() private pure returns(address) { | ||||
|         return 0xAf615b36Db171fD5A369A0060b9bCB88fFf0190d; | ||||
|     } | ||||
| 
 | ||||
|     function getGuageName() private pure returns(string memory) { | ||||
|         return "guage-3"; | ||||
|     } | ||||
| 
 | ||||
|     function getCurveConnectAddress() private pure returns(address) { | ||||
|         return 0x1568a9D336A7aC051DCC4bdcc4A0B09299DE5Daf; | ||||
|     } | ||||
| 
 | ||||
|     function getCurveGuageConnectAddress() private pure returns(address) { | ||||
|         return 0xAf615b36Db171fD5A369A0060b9bCB88fFf0190d; | ||||
|     } | ||||
| 
 | ||||
|     function getUniswapConnectAddress() private pure returns(address) { | ||||
|         return 0x62EbfF47B2Ba3e47796efaE7C51676762dC961c0; | ||||
|     } | ||||
| 
 | ||||
|     function mineCrv(address token, uint amt, uint unitAmt) external { | ||||
|         address[] memory _targets = new address[](2); | ||||
|         bytes[] memory _data = new bytes[](2); | ||||
|         _targets[1] = getCurveConnectAddress(); | ||||
|         _data[1] = abi.encodeWithSignature("deposit(address,uint256,uint256,uint256,uint256)", token, amt, unitAmt, uint(0), uint(0)); | ||||
|         _targets[2] = getCurveGuageConnectAddress(); | ||||
|         _data[2] = abi.encodeWithSignature("deposit(string,uint256,uint256,uint256)", getGuageName(), uint(-1), uint(0), uint(0)); | ||||
|         DSAInterface(getDsaAddress()).cast(_targets, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function redeemCrv(address token, uint amt, uint unitAmt) external { | ||||
|         address[] memory _targets; | ||||
|         bytes[] memory _data; | ||||
|         if (amt == uint(-1)) { | ||||
|             _targets = new address[](2); | ||||
|             _data = new bytes[](2); | ||||
|         } else { | ||||
|             _targets = new address[](3); | ||||
|             _data = new bytes[](3); | ||||
|         } | ||||
|         _targets[0] = getCurveGuageConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("withdraw(string,uint256,uint256,uint256,uint256,uint256)", getGuageName(), uint(-1), uint(0), uint(0), uint(0), uint(0)); | ||||
|         _targets[1] = getCurveConnectAddress(); | ||||
|         _data[1] = abi.encodeWithSignature("withdraw(address,uint256,uint256,uint256,uint256)", token, amt, unitAmt, uint(0), uint(0)); | ||||
|         if (amt != uint(-1)) { | ||||
|             _targets[2] = getCurveGuageConnectAddress(); | ||||
|             _data[2] = abi.encodeWithSignature("deposit(string,uint256,uint256,uint256)", getGuageName(), uint(-1), uint(0), uint(0)); | ||||
|         } | ||||
|         DSAInterface(getDsaAddress()).cast(_targets, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function claimCrv() external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getCurveGuageConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("claimReward(string,uint256,uint256)", getGuageName(), 0, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function claimCrvAndSwap(uint amt, uint unitAmt) external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getUniswapConnectAddress(); // CHECK9898 - Use Uniswap multi path for Good Swap | ||||
|         _data[0] = abi.encodeWithSignature("sell(address,address,unit256,unit256,unit256,unit256)", getDaiAddress(), getCrvAddress(), amt, unitAmt, 0, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										128
									
								
								contracts/logics/settle/dai/maxComp.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								contracts/logics/settle/dai/maxComp.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,128 @@ | |||
| // SPDX-License-Identifier: MIT | ||||
| pragma solidity ^0.6.8; | ||||
| pragma experimental ABIEncoderV2; | ||||
| 
 | ||||
| import { DSMath } from "../../../libs/safeMath.sol"; | ||||
| 
 | ||||
| interface CTokenInterface { | ||||
|     function borrowBalanceCurrent(address account) external returns (uint256); | ||||
|     function exchangeRateCurrent() external returns (uint256); | ||||
| 
 | ||||
|     function balanceOf(address owner) external view returns (uint256); | ||||
| 
 | ||||
|     function underlying() external view returns (address); | ||||
| } | ||||
| 
 | ||||
| interface DSAInterface { | ||||
|     function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin) external payable; | ||||
| } | ||||
| 
 | ||||
| interface CompTroller { | ||||
|     function getAllMarkets() external view returns (address[] memory); | ||||
| } | ||||
| 
 | ||||
| interface OracleComp { | ||||
|     function getUnderlyingPrice(address) external view returns (uint); | ||||
| } | ||||
| 
 | ||||
| interface InstaMapping { | ||||
|     function cTokenMapping(address) external view returns (address); | ||||
| } | ||||
| 
 | ||||
| contract LogicOne is DSMath { | ||||
| 
 | ||||
|     struct CastData { | ||||
|         address[] dsaTargets; | ||||
|         bytes[] dsaData; | ||||
|     } | ||||
| 
 | ||||
|     function getOriginAddress() private pure returns(address) { | ||||
|         return 0xB7fA44c2E964B6EB24893f7082Ecc08c8d0c0F87; // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getCompAddress() private pure returns(address) { | ||||
|         return 0xc00e94Cb662C3520282E6f5717214004A7f26888; // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getComptrollerAddress() private pure returns (address) { | ||||
|         return 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B; | ||||
|     } | ||||
| 
 | ||||
|     function getDaiAddress() private pure returns(address) { | ||||
|         return 0x6B175474E89094C44Da98b954EedeAC495271d0F; // DAI address | ||||
|     } | ||||
| 
 | ||||
|     function getCdaiAddress() private pure returns(address) { | ||||
|         return 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643; // CDAI address | ||||
|     } | ||||
| 
 | ||||
|     function getDsaAddress() private pure returns(address) { | ||||
|         return address(0); // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getCompoundConnectAddress() private pure returns(address) { | ||||
|         return 0x07F81230d73a78f63F0c2A3403AD281b067d28F8; | ||||
|     } | ||||
| 
 | ||||
|     function getFlashloanConnectAddress() private pure returns(address) { | ||||
|         return 0xaA3EA0b22802d68DA73D5f4D3f9F1C7C238fE03A; | ||||
|     } | ||||
| 
 | ||||
|     function getCompConnectAddress() private pure returns(address) { | ||||
|         return 0xB4a04F1C194bEed64FCE27843B5b3079339cdaD4; | ||||
|     } | ||||
| 
 | ||||
|     function getUniswapConnectAddress() private pure returns(address) { | ||||
|         return 0x62EbfF47B2Ba3e47796efaE7C51676762dC961c0; | ||||
|     } | ||||
|      | ||||
|     function checkCompoundAssets() private { | ||||
|         address[] memory allMarkets = CompTroller(getComptrollerAddress()).getAllMarkets(); | ||||
|         uint supply; | ||||
|         uint borrow; | ||||
|         for (uint i = 0; i < allMarkets.length; i++) { | ||||
|             CTokenInterface ctoken = CTokenInterface(allMarkets[i]); | ||||
|             if (allMarkets[i] == getCdaiAddress()) { | ||||
|                 supply = wmul(ctoken.balanceOf(getDsaAddress()), ctoken.exchangeRateCurrent()); | ||||
|             } | ||||
|             borrow = ctoken.borrowBalanceCurrent(getDsaAddress()); | ||||
| 
 | ||||
|             if (allMarkets[i] != getCdaiAddress()) { | ||||
|                 require(borrow == 0, "assets"); | ||||
|             } else { | ||||
|                 require(wdiv(borrow, supply) < 745 * 10 ** 15, "position-risky"); // DAI ratio - should be less than 74.5% | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     function maxComp(uint flashAmt, uint route, address[] calldata _targets, bytes[] calldata _data) external { | ||||
|         address compoundConnect = getCompoundConnectAddress(); | ||||
|         address flashloanConnect = getFlashloanConnectAddress(); | ||||
|         for (uint i = 0; i < _targets.length; i++) { | ||||
|             require(_targets[i] == compoundConnect || _targets[i] == flashloanConnect, "not-authorised-connector"); | ||||
|         } | ||||
|         bytes memory _dataEncode = abi.encode(_targets, _data); | ||||
|         address[] memory _targetFlash = new address[](1); | ||||
|         bytes[] memory _dataFlash = new bytes[](1); | ||||
|         _targetFlash[0] = flashloanConnect; | ||||
|         _dataFlash[0] = abi.encodeWithSignature("flashBorrowAndCast(address,uint256,uint256,bytes)", getDaiAddress(), flashAmt, route, _dataEncode); | ||||
|         DSAInterface(getDsaAddress()).cast(_targetFlash, _dataFlash, getOriginAddress()); | ||||
|         checkCompoundAssets(); | ||||
|     } | ||||
| 
 | ||||
|     function claimComp(address[] calldata tokens) external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getCompConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("ClaimCompTwo(address[],uint256)", tokens, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function swapComp(uint amt, uint unitAmt) external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getUniswapConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("sell(address,address,unit256,unit256,unit256,unit256)", getDaiAddress(), getCompAddress(), amt, unitAmt, 0, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| } | ||||
|  | @ -86,12 +86,10 @@ contract LogicOne { | |||
|     } | ||||
| 
 | ||||
|     function claimCrvAndSwap(uint amt, uint unitAmt) external { | ||||
|         address crv = getCrvAddress(); | ||||
|         address eth = getEthAddress(); | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getUniswapConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("sell(address,address,unit256,unit256,unit256,unit256)", eth, crv, amt, unitAmt, 0, 0); | ||||
|         _data[0] = abi.encodeWithSignature("sell(address,address,unit256,unit256,unit256,unit256)", getEthAddress(), getCrvAddress(), amt, unitAmt, 0, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										95
									
								
								contracts/logics/settle/usdc/crvMining.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								contracts/logics/settle/usdc/crvMining.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,95 @@ | |||
| // SPDX-License-Identifier: MIT | ||||
| pragma solidity ^0.6.8; | ||||
| pragma experimental ABIEncoderV2; | ||||
| 
 | ||||
| import { DSMath } from "../../../libs/safeMath.sol"; | ||||
| 
 | ||||
| interface DSAInterface { | ||||
|     function cast(address[] calldata _targets, bytes[] calldata _data, address _origin) external payable; | ||||
| } | ||||
| 
 | ||||
| contract LogicOne { | ||||
| 
 | ||||
|     function getUsdcAddress() private pure returns(address) { | ||||
|         return 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; | ||||
|     } | ||||
| 
 | ||||
|     function getCrvAddress() private pure returns(address) { | ||||
|         return 0xD533a949740bb3306d119CC777fa900bA034cd52; | ||||
|     } | ||||
| 
 | ||||
|     function getOriginAddress() private pure returns(address) { | ||||
|         return 0xB7fA44c2E964B6EB24893f7082Ecc08c8d0c0F87; | ||||
|     } | ||||
| 
 | ||||
|     function getDsaAddress() private pure returns(address) { | ||||
|         return address(0); // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getGuageAddress() private pure returns(address) { | ||||
|         return 0xAf615b36Db171fD5A369A0060b9bCB88fFf0190d; | ||||
|     } | ||||
| 
 | ||||
|     function getGuageName() private pure returns(string memory) { | ||||
|         return "guage-3"; | ||||
|     } | ||||
| 
 | ||||
|     function getCurveConnectAddress() private pure returns(address) { | ||||
|         return 0x1568a9D336A7aC051DCC4bdcc4A0B09299DE5Daf; | ||||
|     } | ||||
| 
 | ||||
|     function getCurveGuageConnectAddress() private pure returns(address) { | ||||
|         return 0xAf615b36Db171fD5A369A0060b9bCB88fFf0190d; | ||||
|     } | ||||
| 
 | ||||
|     function getUniswapConnectAddress() private pure returns(address) { | ||||
|         return 0x62EbfF47B2Ba3e47796efaE7C51676762dC961c0; | ||||
|     } | ||||
| 
 | ||||
|     function mineCrv(address token, uint amt, uint unitAmt) external { | ||||
|         address[] memory _targets = new address[](2); | ||||
|         bytes[] memory _data = new bytes[](2); | ||||
|         _targets[1] = getCurveConnectAddress(); | ||||
|         _data[1] = abi.encodeWithSignature("deposit(address,uint256,uint256,uint256,uint256)", token, amt, unitAmt, uint(0), uint(0)); | ||||
|         _targets[2] = getCurveGuageConnectAddress(); | ||||
|         _data[2] = abi.encodeWithSignature("deposit(string,uint256,uint256,uint256)", getGuageName(), uint(-1), uint(0), uint(0)); | ||||
|         DSAInterface(getDsaAddress()).cast(_targets, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function redeemCrv(address token, uint amt, uint unitAmt) external { | ||||
|         address[] memory _targets; | ||||
|         bytes[] memory _data; | ||||
|         if (amt == uint(-1)) { | ||||
|             _targets = new address[](2); | ||||
|             _data = new bytes[](2); | ||||
|         } else { | ||||
|             _targets = new address[](3); | ||||
|             _data = new bytes[](3); | ||||
|         } | ||||
|         _targets[0] = getCurveGuageConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("withdraw(string,uint256,uint256,uint256,uint256,uint256)", getGuageName(), uint(-1), uint(0), uint(0), uint(0), uint(0)); | ||||
|         _targets[1] = getCurveConnectAddress(); | ||||
|         _data[1] = abi.encodeWithSignature("withdraw(address,uint256,uint256,uint256,uint256)", token, amt, unitAmt, uint(0), uint(0)); | ||||
|         if (amt != uint(-1)) { | ||||
|             _targets[2] = getCurveGuageConnectAddress(); | ||||
|             _data[2] = abi.encodeWithSignature("deposit(string,uint256,uint256,uint256)", getGuageName(), uint(-1), uint(0), uint(0)); | ||||
|         } | ||||
|         DSAInterface(getDsaAddress()).cast(_targets, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function claimCrv() external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getCurveGuageConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("claimReward(string,uint256,uint256)", getGuageName(), 0, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function claimCrvAndSwap(uint amt, uint unitAmt) external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getUniswapConnectAddress(); // CHECK9898 - Use Uniswap multi path for Good Swap | ||||
|         _data[0] = abi.encodeWithSignature("sell(address,address,unit256,unit256,unit256,unit256)", getUsdcAddress(), getCrvAddress(), amt, unitAmt, 0, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										78
									
								
								contracts/logics/settle/usdc/maker.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								contracts/logics/settle/usdc/maker.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,78 @@ | |||
| // SPDX-License-Identifier: MIT | ||||
| pragma solidity ^0.6.8; | ||||
| pragma experimental ABIEncoderV2; | ||||
| 
 | ||||
| import { DSMath } from "../../../libs/safeMath.sol"; | ||||
| 
 | ||||
| interface VaultDataInterface { | ||||
| 
 | ||||
|     struct VaultData { | ||||
|         uint id; | ||||
|         address owner; | ||||
|         string colType; | ||||
|         uint collateral; | ||||
|         uint art; | ||||
|         uint debt; | ||||
|         uint liquidatedCol; | ||||
|         uint borrowRate; | ||||
|         uint colPrice; | ||||
|         uint liquidationRatio; | ||||
|         address vaultAddress; | ||||
|     } | ||||
| 
 | ||||
|     function getVaultById(uint id) external view returns (VaultData memory); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| interface DSAInterface { | ||||
|     function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin) external payable; | ||||
| } | ||||
| 
 | ||||
| contract LogicOne is DSMath { | ||||
| 
 | ||||
|     function getOriginAddress() private pure returns(address) { | ||||
|         return 0xB7fA44c2E964B6EB24893f7082Ecc08c8d0c0F87; // DSA address | ||||
|     } | ||||
|      | ||||
|     function getMcdAddresses() public pure returns (address) { | ||||
|         return 0xF23196DF1C440345DE07feFbe556a5eF0dcD29F0; | ||||
|     } | ||||
| 
 | ||||
|     function getInstaMakerResolver() public pure returns (address) { | ||||
|         return 0x0A7008B38E7015F8C36A49eEbc32513ECA8801E5; | ||||
|     } | ||||
| 
 | ||||
|     function getMakerConnectAddress() public pure returns (address) { | ||||
|         return 0x6c4E4D4aB22cAB08b8498a3A232D92609e8b2d62; | ||||
|     } | ||||
| 
 | ||||
|     function getDsaAddress() private pure returns(address) { | ||||
|         return address(0); // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function vaultId() private pure returns(uint) { | ||||
|         return 0; // vault ID | ||||
|     } | ||||
| 
 | ||||
|     // No need to check Vault risky status in USDC-A vault because of ~99% borrowing limit | ||||
| 
 | ||||
|     function depositAndBorrow(uint depositAmt, uint borrowAmt) public { | ||||
|         address[] memory _targets = new address[](2); | ||||
|         bytes[] memory _data = new bytes[](2); | ||||
|         _targets[0] = getMakerConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("deposit(uint256,uint256,uint256,uint256)", vaultId(), depositAmt, uint(0), uint(0)); | ||||
|         _targets[1] = getMakerConnectAddress(); | ||||
|         _data[1] = abi.encodeWithSignature("borrow(uint256,uint256,uint256,uint256)", vaultId(), borrowAmt, uint(0), uint(0)); | ||||
|         DSAInterface(getDsaAddress()).cast(_targets, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function paybackAndWithdraw(uint withdrawAmt, uint paybackAmt) public { | ||||
|         address[] memory _targets = new address[](2); | ||||
|         bytes[] memory _data = new bytes[](2); | ||||
|         _targets[0] = getMakerConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("payback(uint256,uint256,uint256,uint256)", vaultId(), paybackAmt, uint(0), uint(0)); | ||||
|         _targets[1] = getMakerConnectAddress(); | ||||
|         _data[1] = abi.encodeWithSignature("withdraw(uint256,uint256,uint256,uint256)", vaultId(), withdrawAmt, uint(0), uint(0)); | ||||
|         DSAInterface(getDsaAddress()).cast(_targets, _data, getOriginAddress()); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										132
									
								
								contracts/logics/settle/usdc/maxComp.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								contracts/logics/settle/usdc/maxComp.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,132 @@ | |||
| // SPDX-License-Identifier: MIT | ||||
| pragma solidity ^0.6.8; | ||||
| pragma experimental ABIEncoderV2; | ||||
| 
 | ||||
| import { DSMath } from "../../../libs/safeMath.sol"; | ||||
| 
 | ||||
| interface CTokenInterface { | ||||
|     function borrowBalanceCurrent(address account) external returns (uint256); | ||||
|     function exchangeRateCurrent() external returns (uint256); | ||||
| 
 | ||||
|     function balanceOf(address owner) external view returns (uint256); | ||||
| 
 | ||||
|     function underlying() external view returns (address); | ||||
| } | ||||
| 
 | ||||
| interface DSAInterface { | ||||
|     function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin) external payable; | ||||
| } | ||||
| 
 | ||||
| interface CompTroller { | ||||
|     function getAllMarkets() external view returns (address[] memory); | ||||
| } | ||||
| 
 | ||||
| interface OracleComp { | ||||
|     function getUnderlyingPrice(address) external view returns (uint); | ||||
| } | ||||
| 
 | ||||
| interface InstaMapping { | ||||
|     function cTokenMapping(address) external view returns (address); | ||||
| } | ||||
| 
 | ||||
| contract LogicOne is DSMath { | ||||
| 
 | ||||
|     struct CastData { | ||||
|         address[] dsaTargets; | ||||
|         bytes[] dsaData; | ||||
|     } | ||||
| 
 | ||||
|     function getOriginAddress() private pure returns(address) { | ||||
|         return 0xB7fA44c2E964B6EB24893f7082Ecc08c8d0c0F87; // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getUsdcAddress() private pure returns(address) { | ||||
|         return 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getCompAddress() private pure returns(address) { | ||||
|         return 0xc00e94Cb662C3520282E6f5717214004A7f26888; // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getComptrollerAddress() private pure returns (address) { | ||||
|         return 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B; | ||||
|     } | ||||
| 
 | ||||
|     function getDaiAddress() private pure returns(address) { | ||||
|         return 0x6B175474E89094C44Da98b954EedeAC495271d0F; // DAI address | ||||
|     } | ||||
| 
 | ||||
|     function getCdaiAddress() private pure returns(address) { | ||||
|         return 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643; // CDAI address | ||||
|     } | ||||
| 
 | ||||
|     function getDsaAddress() private pure returns(address) { | ||||
|         return address(0); // DSA address | ||||
|     } | ||||
| 
 | ||||
|     function getCompoundConnectAddress() private pure returns(address) { | ||||
|         return 0x07F81230d73a78f63F0c2A3403AD281b067d28F8; | ||||
|     } | ||||
| 
 | ||||
|     function getFlashloanConnectAddress() private pure returns(address) { | ||||
|         return 0xaA3EA0b22802d68DA73D5f4D3f9F1C7C238fE03A; | ||||
|     } | ||||
| 
 | ||||
|     function getCompConnectAddress() private pure returns(address) { | ||||
|         return 0xB4a04F1C194bEed64FCE27843B5b3079339cdaD4; | ||||
|     } | ||||
| 
 | ||||
|     function getUniswapConnectAddress() private pure returns(address) { | ||||
|         return 0x62EbfF47B2Ba3e47796efaE7C51676762dC961c0; | ||||
|     } | ||||
|      | ||||
|     function checkCompoundAssets() private { | ||||
|         address[] memory allMarkets = CompTroller(getComptrollerAddress()).getAllMarkets(); | ||||
|         uint supply; | ||||
|         uint borrow; | ||||
|         for (uint i = 0; i < allMarkets.length; i++) { | ||||
|             CTokenInterface ctoken = CTokenInterface(allMarkets[i]); | ||||
|             if (allMarkets[i] == getCdaiAddress()) { | ||||
|                 supply = wmul(ctoken.balanceOf(getDsaAddress()), ctoken.exchangeRateCurrent()); | ||||
|             } | ||||
|             borrow = ctoken.borrowBalanceCurrent(getDsaAddress()); | ||||
| 
 | ||||
|             if (allMarkets[i] != getCdaiAddress()) { | ||||
|                 require(borrow == 0, "assets"); | ||||
|             } else { | ||||
|                 require(wdiv(borrow, supply) < 745 * 10 ** 15, "position-risky"); // DAI ratio - should be less than 74.5% | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     function maxComp(uint flashAmt, uint route, address[] calldata _targets, bytes[] calldata _data) external { | ||||
|         address compoundConnect = getCompoundConnectAddress(); | ||||
|         address flashloanConnect = getFlashloanConnectAddress(); | ||||
|         for (uint i = 0; i < _targets.length; i++) { | ||||
|             require(_targets[i] == compoundConnect || _targets[i] == flashloanConnect, "not-authorised-connector"); | ||||
|         } | ||||
|         bytes memory _dataEncode = abi.encode(_targets, _data); | ||||
|         address[] memory _targetFlash = new address[](1); | ||||
|         bytes[] memory _dataFlash = new bytes[](1); | ||||
|         _targetFlash[0] = flashloanConnect; | ||||
|         _dataFlash[0] = abi.encodeWithSignature("flashBorrowAndCast(address,uint256,uint256,bytes)", getDaiAddress(), flashAmt, route, _dataEncode); | ||||
|         DSAInterface(getDsaAddress()).cast(_targetFlash, _dataFlash, getOriginAddress()); | ||||
|         checkCompoundAssets(); | ||||
|     } | ||||
| 
 | ||||
|     function claimComp(address[] calldata tokens) external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getCompConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("ClaimCompTwo(address[],uint256)", tokens, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| 
 | ||||
|     function swapComp(uint amt, uint unitAmt) external { | ||||
|         address[] memory _target = new address[](1); | ||||
|         bytes[] memory _data = new bytes[](1); | ||||
|         _target[0] = getUniswapConnectAddress(); | ||||
|         _data[0] = abi.encodeWithSignature("sell(address,address,unit256,unit256,unit256,unit256)", getUsdcAddress(), getCompAddress(), amt, unitAmt, 0, 0); | ||||
|         DSAInterface(getDsaAddress()).cast(_target, _data, getOriginAddress()); | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Thrilok Kumar
						Thrilok Kumar