From 4bef3dd2942f090fa3068c799aa488ec172b7519 Mon Sep 17 00:00:00 2001 From: Pierrick Turelier Date: Mon, 28 Jun 2021 11:22:20 +0200 Subject: [PATCH] fix(contract): depositToAave gas optimization --- contracts/yield-source/ATokenYieldSource.sol | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/contracts/yield-source/ATokenYieldSource.sol b/contracts/yield-source/ATokenYieldSource.sol index 04ef3b4..7a5485e 100644 --- a/contracts/yield-source/ATokenYieldSource.sol +++ b/contracts/yield-source/ATokenYieldSource.sol @@ -69,8 +69,8 @@ contract ATokenYieldSource is ERC20Upgradeable, IProtocolYieldSource, AssetManag /// @notice Interface for Aave lendingPoolAddressesProviderRegistry ILendingPoolAddressesProviderRegistry public lendingPoolAddressesProviderRegistry; - - /// @notice Mock Initializer to prevent + + /// @notice Mock Initializer to prevent function freeze() public initializer { //no-op } @@ -171,13 +171,15 @@ contract ATokenYieldSource is ERC20Upgradeable, IProtocolYieldSource, AssetManag /// @notice Deposit asset tokens to Aave /// @param mintAmount The amount of asset tokens to be deposited - /// @return 0 if successful + /// @return 0 if successful function _depositToAave(uint256 mintAmount) internal returns (uint256) { - IERC20Upgradeable _depositToken = IERC20Upgradeable(_tokenAddress()); + address _tokenAddress = _tokenAddress(); + ILendingPool _lendingPool = _lendingPool(); + IERC20Upgradeable _depositToken = IERC20Upgradeable(_tokenAddress); _depositToken.safeTransferFrom(msg.sender, address(this), mintAmount); - _depositToken.safeApprove(address(_lendingPool()), mintAmount); - _lendingPool().deposit(address(_tokenAddress()), mintAmount, address(this), _getRefferalCode()); + _depositToken.safeApprove(address(_lendingPool), mintAmount); + _lendingPool.deposit(_tokenAddress, mintAmount, address(this), _getRefferalCode()); return 0; }