|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.27; |
| 3 | + |
| 4 | +import {IEulerSwapProtocolFeeConfig} from "./interfaces/IEulerSwapProtocolFeeConfig.sol"; |
| 5 | +import {EVCUtil} from "evc/utils/EVCUtil.sol"; |
| 6 | + |
| 7 | +/// @title EulerSwapProtocolFeeConfig contract |
| 8 | +/// @custom:security-contact [email protected] |
| 9 | +/// @author Euler Labs (https://www.eulerlabs.com/) |
| 10 | +contract EulerSwapProtocolFeeConfig is IEulerSwapProtocolFeeConfig, EVCUtil { |
| 11 | + /// @dev Protocol fee admin |
| 12 | + address public admin; |
| 13 | + |
| 14 | + /// @dev Admin is not allowed to set a protocol fee larger than this |
| 15 | + uint64 public constant MAX_PROTOCOL_FEE = 0.15e18; |
| 16 | + |
| 17 | + /// @dev Destination of collected protocol fees, unless overridden |
| 18 | + address public defaultRecipient; |
| 19 | + /// @dev Default protocol fee, 1e18-scale |
| 20 | + uint64 public defaultFee; |
| 21 | + |
| 22 | + struct Override { |
| 23 | + bool exists; |
| 24 | + address recipient; |
| 25 | + uint64 fee; |
| 26 | + } |
| 27 | + |
| 28 | + /// @dev EulerSwap-instance specific fee override |
| 29 | + mapping(address pool => Override) public overrides; |
| 30 | + |
| 31 | + error Unauthorized(); |
| 32 | + error InvalidProtocolFee(); |
| 33 | + |
| 34 | + constructor(address evc, address admin_) EVCUtil(evc) { |
| 35 | + admin = admin_; |
| 36 | + } |
| 37 | + |
| 38 | + modifier onlyAdmin() { |
| 39 | + // Ensures that the caller is not an operator, controller, etc |
| 40 | + _authenticateCallerWithStandardContextState(true); |
| 41 | + |
| 42 | + require(_msgSender() == admin, Unauthorized()); |
| 43 | + |
| 44 | + _; |
| 45 | + } |
| 46 | + |
| 47 | + /// @inheritdoc IEulerSwapProtocolFeeConfig |
| 48 | + function setAdmin(address newAdmin) external onlyAdmin { |
| 49 | + admin = newAdmin; |
| 50 | + } |
| 51 | + |
| 52 | + /// @inheritdoc IEulerSwapProtocolFeeConfig |
| 53 | + function setDefault(address recipient, uint64 fee) external onlyAdmin { |
| 54 | + require(fee <= MAX_PROTOCOL_FEE, InvalidProtocolFee()); |
| 55 | + |
| 56 | + defaultRecipient = recipient; |
| 57 | + defaultFee = fee; |
| 58 | + } |
| 59 | + |
| 60 | + /// @inheritdoc IEulerSwapProtocolFeeConfig |
| 61 | + function setOverride(address pool, address recipient, uint64 fee) external onlyAdmin { |
| 62 | + require(fee <= MAX_PROTOCOL_FEE, InvalidProtocolFee()); |
| 63 | + |
| 64 | + overrides[pool] = Override({exists: true, recipient: recipient, fee: fee}); |
| 65 | + } |
| 66 | + |
| 67 | + /// @inheritdoc IEulerSwapProtocolFeeConfig |
| 68 | + function removeOverride(address pool) external onlyAdmin { |
| 69 | + delete overrides[pool]; |
| 70 | + } |
| 71 | + |
| 72 | + /// @inheritdoc IEulerSwapProtocolFeeConfig |
| 73 | + function getProtocolFee(address pool) external view returns (address recipient, uint64 fee) { |
| 74 | + Override memory o = overrides[pool]; |
| 75 | + |
| 76 | + if (o.exists) { |
| 77 | + recipient = o.recipient; |
| 78 | + fee = o.fee; |
| 79 | + |
| 80 | + if (recipient == address(0)) recipient = defaultRecipient; |
| 81 | + } else { |
| 82 | + recipient = defaultRecipient; |
| 83 | + fee = defaultFee; |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments