Skip to content
Verified contractPartialBUSL-1.1

PlasmaVaultBase

Address0x80f451017066494de93943c36ce453fb98ae0b29
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.30

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
BUSL-1.1
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,255,248
Creation transaction
0xd6f9fd4c91…cfcc4bd924
Main copy (most transactions)
0x233074f6…a1a18c7b

79 files

The source code is large: one file is shown at a time. Choose a file in the list.

lib/ipor-fusion/contracts/managers/access/IporFusionAccessManager.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.30;

import {AccessManager} from "@openzeppelin/contracts/access/manager/AccessManager.sol";
import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
import {IIporFusionAccessManager} from "../../interfaces/IIporFusionAccessManager.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import {RedemptionDelayLib} from "./RedemptionDelayLib.sol";
import {IporFusionAccessManagersStorageLib} from "./IporFusionAccessManagersStorageLib.sol";
import {PlasmaVault} from "../../vaults/PlasmaVault.sol";
import {RoleExecutionTimelockLib} from "./RoleExecutionTimelockLib.sol";
import {
    IporFusionAccessManagerInitializationLib,
    InitializationData
} from "./IporFusionAccessManagerInitializationLib.sol";
import {Roles} from "../../libraries/Roles.sol";

/**
 * @title IporFusionAccessManager
 * @notice Contract responsible for managing access control to the IporFusion protocol
 * @dev Extends OpenZeppelin's AccessManager with custom functionality for IPOR Fusion
 *
 * Role-based permissions:
 * - ADMIN_ROLE: Can initialize the contract and manage roles
 * - GUARDIAN_ROLE: Can cancel scheduled operations, close and reopen targets (emergency pause / unpause)
 * - ATOMIST_ROLE: Can manage vault configurations and market settings
 * - PUBLIC_ROLE: Used for publicly accessible functions
 * - TECH_CONTEXT_MANAGER_ROLE: Technical role for context operations
 * - TECH_PLASMA_VAULT_ROLE: Technical role for plasma vault operations
 *
 * Function permissions:
 * - initialize: Restricted to ADMIN_ROLE
 * - updateTargetClosed: Restricted to GUARDIAN_ROLE
 * - convertToPublicVault: Restricted to TECH_PLASMA_VAULT_ROLE
 * - enableTransferShares: Restricted to TECH_PLASMA_VAULT_ROLE
 * - setMinimalExecutionDelaysForRoles: Restricted to TECH_PLASMA_VAULT_ROLE
 * - setRedemptionDelay: Restricted to TECH_PLASMA_VAULT_ROLE (the OWNER_ROLE reaches it through
 *   PlasmaVaultGovernance.setRedemptionDelay; that path is timelocked only when the owner account holds
 *   OWNER_ROLE with a non-zero execution delay - the default initializer grants it with 0, i.e. immediate)
 * - grantRole: Restricted to authorized roles (via onlyAuthorized)
 *
 * Security features:
 * - Role-based execution delays
 * - Redemption delay mechanism
 * - Guardian role for emergency actions
 * - Timelock controls for sensitive operations
 *
 * Storage layout (not upgradeable, deployed as EIP-1167 clones by AccessManagerFactory):
 * - Slots 0-3 belong to OpenZeppelin AccessManager (_targets, _roles, _schedules, _executionId)
 * - Slot 4 is `_customConsumingSchedule` (bool). Before IL-7910 slot 4 held the public
 *   `REDEMPTION_DELAY_IN_SECONDS` state variable and the flag lived in slot 5; the delay now lives in the
 *   ERC-7201 namespace io.ipor.managers.access.RedemptionDelay. NEVER put this implementation behind a proxy
 *   that already holds pre-IL-7910 storage - a non-zero legacy delay in slot 4 would read as
 *   `_customConsumingSchedule == true` permanently. The layout is pinned by RedemptionDelayUpdateTest.
 *
 */
