Skip to content

Commit

Permalink
refactor: one ProdConfig file to factorize dealAave
Browse files Browse the repository at this point in the history
  • Loading branch information
QGarchery committed Jan 4, 2024
1 parent 9682cdf commit 738ad6d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
25 changes: 25 additions & 0 deletions test/prod/ProdTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

import {SafeTransferLib, ERC20} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol";

import {PercentageMath} from "@morpho-dao/morpho-utils/math/PercentageMath.sol";
import {Math} from "@morpho-dao/morpho-utils/math/Math.sol";
import {WadRayMath} from "@morpho-dao/morpho-utils/math/WadRayMath.sol";

import {BaseConfig} from "config/BaseConfig.sol";
import "@forge-std/console.sol";
import "@forge-std/Test.sol";

contract ProdTest is Test, BaseConfig {
// Needed because AAVE packs the balance struct.
function dealAave(address who, uint104 amount) public {
// The slot of the balance struct "_balances" is 0.
bytes32 slot = keccak256(abi.encode(who, uint256(0)));
bytes32 initialValue = vm.load(aave, slot);
// The balance is stored in the first 104 bits.
bytes32 finalValue = ((initialValue >> 104) << 104) | bytes32(uint256(amount));
vm.store(aave, slot, finalValue);
require(ERC20(aave).balanceOf(who) == uint256(amount));
}
}
21 changes: 3 additions & 18 deletions test/prod/aave-v2/setup/TestSetup.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

import "../../ProdTest.sol";

import "src/aave-v2/interfaces/aave/IVariableDebtToken.sol";
import "src/aave-v2/interfaces/aave/IAToken.sol";
import "src/aave-v2/interfaces/lido/ILido.sol";

import {ReserveConfiguration} from "src/aave-v2/libraries/aave/ReserveConfiguration.sol";
import "@morpho-dao/morpho-utils/math/WadRayMath.sol";
import "@morpho-dao/morpho-utils/math/PercentageMath.sol";
import "@rari-capital/solmate/src/utils/SafeTransferLib.sol";
import "@morpho-dao/morpho-utils/math/Math.sol";

import {InterestRatesManager} from "src/aave-v2/InterestRatesManager.sol";
import {MatchingEngine} from "src/aave-v2/MatchingEngine.sol";
Expand All @@ -20,10 +18,8 @@ import "src/aave-v2/Morpho.sol";

import {User} from "../../../aave-v2/helpers/User.sol";
import "config/aave-v2/Config.sol";
import "@forge-std/console.sol";
import "@forge-std/Test.sol";

contract TestSetup is Config, Test {
contract TestSetup is Config, ProdTest {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using WadRayMath for uint256;
using PercentageMath for uint256;
Expand Down Expand Up @@ -76,17 +72,6 @@ contract TestSetup is Config, Test {
interestRatesManager = morpho.interestRatesManager();
}

// Needed because AAVE packs the balance struct.
function dealAave(address who, uint104 amount) public {
// The slot of the balance struct "_balances" is 0.
bytes32 slot = keccak256(abi.encode(who, uint256(0)));
bytes32 initialValue = vm.load(aave, slot);
// The balance is stored in the first 104 bits.
bytes32 finalValue = initialValue | bytes32(uint256(amount));
vm.store(aave, slot, finalValue);
require(IERC20(aave).balanceOf(who) == uint256(amount));
}

function initUsers() internal {
user = new User(morpho);

Expand Down
21 changes: 3 additions & 18 deletions test/prod/compound/setup/TestSetup.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

import {IERC20} from "src/aave-v2/interfaces/aave/IERC20.sol";
import "../../ProdTest.sol";

import {CompoundMath} from "@morpho-dao/morpho-utils/math/CompoundMath.sol";
import {PercentageMath} from "@morpho-dao/morpho-utils/math/PercentageMath.sol";
import {SafeTransferLib, ERC20} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol";
import {Math} from "@morpho-dao/morpho-utils/math/Math.sol";
import {SafeTransferLib} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol";
import {Types} from "src/compound/libraries/Types.sol";

import {PositionsManager} from "src/compound/PositionsManager.sol";
import {InterestRatesManager} from "src/compound/InterestRatesManager.sol";

import {User} from "../../../compound/helpers/User.sol";
import "config/compound/Config.sol";
import "@forge-std/console.sol";
import "@forge-std/Test.sol";

contract TestSetup is Config, Test {
contract TestSetup is Config, ProdTest {
using CompoundMath for uint256;
using PercentageMath for uint256;
using SafeTransferLib for ERC20;
Expand Down Expand Up @@ -69,17 +65,6 @@ contract TestSetup is Config, Test {
rewardsManagerProxy = TransparentUpgradeableProxy(payable(address(rewardsManager)));
}

// Needed because AAVE packs the balance struct.
function dealAave(address who, uint104 amount) public {
// The slot of the balance struct "_balances" is 0.
bytes32 slot = keccak256(abi.encode(who, uint256(0)));
bytes32 initialValue = vm.load(aave, slot);
// The balance is stored in the first 104 bits.
bytes32 finalValue = initialValue | bytes32(uint256(amount));
vm.store(aave, slot, finalValue);
require(IERC20(aave).balanceOf(who) == uint256(amount));
}

function initUsers() internal {
user = new User(morpho);

Expand Down

0 comments on commit 738ad6d

Please sign in to comment.