mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	feat: optimise
This commit is contained in:
		
							parent
							
								
									d3458ee7e3
								
							
						
					
					
						commit
						001a4777e6
					
				|  | @ -22,17 +22,28 @@ abstract contract Helpers is Stores, Basic { | ||||||
|     /// high precision computations. |     /// high precision computations. | ||||||
|     uint256 internal constant VIRTUAL_SHARES = 1e6; |     uint256 internal constant VIRTUAL_SHARES = 1e6; | ||||||
| 
 | 
 | ||||||
|  | 	enum Mode { | ||||||
|  | 		Collateral, | ||||||
|  | 		Repay, | ||||||
|  | 		Other // Neither collateral nor repay | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	/// @notice Handles Eth to Weth conversion if assets are provided. | 	/// @notice Handles Eth to Weth conversion if assets are provided. | ||||||
| 	function _performEthToWethConversion( | 	function _performEthToWethConversion( | ||||||
| 		MarketParams memory _marketParams, | 		MarketParams memory _marketParams, | ||||||
| 		uint256 _assets, | 		uint256 _assets, | ||||||
| 		address _onBehalf, | 		address _onBehalf, | ||||||
| 		uint256 _getId, | 		uint256 _getId, | ||||||
| 		bool _isCollateral, | 		Mode _mode | ||||||
| 		bool _isRepay |  | ||||||
| 	) internal returns (TokenInterface _tokenContract, uint256 _amt) { | 	) internal returns (TokenInterface _tokenContract, uint256 _amt) { | ||||||
| 		_amt = getUint(_getId, _assets); | 		_amt = getUint(_getId, _assets); | ||||||
| 		bool _isEth = _isCollateral ? _marketParams.collateralToken == ethAddr : _marketParams.loanToken == ethAddr; | 
 | ||||||
|  | 		bool _isEth; | ||||||
|  | 		if (_mode == Mode.Collateral) { | ||||||
|  | 			_isEth = _marketParams.collateralToken == ethAddr; | ||||||
|  | 		} else { | ||||||
|  | 			_isEth = _marketParams.loanToken == ethAddr; | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		// Set the correct token contract | 		// Set the correct token contract | ||||||
| 		_tokenContract = _isEth ? TokenInterface(wethAddr) : TokenInterface(_marketParams.loanToken); | 		_tokenContract = _isEth ? TokenInterface(wethAddr) : TokenInterface(_marketParams.loanToken); | ||||||
|  | @ -40,7 +51,7 @@ abstract contract Helpers is Stores, Basic { | ||||||
| 		// Check for max value | 		// Check for max value | ||||||
| 		if (_assets == type(uint256).max) { | 		if (_assets == type(uint256).max) { | ||||||
| 			uint256 _maxAvailable = _isEth ? address(this).balance : _tokenContract.balanceOf(address(this)); | 			uint256 _maxAvailable = _isEth ? address(this).balance : _tokenContract.balanceOf(address(this)); | ||||||
| 			if (_isRepay) { | 			if (_mode == Mode.Repay) { | ||||||
| 				uint256 _amtDebt = getPaybackBalance(_marketParams, _onBehalf); | 				uint256 _amtDebt = getPaybackBalance(_marketParams, _onBehalf); | ||||||
| 				_amt = min(_maxAvailable, _amtDebt); | 				_amt = min(_maxAvailable, _amtDebt); | ||||||
| 			} else { | 			} else { | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ abstract contract MorphoBlue is Helpers, Events { | ||||||
| 		( | 		( | ||||||
| 			TokenInterface _tokenContract, // Loan token contract | 			TokenInterface _tokenContract, // Loan token contract | ||||||
| 			uint256 _amt | 			uint256 _amt | ||||||
| 		) = _performEthToWethConversion(_marketParams, _assets, address(this), _getId, false, false); | 		) = _performEthToWethConversion(_marketParams, _assets, address(this), _getId, Mode.Other); | ||||||
| 
 | 
 | ||||||
| 		// Approving loan token for supplying | 		// Approving loan token for supplying | ||||||
| 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | ||||||
|  | @ -77,7 +77,7 @@ abstract contract MorphoBlue is Helpers, Events { | ||||||
| 		( | 		( | ||||||
| 			TokenInterface _tokenContract, // Loan token contract | 			TokenInterface _tokenContract, // Loan token contract | ||||||
| 			uint256 _amt | 			uint256 _amt | ||||||
| 		) = _performEthToWethConversion(_marketParams, _assets, _onBehalf, _getId, false, false); | 		) = _performEthToWethConversion(_marketParams, _assets, _onBehalf, _getId, Mode.Other); | ||||||
| 
 | 
 | ||||||
| 		// Approving loan token for supplying | 		// Approving loan token for supplying | ||||||
| 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | ||||||
|  | @ -171,7 +171,7 @@ abstract contract MorphoBlue is Helpers, Events { | ||||||
| 		( | 		( | ||||||
| 			TokenInterface _tokenContract, // Collateral token contract | 			TokenInterface _tokenContract, // Collateral token contract | ||||||
| 			uint256 _amt | 			uint256 _amt | ||||||
| 		) = _performEthToWethConversion(_marketParams, _assets, address(this), _getId, true, false); | 		) = _performEthToWethConversion(_marketParams, _assets, address(this), _getId, Mode.Collateral); | ||||||
| 
 | 
 | ||||||
| 		// Approving collateral token | 		// Approving collateral token | ||||||
| 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | ||||||
|  | @ -216,7 +216,7 @@ abstract contract MorphoBlue is Helpers, Events { | ||||||
| 		( | 		( | ||||||
| 			TokenInterface _tokenContract, // Collateral token contract | 			TokenInterface _tokenContract, // Collateral token contract | ||||||
| 			uint256 _amt | 			uint256 _amt | ||||||
| 		) = _performEthToWethConversion(_marketParams, _assets, _onBehalf, _getId, true, false); | 		) = _performEthToWethConversion(_marketParams, _assets, _onBehalf, _getId, Mode.Collateral); | ||||||
| 
 | 
 | ||||||
| 		// Approving collateral token | 		// Approving collateral token | ||||||
| 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | ||||||
|  | @ -638,7 +638,7 @@ abstract contract MorphoBlue is Helpers, Events { | ||||||
| 		( | 		( | ||||||
| 			TokenInterface _tokenContract, | 			TokenInterface _tokenContract, | ||||||
| 			uint256 _amt // Assets final amount to repay | 			uint256 _amt // Assets final amount to repay | ||||||
| 		) = _performEthToWethConversion(_marketParams, _assets, address(this), _getId, false, true); | 		) = _performEthToWethConversion(_marketParams, _assets, address(this), _getId, Mode.Repay); | ||||||
| 
 | 
 | ||||||
| 		// Approving loan token for repaying | 		// Approving loan token for repaying | ||||||
| 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | ||||||
|  | @ -692,7 +692,7 @@ abstract contract MorphoBlue is Helpers, Events { | ||||||
| 		( | 		( | ||||||
| 			TokenInterface _tokenContract, | 			TokenInterface _tokenContract, | ||||||
| 			uint256 _amt // Assets final amount to repay | 			uint256 _amt // Assets final amount to repay | ||||||
| 		) = _performEthToWethConversion(_marketParams, _assets, _onBehalf, _getId, false, true); | 		) = _performEthToWethConversion(_marketParams, _assets, _onBehalf, _getId, Mode.Repay); | ||||||
| 
 | 
 | ||||||
| 		// Approving loan token for repaying | 		// Approving loan token for repaying | ||||||
| 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | 		approve(_tokenContract, address(MORPHO_BLUE), _amt); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Shriya Tyagi
						Shriya Tyagi