From 056e52102d88a4481aef56a579df13340c434b01 Mon Sep 17 00:00:00 2001 From: Dima Lekhovitsky Date: Wed, 17 Jul 2024 18:15:48 +0300 Subject: [PATCH] feat: move `ZapperRegister` to `test/` --- .../interfaces/zappers/IZapperRegister.sol | 20 ------- .../test/suites/ZapperLiveTestHelper.sol | 24 +++------ contracts/test/suites/ZapperRegister.sol | 53 +++++++++++++++++++ contracts/zappers/ZapperRegister.sol | 48 ----------------- 4 files changed, 59 insertions(+), 86 deletions(-) delete mode 100644 contracts/interfaces/zappers/IZapperRegister.sol create mode 100644 contracts/test/suites/ZapperRegister.sol delete mode 100644 contracts/zappers/ZapperRegister.sol diff --git a/contracts/interfaces/zappers/IZapperRegister.sol b/contracts/interfaces/zappers/IZapperRegister.sol deleted file mode 100644 index fdb8b701..00000000 --- a/contracts/interfaces/zappers/IZapperRegister.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -// Gearbox Protocol. Generalized leverage for DeFi protocols -// (c) Gearbox Foundation, 2023. -pragma solidity ^0.8.17; - -import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol"; - -interface IZapperRegisterEvents { - event AddZapper(address); - - event RemoveZapper(address); -} - -interface IZapperRegister is IVersion, IZapperRegisterEvents { - function zappers(address pool) external view returns (address[] memory); - - function addZapper(address zapper) external; - - function removeZapper(address zapper) external; -} diff --git a/contracts/test/suites/ZapperLiveTestHelper.sol b/contracts/test/suites/ZapperLiveTestHelper.sol index 4214685c..cdacb779 100644 --- a/contracts/test/suites/ZapperLiveTestHelper.sol +++ b/contracts/test/suites/ZapperLiveTestHelper.sol @@ -1,7 +1,7 @@ // 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"; @@ -9,22 +9,19 @@ 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; @@ -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. @@ -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)); _; @@ -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))); diff --git a/contracts/test/suites/ZapperRegister.sol b/contracts/test/suites/ZapperRegister.sol new file mode 100644 index 00000000..27e9260b --- /dev/null +++ b/contracts/test/suites/ZapperRegister.sol @@ -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); + } + } +} diff --git a/contracts/zappers/ZapperRegister.sol b/contracts/zappers/ZapperRegister.sol deleted file mode 100644 index d61e30eb..00000000 --- a/contracts/zappers/ZapperRegister.sol +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// Gearbox Protocol. Generalized leverage for DeFi protocols -// (c) Gearbox Foundation, 2023. -pragma solidity ^0.8.17; - -import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; - -import {ACLNonReentrantTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLNonReentrantTrait.sol"; -import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol"; - -import {IZapper} from "../interfaces/zappers/IZapper.sol"; -import {IZapperRegister} from "../interfaces/zappers/IZapperRegister.sol"; - -contract ZapperRegister is ACLNonReentrantTrait, ContractsRegisterTrait, IZapperRegister { - using EnumerableSet for EnumerableSet.AddressSet; - - uint256 public constant override version = 3_00; - - mapping(address => EnumerableSet.AddressSet) internal _zappersMap; - - constructor(address addressProvider) - ACLNonReentrantTrait(addressProvider) - ContractsRegisterTrait(addressProvider) - {} - - function zappers(address pool) external view override returns (address[] memory) { - return _zappersMap[pool].values(); - } - - function addZapper(address zapper) external override nonZeroAddress(zapper) controllerOnly { - 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 override nonZeroAddress(zapper) controllerOnly { - EnumerableSet.AddressSet storage zapperSet = _zappersMap[IZapper(zapper).pool()]; - if (zapperSet.contains(zapper)) { - zapperSet.remove(zapper); - emit RemoveZapper(zapper); - } - } -}