Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary network-specific instanciation #367

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/WNativeBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ abstract contract WNativeBundler is BaseBundler {
/// @dev Warning: assumes the given addresses are non-zero (they are not expected to be deployment arguments).
/// @param wNative The address of the wNative token contract.
constructor(address wNative) {
require(wNative != address(0), ErrorsLib.ZERO_ADDRESS);

WRAPPED_NATIVE = wNative;
}

Expand Down
3 changes: 0 additions & 3 deletions src/ethereum/libraries/MainnetLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ library MainnetLib {
/// @dev The address of the wstETH contract on Ethereum.
address internal constant WST_ETH = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0;

/// @dev The address of AaveV2's lending pool contract on Ethereum.
address internal constant AAVE_V2_POOL = 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9;

/// @dev The address of DAI on Ethereum mainnet.
address internal constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
}
26 changes: 0 additions & 26 deletions src/ethereum/migration/AaveV2EthereumMigrationBundler.sol

This file was deleted.

15 changes: 13 additions & 2 deletions src/migration/AaveV2MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {IAaveV2} from "./interfaces/IAaveV2.sol";
import {Math} from "../../lib/morpho-utils/src/math/Math.sol";
import {ErrorsLib} from "../libraries/ErrorsLib.sol";

import {BaseBundler} from "../BaseBundler.sol";
import {StEthBundler} from "../StEthBundler.sol";
import {MigrationBundler, ERC20} from "./MigrationBundler.sol";

/// @title AaveV2MigrationBundler
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Contract allowing to migrate a position from Aave V2 to Morpho Blue easily.
/// If deploying to Ethereum, deploy `AaveV2EthereumMigrationBundler` instead.
contract AaveV2MigrationBundler is MigrationBundler {
contract AaveV2MigrationBundler is MigrationBundler, StEthBundler {
/* IMMUTABLES */

/// @dev The AaveV2 contract address.
Expand All @@ -24,7 +26,9 @@ contract AaveV2MigrationBundler is MigrationBundler {
/// @param morpho The Morpho contract Address.
/// @param aaveV2Pool The AaveV2 contract address. Assumes it is non-zero (not expected to be an input at
/// deployment).
constructor(address morpho, address aaveV2Pool) MigrationBundler(morpho) {
constructor(address morpho, address aaveV2Pool, address wstEth) MigrationBundler(morpho) StEthBundler(wstEth) {
require(aaveV2Pool != address(0), ErrorsLib.ZERO_ADDRESS);

AAVE_V2_POOL = IAaveV2(aaveV2Pool);
}

Expand Down Expand Up @@ -53,4 +57,11 @@ contract AaveV2MigrationBundler is MigrationBundler {
function aaveV2Withdraw(address asset, uint256 amount) external payable protected {
AAVE_V2_POOL.withdraw(asset, amount, address(this));
}

/* INTERNAL */

/// @inheritdoc MigrationBundler
function _isSenderAuthorized() internal view virtual override(BaseBundler, MigrationBundler) returns (bool) {
return MigrationBundler._isSenderAuthorized();
}
}
2 changes: 2 additions & 0 deletions src/migration/AaveV3MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ contract AaveV3MigrationBundler is MigrationBundler {
/// @param aaveV3Pool The AaveV3 contract address. Assumes it is non-zero (not expected to be an input at
/// deployment).
constructor(address morpho, address aaveV3Pool) MigrationBundler(morpho) {
require(aaveV3Pool != address(0), ErrorsLib.ZERO_ADDRESS);

AAVE_V3_POOL = IAaveV3(aaveV3Pool);
}

Expand Down
2 changes: 2 additions & 0 deletions src/migration/AaveV3OptimizerMigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler {
/// @param aaveV3Optimizer The AaveV3 optimizer contract address. Assumes it is non-zero (not expected to be an
/// input at deployment).
constructor(address morpho, address aaveV3Optimizer) MigrationBundler(morpho) {
require(aaveV3Optimizer != address(0), ErrorsLib.ZERO_ADDRESS);

AAVE_V3_OPTIMIZER = IAaveV3Optimizer(aaveV3Optimizer);
}

Expand Down
2 changes: 2 additions & 0 deletions src/migration/CompoundV2MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ contract CompoundV2MigrationBundler is WNativeBundler, MigrationBundler {
/// @param wNative The address of the wNative token contract.
/// @param cEth The address of the cETH contract.
constructor(address morpho, address wNative, address cEth) WNativeBundler(wNative) MigrationBundler(morpho) {
require(cEth != address(0), ErrorsLib.ZERO_ADDRESS);

C_ETH = cEth;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {IStEth} from "../../../../src/interfaces/IStEth.sol";
import {IAaveV2} from "../../../../src/migration/interfaces/IAaveV2.sol";
import {IERC4626} from "../../../../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";

import "../../../../src/ethereum/migration/AaveV2EthereumMigrationBundler.sol";
import "../../../../src/migration/AaveV2MigrationBundler.sol";

import "./helpers/EthereumMigrationTest.sol";

contract AaveV2EthereumMigrationBundlerEthereumTest is EthereumMigrationTest {
contract AaveV2MigrationBundlerEthereumTest is EthereumMigrationTest {
using SafeTransferLib for ERC20;
using MarketParamsLib for MarketParams;
using MorphoLib for IMorpho;
Expand All @@ -27,14 +27,21 @@ contract AaveV2EthereumMigrationBundlerEthereumTest is EthereumMigrationTest {

vm.label(AAVE_V2_POOL, "Aave V2 Pool");

bundler = new AaveV2EthereumMigrationBundler(address(morpho));
bundler = new AaveV2MigrationBundler(address(morpho), AAVE_V2_POOL, WST_ETH);
}

function testAaveV2RepayUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV2EthereumMigrationBundler(address(bundler)).aaveV2Repay(marketParams.loanToken, amount, 1);
AaveV2MigrationBundler(address(bundler)).aaveV2Repay(marketParams.loanToken, amount, 1);
}

function testAaveV2WithdrawUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV2MigrationBundler(address(bundler)).aaveV2Withdraw(marketParams.loanToken, amount);
}

function testAaveV2RepayZeroAmount() public {
Expand Down
Loading