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

refactor: fork setup #171

Merged
merged 8 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 4 additions & 4 deletions .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ jobs:
type: ["slow", "fast"]
include:
- type: "slow"
fuzz-runs: 1024
fuzz-runs: 256
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
max-test-rejects: 65536
invariant-runs: 64
invariant-runs: 16
invariant-depth: 1024
- type: "fast"
fuzz-runs: 256
fuzz-runs: 64
max-test-rejects: 65536
invariant-runs: 16
invariant-runs: 4
invariant-depth: 256

steps:
Expand Down
7 changes: 0 additions & 7 deletions config/Configured.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ abstract contract Configured is StdChains {
address internal LINK;
address internal WBTC;
address internal WETH;
address internal CB_ETH;
address internal WNATIVE;
address[] internal lsdNatives;
address[] internal allAssets;

address internal AAVE_V2_POOL;
Expand Down Expand Up @@ -58,20 +56,15 @@ abstract contract Configured is StdChains {
LINK = CONFIG.getAddress("LINK");
WBTC = CONFIG.getAddress("WBTC");
WETH = CONFIG.getAddress("WETH");
CB_ETH = CONFIG.getAddress("cbETH");
WNATIVE = CONFIG.getWrappedNative();

lsdNatives = CONFIG.getLsdNatives();
allAssets = [DAI, USDC, USDT, LINK, WBTC, WETH];

ConfigMarket[] memory allConfigMarkets = CONFIG.getMarkets();
for (uint256 i; i < allConfigMarkets.length; ++i) {
configMarkets.push(allConfigMarkets[i]);
}

for (uint256 i; i < lsdNatives.length; ++i) {
allAssets.push(lsdNatives[i]);
}
AAVE_V3_POOL = CONFIG.getAddress("aaveV3Pool");
AAVE_V2_POOL = CONFIG.getAddress("aaveV2Pool");
AAVE_V3_OPTIMIZER = CONFIG.getAddress("aaveV3Optimizer");
Expand Down
31 changes: 31 additions & 0 deletions config/ConfiguredEthereum.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

import "./Configured.sol";

abstract contract ConfiguredEthereum is Configured {
using ConfigLib for Config;

address internal ST_ETH;
address internal WST_ETH;
address internal CB_ETH;
address[] internal allEthereumMainnetAssets;

function _network() internal view virtual override returns (string memory){
return "ethereum-mainnet";
}

function _loadConfig() internal virtual override {
super._loadConfig();

ST_ETH = CONFIG.getAddress("stETH");
WST_ETH = CONFIG.getAddress("wstETH");
CB_ETH = CONFIG.getAddress("cbETH");

allEthereumMainnetAssets = [ST_ETH, WST_ETH, CB_ETH];

for (uint256 i; i < allEthereumMainnetAssets.length; ++i) {
allAssets.push(allEthereumMainnetAssets[i]);
}
}
}
6 changes: 1 addition & 5 deletions config/ethereum-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
"LINK": "0x514910771AF9Ca656af840dff83E8264EcF986CA",
"WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
"WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"stETH": "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
"wstETH": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
"cbETH": "0xBe9895146f7AF43049ca1c1AE358B0541Ea49704",
"rETH": "0xae78736Cd615f374D3085123A210448E74Fc6393",
"wrappedNative": "WETH",
"lsdNatives": [
"wstETH",
"cbETH",
"rETH"
],
"aaveV2Pool": "0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9",
"aaveV3Pool": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
"aaveV3Optimizer": "0x33333aea097c193e66081E930c33020272b33333",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import "contracts/ethereum-mainnet/EthereumBundler.sol";
import {MorphoBundler} from "contracts/MorphoBundler.sol";
import {Permit2Bundler} from "contracts/Permit2Bundler.sol";

import "../helpers/ForkTest.sol";
import "./EthereumTest.sol";

contract EthereumBundlerEthereumTest is ForkTest {
contract EthereumBundlerEthereumTest is EthereumTest {
using MathLib for uint256;
using MorphoLib for IMorpho;
using MorphoBalancesLib for IMorpho;
Expand All @@ -20,10 +20,6 @@ contract EthereumBundlerEthereumTest is ForkTest {

EthereumBundler private bundler;

function _network() internal pure override returns (string memory) {
return "ethereum-mainnet";
}

function setUp() public override {
super.setUp();

Expand Down
15 changes: 15 additions & 0 deletions test/forge/ethereum-mainnet/EthereumTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import "../helpers/ForkTest.sol";
import "config/ConfiguredEthereum.sol";

contract EthereumTest is ConfiguredEthereum, ForkTest {
function _network() internal view virtual override(Configured, ConfiguredEthereum) returns (string memory) {
return ConfiguredEthereum._network();
}

function _loadConfig() internal virtual override(Configured, ConfiguredEthereum) {
ConfiguredEthereum._loadConfig();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ pragma solidity ^0.8.0;

import {ErrorsLib as BulkerErrorsLib} from "contracts/libraries/ErrorsLib.sol";

import "../helpers/ForkTest.sol";
import "./EthereumTest.sol";

import "../mocks/WNativeBundlerMock.sol";

contract WNativeBundlerEthereumTest is ForkTest {
contract WNativeBundlerEthereumTest is EthereumTest {
WNativeBundlerMock private bundler;

function _network() internal pure override returns (string memory) {
return "ethereum-mainnet";
}

function setUp() public override {
super.setUp();

Expand Down
8 changes: 2 additions & 6 deletions test/forge/ethereum-mainnet/migration/BaseMigrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {MarketParamsLib} from "@morpho-blue/libraries/MarketParamsLib.sol";
import {MorphoLib} from "@morpho-blue/libraries/periphery/MorphoLib.sol";
import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol";

import "../../helpers/ForkTest.sol";
import "../EthereumTest.sol";
import {MorphoBundler} from "contracts/MorphoBundler.sol";
import {ERC4626Bundler} from "contracts/ERC4626Bundler.sol";
import {Permit2Bundler} from "contracts/Permit2Bundler.sol";
import {ERC4626Mock} from "../../mocks/ERC4626Mock.sol";

contract BaseMigrationTest is ForkTest {
contract BaseMigrationTest is EthereumTest {
using SafeTransferLib for ERC20;
using MarketParamsLib for MarketParams;
using MorphoLib for IMorpho;
Expand Down Expand Up @@ -49,10 +49,6 @@ contract BaseMigrationTest is ForkTest {
return (privateKey, user);
}

function _network() internal pure override returns (string memory) {
return "ethereum-mainnet";
}

function _morphoSetAuthorizationWithSigCall(
uint256 privateKey,
address authorized,
Expand Down
26 changes: 1 addition & 25 deletions test/forge/helpers/ForkTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract contract ForkTest is BaseTest, Configured {
_initConfig();
_loadConfig();

_setBalances(address(this), type(uint96).max);
_fork();
}

function setUp() public virtual override {
Expand Down Expand Up @@ -58,12 +58,6 @@ abstract contract ForkTest is BaseTest, Configured {
vm.chainId(CONFIG.getChainId());
}

function _loadConfig() internal virtual override {
super._loadConfig();

_fork();
}

function _label() internal virtual {
for (uint256 i; i < allAssets.length; ++i) {
address asset = allAssets[i];
Expand All @@ -73,14 +67,6 @@ abstract contract ForkTest is BaseTest, Configured {
}
}

function _setBalances(address user, uint256 balance) internal {
for (uint256 i; i < allAssets.length; ++i) {
address asset = allAssets[i];

deal(asset, user, balance / (10 ** (18 - ERC20(asset).decimals())));
}
}

/// @dev Avoids to revert because of AAVE token snapshots:
/// https://github.com/aave/aave-token-v2/blob/master/contracts/token/base/GovernancePowerDelegationERC20.sol#L174
function _deal(address asset, address user, uint256 amount) internal {
Expand All @@ -103,20 +89,10 @@ abstract contract ForkTest is BaseTest, Configured {
}
}

function _assumeNotLsdNative(address input) internal view {
for (uint256 i; i < lsdNatives.length; ++i) {
vm.assume(input != lsdNatives[i]);
}
}

function _randomAsset(uint256 seed) internal view returns (address) {
return allAssets[seed % allAssets.length];
}

function _randomLsdNative(uint256 seed) internal view returns (address) {
return lsdNatives[seed % lsdNatives.length];
}

function _randomMarketParams(uint256 seed) internal view returns (MarketParams memory) {
return allMarketParams[seed % allMarketParams.length];
}
Expand Down
Loading