PermissionsManager

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "src/PermissionsManager.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/// @title PermissionsManager
/// @notice Manages admin and whitelisted caller permissions for the lending system
contract PermissionsManager {
    /*//////////////////////////////////////////////////////////////
                                STORAGE
    //////////////////////////////////////////////////////////////*/

    /// @notice The admin address who can manage permissions
    address public admin;

    /// @notice Mapping of whitelisted callers
    mapping(address => bool) public whitelistedCallers;

    /*//////////////////////////////////////////////////////////////
                                EVENTS
    //////////////////////////////////////////////////////////////*/

    event AdminUpdated(address indexed oldAdmin, address indexed newAdmin);
    event CallerWhitelisted(address indexed caller);
    event CallerRemovedFromWhitelist(address indexed caller);

    /*//////////////////////////////////////////////////////////////
                                ERRORS
    //////////////////////////////////////////////////////////////*/

    error OnlyAdmin();
    error UnauthorizedCaller();
    error AdminZeroAddress();
    error CallerAlreadyWhitelisted();
    error CallerNotWhitelisted();

    /*//////////////////////////////////////////////////////////////
                               MODIFIERS
    //////////////////////////////////////////////////////////////*/

    /// @notice Restricts function access to admin only
    modifier onlyAdmin() {
        if (msg.sender != admin) revert OnlyAdmin();
        _;
    }

    /// @notice Restricts function access to whitelisted callers only
    modifier onlyAuthorized() {
        if (!whitelistedCallers[msg.sender]) revert UnauthorizedCaller();
        _;
    }

    /*//////////////////////////////////////////////////////////////
                              CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    /// @notice Constructor sets the initial admin
    /// @param _admin The initial admin address
    constructor(address _admin) {
        if (_admin == address(0)) revert AdminZeroAddress();
        admin = _admin;

        // Admin is automatically whitelisted
        whitelistedCallers[_admin] = true;

        emit AdminUpdated(address(0), _admin);
        emit CallerWhitelisted(_admin);
    }

    /*//////////////////////////////////////////////////////////////
                           ADMIN FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Updates the admin address
    /// @param newAdmin The new admin address
    function updateAdmin(address newAdmin) external onlyAdmin {
        if (newAdmin == address(0)) revert AdminZeroAddress();

        address oldAdmin = admin;
        admin = newAdmin;

        // Automatically whitelist new admin
        whitelistedCallers[newAdmin] = true;

        emit AdminUpdated(oldAdmin, newAdmin);
        emit CallerWhitelisted(newAdmin);
    }

    /// @notice Adds a caller to the whitelist
    /// @param caller The address to whitelist
    function addWhitelistedCaller(address caller) external onlyAdmin {
        if (whitelistedCallers[caller]) revert CallerAlreadyWhitelisted();

        whitelistedCallers[caller] = true;
        emit CallerWhitelisted(caller);
    }

    /// @notice Removes a caller from the whitelist
    /// @param caller The address to remove from whitelist
    function removeWhitelistedCaller(address caller) external onlyAdmin {
        if (!whitelistedCallers[caller]) revert CallerNotWhitelisted();
        if (caller == admin) revert OnlyAdmin(); // Cannot remove admin from whitelist

        whitelistedCallers[caller] = false;
        emit CallerRemovedFromWhitelist(caller);
    }

    /*//////////////////////////////////////////////////////////////
                            VIEW FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Checks if a caller is authorized (whitelisted)
    /// @param caller The address to check
    /// @return True if the caller is whitelisted
    function isAuthorized(address caller) external view returns (bool) {
        return whitelistedCallers[caller];
    }

    /// @notice Gets the current admin address
    /// @return The admin address
    function getAdmin() external view returns (address) {
        return admin;
    }
}
"
    }
  },
  "settings": {
    "remappings": [
      "@pendle/core-v2/=lib/pendle-core-v2-public/",
      "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
      "ds-test/=lib/forge-std/lib/ds-test/src/",
      "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
      "forge-std/=lib/forge-std/src/",
      "openzeppelin-contracts/=lib/openzeppelin-contracts/",
      "aave-v3-core/=lib/aave-v3-core/",
      "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
      "morpho-blue/=lib/morpho-blue/",
      "pendle-core-v2-public/=lib/pendle-core-v2-public/contracts/"
    ],
    "optimizer": {
      "enabled": true,
      "runs": 10000
    },
    "metadata": {
      "useLiteralContent": false,
      "bytecodeHash": "ipfs",
      "appendCBOR": true
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "paris",
    "viaIR": true
  }
}}

Tags:
Factory|addr:0x4cd22e396845f8eccf0d36cb6036e1425ece0423|verified:true|block:23601831|tx:0xfba69f9f904029ec57530b54a11468c49e108bf82631ccfb435cc978fb848b28|first_check:1760776525

Submitted on: 2025-10-18 10:35:27

Comments

Log in to comment.

No comments yet.