Skip to content

Commit

Permalink
feat: move ZapperRegister from periphery
Browse files Browse the repository at this point in the history
Needed for proper zappers testing
  • Loading branch information
lekhovitsky committed Apr 10, 2024
1 parent ec63b2e commit 3dbc6f7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
20 changes: 20 additions & 0 deletions contracts/interfaces/zappers/IZapperRegister.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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;
}
48 changes: 48 additions & 0 deletions contracts/zappers/ZapperRegister.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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);
}
}
}

0 comments on commit 3dbc6f7

Please sign in to comment.