contract IporFusionAccessManager is Initializable, IIporFusionAccessManager, AccessManager {
    error AccessManagedUnauthorized(address caller);
    error TooShortExecutionDelayForRole(uint64 roleId, uint32 executionDelay);
    error TooLongRedemptionDelay(uint256 redemptionDelayInSeconds);

    /// @notice Emitted when the vault-wide redemption delay is changed (also once at initialization, with old value 0)
    /// @dev Carries the previous value so monitoring can alert on the exact transition (e.g. a change to or from 0)
    /// @param oldRedemptionDelayInSeconds The redemption delay in force before the change
    /// @param newRedemptionDelayInSeconds The redemption delay in force after the change
    event RedemptionDelayUpdated(uint256 oldRedemptionDelayInSeconds, uint256 newRedemptionDelayInSeconds);

    /// @notice Maximum allowed redemption delay in seconds (7 days)
    uint256 public constant MAX_REDEMPTION_DELAY_IN_SECONDS = 7 days;

    /// @dev Flag to track custom schedule consumption. Occupies slot 4, right after OpenZeppelin AccessManager's
    /// four state variables - see the storage layout note in the contract NatSpec
    bool private _customConsumingSchedule;

    /**
     * @notice Modifier to restrict function access to authorized callers
     * @dev Checks if the caller can execute the function and handles scheduled operations
     */
    modifier restricted() {
        _checkCanCall(_msgSender(), _msgData());
        _;
    }

    /// @custom:oz-upgrades-unsafe-allow constructor
    /// @notice Constructor that initializes the IporFusionAccessManager with an admin and redemption delay
    /// @dev Used when deploying directly without proxy
    /// @param initialAdmin_ The address that will be granted the ADMIN_ROLE
    /// @param redemptionDelayInSeconds_ The initial redemption delay period in seconds
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor(address initialAdmin_, uint256 redemptionDelayInSeconds_) AccessManager(initialAdmin_) initializer {
        _initialize(initialAdmin_, redemptionDelayInSeconds_);
    }

    /// @notice Initializes the IporFusionAccessManager with access control and redemption delay (for cloning)
    /// @param initialAdmin_ The address that will be granted the ADMIN_ROLE
    /// @param redemptionDelayInSeconds_ The initial redemption delay period in seconds
    /// @dev This method is called after cloning to initialize the contract
    /// @custom:access Only during initialization
    function proxyInitialize(address initialAdmin_, uint256 redemptionDelayInSeconds_) external initializer {
        _initialize(initialAdmin_, redemptionDelayInSeconds_);
    }

    /// @notice Private method containing the common initialization logic
    /// @param initialAdmin_ The initial admin address
    /// @param redemptionDelayInSeconds_ The redemption delay in seconds
    /// @dev This method is used by both constructor and proxyInitialize to avoid code duplication
    function _initialize(address initialAdmin_, uint256 redemptionDelayInSeconds_) private {
        _setRedemptionDelay(redemptionDelayInSeconds_);
        _grantRole(ADMIN_ROLE, initialAdmin_, 0, 0);
    }

    /**
     * @notice Initializes the access manager with role configurations
     * @param initialData_ Initial configuration data for roles and permissions
     * @dev Sets up role hierarchies, function permissions, and execution delays
     * @custom:access Restricted to ADMIN_ROLE
     */
    function initialize(InitializationData calldata initialData_) external restricted {
        IporFusionAccessManagerInitializationLib.isInitialized();
        _revokeRole(ADMIN_ROLE, msg.sender);

        uint256 roleToFunctionsLength = initialData_.roleToFunctions.length;
        uint64[] memory roleIds = new uint64[](roleToFunctionsLength);
        uint256[] memory minimalDelays = new uint256[](roleToFunctionsLength);

        if (roleToFunctionsLength > 0) {
            for (uint256 i; i < roleToFunctionsLength; ++i) {
                _setTargetFunctionRole(
                    initialData_.roleToFunctions[i].target,
                    initialData_.roleToFunctions[i].functionSelector,
                    initialData_.roleToFunctions[i].roleId
                );
                roleIds[i] = initialData_.roleToFunctions[i].roleId;
                minimalDelays[i] = initialData_.roleToFunctions[i].minimalExecutionDelay;
                if (
                    initialData_.roleToFunctions[i].roleId != Roles.ADMIN_ROLE &&
                    initialData_.roleToFunctions[i].roleId != Roles.GUARDIAN_ROLE &&
                    initialData_.roleToFunctions[i].roleId != Roles.PUBLIC_ROLE
                ) {
                    _setRoleGuardian(initialData_.roleToFunctions[i].roleId, Roles.GUARDIAN_ROLE);
                }
            }
        }
        RoleExecutionTimelockLib.setMinimalExecutionDelaysForRoles(roleIds, minimalDelays);

        uint256 adminRolesLength = initialData_.adminRoles.length;
        if (adminRolesLength > 0) {
            for (uint256 i; i < adminRolesLength; ++i) {
                _setRoleAdmin(initialData_.adminRoles[i].roleId, initialData_.adminRoles[i].adminRoleId);
            }
        }

        uint256 accountToRolesLength = initialData_.accountToRoles.length;
        if (accountToRolesLength > 0) {
            for (uint256 i; i < accountToRolesLength; ++i) {
                _grantRoleInternal(
                    initialData_.accountToRoles[i].roleId,
                    initialData_.accountToRoles[i].account,
                    initialData_.accountToRoles[i].executionDelay
                );
            }
        }
    }

    /**
     * @notice Checks if a caller can execute a function and updates state if needed
     * @param caller_ Address attempting to call the function
     * @param target_ Target contract address
     * @param selector_ Function selector being called
     * @return immediate Whether the call can be executed immediately
     * @return delay The required delay before execution
     * @custom:security Updates redemption delay state if applicable
     */
    function canCallAndUpdate(
        address caller_,
        address target_,
        bytes4 selector_
    ) external override restricted returns (bool immediate, uint32 delay) {
        RedemptionDelayLib.lockChecks(caller_, selector_);
        return super.canCall(caller_, target_, selector_);
    }

    /**
     * @notice Updates whether a target contract is closed for operations (emergency pause / unpause)
     * @param target_ Target contract address
     * @param closed_ New closed status
     * @custom:access Restricted to GUARDIAN_ROLE
     */
    function updateTargetClosed(address target_, bool closed_) external override restricted {
        _setTargetClosed(target_, closed_);
    }

    /**
     * @notice Converts a vault to public access mode
     * @param vault_ Address of the vault to convert
     * @custom:access Restricted to TECH_PLASMA_VAULT_ROLE
     */
    function convertToPublicVault(address vault_) external override restricted {
        _setTargetFunctionRole(vault_, PlasmaVault.mint.selector, PUBLIC_ROLE);
        _setTargetFunctionRole(vault_, PlasmaVault.deposit.selector, PUBLIC_ROLE);
        _setTargetFunctionRole(vault_, PlasmaVault.depositWithPermit.selector, PUBLIC_ROLE);
    }

    /**
     * @notice Enables share transfer functionality for a vault
     * @param vault_ Address of the vault
     * @custom:access Restricted to TECH_PLASMA_VAULT_ROLE
     */
    function enableTransferShares(address vault_) external override restricted {
        _setTargetFunctionRole(vault_, PlasmaVault.transfer.selector, PUBLIC_ROLE);
        _setTargetFunctionRole(vault_, PlasmaVault.transferFrom.selector, PUBLIC_ROLE);
    }

    /**
     * @notice Sets minimal execution delays for specified roles
     * @param rolesIds_ Array of role IDs
     * @param delays_ Array of corresponding delays
     * @custom:access Restricted to TECH_PLASMA_VAULT_ROLE
     */
    function setMinimalExecutionDelaysForRoles(
        uint64[] calldata rolesIds_,
        uint256[] calldata delays_
    ) external override restricted {
        RoleExecutionTimelockLib.setMinimalExecutionDelaysForRoles(rolesIds_, delays_);
    }

    /**
     * @notice Sets the vault-wide redemption delay
     * @param redemptionDelayInSeconds_ The new redemption delay in seconds
     * @dev The new value governs every account immediately - each account's unlock time is computed
     * at check time as its last deposit timestamp plus the current delay, so lowering the delay
     * releases existing depositors and raising it extends their locks, measured from their own deposits.
     * Governance calls it through PlasmaVaultGovernance.setRedemptionDelay - AccessManager cannot schedule
     * its own custom functions, so a setter restricted here to the OWNER_ROLE could never be timelocked.
     * Note that the vault path is timelocked only when the calling owner holds OWNER_ROLE with a non-zero
     * execution delay; with the default initializer configuration (execution delay 0) the change is immediate
     * @custom:access Restricted to TECH_PLASMA_VAULT_ROLE (the PlasmaVault)
     * @custom:risk Raising the delay retroactively locks accounts that deposited under a shorter (or zero) delay,
     * for at most MAX_REDEMPTION_DELAY_IN_SECONDS counted from their last deposit - see PlasmaVaultGovernance
     * @custom:error TooLongRedemptionDelay if redemptionDelayInSeconds_ exceeds MAX_REDEMPTION_DELAY_IN_SECONDS
     */
    function setRedemptionDelay(uint256 redemptionDelayInSeconds_) external override restricted {
        _setRedemptionDelay(redemptionDelayInSeconds_);
    }

    /**
     * @notice Grants a role to an account with a specified execution delay
     * @param roleId_ The role identifier to grant
     * @param account_ The account to receive the role
     * @param executionDelay_ The execution delay for the role operations
     * @dev Overrides AccessManager.grantRole to add execution delay validation
     * @custom:access
     * - Restricted to authorized roles via onlyAuthorized modifier
     * - Can only be called by the admin of the role being granted (e.g., ADMIN_ROLE can grant OWNER_ROLE, OWNER_ROLE can grant ATOMIST_ROLE)
     * - Role hierarchy must be followed according to Roles.sol documentation
     * @custom:security
     * - Validates that execution delay meets minimum requirements
     * - Role hierarchy must be respected (e.g., ADMIN_ROLE can grant OWNER_ROLE)
     * @custom:error TooShortExecutionDelayForRole if executionDelay_ is less than the minimum required
     */
    function grantRole(
        uint64 roleId_,
        address account_,
        uint32 executionDelay_
    ) public override(IAccessManager, AccessManager) onlyAuthorized {
        _grantRoleInternal(roleId_, account_, executionDelay_);
    }

    /**
     * @notice Retrieves the minimal execution delay configured for a specific role
     * @param roleId_ The role identifier to query
     * @return The minimal execution delay in seconds for the specified role
     * @dev This delay represents the minimum time that must pass between scheduling and executing an operation
     * @custom:access No access restrictions - can be called by anyone
     * @custom:security Used to enforce timelock restrictions on role operations
     */
    function getMinimalExecutionDelayForRole(uint64 roleId_) external view override returns (uint256) {
        return RoleExecutionTimelockLib.getMinimalExecutionDelayForRole(roleId_);
    }

    /**
     * @notice Retrieves the effective unlock time for a specific account under the current redemption delay
     * @param account_ The account address to query
     * @return The timestamp until which the account is locked for redemption operations, computed as
     * the account's last deposit timestamp plus the current REDEMPTION_DELAY_IN_SECONDS. May be in the
     * past when the lock has already expired. Returns 0 when the account never deposited.
     * @dev Used to enforce redemption delay periods after certain operations. The returned value moves
     * immediately, in both directions, whenever the redemption delay is changed via setRedemptionDelay.
     * @custom:access No access restrictions - can be called by anyone
     * @custom:security
     * - Part of the redemption delay mechanism
     * - Used to prevent immediate withdrawals after specific actions
     * - Lock time is managed by RedemptionDelayLib
     */
    function getAccountLockTime(address account_) external view override returns (uint256) {
        return RedemptionDelayLib.getAccountLockTime(account_);
    }

    /**
     * @notice Retrieves the current vault-wide redemption delay
     * @return The redemption delay in seconds, changeable by the OWNER_ROLE via PlasmaVaultGovernance.setRedemptionDelay
     * @dev The value lives in ERC-7201 namespaced storage; the constant-style name is kept for
     * ABI compatibility with instances deployed when the value was set once at initialization
     * @custom:access No access restrictions - can be called by anyone
     */
    // solhint-disable-next-line func-name-mixedcase
    function REDEMPTION_DELAY_IN_SECONDS() external view override returns (uint256) {
        return IporFusionAccessManagersStorageLib.getRedemptionDelay();
    }

    /**
     * @notice Checks if the contract is currently consuming a scheduled operation
     * @return bytes4 Returns the function selector if consuming a scheduled operation, or bytes4(0) if not
     * @dev Used to track the state of scheduled operation execution
     * @custom:access No access restrictions - can be called by anyone
     * @custom:security
     * - Used internally to prevent reentrancy during scheduled operation execution
     * - Returns this.isConsumingScheduledOp.selector when _customConsumingSchedule is true
     * - Returns bytes4(0) when not consuming a scheduled operation
     */
    function isConsumingScheduledOp() external view override returns (bytes4) {
        return _customConsumingSchedule ? this.isConsumingScheduledOp.selector : bytes4(0);
    }

    function _setRedemptionDelay(uint256 redemptionDelayInSeconds_) private {
        if (redemptionDelayInSeconds_ > MAX_REDEMPTION_DELAY_IN_SECONDS) {
            revert TooLongRedemptionDelay(redemptionDelayInSeconds_);
        }
        uint256 oldRedemptionDelayInSeconds = IporFusionAccessManagersStorageLib.getRedemptionDelay();
        IporFusionAccessManagersStorageLib.setRedemptionDelay(redemptionDelayInSeconds_);
        emit RedemptionDelayUpdated(oldRedemptionDelayInSeconds, redemptionDelayInSeconds_);
    }

    function _grantRoleInternal(uint64 roleId_, address account_, uint32 executionDelay_) internal {
        if (executionDelay_ < RoleExecutionTimelockLib.getMinimalExecutionDelayForRole(roleId_)) {
            revert TooShortExecutionDelayForRole(roleId_, executionDelay_);
        }
        _grantRole(roleId_, account_, getRoleGrantDelay(roleId_), executionDelay_);
    }

    function _checkCanCall(address caller_, bytes calldata data_) internal virtual {
        (bool immediate, uint32 delay) = canCall(caller_, address(this), bytes4(data_[0:4]));
        if (!immediate) {
            if (delay > 0) {
                _customConsumingSchedule = true;
                IAccessManager(address(this)).consumeScheduledOp(caller_, data_);
                _customConsumingSchedule = false;
            } else {
                revert AccessManagedUnauthorized(caller_);
            }
        }
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/=lib/ipor-fusion/node_modules/@openzeppelin/",
    "@chainlink/=lib/ipor-fusion/node_modules/@chainlink/",
    "@uniswap/v4-core/=lib/ipor-fusion/node_modules/@uniswap/v4-core/",
    "eth-gas-reporter/=node_modules/eth-gas-reporter/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "@ipor-protocol-deploy/=contracts/",
    "@ipor-fusion/=lib/ipor-fusion/",
    "@ipor-protocol/=lib/ipor-protocol/",
    "scripts/=scripts/",
    "@eth-optimism/=lib/ipor-fusion/node_modules/@eth-optimism/",
    "@ethereum-vault-connector/=lib/ipor-fusion/node_modules/ethereum-vault-connector/",
    "@morpho-org/=lib/ipor-fusion/node_modules/@morpho-org/",
    "@pendle/=lib/ipor-fusion/node_modules/@pendle/",
    "@prb/test/=lib/ipor-fusion/lib/foundry-random/lib/prb-test/src/",
    "@scroll-tech/=lib/ipor-fusion/node_modules/@scroll-tech/",
    "@uniswap/v3-core/=lib/ipor-fusion/node_modules/@uniswap/v3-core/",
    "CramBit/=lib/ipor-fusion/lib/foundry-random/lib/CramBit/",
    "abdk-libraries-solidity/=node_modules/abdk-libraries-solidity/",
    "base64-sol/=lib/ipor-fusion/node_modules/base64-sol/",
    "crambit/=lib/ipor-fusion/lib/foundry-random/lib/CramBit/src/",
    "erc4626-tests/=lib/ipor-fusion/node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "ethereum-vault-connector/=lib/ipor-fusion/node_modules/ethereum-vault-connector/",
    "foundry-random/=lib/ipor-fusion/lib/foundry-random/src/",
    "hardhat-deploy/=node_modules/hardhat-deploy/",
    "hardhat/=node_modules/hardhat/",
    "ipor-fusion/=lib/ipor-fusion/contracts/",
    "openzeppelin-contracts/=lib/ipor-fusion/node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
    "openzeppelin/=lib/ipor-fusion/node_modules/ethereum-vault-connector/lib/openzeppelin-contracts/contracts/",
    "prb-test/=lib/ipor-fusion/lib/foundry-random/lib/prb-test/src/",
    "solidity-bytes-utils/=lib/ipor-fusion/lib/foundry-random/lib/solidity-bytes-utils/contracts/",
    "solmate/=lib/ipor-fusion/node_modules/@uniswap/v4-core/lib/solmate/",
    "src/=lib/ipor-fusion/lib/foundry-random/src/",
    "test/=lib/ipor-fusion/test/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.