|
| 1 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | +pragma solidity 0.8.18; |
| 3 | + |
| 4 | +import {ISSVOperatorsWhitelist} from "../interfaces/ISSVOperatorsWhitelist.sol"; |
| 5 | +import {ISSVWhitelistingContract} from "../interfaces/external/ISSVWhitelistingContract.sol"; |
| 6 | +import {Types64, Types256} from "../libraries/Types.sol"; |
| 7 | +import {StorageData, SSVStorage} from "../libraries/SSVStorage.sol"; |
| 8 | +import {OperatorLib} from "../libraries/OperatorLib.sol"; |
| 9 | + |
| 10 | +contract SSVOperatorsWhitelist is ISSVOperatorsWhitelist { |
| 11 | + using Types256 for uint256; |
| 12 | + using Types64 for uint64; |
| 13 | + using OperatorLib for Operator; |
| 14 | + |
| 15 | + /*******************************/ |
| 16 | + /* Operator External Functions */ |
| 17 | + /*******************************/ |
| 18 | + |
| 19 | + function setOperatorWhitelist(uint64 operatorId, address whitelistAddress) external override { |
| 20 | + StorageData storage s = SSVStorage.load(); |
| 21 | + s.operators[operatorId].checkOwner(); |
| 22 | + |
| 23 | + if (OperatorLib.isWhitelistingContract(whitelistAddress)) |
| 24 | + revert AddressIsWhitelistingContract(whitelistAddress); |
| 25 | + |
| 26 | + // Set the bit at bitPosition for the operatorId in the corresponding uint256 blockIndex |
| 27 | + (uint256 blockIndex, uint256 bitPosition) = OperatorLib.getBitmapIndexes(operatorId); |
| 28 | + |
| 29 | + s.addressWhitelistedForOperators[whitelistAddress][blockIndex] |= (1 << bitPosition); |
| 30 | + if (!s.operators[operatorId].whitelisted) s.operators[operatorId].whitelisted = true; |
| 31 | + |
| 32 | + emit OperatorWhitelistUpdated(operatorId, whitelistAddress); |
| 33 | + } |
| 34 | + |
| 35 | + function setOperatorMultipleWhitelists( |
| 36 | + uint64[] calldata operatorIds, |
| 37 | + address[] calldata whitelistAddresses |
| 38 | + ) external override { |
| 39 | + OperatorLib.updateMultipleWhitelists(whitelistAddresses, operatorIds, true, SSVStorage.load()); |
| 40 | + } |
| 41 | + |
| 42 | + function removeOperatorMultipleWhitelists( |
| 43 | + uint64[] calldata operatorIds, |
| 44 | + address[] calldata whitelistAddresses |
| 45 | + ) external override { |
| 46 | + OperatorLib.updateMultipleWhitelists(whitelistAddresses, operatorIds, false, SSVStorage.load()); |
| 47 | + } |
| 48 | + |
| 49 | + function setOperatorsWhitelistingContract( |
| 50 | + uint64[] calldata operatorIds, |
| 51 | + ISSVWhitelistingContract whitelistingContract |
| 52 | + ) external { |
| 53 | + uint256 operatorsLength = operatorIds.length; |
| 54 | + if (operatorsLength == 0) revert InvalidOperatorIdsLength(); |
| 55 | + |
| 56 | + StorageData storage s = SSVStorage.load(); |
| 57 | + |
| 58 | + for (uint256 i = 0; i < operatorsLength; ++i) { |
| 59 | + OperatorLib.updateWhitelistingContract(operatorIds[i], whitelistingContract, s); |
| 60 | + } |
| 61 | + |
| 62 | + // TODO test set event param type to ISSVOperatorsWhitelist |
| 63 | + emit OperatorWhitelistingContractUpdated(operatorIds, address(whitelistingContract)); |
| 64 | + } |
| 65 | +} |
0 commit comments