-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move
ZapperRegister
from periphery
Needed for proper zappers testing
- Loading branch information
1 parent
ec63b2e
commit 3dbc6f7
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |