mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	lint added
This commit is contained in:
		
							parent
							
								
									37103d99ef
								
							
						
					
					
						commit
						a110574642
					
				|  | @ -2,100 +2,93 @@ | |||
| pragma solidity ^0.7.0; | ||||
| 
 | ||||
| contract Events { | ||||
| 	event LogDeposit( | ||||
| 		uint256 subaccount, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		bool enableCollateral, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogDeposit( | ||||
|         uint256 subaccount, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         bool enableCollateral, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 	event LogWithdraw( | ||||
| 		uint256 subaccount, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogWithdraw( | ||||
|         uint256 subaccount, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 	event LogBorrow( | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogBorrow( | ||||
|         uint256 subAccount, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 	event LogRepay( | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogRepay( | ||||
|         uint256 subAccount, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 	event LogMint( | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogMint( | ||||
|         uint256 subAccount, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 	event LogBurn( | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogBurn( | ||||
|         uint256 subAccount, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 	event LogETransfer( | ||||
| 		uint256 subAccount1, | ||||
| 		uint256 subAccount2, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogETransfer( | ||||
|         uint256 subAccount1, | ||||
|         uint256 subAccount2, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 	event LogDTransfer( | ||||
| 		uint256 subAccount1, | ||||
| 		uint256 subAccount2, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	); | ||||
| 
 | ||||
|     event LogDTransfer( | ||||
|         uint256 subAccount1, | ||||
|         uint256 subAccount2, | ||||
|         address token, | ||||
|         uint256 amount, | ||||
|         uint256 getId, | ||||
|         uint256 setId | ||||
|     ); | ||||
| 
 | ||||
|     event LogApproveDebt( | ||||
|         uint256 subAccountId, | ||||
| 	event LogApproveDebt( | ||||
| 		uint256 subAccountId, | ||||
| 		address debtReceiver, | ||||
| 		address token, | ||||
| 		uint256 amount, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
|     ); | ||||
| 	); | ||||
| 
 | ||||
|     event LogSwap( | ||||
|         uint256 subAccountFrom, | ||||
| 		uint subAccountTo, | ||||
|         address buyAddr, | ||||
|         address sellAddr, | ||||
|         uint sellAmt, | ||||
|         uint unitAmt, | ||||
|         bytes callData | ||||
|     ); | ||||
| 	event LogSwap( | ||||
| 		uint256 subAccountFrom, | ||||
| 		uint256 subAccountTo, | ||||
| 		address buyAddr, | ||||
| 		address sellAddr, | ||||
| 		uint256 sellAmt, | ||||
| 		uint256 unitAmt, | ||||
| 		bytes callData | ||||
| 	); | ||||
| 
 | ||||
|     event LogEnterMarket( | ||||
|         uint subAccountId, | ||||
|         address[] newMarkets | ||||
|     ); | ||||
| 	event LogEnterMarket(uint256 subAccountId, address[] newMarkets); | ||||
| 
 | ||||
|     event LogExitMarket( | ||||
|         uint subAccountId, | ||||
|         address oldMarket | ||||
|     ); | ||||
| 	event LogExitMarket(uint256 subAccountId, address oldMarket); | ||||
| } | ||||
|  |  | |||
|  | @ -5,8 +5,7 @@ import "./events.sol"; | |||
| import { Basic } from "../../common/basic.sol"; | ||||
| 
 | ||||
| contract Helpers is Basic, Variables, Events { | ||||
| 
 | ||||
|     /** | ||||
| 	/** | ||||
| 	 * @dev Get total collateral balance for an asset | ||||
| 	 */ | ||||
| 	function getEnteredMarkets() | ||||
|  | @ -17,21 +16,24 @@ contract Helpers is Basic, Variables, Events { | |||
| 		enteredMarkets = markets.getEnteredMarkets(address(this)); | ||||
| 	} | ||||
| 
 | ||||
| 	function getSubAccount(address primary, uint subAccountId) public pure returns (address) { | ||||
|         require(subAccountId < 256, "sub-account-id-too-big"); | ||||
|         return address(uint160(primary) ^ uint160(subAccountId)); | ||||
|     } | ||||
| 	function getSubAccount(address primary, uint256 subAccountId) | ||||
| 		public | ||||
| 		pure | ||||
| 		returns (address) | ||||
| 	{ | ||||
| 		require(subAccountId < 256, "sub-account-id-too-big"); | ||||
| 		return address(uint160(primary) ^ uint160(subAccountId)); | ||||
| 	} | ||||
| 
 | ||||
| 	function checkIfEnteredMarket(address token) public view returns(bool) { | ||||
| 	function checkIfEnteredMarket(address token) public view returns (bool) { | ||||
| 		address[] memory enteredMarkets = getEnteredMarkets(); | ||||
| 		uint256 length = enteredMarkets.length; | ||||
| 
 | ||||
| 		for(uint i = 0; i < length; i++) { | ||||
| 			if(enteredMarkets[i] == token) { | ||||
| 		for (uint256 i = 0; i < length; i++) { | ||||
| 			if (enteredMarkets[i] == token) { | ||||
| 				return true; | ||||
| 			} | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -3,44 +3,77 @@ pragma solidity ^0.7.0; | |||
| pragma experimental ABIEncoderV2; | ||||
| 
 | ||||
| interface IEulerMarkets { | ||||
|     function enterMarket(uint subAccountId, address newMarket) external; | ||||
|     function getEnteredMarkets(address account) external view returns (address[] memory); | ||||
|     function exitMarket(uint subAccountId, address oldMarket) external; | ||||
|     function underlyingToEToken(address underlying) external view returns (address); | ||||
|     function underlyingToDToken(address underlying) external view returns (address); | ||||
| 	function enterMarket(uint256 subAccountId, address newMarket) external; | ||||
| 
 | ||||
| 	function getEnteredMarkets(address account) | ||||
| 		external | ||||
| 		view | ||||
| 		returns (address[] memory); | ||||
| 
 | ||||
| 	function exitMarket(uint256 subAccountId, address oldMarket) external; | ||||
| 
 | ||||
| 	function underlyingToEToken(address underlying) | ||||
| 		external | ||||
| 		view | ||||
| 		returns (address); | ||||
| 
 | ||||
| 	function underlyingToDToken(address underlying) | ||||
| 		external | ||||
| 		view | ||||
| 		returns (address); | ||||
| } | ||||
| 
 | ||||
| interface IEulerEToken { | ||||
|     function deposit(uint subAccountId, uint amount) external; | ||||
|     function withdraw(uint subAccountId, uint amount) external; | ||||
|     function decimals() external view returns (uint8); | ||||
|     function mint(uint subAccountId, uint amount) external; | ||||
|     function burn(uint subAccountId, uint amount) external; | ||||
|     function balanceOf(address account) external view returns (uint); | ||||
|     function transfer(address to, uint amount) external returns (bool); | ||||
|     function approve(address spender, uint amount) external returns (bool); | ||||
| 	function deposit(uint256 subAccountId, uint256 amount) external; | ||||
| 
 | ||||
| 	function withdraw(uint256 subAccountId, uint256 amount) external; | ||||
| 
 | ||||
| 	function decimals() external view returns (uint8); | ||||
| 
 | ||||
| 	function mint(uint256 subAccountId, uint256 amount) external; | ||||
| 
 | ||||
| 	function burn(uint256 subAccountId, uint256 amount) external; | ||||
| 
 | ||||
| 	function balanceOf(address account) external view returns (uint256); | ||||
| 
 | ||||
| 	function transfer(address to, uint256 amount) external returns (bool); | ||||
| 
 | ||||
| 	function approve(address spender, uint256 amount) external returns (bool); | ||||
| } | ||||
| 
 | ||||
| interface IEulerDToken { | ||||
|     function underlyingToDToken(address underlying) external view returns (address); | ||||
|     function decimals() external view returns (uint8); | ||||
|     function borrow(uint subAccountId, uint amount) external; | ||||
|     function repay(uint subAccountId, uint amount) external; | ||||
|     function balanceOf(address account) external view returns (uint); | ||||
|     function transfer(address to, uint amount) external returns (bool); | ||||
|     function approveDebt(uint subAccountId, address spender, uint amount) external returns (bool); | ||||
| 	function underlyingToDToken(address underlying) | ||||
| 		external | ||||
| 		view | ||||
| 		returns (address); | ||||
| 
 | ||||
| 	function decimals() external view returns (uint8); | ||||
| 
 | ||||
| 	function borrow(uint256 subAccountId, uint256 amount) external; | ||||
| 
 | ||||
| 	function repay(uint256 subAccountId, uint256 amount) external; | ||||
| 
 | ||||
| 	function balanceOf(address account) external view returns (uint256); | ||||
| 
 | ||||
| 	function transfer(address to, uint256 amount) external returns (bool); | ||||
| 
 | ||||
| 	function approveDebt( | ||||
| 		uint256 subAccountId, | ||||
| 		address spender, | ||||
| 		uint256 amount | ||||
| 	) external returns (bool); | ||||
| } | ||||
| 
 | ||||
| interface IEulerSwap { | ||||
|     struct Swap1InchParams { | ||||
|         uint subAccountIdIn; | ||||
|         uint subAccountIdOut; | ||||
|         address underlyingIn; | ||||
|         address underlyingOut; | ||||
|         uint amount; | ||||
|         uint amountOutMinimum; | ||||
|         bytes payload; | ||||
|     } | ||||
| 	struct Swap1InchParams { | ||||
| 		uint256 subAccountIdIn; | ||||
| 		uint256 subAccountIdOut; | ||||
| 		address underlyingIn; | ||||
| 		address underlyingOut; | ||||
| 		uint256 amount; | ||||
| 		uint256 amountOutMinimum; | ||||
| 		bytes payload; | ||||
| 	} | ||||
| 
 | ||||
|     function swap1Inch(Swap1InchParams memory) external; | ||||
| 	function swap1Inch(Swap1InchParams memory) external; | ||||
| } | ||||
|  |  | |||
|  | @ -9,21 +9,21 @@ import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; | |||
| abstract contract Euler is Helpers { | ||||
| 	using SafeERC20 for IERC20; | ||||
| 
 | ||||
|     /** | ||||
| 	/** | ||||
| 	 * @dev Deposit ETH/ERC20_Token. | ||||
| 	 * @notice Deposit a token to Euler for lending / collaterization. | ||||
|      * @param subAccount Subaccount number | ||||
| 	 * @param subAccount Subaccount number | ||||
| 	 * @param token The address of the token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to deposit. (For max: `uint256(-1)`) | ||||
|      * @param enableCollateral True for entering the market | ||||
| 	 * @param enableCollateral True for entering the market | ||||
| 	 * @param getId ID to retrieve amt. | ||||
| 	 * @param setId ID stores the amount of tokens deposited. | ||||
| 	 */ | ||||
| 	function deposit( | ||||
|         uint256 subAccount, | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
|         bool enableCollateral, | ||||
| 		bool enableCollateral, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	) | ||||
|  | @ -50,28 +50,35 @@ abstract contract Euler is Helpers { | |||
| 		approve(tokenContract, EULER_MAINNET, _amt); | ||||
| 
 | ||||
| 		IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); | ||||
| 		eToken.deposit(subAccount, _amt);//0 for primary | ||||
| 		eToken.deposit(subAccount, _amt); //0 for primary | ||||
| 
 | ||||
|         if (enableCollateral) { | ||||
|             markets.enterMarket(subAccount, _token); | ||||
|         } | ||||
| 		if (enableCollateral) { | ||||
| 			markets.enterMarket(subAccount, _token); | ||||
| 		} | ||||
| 		setUint(setId, _amt); | ||||
| 
 | ||||
| 		_eventName = "LogDeposit(uint256,address,uint256,bool,uint256,uint256)"; | ||||
| 		_eventParam = abi.encode(subAccount, token, _amt, enableCollateral, getId, setId); | ||||
| 		_eventParam = abi.encode( | ||||
| 			subAccount, | ||||
| 			token, | ||||
| 			_amt, | ||||
| 			enableCollateral, | ||||
| 			getId, | ||||
| 			setId | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
|     /** | ||||
| 	/** | ||||
| 	 * @dev Withdraw ETH/ERC20_Token. | ||||
| 	 * @notice Withdraw deposited token Euler | ||||
|      * @param subAccount Subaccount number | ||||
| 	 * @param subAccount Subaccount number | ||||
| 	 * @param token The address of the token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to withdraw. (For max: `uint256(-1)`) | ||||
| 	 * @param getId ID to retrieve amt. | ||||
| 	 * @param setId ID stores the amount of tokens withdrawn. | ||||
| 	 */ | ||||
| 	function withdraw( | ||||
|         uint256 subAccount, | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
| 		uint256 getId, | ||||
|  | @ -87,8 +94,8 @@ abstract contract Euler is Helpers { | |||
| 		address _token = isEth ? wethAddr : token; | ||||
| 
 | ||||
| 		TokenInterface tokenContract = TokenInterface(_token); | ||||
|          | ||||
|         IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); | ||||
| 
 | ||||
| 		IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); | ||||
| 
 | ||||
| 		uint256 initialBal = tokenContract.balanceOf(address(this)); | ||||
| 		eToken.withdraw(subAccount, _amt); | ||||
|  | @ -107,14 +114,14 @@ abstract contract Euler is Helpers { | |||
| 	/** | ||||
| 	 * @dev Borrow ETH/ERC20_Token. | ||||
| 	 * @notice Borrow a token from Euler | ||||
|      * @param subAccount Subaccount number | ||||
| 	 * @param subAccount Subaccount number | ||||
| 	 * @param token The address of the token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to borrow. (For max: `uint256(-1)`) | ||||
| 	 * @param getId ID to retrieve amt. | ||||
| 	 * @param setId ID stores the amount of tokens deposited. | ||||
| 	 */ | ||||
|     function borrow( | ||||
|         uint256 subAccount, | ||||
| 	function borrow( | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
| 		uint256 getId, | ||||
|  | @ -124,33 +131,35 @@ abstract contract Euler is Helpers { | |||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
|         uint256 _amt = getUint(getId, amt);//max value? | ||||
| 		uint256 _amt = getUint(getId, amt); | ||||
| 
 | ||||
|         bool isEth = token == ethAddr ? true : false; | ||||
|         address _token = isEth ? wethAddr : token; | ||||
| 		bool isEth = token == ethAddr ? true : false; | ||||
| 		address _token = isEth ? wethAddr : token; | ||||
| 
 | ||||
|         IEulerDToken borrowedDToken = IEulerDToken(markets.underlyingToDToken(_token)); | ||||
|         borrowedDToken.borrow(subAccount, amt); | ||||
| 		IEulerDToken borrowedDToken = IEulerDToken( | ||||
| 			markets.underlyingToDToken(_token) | ||||
| 		); | ||||
| 		borrowedDToken.borrow(subAccount, amt); | ||||
| 
 | ||||
|         convertWethToEth(isEth, TokenInterface(_token), _amt); | ||||
| 		convertWethToEth(isEth, TokenInterface(_token), _amt); | ||||
| 
 | ||||
|         setUint(setId, _amt); | ||||
| 		setUint(setId, _amt); | ||||
| 
 | ||||
|         _eventName = "LogBorrow(uint256,address,uint256,uint256,uint256)"; | ||||
| 		_eventName = "LogBorrow(uint256,address,uint256,uint256,uint256)"; | ||||
| 		_eventParam = abi.encode(subAccount, token, _amt, getId, setId); | ||||
|     } | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @dev Repay ETH/ERC20_Token. | ||||
| 	 * @notice Repay a token from Euler | ||||
|      * @param subAccount Subaccount number | ||||
| 	 * @param subAccount Subaccount number | ||||
| 	 * @param token The address of the token to repay.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to repay. (For max: `uint256(-1)`) | ||||
| 	 * @param getId ID to retrieve amt. | ||||
| 	 * @param setId ID stores the amount of tokens deposited. | ||||
| 	 */ | ||||
|     function repay( | ||||
|         uint256 subAccount, | ||||
| 	function repay( | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
| 		uint256 getId, | ||||
|  | @ -160,37 +169,41 @@ abstract contract Euler is Helpers { | |||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
|         uint256 _amt = getUint(getId, amt); | ||||
| 		uint256 _amt = getUint(getId, amt); | ||||
| 
 | ||||
|         bool isEth = token == ethAddr ? true : false; | ||||
| 		bool isEth = token == ethAddr ? true : false; | ||||
| 
 | ||||
|         address _token = isEth ? wethAddr : token; | ||||
| 		IEulerDToken borrowedDToken = IEulerDToken(markets.underlyingToDToken(_token)); | ||||
| 		address _token = isEth ? wethAddr : token; | ||||
| 		IEulerDToken borrowedDToken = IEulerDToken( | ||||
| 			markets.underlyingToDToken(_token) | ||||
| 		); | ||||
| 
 | ||||
|         if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 		if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 
 | ||||
| 		_amt = _amt == type(uint).max ? borrowedDToken.balanceOf(address(this)) : _amt; | ||||
| 		_amt = _amt == type(uint256).max | ||||
| 			? borrowedDToken.balanceOf(address(this)) | ||||
| 			: _amt; | ||||
| 
 | ||||
| 		TokenInterface(_token).approve(EULER_MAINNET, _amt); | ||||
|         borrowedDToken.repay(subAccount, amt); | ||||
| 		borrowedDToken.repay(subAccount, amt); | ||||
| 
 | ||||
| 		setUint(setId, _amt); | ||||
| 
 | ||||
| 		_eventName = "LogRepay(uint256,address,uint256,uint256,uint256)"; | ||||
| 		_eventParam = abi.encode(subAccount, token, _amt, getId, setId); | ||||
|     } | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @dev Mint ETH/ERC20_Token. | ||||
| 	 * @notice Mint a token from Euler. Maint creates equal amount of deposits and debts. | ||||
|      * @param subAccount Subaccount number | ||||
| 	 * @param subAccount Subaccount number | ||||
| 	 * @param token The address of the token to mint.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to mint. | ||||
| 	 * @param getId ID to retrieve amt. | ||||
| 	 * @param setId ID stores the amount of tokens deposited. | ||||
| 	 */ | ||||
| 	function mint( | ||||
|         uint256 subAccount, | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
| 		uint256 getId, | ||||
|  | @ -200,66 +213,68 @@ abstract contract Euler is Helpers { | |||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
|         uint256 _amt = getUint(getId, amt); | ||||
| 		uint256 _amt = getUint(getId, amt); | ||||
| 
 | ||||
|         bool isEth = token == ethAddr ? true : false; | ||||
|         address _token = isEth ? wethAddr : token; | ||||
| 		bool isEth = token == ethAddr ? true : false; | ||||
| 		address _token = isEth ? wethAddr : token; | ||||
| 		IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); | ||||
| 
 | ||||
|         if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 		if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 
 | ||||
|         eToken.mint(subAccount, amt); | ||||
| 		eToken.mint(subAccount, amt); | ||||
| 
 | ||||
| 		setUint(setId, _amt); | ||||
| 
 | ||||
| 		_eventName = "LogMint(uint256,address,uint256,uint256,uint256)"; | ||||
| 		_eventParam = abi.encode(subAccount, token, _amt, getId, setId); | ||||
|     } | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @dev Burn ETH/ERC20_Token. | ||||
| 	 * @notice Burn a token from Euler. Burn removes equal amount of deposits and debts. | ||||
|      * @param subAccount Subaccount number | ||||
| 	 * @param subAccount Subaccount number | ||||
| 	 * @param token The address of the token to burn.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to burn. (For max: `uint256(-1)`) | ||||
| 	 * @param getId ID to retrieve amt. | ||||
| 	 * @param setId ID stores the amount of tokens deposited. | ||||
| 	 */ | ||||
| 	function burn( | ||||
|         uint256 subAccount, | ||||
| 		address token,//eth | ||||
| 		uint256 amt,//max | ||||
| 		uint256 getId,//1 | ||||
| 		uint256 subAccount, | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	) | ||||
| 		external | ||||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
|         uint256 _amt = getUint(getId, amt); | ||||
| 		uint256 _amt = getUint(getId, amt); | ||||
| 
 | ||||
|         bool isEth = token == ethAddr ? true : false; | ||||
|         address _token = isEth ? wethAddr : token; | ||||
| 		bool isEth = token == ethAddr ? true : false; | ||||
| 		address _token = isEth ? wethAddr : token; | ||||
| 
 | ||||
| 		IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token)); | ||||
| 		IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); | ||||
| 
 | ||||
| 		_amt = _amt == type(uint).max ? dToken.balanceOf(address(this)) : _amt; | ||||
| 		_amt = _amt == type(uint256).max | ||||
| 			? dToken.balanceOf(address(this)) | ||||
| 			: _amt; | ||||
| 
 | ||||
|         if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 		if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 
 | ||||
|         eToken.burn(subAccount, amt); | ||||
| 		eToken.burn(subAccount, amt); | ||||
| 
 | ||||
| 		setUint(setId, _amt); | ||||
| 
 | ||||
| 		_eventName = "LogBurn(uint256,address,uint256,uint256,uint256)"; | ||||
| 		_eventParam = abi.encode(subAccount, token, _amt, getId, setId); | ||||
|     } | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @dev ETransfer ETH/ERC20_Token. | ||||
| 	 * @notice ETransfer deposits from account to another. | ||||
|      * @param subAccountFrom subAccount from which deposit is transferred | ||||
| 	 * @param subAccountFrom subAccount from which deposit is transferred | ||||
| 	 * @param subAccountTo subAccount to which deposit is transferred | ||||
| 	 * @param token The address of the token to etransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to etransfer. (For max: `uint256(-1)`) | ||||
|  | @ -267,42 +282,51 @@ abstract contract Euler is Helpers { | |||
| 	 * @param setId ID stores the amount of tokens deposited. | ||||
| 	 */ | ||||
| 	function eTransfer( | ||||
|         uint256 subAccountFrom, | ||||
| 		uint256 subAccountFrom, | ||||
| 		uint256 subAccountTo, | ||||
| 		address token,//eth | ||||
| 		uint256 amt,//max | ||||
| 		uint256 getId,//1 | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	) | ||||
| 		external | ||||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
|         uint256 _amt = getUint(getId, amt); | ||||
| 		uint256 _amt = getUint(getId, amt); | ||||
| 
 | ||||
|         bool isEth = token == ethAddr ? true : false; | ||||
|         address _token = isEth ? wethAddr : token; | ||||
| 		bool isEth = token == ethAddr ? true : false; | ||||
| 		address _token = isEth ? wethAddr : token; | ||||
| 
 | ||||
| 		IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); | ||||
| 
 | ||||
| 		_amt = _amt == type(uint).max ? eToken.balanceOf(address(this)) : _amt; | ||||
| 		_amt = _amt == type(uint256).max | ||||
| 			? eToken.balanceOf(address(this)) | ||||
| 			: _amt; | ||||
| 
 | ||||
|         if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 		if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 
 | ||||
| 		address _subAccountToAddr = getSubAccount(address(this), subAccountTo); | ||||
| 
 | ||||
|         eToken.transfer(_subAccountToAddr, amt); | ||||
| 		eToken.transfer(_subAccountToAddr, amt); | ||||
| 
 | ||||
| 		setUint(setId, _amt); | ||||
| 
 | ||||
| 		_eventName = "LogETransfer(uint256,uint256,address,uint256,uint256,uint256)"; | ||||
| 		_eventParam = abi.encode(subAccountFrom, subAccountTo, token, _amt, getId, setId); | ||||
|     } | ||||
| 		_eventParam = abi.encode( | ||||
| 			subAccountFrom, | ||||
| 			subAccountTo, | ||||
| 			token, | ||||
| 			_amt, | ||||
| 			getId, | ||||
| 			setId | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @dev DTransfer ETH/ERC20_Token. | ||||
| 	 * @notice DTransfer deposits from account to another. | ||||
|      * @param subAccountFrom subAccount from which debt is transferred | ||||
| 	 * @param subAccountFrom subAccount from which debt is transferred | ||||
| 	 * @param subAccountTo subAccount to which debt is transferred | ||||
| 	 * @param token The address of the token to dtransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||
| 	 * @param amt The amount of the token to dtransfer. (For max: `uint256(-1)`) | ||||
|  | @ -310,36 +334,45 @@ abstract contract Euler is Helpers { | |||
| 	 * @param setId ID stores the amount of tokens deposited. | ||||
| 	 */ | ||||
| 	function dTransfer( | ||||
|         uint256 subAccountFrom, | ||||
| 		uint256 subAccountFrom, | ||||
| 		uint256 subAccountTo, | ||||
| 		address token,//eth | ||||
| 		uint256 amt,//max | ||||
| 		uint256 getId,//1 | ||||
| 		address token, | ||||
| 		uint256 amt, | ||||
| 		uint256 getId, | ||||
| 		uint256 setId | ||||
| 	) | ||||
| 		external | ||||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
|         uint256 _amt = getUint(getId, amt); | ||||
| 		uint256 _amt = getUint(getId, amt); | ||||
| 
 | ||||
|         bool isEth = token == ethAddr ? true : false; | ||||
|         address _token = isEth ? wethAddr : token; | ||||
| 		bool isEth = token == ethAddr ? true : false; | ||||
| 		address _token = isEth ? wethAddr : token; | ||||
| 
 | ||||
| 		IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token)); | ||||
| 
 | ||||
| 		_amt = _amt == type(uint).max ? dToken.balanceOf(address(this)) : _amt; | ||||
| 		_amt = _amt == type(uint256).max | ||||
| 			? dToken.balanceOf(address(this)) | ||||
| 			: _amt; | ||||
| 
 | ||||
|         if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 		if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); | ||||
| 
 | ||||
| 		address _subAccountToAddr = getSubAccount(address(this), subAccountTo); | ||||
|         dToken.transfer(_subAccountToAddr, amt); | ||||
| 		dToken.transfer(_subAccountToAddr, amt); | ||||
| 
 | ||||
| 		setUint(setId, _amt); | ||||
| 
 | ||||
| 		_eventName = "LogDTransfer(uint256,uint256,address,uint256,uint256,uint256)"; | ||||
| 		_eventParam = abi.encode(subAccountFrom, subAccountTo, token, _amt, getId, setId); | ||||
|     } | ||||
| 		_eventParam = abi.encode( | ||||
| 			subAccountFrom, | ||||
| 			subAccountTo, | ||||
| 			token, | ||||
| 			_amt, | ||||
| 			getId, | ||||
| 			setId | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| 	function approveDebt( | ||||
| 		uint256 subAccountId, | ||||
|  | @ -359,7 +392,9 @@ abstract contract Euler is Helpers { | |||
| 		address _token = isEth ? wethAddr : token; | ||||
| 
 | ||||
| 		IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token)); | ||||
| 		_amt = _amt == type(uint).max ? dToken.balanceOf(address(this)) : _amt; | ||||
| 		_amt = _amt == type(uint256).max | ||||
| 			? dToken.balanceOf(address(this)) | ||||
| 			: _amt; | ||||
| 
 | ||||
| 		dToken.approveDebt(subAccountId, debtReceiver, _amt); | ||||
| 
 | ||||
|  | @ -372,67 +407,87 @@ abstract contract Euler is Helpers { | |||
| 	struct swapHelper { | ||||
| 		address _sellAddr; | ||||
| 		address _buyAddr; | ||||
| 		uint _buyDec; | ||||
| 		uint _sellDec; | ||||
| 		uint _sellAmt18; | ||||
| 		uint _slippageAmt; | ||||
| 		uint256 _buyDec; | ||||
| 		uint256 _sellDec; | ||||
| 		uint256 _sellAmt18; | ||||
| 		uint256 _slippageAmt; | ||||
| 	} | ||||
| 
 | ||||
| 	struct swapParams { | ||||
| 		uint256 subAccountFrom; | ||||
| 		uint subAccountTo; | ||||
|         address buyAddr; | ||||
|         address sellAddr; | ||||
|         uint sellAmt; | ||||
|         uint unitAmt; | ||||
|         bytes callData; | ||||
| 		uint256 subAccountTo; | ||||
| 		address buyAddr; | ||||
| 		address sellAddr; | ||||
| 		uint256 sellAmt; | ||||
| 		uint256 unitAmt; | ||||
| 		bytes callData; | ||||
| 	} | ||||
| 
 | ||||
| 	function swap( | ||||
| 		swapParams memory params | ||||
| 	) | ||||
| 	function swap(swapParams memory params) | ||||
| 		external | ||||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
| 		swapHelper memory helperParams; | ||||
| 
 | ||||
| 		helperParams._sellAddr = params.sellAddr == ethAddr ? wethAddr : params.sellAddr; | ||||
| 		helperParams._buyAddr = params.sellAddr == ethAddr ? wethAddr : params.buyAddr; | ||||
| 		helperParams._sellAddr = params.sellAddr == ethAddr | ||||
| 			? wethAddr | ||||
| 			: params.sellAddr; | ||||
| 		helperParams._buyAddr = params.sellAddr == ethAddr | ||||
| 			? wethAddr | ||||
| 			: params.buyAddr; | ||||
| 
 | ||||
| 		TokenInterface sellToken = TokenInterface(helperParams._sellAddr); | ||||
| 		TokenInterface buyToken = TokenInterface(helperParams._buyAddr); | ||||
| 
 | ||||
| 		approve(sellToken, address(swapExec), params.sellAmt); | ||||
| 
 | ||||
|     	(helperParams._buyDec, helperParams._sellDec) = getTokensDec(buyToken, sellToken); | ||||
|         helperParams._sellAmt18 = convertTo18(helperParams._sellDec, params.sellAmt); | ||||
|         helperParams._slippageAmt = convert18ToDec(helperParams._buyDec, wmul(params.unitAmt, helperParams._sellAmt18)); | ||||
| 		(helperParams._buyDec, helperParams._sellDec) = getTokensDec( | ||||
| 			buyToken, | ||||
| 			sellToken | ||||
| 		); | ||||
| 		helperParams._sellAmt18 = convertTo18( | ||||
| 			helperParams._sellDec, | ||||
| 			params.sellAmt | ||||
| 		); | ||||
| 		helperParams._slippageAmt = convert18ToDec( | ||||
| 			helperParams._buyDec, | ||||
| 			wmul(params.unitAmt, helperParams._sellAmt18) | ||||
| 		); | ||||
| 
 | ||||
| 		IEulerSwap.Swap1InchParams memory oneInchParams = IEulerSwap.Swap1InchParams({ | ||||
|             subAccountIdIn: params.subAccountFrom, | ||||
| 			subAccountIdOut: params.subAccountTo, | ||||
| 			underlyingIn: helperParams._sellAddr, | ||||
|             underlyingOut: helperParams._buyAddr, | ||||
|             amount: params.sellAmt, | ||||
| 			amountOutMinimum: helperParams._slippageAmt, | ||||
|             payload: params.callData | ||||
|         }); | ||||
| 		IEulerSwap.Swap1InchParams memory oneInchParams = IEulerSwap | ||||
| 			.Swap1InchParams({ | ||||
| 				subAccountIdIn: params.subAccountFrom, | ||||
| 				subAccountIdOut: params.subAccountTo, | ||||
| 				underlyingIn: helperParams._sellAddr, | ||||
| 				underlyingOut: helperParams._buyAddr, | ||||
| 				amount: params.sellAmt, | ||||
| 				amountOutMinimum: helperParams._slippageAmt, | ||||
| 				payload: params.callData | ||||
| 			}); | ||||
| 
 | ||||
| 		swapExec.swap1Inch(oneInchParams); | ||||
| 
 | ||||
| 		if(!checkIfEnteredMarket(helperParams._buyAddr)) { | ||||
| 		if (!checkIfEnteredMarket(helperParams._buyAddr)) { | ||||
| 			markets.enterMarket(params.subAccountTo, helperParams._buyAddr); | ||||
| 		} | ||||
| 
 | ||||
| 		_eventName = "LogSwap(uint256,uint256,address,address,uint256,uint256,bytes)"; | ||||
| 		_eventParam = abi.encode(params.subAccountFrom, params.subAccountTo, params.buyAddr, params.sellAddr, params.sellAmt, params.unitAmt, params.callData); | ||||
|     } | ||||
| 		_eventParam = abi.encode( | ||||
| 			params.subAccountFrom, | ||||
| 			params.subAccountTo, | ||||
| 			params.buyAddr, | ||||
| 			params.sellAddr, | ||||
| 			params.sellAmt, | ||||
| 			params.unitAmt, | ||||
| 			params.callData | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| 	function enterMarket(uint subAccountId, address[] memory newMarkets)  | ||||
| 		external  | ||||
| 		payable  | ||||
| 		returns (string memory _eventName, bytes memory _eventParam)  | ||||
| 	function enterMarket(uint256 subAccountId, address[] memory newMarkets) | ||||
| 		external | ||||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
| 		uint256 _length = newMarkets.length; | ||||
| 		require(_length > 0, "0-markets-not-allowed"); | ||||
|  | @ -441,7 +496,9 @@ abstract contract Euler is Helpers { | |||
| 			bool isEth = newMarkets[i] == ethAddr; | ||||
| 			address _token = isEth ? wethAddr : newMarkets[i]; | ||||
| 
 | ||||
| 			IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); | ||||
| 			IEulerEToken eToken = IEulerEToken( | ||||
| 				markets.underlyingToEToken(_token) | ||||
| 			); | ||||
| 			markets.enterMarket(subAccountId, _token); | ||||
| 		} | ||||
| 
 | ||||
|  | @ -449,10 +506,10 @@ abstract contract Euler is Helpers { | |||
| 		_eventParam = abi.encode(subAccountId, newMarkets); | ||||
| 	} | ||||
| 
 | ||||
| 	function exitMarket(uint subAccountId, address oldMarket)  | ||||
| 		external  | ||||
| 		payable  | ||||
| 		returns (string memory _eventName, bytes memory _eventParam)  | ||||
| 	function exitMarket(uint256 subAccountId, address oldMarket) | ||||
| 		external | ||||
| 		payable | ||||
| 		returns (string memory _eventName, bytes memory _eventParam) | ||||
| 	{ | ||||
| 		bool isEth = oldMarket == ethAddr; | ||||
| 		address _token = isEth ? wethAddr : oldMarket; | ||||
|  |  | |||
|  | @ -3,7 +3,10 @@ pragma solidity ^0.7.0; | |||
| import "./interface.sol"; | ||||
| 
 | ||||
| contract Variables { | ||||
|     address internal constant EULER_MAINNET = 0x27182842E098f60e3D576794A5bFFb0777E025d3; | ||||
|     IEulerMarkets internal constant markets = IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3); | ||||
|     IEulerSwap internal constant swapExec = IEulerSwap(0x7123C8cBBD76c5C7fCC9f7150f23179bec0bA341); | ||||
| 	address internal constant EULER_MAINNET = | ||||
| 		0x27182842E098f60e3D576794A5bFFb0777E025d3; | ||||
| 	IEulerMarkets internal constant markets = | ||||
| 		IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3); | ||||
| 	IEulerSwap internal constant swapExec = | ||||
| 		IEulerSwap(0x7123C8cBBD76c5C7fCC9f7150f23179bec0bA341); | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Shriya Tyagi
						Shriya Tyagi