Skip to content

Commit

Permalink
feat: support @aave/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
kartojal committed Jan 12, 2022
1 parent 8e8dfad commit 5426eab
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 26 deletions.
30 changes: 30 additions & 0 deletions contracts/libraries/DataTypesHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.10;

import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';

/**
* @title DataTypesHelper
* @author Aave
* @dev Helper library to track user current debt balance, used by WETHGateway
*/
library DataTypesHelper {
/**
* @notice Fetches the user current stable and variable debt balances
* @param user The user address
* @param reserve The reserve data object
* @return The stable debt balance
* @return The variable debt balance
**/
function getUserCurrentDebt(address user, DataTypes.ReserveData memory reserve)
internal
view
returns (uint256, uint256)
{
return (
IERC20(reserve.stableDebtTokenAddress).balanceOf(user),
IERC20(reserve.variableDebtTokenAddress).balanceOf(user)
);
}
}
2 changes: 1 addition & 1 deletion contracts/misc/UiIncentiveDataProviderV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAd
import {IRewardsController} from '../rewards/interfaces/IRewardsController.sol';
import {IUiIncentiveDataProviderV3} from './interfaces/IUiIncentiveDataProviderV3.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {IncentivizedERC20} from '@aave/core-v3/contracts/protocol/tokenization/IncentivizedERC20.sol';
import {IncentivizedERC20} from '@aave/core-v3/contracts/protocol/tokenization/base/IncentivizedERC20.sol';
import {UserConfiguration} from '@aave/core-v3/contracts/protocol/libraries/configuration/UserConfiguration.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
import {IERC20Detailed} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol';
Expand Down
27 changes: 10 additions & 17 deletions contracts/misc/WETHGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {IAToken} from '@aave/core-v3/contracts/interfaces/IAToken.sol';
import {ReserveConfiguration} from '@aave/core-v3/contracts/protocol/libraries/configuration/ReserveConfiguration.sol';
import {UserConfiguration} from '@aave/core-v3/contracts/protocol/libraries/configuration/UserConfiguration.sol';
import {Helpers} from '@aave/core-v3/contracts/protocol/libraries/helpers/Helpers.sol';
import {DataTypes} from '@aave/core-v3/contracts/protocol/libraries/types/DataTypes.sol';
import {DataTypesHelper} from '../libraries/DataTypesHelper.sol';

contract WETHGateway is IWETHGateway, Ownable {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
Expand Down Expand Up @@ -84,16 +84,15 @@ contract WETHGateway is IWETHGateway, Ownable {
uint256 rateMode,
address onBehalfOf
) external payable override {
(uint256 stableDebt, uint256 variableDebt) =
Helpers.getUserCurrentDebtMemory(
onBehalfOf,
IPool(pool).getReserveData(address(WETH))
);
(uint256 stableDebt, uint256 variableDebt) = DataTypesHelper.getUserCurrentDebt(
onBehalfOf,
IPool(pool).getReserveData(address(WETH))
);

uint256 paybackAmount =
DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.STABLE
? stableDebt
: variableDebt;
uint256 paybackAmount = DataTypes.InterestRateMode(rateMode) ==
DataTypes.InterestRateMode.STABLE
? stableDebt
: variableDebt;

if (amount < paybackAmount) {
paybackAmount = amount;
Expand All @@ -119,13 +118,7 @@ contract WETHGateway is IWETHGateway, Ownable {
uint256 interesRateMode,
uint16 referralCode
) external override {
IPool(pool).borrow(
address(WETH),
amount,
interesRateMode,
referralCode,
msg.sender
);
IPool(pool).borrow(address(WETH), amount, interesRateMode, referralCode, msg.sender);
WETH.withdraw(amount);
_safeTransferETH(msg.sender, amount);
}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@
"url": "git://github.com/aave/aave-v3-periphery"
},
"dependencies": {
"@aave/core-v3": "^1.9.0"
"@aave/core-v3": "^1.10.0"
}
}

0 comments on commit 5426eab

Please sign in to comment.