Skip to content

Commit

Permalink
feat: move ZapperRegister to test/
Browse files Browse the repository at this point in the history
  • Loading branch information
lekhovitsky committed Jul 17, 2024
1 parent 5e5d8eb commit 056e521
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 86 deletions.
20 changes: 0 additions & 20 deletions contracts/interfaces/zappers/IZapperRegister.sol

This file was deleted.

24 changes: 6 additions & 18 deletions contracts/test/suites/ZapperLiveTestHelper.sol
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
// SPDX-License-Identifier: UNLICENSED
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;
pragma solidity ^0.8.23;

import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";

import {PoolV3} from "@gearbox-protocol/core-v3/contracts/pool/PoolV3.sol";
import {Tokens} from "@gearbox-protocol/sdk-gov/contracts/Tokens.sol";

import {IZapper} from "../../interfaces/zappers/IZapper.sol";
import {IZapperRegister} from "../../interfaces/zappers/IZapperRegister.sol";

import {DTokenDepositZapper} from "../../zappers/DTokenDepositZapper.sol";
import {DTokenFarmingZapper} from "../../zappers/DTokenFarmingZapper.sol";
import {UnderlyingDepositZapper} from "../../zappers/UnderlyingDepositZapper.sol";
import {UnderlyingFarmingZapper} from "../../zappers/UnderlyingFarmingZapper.sol";
import {WETHDepositZapper} from "../../zappers/WETHDepositZapper.sol";
import {WETHFarmingZapper} from "../../zappers/WETHFarmingZapper.sol";
import {WstETHDepositZapper} from "../../zappers/WstETHDepositZapper.sol";
import {WstETHFarmingZapper} from "../../zappers/WstETHFarmingZapper.sol";
import {ZapperRegister} from "../../zappers/ZapperRegister.sol";

import {ZapperRegister} from "./ZapperRegister.sol";
import {LiveTestHelper} from "./LiveTestHelper.sol";

contract ZapperLiveTestHelper is LiveTestHelper {
IZapperRegister zapperRegister;
ZapperRegister zapperRegister;
mapping(address => address) farmingPools;
mapping(address => address) legacyPools;

Expand All @@ -45,10 +42,10 @@ contract ZapperLiveTestHelper is LiveTestHelper {
// To test the ones that are not deployed yet, set `REDEPLOY_ZAPPERS` to `true`.
bool redeployZappers = vm.envOr("REDEPLOY_ZAPPERS", false);
if (redeployZappers) {
zapperRegister = new ZapperRegister(address(addressProvider));
zapperRegister = new ZapperRegister(address(addressProvider), address(addressProvider));
} else {
uint256 version = vm.envOr("ATTACH_ZAPPER_REGISTER_VERSION", uint256(300));
zapperRegister = IZapperRegister(addressProvider.getAddressOrRevert("ZAPPER_REGISTER", version));
zapperRegister = ZapperRegister(addressProvider.getAddressOrRevert("ZAPPER_REGISTER", version));
}

// If `ATTACH_POOL` is specified, the tests are executed only for this pool's zappers.
Expand All @@ -72,7 +69,7 @@ contract ZapperLiveTestHelper is LiveTestHelper {
// Deploy the system from scratch using given config.
_setupCore();
_attachState();
zapperRegister = new ZapperRegister(address(addressProvider));
zapperRegister = new ZapperRegister(address(addressProvider), address(addressProvider));
_deployPool(getDeployConfig(vm.envString("LIVE_TEST_CONFIG")));
_deployZappers(address(pool));
_;
Expand Down Expand Up @@ -102,15 +99,6 @@ contract ZapperLiveTestHelper is LiveTestHelper {
zapperRegister.addZapper(address(new UnderlyingFarmingZapper(pool, farmingPool)));
}

// dToken zapper
address legacyPool = legacyPools[underlying];
if (legacyPool != address(0)) {
zapperRegister.addZapper(address(new DTokenDepositZapper(pool, legacyPool)));
if (farmingPool != address(0)) {
zapperRegister.addZapper(address(new DTokenFarmingZapper(pool, legacyPool, farmingPool)));
}
}

// WETH zapper
if (underlying == tokenTestSuite.addressOf(Tokens.WETH)) {
zapperRegister.addZapper(address(new WETHDepositZapper(pool)));
Expand Down
53 changes: 53 additions & 0 deletions contracts/test/suites/ZapperRegister.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.23;

import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
import {ControlledTrait} from "@gearbox-protocol/core-v3/contracts/traits/ControlledTrait.sol";
import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
import {SanityCheckTrait} from "@gearbox-protocol/core-v3/contracts/traits/SanityCheckTrait.sol";

import {IZapper} from "../../interfaces/zappers/IZapper.sol";

contract ZapperRegister is IVersion, ControlledTrait, ContractsRegisterTrait, SanityCheckTrait {
using EnumerableSet for EnumerableSet.AddressSet;

event AddZapper(address indexed zapper);
event RemoveZapper(address indexed zapper);

uint256 public constant version = 3_10;
bytes32 public constant contractType = "ZR";

mapping(address => EnumerableSet.AddressSet) internal _zappersMap;

constructor(address acl_, address contractsRegister_)
ControlledTrait(acl_)
ContractsRegisterTrait(contractsRegister_)
{}

function zappers(address pool) external view returns (address[] memory) {
return _zappersMap[pool].values();
}

function addZapper(address zapper) external nonZeroAddress(zapper) controllerOrConfiguratorOnly {
address pool = IZapper(zapper).pool();
_ensureRegisteredPool(pool);

EnumerableSet.AddressSet storage zapperSet = _zappersMap[pool];
if (!zapperSet.contains(zapper)) {
zapperSet.add(zapper);
emit AddZapper(zapper);
}
}

function removeZapper(address zapper) external nonZeroAddress(zapper) controllerOrConfiguratorOnly {
EnumerableSet.AddressSet storage zapperSet = _zappersMap[IZapper(zapper).pool()];
if (zapperSet.contains(zapper)) {
zapperSet.remove(zapper);
emit RemoveZapper(zapper);
}
}
}
48 changes: 0 additions & 48 deletions contracts/zappers/ZapperRegister.sol

This file was deleted.

0 comments on commit 056e521

Please sign in to comment.