Skip to content
Verified contractPartialBUSL-1.1

MaplePoolManager

Address0x47feaa096efe5d44ed9378a29705c47c60ffc3b5
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
BUSL-1.1
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,205,260
Creation transaction
0x7e7d810d3f…1499adb053

modules/pool/contracts/MaplePoolManager.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.34;

import { ERC20Helper } from "../modules/erc20-helper/src/ERC20Helper.sol";
import { IMapleProxyFactory } from "../modules/maple-proxy-factory/contracts/interfaces/IMapleProxyFactory.sol";
import { IMapleProxied } from "../modules/maple-proxy-factory/contracts/interfaces/IMapleProxied.sol";
import { MapleProxiedInternals } from "../modules/maple-proxy-factory/contracts/MapleProxiedInternals.sol";

import { MaplePoolManagerStorage } from "./proxy/MaplePoolManagerStorage.sol";

import {
    IERC20Like,
    IGlobalsLike,
    ILoanLike,
    ILoanManagerLike,
    IPoolLike,
    IPoolPermissionManagerLike,
    IStrategyLike,
    IStrategyManagerLike,
    IWithdrawalManagerLike
} from "./interfaces/Interfaces.sol";

import { IMaplePoolManager } from "./interfaces/IMaplePoolManager.sol";

/*

   ███╗   ███╗ █████╗ ██████╗ ██╗     ███████╗
   ████╗ ████║██╔══██╗██╔══██╗██║     ██╔════╝
   ██╔████╔██║███████║██████╔╝██║     █████╗
   ██║╚██╔╝██║██╔══██║██╔═══╝ ██║     ██╔══╝
   ██║ ╚═╝ ██║██║  ██║██║     ███████╗███████╗
   ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝     ╚══════╝╚══════╝


   ██████╗  ██████╗  ██████╗ ██╗         ███╗   ███╗ █████╗ ███╗   ██╗ █████╗  ██████╗ ███████╗██████╗
   ██╔══██╗██╔═══██╗██╔═══██╗██║         ████╗ ████║██╔══██╗████╗  ██║██╔══██╗██╔════╝ ██╔════╝██╔══██╗
   ██████╔╝██║   ██║██║   ██║██║         ██╔████╔██║███████║██╔██╗ ██║███████║██║  ███╗█████╗  ██████╔╝
   ██╔═══╝ ██║   ██║██║   ██║██║         ██║╚██╔╝██║██╔══██║██║╚██╗██║██╔══██║██║   ██║██╔══╝  ██╔══██╗
   ██║     ╚██████╔╝╚██████╔╝███████╗    ██║ ╚═╝ ██║██║  ██║██║ ╚████║██║  ██║╚██████╔╝███████╗██║  ██║
   ╚═╝      ╚═════╝  ╚═════╝ ╚══════╝    ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝╚═╝  ╚═╝ ╚═════╝ ╚══════╝╚═╝  ╚═╝

*/

contract MaplePoolManager is IMaplePoolManager, MapleProxiedInternals, MaplePoolManagerStorage {

    uint256 public constant HUNDRED_PERCENT = 100_0000; // Four decimal precision.

    /**************************************************************************************************************************************/
    /*** Modifiers                                                                                                                      ***/
    /**************************************************************************************************************************************/

    modifier nonReentrant() {
        require(_locked == 1, "PM:LOCKED");

        _locked = 2;

        _;

        _locked = 1;
    }

    modifier onlyGovernorOrNotConfigured() {
        _revertIfConfiguredAndNotGovernor();
        _;
    }

    modifier onlyIfNotConfigured() {
        _revertIfConfigured();
        _;
    }

    modifier onlyProtocolAdminsOrNotConfigured() {
        _revertIfConfiguredAndNotProtocolAdmins();
        _;
    }

    modifier onlyPool() {
        _revertIfNotPool();
        _;
    }

    modifier onlyOperationalAdmin() {
        _revertIfNotOperationalAdmin();
        _;
    }

    modifier whenNotPaused() {
        _revertIfPaused();
        _;
    }

    /**************************************************************************************************************************************/
    /*** Migration Functions                                                                                                            ***/
    /**************************************************************************************************************************************/

    function migrate(address migrator_, bytes calldata arguments_) external override whenNotPaused {
        require(msg.sender == _factory(),        "PM:M:NOT_FACTORY");
        require(_migrate(migrator_, arguments_), "PM:M:FAILED");
    }

    function setImplementation(address implementation_) external override whenNotPaused {
        require(msg.sender == _factory(), "PM:SI:NOT_FACTORY");
        _setImplementation(implementation_);
    }

    function upgrade(uint256 version_, bytes calldata arguments_) external override whenNotPaused {
        require(msg.sender == IGlobalsLike(globals()).securityAdmin(), "PM:U:NO_AUTH");

        emit Upgraded(version_, arguments_);

        IMapleProxyFactory(_factory()).upgradeInstance(version_, arguments_);
    }

    /**************************************************************************************************************************************/
    /*** Initial Configuration Function                                                                                                 ***/
    /**************************************************************************************************************************************/

    // NOTE: This function is always called atomically during the deployment process so a DoS attack is not possible.
    function completeConfiguration() external override whenNotPaused onlyIfNotConfigured {
        configured = true;

        emit PoolConfigurationComplete();
    }

    /**************************************************************************************************************************************/
    /*** Ownership Transfer Functions                                                                                                   ***/
    /**************************************************************************************************************************************/

    function acceptPoolDelegate() external override whenNotPaused {
        require(msg.sender == pendingPoolDelegate, "PM:APD:NOT_PENDING_PD");

        IGlobalsLike(globals()).transferOwnedPoolManager(poolDelegate, msg.sender);

        emit PendingDelegateAccepted(poolDelegate, pendingPoolDelegate);

        poolDelegate        = pendingPoolDelegate;
        pendingPoolDelegate = address(0);
    }

    function setPendingPoolDelegate(address pendingPoolDelegate_) external override whenNotPaused onlyOperationalAdmin {
        pendingPoolDelegate = pendingPoolDelegate_;

        emit PendingDelegateSet(poolDelegate, pendingPoolDelegate_);
    }

    /**************************************************************************************************************************************/
    /*** Globals Admin Functions                                                                                                        ***/
    /**************************************************************************************************************************************/

    function setActive(bool active_) external override whenNotPaused {
        require(msg.sender == globals(), "PM:SA:NOT_GLOBALS");
        emit SetAsActive(active = active_);
    }

    /**************************************************************************************************************************************/
    /*** Pool Delegate Admin Functions                                                                                                  ***/
    /**************************************************************************************************************************************/

    function addStrategy(
        address strategyFactory_,
        bytes32 salt_,
        bytes calldata extraDeploymentData_
    )
        external
        override
        whenNotPaused
        onlyGovernorOrNotConfigured
        returns (address strategy_)
    {
        require(IGlobalsLike(globals()).isInstanceOf("STRATEGY_FACTORY", strategyFactory_), "PM:AS:INVALID_FACTORY");

        strategy_ =
            IMapleProxyFactory(strategyFactory_).createInstance(bytes.concat(abi.encode(address(this)), extraDeploymentData_), salt_);

        isStrategy[strategy_] = true;

        strategyList.push(strategy_);

        // Check the accounting of the newly added strategy isn't broken.
        (bool success_,) = strategy_.staticcall(abi.encodeWithSelector(IStrategyLike.assetsUnderManagement.selector));

        require(success_, "PM:AS:AUM_FAILURE");

        emit StrategyAdded(strategy_);
    }

    function addStrategyManager(address strategyManager_) external override whenNotPaused onlyGovernorOrNotConfigured {
        require(!isStrategy[strategyManager_],                                  "PM:ASM:ALREADY_STRATEGY");
        require(!isStrategyManager[strategyManager_],                           "PM:ASM:ALREADY_STRATEGY_MANAGER");
        require(_isValidStrategyManager(strategyManager_),                      "PM:ASM:INVALID_STRATEGY_MANAGER");
        require(IStrategyManagerLike(strategyManager_).isAssetSupported(asset), "PM:ASM:ASSET_NOT_SUPPORTED");

        isStrategyManager[strategyManager_] = true;
        strategyList.push(strategyManager_);

        (bool success_,) = strategyManager_.staticcall(abi.encodeWithSelector(IStrategyManagerLike.assetsOf.selector, address(this)));

        require(success_, "PM:ASM:ASSETS_OF_FAILURE");

        emit StrategyManagerAdded(strategyManager_);
    }

    function multicall(bytes[] calldata data_) external override {
        for (uint256 i = 0; i < data_.length; i++) {
            (bool success_, bytes memory returnData_) = address(this).delegatecall(data_[i]);

            if (!success_) {
                assembly ("memory-safe") {
                    revert(add(32, returnData_), mload(returnData_))
                }
            }
        }
    }

    function removeStrategyManager(address strategyManager_) external override whenNotPaused onlyOperationalAdmin {
        require(isStrategyManager[strategyManager_],                                 "PM:RSM:NOT_STRATEGY_MANAGER");
        require(IStrategyManagerLike(strategyManager_).assetsOf(address(this)) == 0, "PM:RSM:NON_ZERO_ASSETS");

        uint256 length_ = strategyList.length;

        for (uint256 i_; i_ < length_; ++i_) {
            if (strategyList[i_] != strategyManager_) continue;

            strategyList[i_] = strategyList[length_ - 1];

            strategyList.pop();

            break;
        }

        delete isStrategyManager[strategyManager_];

        if (strategyCapOf[strategyManager_] != 0) {
            strategyCapOf[strategyManager_] = 0;
            emit StrategyCapSet(strategyManager_, 0);
        }

        emit StrategyManagerRemoved(strategyManager_);
    }

    function setDelegateManagementFeeRate(uint256 delegateManagementFeeRate_)
        external
        override
        whenNotPaused
        onlyProtocolAdminsOrNotConfigured
    {
        require(delegateManagementFeeRate_ <= HUNDRED_PERCENT, "PM:SDMFR:OOB");

        emit DelegateManagementFeeRateSet(delegateManagementFeeRate = delegateManagementFeeRate_);
    }

    function setLiquidityCap(uint256 liquidityCap_) external override whenNotPaused onlyProtocolAdminsOrNotConfigured {
        emit LiquidityCapSet(liquidityCap = liquidityCap_);
    }

    function setStrategyCap(address strategy_, uint256 cap_) external override whenNotPaused onlyProtocolAdminsOrNotConfigured {
        require(strategyCapOf[strategy_] != cap_,                  "PM:SSC:NO_CHANGE");
        require(cap_ == 0 || _isValidStrategyOrManager(strategy_), "PM:SSC:NOT_STRATEGY_OR_MANAGER");

        strategyCapOf[strategy_] = cap_;

        emit StrategyCapSet(strategy_, cap_);
    }

    function setWithdrawalManager(address withdrawalManager_) external override whenNotPaused onlyIfNotConfigured {
        address factory_ = IMapleProxied(withdrawalManager_).factory();

        require(IGlobalsLike(globals()).isInstanceOf("WITHDRAWAL_MANAGER_QUEUE_FACTORY", factory_), "PM:SWM:INVALID_FACTORY");
        require(IMapleProxyFactory(factory_).isInstance(withdrawalManager_),                        "PM:SWM:INVALID_INSTANCE");

        emit WithdrawalManagerSet(withdrawalManager = withdrawalManager_);
    }

    function setPoolPermissionManager(address poolPermissionManager_) external override whenNotPaused onlyProtocolAdminsOrNotConfigured {
        require(IGlobalsLike(globals()).isInstanceOf("POOL_PERMISSION_MANAGER", poolPermissionManager_), "PM:SPPM:INVALID_INSTANCE");

        emit PoolPermissionManagerSet(poolPermissionManager = poolPermissionManager_);
    }

    function triggerDefault(address loan_) external override whenNotPaused nonReentrant {
        require(
            msg.sender == poolDelegate || msg.sender == governor() || msg.sender == IGlobalsLike(globals()).operationalAdmin(),
            "PM:NOT_PD_OR_GOV_OR_OA"
        );

        (, uint256 losses_,) = ILoanManagerLike(ILoanLike(loan_).lender()).triggerDefault(loan_, address(0));

        emit CollateralLiquidationFinished(loan_, losses_);
    }

    /**************************************************************************************************************************************/
    /*** Funding Functions                                                                                                              ***/
    /**************************************************************************************************************************************/

    function requestFunds(address destination_, uint256 amount_) external override whenNotPaused nonReentrant {
        address pool_   = pool;
        address caller_ = msg.sender;

        require(destination_ != address(0),           "PM:RF:ZERO_DESTINATION");
        require(amount_ != 0,                         "PM:RF:ZERO_AMOUNT");
        require(IERC20Like(pool_).totalSupply() != 0, "PM:RF:ZERO_SUPPLY");
        require(_isValidStrategyOrManager(caller_),   "PM:RF:INVALID_STRATEGY_OR_MANAGER");

        require(_assetsUnderManagement(caller_) + amount_ <= strategyCapOf[caller_], "PM:RF:STRATEGY_CAP");

        require(ERC20Helper.transferFrom(asset, pool_, destination_, amount_), "PM:RF:TRANSFER_FAIL");
    }

    /**************************************************************************************************************************************/
    /*** Pool Exit Functions                                                                                                            ***/
    /**************************************************************************************************************************************/

    function processRedeem(
        uint256 shares_,
        address owner_,
        address sender_
    )
        external
        override
        whenNotPaused
        nonReentrant
        onlyPool
        returns (uint256 redeemableShares_, uint256 resultingAssets_)
    {
        require(owner_ == sender_ || IPoolLike(pool).allowance(owner_, sender_) > 0, "PM:PR:NO_ALLOWANCE");

        (redeemableShares_, resultingAssets_) = IWithdrawalManagerLike(withdrawalManager).processExit(shares_, owner_);
        emit RedeemProcessed(owner_, redeemableShares_, resultingAssets_);
    }

    function processWithdraw(
        uint256 assets_,
        address owner_,
        address sender_
    )
        external
        override
        whenNotPaused
        nonReentrant
        returns (uint256 redeemableShares_, uint256 resultingAssets_)
    {
        assets_; // Silence compiler warnings
        owner_;
        sender_;
        redeemableShares_;
        resultingAssets_;
        require(false, "PM:PW:NOT_ENABLED");
    }

    function removeShares(
        uint256 shares_,
        address owner_
    )
        external
        override
        whenNotPaused
        nonReentrant
        onlyPool
        returns (uint256 sharesReturned_)
    {
        emit SharesRemoved(owner_, sharesReturned_ = IWithdrawalManagerLike(withdrawalManager).removeShares(shares_, owner_));
    }

    function requestRedeem(uint256 shares_, address owner_, address sender_) external override whenNotPaused nonReentrant onlyPool {
        address pool_ = pool;

        require(ERC20Helper.approve(pool_, withdrawalManager, shares_), "PM:RR:APPROVE_FAIL");

        IWithdrawalManagerLike(withdrawalManager).addShares(shares_, owner_);

        emit RedeemRequested(owner_, shares_);
    }

    function requestWithdraw(
        uint256 shares_,
        uint256 assets_,
        address owner_,
        address sender_
    )
        external
        override
        whenNotPaused
        nonReentrant
    {
        shares_; // Silence compiler warnings
        assets_;
        owner_;
        sender_;
        require(false, "PM:RW:NOT_ENABLED");
    }

    /**************************************************************************************************************************************/
    /*** View Functions                                                                                                                 ***/
    /**************************************************************************************************************************************/

    function canCall(
        bytes32 functionId_,
        address caller_,
        bytes calldata data_
    )
        external
        view
        override
        returns (bool canCall_, string memory errorMessage_)
    {
        if (IGlobalsLike(globals()).isFunctionPaused(msg.sig)) return (false, "PM:CC:PAUSED");

        uint256[3] memory params_ = _decodeParameters(data_);

        uint256 assets_ = params_[0];
        address lender_ = _address(params_[1]);

        // For mint functions there's a need to convert shares into assets.
        if (functionId_ == "P:mint" || functionId_ == "P:mintWithPermit") assets_ = IPoolLike(pool).previewMint(params_[0]);

        // Redeem and withdraw require getting the third word from the calldata.
        if (functionId_ == "P:redeem" || functionId_ == "P:withdraw") lender_ = _address(params_[2]);

        // Transfers need to check both the sender and the recipient.
        if (functionId_ == "P:transfer" || functionId_ == "P:transferFrom") {
            address[] memory lenders_ = new address[](2);

            (lenders_[0], lenders_[1]) =
                functionId_ == "P:transfer" ? (caller_, _address(params_[0])) : (_address(params_[0]), _address(params_[1]));

            // Check both lenders in a single call.
            if (!IPoolPermissionManagerLike(poolPermissionManager).hasPermission(address(this), lenders_, functionId_)) {
                return (false, "PM:CC:NOT_ALLOWED");
            }
        } else {
            if (!IPoolPermissionManagerLike(poolPermissionManager).hasPermission(address(this), lender_, functionId_)) {
                return (false, "PM:CC:NOT_ALLOWED");
            }
        }

        if (
            functionId_ == "P:redeem" || functionId_ == "P:withdraw" || functionId_ == "P:removeShares" || functionId_ == "P:requestRedeem"
                || functionId_ == "P:requestWithdraw" || functionId_ == "P:transfer" || functionId_ == "P:transferFrom"
        ) return (true, "");

        if (
            functionId_ == "P:deposit" || functionId_ == "P:depositWithPermit" || functionId_ == "P:mint"
                || functionId_ == "P:mintWithPermit"
        ) return _canDeposit(assets_);

        return (false, "PM:CC:INVALID_FUNCTION_ID");
    }

    function factory() external view override returns (address factory_) {
        factory_ = _factory();
    }

    function globals() public view override returns (address globals_) {
        globals_ = IMapleProxyFactory(_factory()).mapleGlobals();
    }

    function governor() public view override returns (address governor_) {
        governor_ = IGlobalsLike(globals()).governor();
    }

    // Pool delegate cover is deprecated; always reports as sufficient so downstream loan-manager fee logic keeps paying the delegate.
    function hasSufficientCover() public pure override returns (bool hasSufficientCover_) {
        hasSufficientCover_ = true;
    }

    function implementation() external view override returns (address implementation_) {
        implementation_ = _implementation();
    }

    function strategyListLength() external view override returns (uint256 strategyListLength_) {
        strategyListLength_ = strategyList.length;
    }

    function totalAssets() public view override returns (uint256 totalAssets_) {
        totalAssets_ = IERC20Like(asset).balanceOf(pool);

        uint256 length_ = strategyList.length;

        for (uint256 i_; i_ < length_; i_++) {
            totalAssets_ += _assetsUnderManagement(strategyList[i_]);
        }
    }

    /**************************************************************************************************************************************/
    /*** LP Token View Functions                                                                                                        ***/
    /**************************************************************************************************************************************/

    function convertToExitShares(uint256 assets_) public view override returns (uint256 shares_) {
        shares_ = IPoolLike(pool).convertToExitShares(assets_);
    }

    function getEscrowParams(address, uint256 shares_) external view override returns (uint256 escrowShares_, address destination_) {
        // NOTE: `owner_` param not named to avoid compiler warning.
        (escrowShares_, destination_) = (shares_, address(this));
    }

    function maxDeposit(address receiver_) external view virtual override returns (uint256 maxAssets_) {
        maxAssets_ = _getMaxAssets(receiver_, totalAssets(), "P:deposit");
    }

    function maxMint(address receiver_) external view virtual override returns (uint256 maxShares_) {
        uint256 totalAssets_ = totalAssets();
        uint256 maxAssets_   = _getMaxAssets(receiver_, totalAssets_, "P:mint");

        maxShares_ = IPoolLike(pool).previewDeposit(maxAssets_);
    }

    function maxRedeem(address owner_) external view virtual override returns (uint256 maxShares_) {
        uint256 lockedShares_ = IWithdrawalManagerLike(withdrawalManager).lockedShares(owner_);
        maxShares_            = IWithdrawalManagerLike(withdrawalManager).isInExitWindow(owner_) ? lockedShares_ : 0;
    }

    function maxWithdraw(address owner_) external view virtual override returns (uint256 maxAssets_) {
        owner_; // Silence compiler warning
        maxAssets_ = 0; // NOTE: always returns 0 as withdraw is not implemented
    }

    function previewRedeem(address owner_, uint256 shares_) external view virtual override returns (uint256 assets_) {
        (, assets_) = IWithdrawalManagerLike(withdrawalManager).previewRedeem(owner_, shares_);
    }

    function previewWithdraw(address owner_, uint256 assets_) external view virtual override returns (uint256 shares_) {
        (, shares_) = IWithdrawalManagerLike(withdrawalManager).previewWithdraw(owner_, assets_);
    }

    function unrealizedLosses() public view override returns (uint256 unrealizedLosses_) {
        uint256 length_ = strategyList.length;

        for (uint256 i_; i_ < length_; i_++) {
            unrealizedLosses_ += _unrealizedLosses(strategyList[i_]);
        }

        unrealizedLosses_ = _min(unrealizedLosses_, totalAssets());
    }

    /**************************************************************************************************************************************/
    /*** Internal Functions                                                                                                             ***/
    /**************************************************************************************************************************************/

    function _address(uint256 word_) internal pure returns (address address_) {
        address_ = address(uint160(word_));
    }

    function _assetsUnderManagement(address strategy_) internal view returns (uint256 exposure_) {
        exposure_ = isStrategyManager[strategy_]
            ? IStrategyManagerLike(strategy_).assetsOf(address(this))
            : IStrategyLike(strategy_).assetsUnderManagement();
    }

    function _canDeposit(uint256 assets_) internal view returns (bool canDeposit_, string memory errorMessage_) {
        if (!active) return (false, "P:NOT_ACTIVE");
        if (assets_ + totalAssets() > liquidityCap) return (false, "P:DEPOSIT_GT_LIQ_CAP");

        return (true, "");
    }

    function _decodeParameters(bytes calldata data_) internal pure returns (uint256[3] memory words) {
        if (data_.length > 64) {
            (words[0], words[1], words[2]) = abi.decode(data_, (uint256, uint256, uint256));
        } else {
            (words[0], words[1]) = abi.decode(data_, (uint256, uint256));
        }
    }

    function _getMaxAssets(address receiver_, uint256 totalAssets_, bytes32 functionId_) internal view returns (uint256 maxAssets_) {
        bool    depositAllowed_ = IPoolPermissionManagerLike(poolPermissionManager).hasPermission(address(this), receiver_, functionId_);
        uint256 liquidityCap_   = liquidityCap;
        maxAssets_              = liquidityCap_ > totalAssets_ && depositAllowed_ ? liquidityCap_ - totalAssets_ : 0;
    }

    function _isValidStrategy(address strategy_) internal view returns (bool) {
        if (strategy_ == address(0)) return false;

        address factory_ = IMapleProxied(strategy_).factory();

        if (!IGlobalsLike(globals()).isInstanceOf("STRATEGY_FACTORY", factory_)) return false;
        if (!IMapleProxyFactory(factory_).isInstance(strategy_)) return false;

        return true;
    }

    function _isValidStrategyManager(address strategyManager_) internal view returns (bool) {
        if (strategyManager_ == address(0)) return false;

        address factory_ = IMapleProxied(strategyManager_).factory();

        if (!IGlobalsLike(globals()).isInstanceOf("STRATEGY_MANAGER_FACTORY", factory_)) return false;
        if (!IMapleProxyFactory(factory_).isInstance(strategyManager_)) return false;

        return true;
    }

    function _isValidStrategyOrManager(address caller_) internal view returns (bool) {
        if (isStrategyManager[caller_]) return _isValidStrategyManager(caller_);
        if (isStrategy[caller_]) return _isValidStrategy(caller_);

        return false;
    }

    function _unrealizedLosses(address strategy_) internal view returns (uint256 unrealizedLosses_) {
        unrealizedLosses_ = isStrategyManager[strategy_]
            ? IStrategyManagerLike(strategy_).unrealizedLossesOf(address(this))
            : IStrategyLike(strategy_).unrealizedLosses();
    }

    function _revertIfConfigured() internal view {
        require(!configured, "PM:ALREADY_CONFIGURED");
    }

    function _revertIfConfiguredAndNotGovernor() internal view {
        require(!configured || msg.sender == governor(), "PM:NOT_GOV_OR_NOT_CONFIGURED");
    }

    function _revertIfConfiguredAndNotProtocolAdmins() internal view {
        require(
            !configured || msg.sender == poolDelegate || msg.sender == governor()
                || msg.sender == IGlobalsLike(globals()).operationalAdmin(),
            "PM:NOT_PA_OR_NOT_CONFIGURED"
        );
    }

    function _revertIfNotOperationalAdmin() internal view {
        require(msg.sender == IGlobalsLike(globals()).operationalAdmin(), "PM:NOT_OPERATIONAL_ADMIN");
    }

    function _revertIfNotPool() internal view {
        require(msg.sender == pool, "PM:NOT_POOL");
    }

    function _revertIfPaused() internal view {
        require(!IGlobalsLike(globals()).isFunctionPaused(msg.sig), "PM:PAUSED");
    }

    function _min(uint256 a_, uint256 b_) internal pure returns (uint256 min_) {
        min_ = a_ < b_ ? a_ : b_;
    }

}

modules/pool/contracts/interfaces/IMaplePoolManager.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import { IMapleProxied } from "../../modules/maple-proxy-factory/contracts/interfaces/IMapleProxied.sol";

import { IMaplePoolManagerStorage } from "./IMaplePoolManagerStorage.sol";

interface IMaplePoolManager is IMapleProxied, IMaplePoolManagerStorage {

    /**************************************************************************************************************************************/
    /*** Events                                                                                                                         ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev   Emitted when a collateral liquidations is finished.
     *  @param loan_             The address of the loan.
     *  @param unrealizedLosses_ The amount of unrealized losses.
     */
    event CollateralLiquidationFinished(address indexed loan_, uint256 unrealizedLosses_);

    /**
     *  @dev   Emitted when a new management fee rate is set.
     *  @param managementFeeRate The amount of management fee rate.
     */
    event DelegateManagementFeeRateSet(uint256 managementFeeRate);

    /**
     *  @dev   Emitted when a new liquidity cap is set.
     *  @param liquidityCap The value of liquidity cap.
     */
    event LiquidityCapSet(uint256 liquidityCap);

    /**
     *  @dev   Emitted when a new strategy is added.
     *  @param strategy The address of the new strategy.
     */
    event StrategyAdded(address indexed strategy);

    /**
     *  @dev   Emitted when the pool's AUM exposure cap to a strategy is set.
     *  @param strategy The address of the strategy.
     *  @param cap      The pool's AUM exposure cap to the strategy.
     */
    event StrategyCapSet(address indexed strategy, uint256 cap);

    /**
     *  @dev   Emitted when a strategy manager is registered with the pool.
     *  @param strategyManager The address of the strategy manager.
     */
    event StrategyManagerAdded(address indexed strategyManager);

    /**
     *  @dev   Emitted when a strategy manager is removed from the pool.
     *  @param strategyManager The address of the strategy manager.
     */
    event StrategyManagerRemoved(address indexed strategyManager);

    /**
     *  @dev   Emitted when the pending pool delegate accepts the ownership transfer.
     *  @param previousDelegate The address of the previous delegate.
     *  @param newDelegate      The address of the new delegate.
     */
    event PendingDelegateAccepted(address indexed previousDelegate, address indexed newDelegate);

    /**
     *  @dev   Emitted when the pending pool delegate is set.
     *  @param previousDelegate The address of the previous delegate.
     *  @param newDelegate      The address of the new delegate.
     */
    event PendingDelegateSet(address indexed previousDelegate, address indexed newDelegate);

    /**
     *  @dev Emitted when the pool configuration is marked as complete.
     */
    event PoolConfigurationComplete();

    /**
     *  @dev   Emitted when the pool permission manager is set.
     *  @param poolPermissionManager The address of the pool permission manager.
     */
    event PoolPermissionManagerSet(address indexed poolPermissionManager);

    /**
     *  @dev   Emitted when a redemption of shares from the pool is processed.
     *  @param owner            The owner of the shares.
     *  @param redeemableShares The amount of redeemable shares.
     *  @param resultingAssets  The amount of assets redeemed.
     */
    event RedeemProcessed(address indexed owner, uint256 redeemableShares, uint256 resultingAssets);

    /**
     *  @dev   Emitted when a redemption of shares from the pool is requested.
     *  @param owner  The owner of the shares.
     *  @param shares The amount of redeemable shares.
     */
    event RedeemRequested(address indexed owner, uint256 shares);

    /**
     *  @dev   Emitted when a pool is sets to be active or inactive.
     *  @param active Whether the pool is active.
     */
    event SetAsActive(bool active);

    /**
     *  @dev   Emitted when shares are removed from the pool.
     *  @param owner  The address of the owner of the shares.
     *  @param shares The amount of shares removed.
     */
    event SharesRemoved(address indexed owner, uint256 shares);

    /**
     *  @dev   Emitted when the withdrawal manager is set.
     *  @param withdrawalManager The address of the withdrawal manager.
     */
    event WithdrawalManagerSet(address indexed withdrawalManager);

    /**************************************************************************************************************************************/
    /*** Ownership Transfer Functions                                                                                                   ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev Accepts the role of pool delegate.
     */
    function acceptPoolDelegate() external;

    /**
     *  @dev   Sets an address as the pending pool delegate. Passing address(0) cancels a pending transfer.
     *         Can only be called by the operational admin.
     *  @param pendingPoolDelegate The address of the new pool delegate.
     */
    function setPendingPoolDelegate(address pendingPoolDelegate) external;

    /**************************************************************************************************************************************/
    /*** Administrative Functions                                                                                                       ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev    Adds a new strategy.
     *          NOTE: The PoolManager address is encoded and prepended to the extraDeploymentData.
     *  @param  strategyFactory     The address of the strategy factory to use.
     *  @param  salt                The salt used by the factory to deploy the strategy instance.
     *  @param  extraDeploymentData The data to construct the strategy.
     *  @return strategy            The address of the new strategy.
     */
    function addStrategy(address strategyFactory, bytes32 salt, bytes calldata extraDeploymentData) external returns (address strategy);

    /**
     *  @dev   Registers an already-deployed strategy manager with the pool.
     *         Callable by any caller while the pool manager is not yet configured (typically during deployment).
     *         Once `completeConfiguration()` has been called, only the governor (timelock-gated) may call this function.
     *  @param strategyManager The address of the strategy manager.
     */
    function addStrategyManager(address strategyManager) external;

    /**
     *  @dev   Allows EOAs to batch admin calls.
     *  @param data Array of calldata.
     */
    function multicall(bytes[] calldata data) external;

    /**
     *  @dev   Removes a strategy manager from the pool and clears its strategy cap.
     *         Only callable by the operational admin after this pool manager has no assets in the strategy manager.
     *  @param strategyManager The address of the strategy manager.
     */
    function removeStrategyManager(address strategyManager) external;

    /**
     *  @dev Complete the configuration.
     */
    function completeConfiguration() external;

    /**
     *  @dev   Sets a the pool to be active or inactive.
     *  @param active Whether the pool is active.
     */
    function setActive(bool active) external;

    /**
     *  @dev   Sets the value for the delegate management fee rate.
     *  @param delegateManagementFeeRate The value for the delegate management fee rate.
     */
    function setDelegateManagementFeeRate(uint256 delegateManagementFeeRate) external;

    /**
     *  @dev   Sets the value for liquidity cap.
     *  @param liquidityCap The value for liquidity cap.
     */
    function setLiquidityCap(uint256 liquidityCap) external;

    /**
     *  @dev   Sets the pool's AUM exposure cap to a strategy.
     *         The strategy must be an instance of a valid strategy factory if the cap is non-zero.
     *  @param strategy The address of the strategy.
     *  @param cap      The pool's AUM exposure cap to the strategy.
     */
    function setStrategyCap(address strategy, uint256 cap) external;

    /**
     *  @dev   Sets the address of the pool permission manager.
     *  @param poolPermission The address of the pool permission manager.
     */
    function setPoolPermissionManager(address poolPermission) external;

    /**
     *  @dev   Sets the address of the withdrawal manager.
     *  @param withdrawalManager The address of the withdrawal manager.
     */
    function setWithdrawalManager(address withdrawalManager) external;

    /**
     *  @dev   Triggers the default of a loan held by the pool's loan manager.
     *  @param loan_ The address of the loan to default.
     */
    function triggerDefault(address loan_) external;

    /**************************************************************************************************************************************/
    /*** Funding Functions                                                                                                              ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev   Strategy can request funds from the pool via the poolManager.
     *  @param destination The address to send the funds to.
     *  @param amount      Amount to fund the strategy with.
     */
    function requestFunds(address destination, uint256 amount) external;

    /**************************************************************************************************************************************/
    /*** Exit Functions                                                                                                                 ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev    Processes a redemptions of shares for assets from the pool.
     *  @param  shares           The amount of shares to redeem.
     *  @param  owner            The address of the owner of the shares.
     *  @param  sender           The address of the sender of the redeem call.
     *  @return redeemableShares The amount of shares redeemed.
     *  @return resultingAssets  The amount of assets withdrawn.
     */
    function processRedeem(
        uint256 shares,
        address owner,
        address sender
    )
        external
        returns (uint256 redeemableShares, uint256 resultingAssets);

    /**
     *  @dev    Processes a redemptions of shares for assets from the pool.
     *  @param  assets           The amount of assets to withdraw.
     *  @param  owner            The address of the owner of the shares.
     *  @param  sender           The address of the sender of the withdraw call.
     *  @return redeemableShares The amount of shares redeemed.
     *  @return resultingAssets  The amount of assets withdrawn.
     */
    function processWithdraw(
        uint256 assets,
        address owner,
        address sender
    )
        external
        returns (uint256 redeemableShares, uint256 resultingAssets);

    /**
     *  @dev    Requests a redemption of shares from the pool.
     *  @param  shares         The amount of shares to redeem.
     *  @param  owner          The address of the owner of the shares.
     *  @return sharesReturned The amount of shares withdrawn.
     */
    function removeShares(uint256 shares, address owner) external returns (uint256 sharesReturned);

    /**
     *  @dev   Requests a redemption of shares from the pool.
     *  @param shares The amount of shares to redeem.
     *  @param owner  The address of the owner of the shares.
     *  @param sender The address of the sender of the shares.
     */
    function requestRedeem(uint256 shares, address owner, address sender) external;

    /**
     *  @dev   Requests a withdrawal of assets from the pool.
     *  @param shares The amount of shares to redeem.
     *  @param assets The amount of assets to withdraw.
     *  @param owner  The address of the owner of the shares.
     *  @param sender The address of the sender of the shares.
     */
    function requestWithdraw(uint256 shares, uint256 assets, address owner, address sender) external;

    /**************************************************************************************************************************************/
    /*** LP Token View Functions                                                                                                        ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev    Returns the amount of exit shares for the input amount.
     *  @param  amount  Address of the account.
     *  @return shares  Amount of shares able to be exited.
     */
    function convertToExitShares(uint256 amount) external view returns (uint256 shares);

    /**
     *  @dev    Gets the information of escrowed shares.
     *  @param  owner        The address of the owner of the shares.
     *  @param  shares       The amount of shares to get the information of.
     *  @return escrowShares The amount of escrowed shares.
     *  @return destination  The address of the destination.
     */
    function getEscrowParams(address owner, uint256 shares) external view returns (uint256 escrowShares, address destination);

    /**
     *  @dev   Gets the amount of assets that can be deposited.
     *  @param receiver  The address to check the deposit for.
     *  @param maxAssets The maximum amount assets to deposit.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     *  @dev   Gets the amount of shares that can be minted.
     *  @param receiver  The address to check the mint for.
     *  @param maxShares The maximum amount shares to mint.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     *  @dev   Gets the amount of shares that can be redeemed.
     *  @param owner     The address to check the redemption for.
     *  @param maxShares The maximum amount shares to redeem.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     *  @dev   Gets the amount of assets that can be withdrawn.
     *  @param owner     The address to check the withdraw for.
     *  @param maxAssets The maximum amount assets to withdraw.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     *  @dev    Gets the amount of shares that can be redeemed.
     *  @param  owner   The address to check the redemption for.
     *  @param  shares  The amount of requested shares to redeem.
     *  @return assets  The amount of assets that will be returned for `shares`.
     */
    function previewRedeem(address owner, uint256 shares) external view returns (uint256 assets);

    /**
     *  @dev    Gets the amount of assets that can be redeemed.
     *  @param  owner   The address to check the redemption for.
     *  @param  assets  The amount of requested shares to redeem.
     *  @return shares  The amount of assets that will be returned for `assets`.
     */
    function previewWithdraw(address owner, uint256 assets) external view returns (uint256 shares);

    /**************************************************************************************************************************************/
    /*** View Functions                                                                                                                 ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev    Checks if a scheduled call can be executed.
     *  @param  functionId   The function to check.
     *  @param  caller       The address of the caller.
     *  @param  data         The data of the call.
     *  @return canCall      True if the call can be executed, false otherwise.
     *  @return errorMessage The error message if the call cannot be executed.
     */
    function canCall(bytes32 functionId, address caller, bytes memory data) external view returns (bool canCall, string memory errorMessage);

    /**
     *  @dev    Gets the address of the globals.
     *  @return globals The address of the globals.
     */
    function globals() external view returns (address globals);

    /**
     *  @dev    Gets the address of the governor.
     *  @return governor The address of the governor.
     */
    function governor() external view returns (address governor);

    /**
     *  @dev    Returns whether the pool has sufficient cover. Pool delegate cover is deprecated, so this always returns true.
     *  @return hasSufficientCover True.
     */
    function hasSufficientCover() external pure returns (bool hasSufficientCover);

    /**
     *  @dev    Returns the length of the `strategyList`.
     *  @return strategyListLength The length of the `strategyList`.
     */
    function strategyListLength() external view returns (uint256 strategyListLength);

    /**
     *  @dev    Returns the amount of total assets.
     *  @return totalAssets Amount of of total assets.
     */
    function totalAssets() external view returns (uint256 totalAssets);

    /**
     *  @dev    Returns the sum of unrealized losses reported by every registered strategy and strategy manager.
     *  @return unrealizedLosses Aggregate unrealized losses across all strategies and strategy managers.
     */
    function unrealizedLosses() external view returns (uint256 unrealizedLosses);

}

modules/pool/contracts/interfaces/IMaplePoolManagerStorage.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

interface IMaplePoolManagerStorage {

    /**
     *  @dev    Returns whether or not a pool is active.
     *  @return active_ True if the pool is active.
     */
    function active() external view returns (bool active_);

    /**
     *  @dev    Gets the address of the funds asset.
     *  @return asset_ The address of the funds asset.
     */
    function asset() external view returns (address asset_);

    /**
     *  @dev    Returns whether or not a pool is configured.
     *  @return configured_ True if the pool is configured.
     */
    function configured() external view returns (bool configured_);

    /**
     *  @dev    Gets the delegate management fee rate.
     *  @return delegateManagementFeeRate_ The value for the delegate management fee rate.
     */
    function delegateManagementFeeRate() external view returns (uint256 delegateManagementFeeRate_);

    /**
     *  @dev    Returns whether or not the given address is a registered strategy.
     *          These are legacy strategies set to be depreciated in future for the new modular strategies.
     *  @param  strategy_   The address of the strategy.
     *  @return isStrategy_ True if the address is a registered strategy.
     */
    function isStrategy(address strategy_) external view returns (bool isStrategy_);

    /**
     *  @dev    Returns whether or not the given address is a registered strategy manager.
     *  @param  strategyManager_   The address of the strategy manager.
     *  @return isStrategyManager_ True if the address is a registered strategy manager.
     */
    function isStrategyManager(address strategyManager_) external view returns (bool isStrategyManager_);

    /**
     *  @dev    Gets the liquidity cap for the pool.
     *  @return liquidityCap_ The liquidity cap for the pool.
     */
    function liquidityCap() external view returns (uint256 liquidityCap_);

    /**
     *  @dev    Gets the pool's AUM exposure cap to a given strategy or strategy manager.
     *          The maximum amount of this pool's assets that may be deployed at any one time.
     *  @param  strategy_ The address of the strategy or strategy manager.
     *  @return cap_      The pool's AUM exposure cap.
     */
    function strategyCapOf(address strategy_) external view returns (uint256 cap_);

    /**
     *  @dev    Gets the address of the strategy in the list.
     *  @param  index_    The index to get the address of.
     *  @return strategy_ The address in the list.
     */
    function strategyList(uint256 index_) external view returns (address strategy_);

    /**
     *  @dev    Gets the address of the pending pool delegate.
     *  @return pendingPoolDelegate_ The address of the pending pool delegate.
     */
    function pendingPoolDelegate() external view returns (address pendingPoolDelegate_);

    /**
     *  @dev    Gets the address of the pool.
     *  @return pool_ The address of the pool.
     */
    function pool() external view returns (address pool_);

    /**
     *  @dev    Gets the address of the pool delegate.
     *  @return poolDelegate_ The address of the pool delegate.
     */
    function poolDelegate() external view returns (address poolDelegate_);

    /**
     *  @dev    Gets the address of the pool permission manager.
     *  @return poolPermissionManager_ The address of the pool permission manager.
     */
    function poolPermissionManager() external view returns (address poolPermissionManager_);

    /**
     *  @dev    Gets the address of the withdrawal manager.
     *  @return withdrawalManager_ The address of the withdrawal manager.
     */
    function withdrawalManager() external view returns (address withdrawalManager_);

}

modules/pool/contracts/interfaces/Interfaces.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.7;

interface IERC20Like {

    function allowance(address owner_, address spender_) external view returns (uint256 allowance_);

    function balanceOf(address account_) external view returns (uint256 balance_);

    function totalSupply() external view returns (uint256 totalSupply_);

}

interface IGlobalsLike {

    function bootstrapMint(address asset_) external view returns (uint256 bootstrapMint_);

    function governor() external view returns (address governor_);

    function isFunctionPaused(bytes4 sig_) external view returns (bool isFunctionPaused_);

    function isInstanceOf(bytes32 instanceId_, address instance_) external view returns (bool isInstance_);

    function isPoolAsset(address asset_) external view returns (bool isPoolAsset_);

    function isPoolDelegate(address account_) external view returns (bool isPoolDelegate_);

    function isPoolDeployer(address poolDeployer_) external view returns (bool isPoolDeployer_);

    function migrationAdmin() external view returns (address migrationAdmin_);

    function operationalAdmin() external view returns (address operationalAdmin_);

    function ownedPoolManager(address poolDelegate_) external view returns (address poolManager_);

    function securityAdmin() external view returns (address securityAdmin_);

    function transferOwnedPoolManager(address fromPoolDelegate_, address toPoolDelegate_) external;

}

interface ILoanLike {

    function lender() external view returns (address lender_);

}

interface ILoanManagerLike {

    function triggerDefault(address loan_, address liquidatorFactory_)
        external returns (bool liquidationComplete_, uint256 remainingLosses_, uint256 unrecoveredPlatformFees_);

}

interface IMapleProxyFactoryLike {

    function isInstance(address instance_) external view returns (bool isInstance_);

    function mapleGlobals() external view returns (address mapleGlobals_);

}

interface IPoolLike is IERC20Like {

    function convertToExitShares(uint256 assets_) external view returns (uint256 shares_);

    function previewDeposit(uint256 assets_) external view returns (uint256 shares_);

    function previewMint(uint256 shares_) external view returns (uint256 assets_);

}

interface IPoolManagerLike {

    function addStrategy(address strategyFactory_, bytes32 salt_, bytes calldata deploymentData_) external returns (address strategy_);

    function addStrategyManager(address strategyManager_) external;

    function canCall(bytes32 functionId_, address caller_, bytes memory data_)
        external view
        returns (bool canCall_, string memory errorMessage_);

    function completeConfiguration() external;

    function getEscrowParams(address owner_, uint256 shares_) external view returns (uint256 escrowShares_, address escrow_);

    function maxDeposit(address receiver_) external view returns (uint256 maxAssets_);

    function maxMint(address receiver_) external view returns (uint256 maxShares_);

    function maxRedeem(address owner_) external view returns (uint256 maxShares_);

    function maxWithdraw(address owner_) external view returns (uint256 maxAssets_);

    function pool() external view returns (address pool_);

    function previewRedeem(address owner_, uint256 shares_) external view returns (uint256 assets_);

    function previewWithdraw(address owner_, uint256 assets_) external view returns (uint256 shares_);

    function processRedeem(uint256 shares_, address owner_, address sender_)
        external
        returns (uint256 redeemableShares_, uint256 resultingAssets_);

    function processWithdraw(uint256 assets_, address owner_, address sender_)
        external
        returns (uint256 redeemableShares_, uint256 resultingAssets_);

    function removeShares(uint256 shares_, address owner_) external returns (uint256 sharesReturned_);

    function removeStrategyManager(address strategyManager_) external;

    function requestRedeem(uint256 shares_, address owner_, address sender_) external;

    function requestWithdraw(uint256 shares_, uint256 assets_, address owner_, address sender_) external;

    function setDelegateManagementFeeRate(uint256 delegateManagementFeeRate_) external;

    function setLiquidityCap(uint256 liquidityCap_) external;

    function setPoolPermissionManager(address poolPermissionManager_) external;

    function setStrategyCap(address strategy_, uint256 cap_) external;

    function setWithdrawalManager(address withdrawalManager_) external;

    function totalAssets() external view returns (uint256 totalAssets_);

    function unrealizedLosses() external view returns (uint256 unrealizedLosses_);

}

interface IPoolPermissionManagerLike {

    function hasPermission(address poolManager, address caller, bytes32 functionId) external view returns (bool allowed);

    function hasPermission(address poolManager, address[] calldata caller, bytes32 functionId) external view returns (bool allowed);

}

interface IStrategyLike {

    function assetsUnderManagement() external view returns (uint256 assetsUnderManagement_);

    function unrealizedLosses() external view returns (uint256 unrealizedLosses_);

}

interface IStrategyManagerLike {

    function assetsOf(address poolManager_) external view returns (uint256 assets_);

    function isAssetSupported(address asset_) external view returns (bool isAssetSupported_);

    function unrealizedLossesOf(address poolManager_) external view returns (uint256 unrealizedLosses_);

}

interface IWithdrawalManagerLike {

    function addShares(uint256 shares_, address owner_) external;

    function factory() external view returns (address factory_);

    function isInExitWindow(address owner_) external view returns (bool isInExitWindow_);

    function lockedLiquidity() external view returns (uint256 lockedLiquidity_);

    function lockedShares(address owner_) external view returns (uint256 lockedShares_);

    function previewRedeem(address owner_, uint256 shares) external view returns (uint256 redeemableShares, uint256 resultingAssets_);

    function previewWithdraw(address owner_, uint256 assets_) external view returns (uint256 redeemableAssets_, uint256 resultingShares_);

    function processExit(uint256 shares_, address account_) external returns (uint256 redeemableShares_, uint256 resultingAssets_);

    function removeShares(uint256 shares_, address owner_) external returns (uint256 sharesReturned_);

}

modules/pool/contracts/proxy/MaplePoolManagerStorage.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.34;

import { IMaplePoolManagerStorage } from "../interfaces/IMaplePoolManagerStorage.sol";

abstract contract MaplePoolManagerStorage is IMaplePoolManagerStorage {

    uint256 internal _locked; // Used when checking for reentrancy.

    address public override poolDelegate;
    address public override pendingPoolDelegate;

    address public override asset;
    address public override pool;

    address __deprecated_poolDelegateCover;

    address public override withdrawalManager;

    bool public override active;
    bool public override configured;

    bool __deprecated_openToPublic;

    uint256 public override liquidityCap;
    uint256 public override delegateManagementFeeRate;

    mapping(address => bool) public override isStrategy;

    mapping(address => bool) __deprecated_isValidLender;

    address[] public override strategyList;

    address public override poolPermissionManager;

    mapping(address => bool) public override isStrategyManager;

    mapping(address => uint256) public override strategyCapOf;

}

modules/pool/modules/erc20-helper/src/ERC20Helper.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.7;

import { IERC20Like } from "./interfaces/IERC20Like.sol";

/**
 * @title Small Library to standardize erc20 token interactions.
 */
library ERC20Helper {

    /**************************************************************************************************************************************/
    /*** Internal Functions                                                                                                             ***/
    /**************************************************************************************************************************************/

    function transfer(address token_, address to_, uint256 amount_) internal returns (bool success_) {
        return _call(token_, abi.encodeWithSelector(IERC20Like.transfer.selector, to_, amount_));
    }

    function transferFrom(address token_, address from_, address to_, uint256 amount_) internal returns (bool success_) {
        return _call(token_, abi.encodeWithSelector(IERC20Like.transferFrom.selector, from_, to_, amount_));
    }

    function approve(address token_, address spender_, uint256 amount_) internal returns (bool success_) {
        // If setting approval to zero fails, return false.
        if (!_call(token_, abi.encodeWithSelector(IERC20Like.approve.selector, spender_, uint256(0)))) return false;

        // If `amount_` is zero, return true as the previous step already did this.
        if (amount_ == uint256(0)) return true;

        // Return the result of setting the approval to `amount_`.
        return _call(token_, abi.encodeWithSelector(IERC20Like.approve.selector, spender_, amount_));
    }

    function _call(address token_, bytes memory data_) private returns (bool success_) {
        if (token_.code.length == uint256(0)) return false;

        bytes memory returnData;
        ( success_, returnData ) = token_.call(data_);

        return success_ && (returnData.length == uint256(0) || abi.decode(returnData, (bool)));
    }

}

modules/pool/modules/erc20-helper/src/interfaces/IERC20Like.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.7;

/// @title Interface of the ERC20 standard as needed by ERC20Helper.
interface IERC20Like {

    function approve(address spender_, uint256 amount_) external returns (bool success_);

    function transfer(address recipient_, uint256 amount_) external returns (bool success_);

    function transferFrom(address owner_, address recipient_, uint256 amount_) external returns (bool success_);

}

modules/pool/modules/maple-proxy-factory/contracts/MapleProxiedInternals.sol

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.7;

import { ProxiedInternals } from "../modules/proxy-factory/contracts/ProxiedInternals.sol";

/// @title A Maple implementation that is to be proxied, will need MapleProxiedInternals.
abstract contract MapleProxiedInternals is ProxiedInternals { }

modules/pool/modules/maple-proxy-factory/contracts/interfaces/IMapleProxied.sol

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.7;

import { IProxied } from "../../modules/proxy-factory/contracts/interfaces/IProxied.sol";

/// @title A Maple implementation that is to be proxied, must implement IMapleProxied.
interface IMapleProxied is IProxied {

    /**
     *  @dev   The instance was upgraded.
     *  @param toVersion_ The new version of the loan.
     *  @param arguments_ The upgrade arguments, if any.
     */
    event Upgraded(uint256 toVersion_, bytes arguments_);

    /**
     *  @dev   Upgrades a contract implementation to a specific version.
     *         Access control logic critical since caller can force a selfdestruct via a malicious `migrator_` which is delegatecalled.
     *  @param toVersion_ The version to upgrade to.
     *  @param arguments_ Some encoded arguments to use for the upgrade.
     */
    function upgrade(uint256 toVersion_, bytes calldata arguments_) external;

}

modules/pool/modules/maple-proxy-factory/contracts/interfaces/IMapleProxyFactory.sol

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.7;

import { IDefaultImplementationBeacon } from "../../modules/proxy-factory/contracts/interfaces/IDefaultImplementationBeacon.sol";

/// @title A Maple factory for Proxy contracts that proxy MapleProxied implementations.
interface IMapleProxyFactory is IDefaultImplementationBeacon {

    /**************************************************************************************************************************************/
    /*** Events                                                                                                                         ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev   A default version was set.
     *  @param version_ The default version.
     */
    event DefaultVersionSet(uint256 indexed version_);

    /**
     *  @dev   A version of an implementation, at some address, was registered, with an optional initializer.
     *  @param version_               The version registered.
     *  @param implementationAddress_ The address of the implementation.
     *  @param initializer_           The address of the initializer, if any.
     */
    event ImplementationRegistered(uint256 indexed version_, address indexed implementationAddress_, address indexed initializer_);

    /**
     *  @dev   A proxy contract was deployed with some initialization arguments.
     *  @param version_                 The version of the implementation being proxied by the deployed proxy contract.
     *  @param instance_                The address of the proxy contract deployed.
     *  @param initializationArguments_ The arguments used to initialize the proxy contract, if any.
     */
    event InstanceDeployed(uint256 indexed version_, address indexed instance_, bytes initializationArguments_);

    /**
     *  @dev   A instance has upgraded by proxying to a new implementation, with some migration arguments.
     *  @param instance_           The address of the proxy contract.
     *  @param fromVersion_        The initial implementation version being proxied.
     *  @param toVersion_          The new implementation version being proxied.
     *  @param migrationArguments_ The arguments used to migrate, if any.
     */
    event InstanceUpgraded(address indexed instance_, uint256 indexed fromVersion_, uint256 indexed toVersion_, bytes migrationArguments_);

    /**
     *  @dev   The MapleGlobals was set.
     *  @param mapleGlobals_ The address of a Maple Globals contract.
     */
    event MapleGlobalsSet(address indexed mapleGlobals_);

    /**
     *  @dev   An upgrade path was disabled, with an optional migrator contract.
     *  @param fromVersion_ The starting version of the upgrade path.
     *  @param toVersion_   The destination version of the upgrade path.
     */
    event UpgradePathDisabled(uint256 indexed fromVersion_, uint256 indexed toVersion_);

    /**
     *  @dev   An upgrade path was enabled, with an optional migrator contract.
     *  @param fromVersion_ The starting version of the upgrade path.
     *  @param toVersion_   The destination version of the upgrade path.
     *  @param migrator_    The address of the migrator, if any.
     */
    event UpgradePathEnabled(uint256 indexed fromVersion_, uint256 indexed toVersion_, address indexed migrator_);

    /**************************************************************************************************************************************/
    /*** State Variables                                                                                                                ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev The default version.
     */
    function defaultVersion() external view returns (uint256 defaultVersion_);

    /**
     *  @dev The address of the MapleGlobals contract.
     */
    function mapleGlobals() external view returns (address mapleGlobals_);

    /**
     *  @dev    Whether the upgrade is enabled for a path from a version to another version.
     *  @param  toVersion_   The initial version.
     *  @param  fromVersion_ The destination version.
     *  @return allowed_     Whether the upgrade is enabled.
     */
    function upgradeEnabledForPath(uint256 toVersion_, uint256 fromVersion_) external view returns (bool allowed_);

    /**************************************************************************************************************************************/
    /*** State Changing Functions                                                                                                       ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev    Deploys a new instance proxying the default implementation version, with some initialization arguments.
     *          Uses a nonce and `msg.sender` as a salt for the CREATE2 opcode during instantiation to produce deterministic addresses.
     *  @param  arguments_ The initialization arguments to use for the instance deployment, if any.
     *  @param  salt_      The salt to use in the contract creation process.
     *  @return instance_  The address of the deployed proxy contract.
     */
    function createInstance(bytes calldata arguments_, bytes32 salt_) external returns (address instance_);

    /**
     *  @dev   Enables upgrading from a version to a version of an implementation, with an optional migrator.
     *         Only the Governor can call this function.
     *  @param fromVersion_ The starting version of the upgrade path.
     *  @param toVersion_   The destination version of the upgrade path.
     *  @param migrator_    The address of the migrator, if any.
     */
    function enableUpgradePath(uint256 fromVersion_, uint256 toVersion_, address migrator_) external;

    /**
     *  @dev   Disables upgrading from a version to a version of a implementation.
     *         Only the Governor can call this function.
     *  @param fromVersion_ The starting version of the upgrade path.
     *  @param toVersion_   The destination version of the upgrade path.
     */
    function disableUpgradePath(uint256 fromVersion_, uint256 toVersion_) external;

    /**
     *  @dev   Registers the address of an implementation contract as a version, with an optional initializer.
     *         Only the Governor can call this function.
     *  @param version_               The version to register.
     *  @param implementationAddress_ The address of the implementation.
     *  @param initializer_           The address of the initializer, if any.
     */
    function registerImplementation(uint256 version_, address implementationAddress_, address initializer_) external;

    /**
     *  @dev   Sets the default version.
     *         Only the Governor can call this function.
     *  @param version_ The implementation version to set as the default.
     */
    function setDefaultVersion(uint256 version_) external;

    /**
     *  @dev   Sets the Maple Globals contract.
     *         Only the Governor can call this function.
     *  @param mapleGlobals_ The address of a Maple Globals contract.
     */
    function setGlobals(address mapleGlobals_) external;

    /**
     *  @dev   Upgrades the calling proxy contract's implementation, with some migration arguments.
     *  @param toVersion_ The implementation version to upgrade the proxy contract to.
     *  @param arguments_ The migration arguments, if any.
     */
    function upgradeInstance(uint256 toVersion_, bytes calldata arguments_) external;

    /**************************************************************************************************************************************/
    /*** View Functions                                                                                                                 ***/
    /**************************************************************************************************************************************/

    /**
     *  @dev    Returns the deterministic address of a potential proxy, given some arguments and salt.
     *  @param  arguments_       The initialization arguments to be used when deploying the proxy.
     *  @param  salt_            The salt to be used when deploying the proxy.
     *  @return instanceAddress_ The deterministic address of a potential proxy.
     */
    function getInstanceAddress(bytes calldata arguments_, bytes32 salt_) external view returns (address instanceAddress_);

    /**
     *  @dev    Returns the address of an implementation version.
     *  @param  version_        The implementation version.
     *  @return implementation_ The address of the implementation.
     */
    function implementationOf(uint256 version_) external view returns (address implementation_);

    /**
     *  @dev    Returns if a given address has been deployed by this factory/
     *  @param  instance_   The address to check.
     *  @return isInstance_ A boolean indication if the address has been deployed by this factory.
     */
    function isInstance(address instance_) external view returns (bool isInstance_);

    /**
     *  @dev    Returns the address of a migrator contract for a migration path (from version, to version).
     *          If oldVersion_ == newVersion_, the migrator is an initializer.
     *  @param  oldVersion_ The old version.
     *  @param  newVersion_ The new version.
     *  @return migrator_   The address of a migrator contract.
     */
    function migratorForPath(uint256 oldVersion_, uint256 newVersion_) external view returns (address migrator_);

    /**
     *  @dev    Returns the version of an implementation contract.
     *  @param  implementation_ The address of an implementation contract.
     *  @return version_        The version of the implementation contract.
     */
    function versionOf(address implementation_) external view returns (uint256 version_);

}

modules/pool/modules/maple-proxy-factory/modules/proxy-factory/contracts/ProxiedInternals.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.7;

import { SlotManipulatable } from "./SlotManipulatable.sol";

/// @title An implementation that is to be proxied, will need ProxiedInternals.
abstract contract ProxiedInternals is SlotManipulatable {

    /// @dev Storage slot with the address of the current factory. `keccak256('eip1967.proxy.factory') - 1`.
    bytes32 private constant FACTORY_SLOT = bytes32(0x7a45a402e4cb6e08ebc196f20f66d5d30e67285a2a8aa80503fa409e727a4af1);

    /// @dev Storage slot with the address of the current factory. `keccak256('eip1967.proxy.implementation') - 1`.
    bytes32 private constant IMPLEMENTATION_SLOT = bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);

    /// @dev Delegatecalls to a migrator contract to manipulate storage during an initialization or migration.
    function _migrate(address migrator_, bytes calldata arguments_) internal virtual returns (bool success_) {
        uint256 size;

        assembly {
            size := extcodesize(migrator_)
        }

        if (size == uint256(0)) return false;

        ( success_, ) = migrator_.delegatecall(arguments_);
    }

    /// @dev Sets the factory address in storage.
    function _setFactory(address factory_) internal virtual returns (bool success_) {
        _setSlotValue(FACTORY_SLOT, bytes32(uint256(uint160(factory_))));
        return true;
    }

    /// @dev Sets the implementation address in storage.
    function _setImplementation(address implementation_) internal virtual returns (bool success_) {
        _setSlotValue(IMPLEMENTATION_SLOT, bytes32(uint256(uint160(implementation_))));
        return true;
    }

    /// @dev Returns the factory address.
    function _factory() internal view virtual returns (address factory_) {
        return address(uint160(uint256(_getSlotValue(FACTORY_SLOT))));
    }

    /// @dev Returns the implementation address.
    function _implementation() internal view virtual returns (address implementation_) {
        return address(uint160(uint256(_getSlotValue(IMPLEMENTATION_SLOT))));
    }

}

modules/pool/modules/maple-proxy-factory/modules/proxy-factory/contracts/SlotManipulatable.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.7;

abstract contract SlotManipulatable {

    function _getReferenceTypeSlot(bytes32 slot_, bytes32 key_) internal pure returns (bytes32 value_) {
        return keccak256(abi.encodePacked(key_, slot_));
    }

    function _getSlotValue(bytes32 slot_) internal view returns (bytes32 value_) {
        assembly {
            value_ := sload(slot_)
        }
    }

    function _setSlotValue(bytes32 slot_, bytes32 value_) internal {
        assembly {
            sstore(slot_, value_)
        }
    }

}

modules/pool/modules/maple-proxy-factory/modules/proxy-factory/contracts/interfaces/IDefaultImplementationBeacon.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.7;

/// @title An beacon that provides a default implementation for proxies, must implement IDefaultImplementationBeacon.
interface IDefaultImplementationBeacon {

    /// @dev The address of an implementation for proxies.
    function defaultImplementation() external view returns (address defaultImplementation_);

}

modules/pool/modules/maple-proxy-factory/modules/proxy-factory/contracts/interfaces/IProxied.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.7;

/// @title An implementation that is to be proxied, must implement IProxied.
interface IProxied {

    /**
     *  @dev The address of the proxy factory.
     */
    function factory() external view returns (address factory_);

    /**
     *  @dev The address of the implementation contract being proxied.
     */
    function implementation() external view returns (address implementation_);

    /**
     *  @dev   Modifies the proxy's implementation address.
     *  @param newImplementation_ The address of an implementation contract.
     */
    function setImplementation(address newImplementation_) external;

    /**
     *  @dev   Modifies the proxy's storage by delegate-calling a migrator contract with some arguments.
     *         Access control logic critical since caller can force a selfdestruct via a malicious `migrator_` which is delegatecalled.
     *  @param migrator_  The address of a migrator contract.
     *  @param arguments_ Some encoded arguments to use for the migration.
     */
    function migrate(address migrator_, bytes calldata arguments_) external;

}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "modules/syrup-utils/modules/lite-psm/lib/dss-test/lib/forge-std/:ds-test/=modules/syrup-utils/modules/lite-psm/lib/dss-test/lib/forge-std/lib/ds-test/src/",
    "modules/syrup-utils/modules/lite-psm/lib/dss-test/lib/forge-std/:ds-test/=modules/syrup-utils/modules/lite-psm/lib/dss-test/lib/forge-std/lib/ds-test/src/",
    "modules/syrup-utils/modules/globals-v2/modules/forge-std/:ds-test/=modules/syrup-utils/modules/globals-v2/modules/forge-std/lib/ds-test/src/",
    "modules/syrup-utils/modules/globals-v2/modules/forge-std/:ds-test/=modules/syrup-utils/modules/globals-v2/modules/forge-std/lib/ds-test/src/",
    "modules/syrup-utils/modules/lite-psm/lib/dss-test/:forge-std/=modules/syrup-utils/modules/lite-psm/lib/dss-test/lib/forge-std/src/",
    "modules/syrup-utils/modules/lite-psm/lib/dss-test/:forge-std/=modules/syrup-utils/modules/lite-psm/lib/dss-test/lib/forge-std/src/",
    "modules/syrup-utils/modules/mpl-migration/modules/erc20-helper/:contract-test-utils/=modules/syrup-utils/modules/mpl-migration/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/syrup-utils/modules/mpl-migration/modules/erc20-helper/:contract-test-utils/=modules/syrup-utils/modules/mpl-migration/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/syrup-utils/modules/mpl-v2/modules/forge-std/:ds-test/=modules/syrup-utils/modules/mpl-v2/modules/forge-std/lib/ds-test/src/",
    "modules/syrup-utils/modules/mpl-v2/modules/forge-std/:ds-test/=modules/syrup-utils/modules/mpl-v2/modules/forge-std/lib/ds-test/src/",
    "modules/syrup-utils/modules/open-zeppelin/lib/forge-std/:ds-test/=modules/syrup-utils/modules/open-zeppelin/lib/forge-std/lib/ds-test/src/",
    "modules/syrup-utils/modules/open-zeppelin/lib/forge-std/:ds-test/=modules/syrup-utils/modules/open-zeppelin/lib/forge-std/lib/ds-test/src/",
    "modules/allocation-strategy/modules/erc20-helper/:contract-test-utils/=modules/allocation-strategy/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/allocation-strategy/modules/erc20-helper/:contract-test-utils/=modules/allocation-strategy/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/defi-strategies/modules/erc20-helper/:contract-test-utils/=modules/defi-strategies/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/defi-strategies/modules/erc20-helper/:contract-test-utils/=modules/defi-strategies/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/globals/modules/forge-std/:ds-test/=modules/globals/modules/forge-std/lib/ds-test/src/",
    "modules/globals/modules/forge-std/:ds-test/=modules/globals/modules/forge-std/lib/ds-test/src/",
    "modules/open-term-loan-manager/modules/forge-std/:ds-test/=modules/open-term-loan-manager/modules/forge-std/lib/ds-test/src/",
    "modules/open-term-loan-manager/modules/forge-std/:ds-test/=modules/open-term-loan-manager/modules/forge-std/lib/ds-test/src/",
    "modules/open-term-loan/modules/forge-std/:ds-test/=modules/open-term-loan/modules/forge-std/lib/ds-test/src/",
    "modules/open-term-loan/modules/forge-std/:ds-test/=modules/open-term-loan/modules/forge-std/lib/ds-test/src/",
    "modules/pool-permission-manager/modules/forge-std/:ds-test/=modules/pool-permission-manager/modules/forge-std/lib/ds-test/src/",
    "modules/pool-permission-manager/modules/forge-std/:ds-test/=modules/pool-permission-manager/modules/forge-std/lib/ds-test/src/",
    "modules/pool/modules/forge-std/:ds-test/=modules/pool/modules/forge-std/lib/ds-test/src/",
    "modules/pool/modules/forge-std/:ds-test/=modules/pool/modules/forge-std/lib/ds-test/src/",
    "modules/strategy-manager/modules/erc20-helper/:contract-test-utils/=modules/strategy-manager/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/strategy-manager/modules/erc20-helper/:contract-test-utils/=modules/strategy-manager/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/syrup-utils/modules/erc20-helper/:contract-test-utils/=modules/syrup-utils/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/syrup-utils/modules/erc20-helper/:contract-test-utils/=modules/syrup-utils/modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/syrup-utils/modules/open-zeppelin/:forge-std/=modules/syrup-utils/modules/open-zeppelin/lib/forge-std/src/",
    "modules/syrup-utils/modules/open-zeppelin/:forge-std/=modules/syrup-utils/modules/open-zeppelin/lib/forge-std/src/",
    "modules/withdrawal-manager-cyclical/modules/forge-std/:ds-test/=modules/withdrawal-manager-cyclical/modules/forge-std/lib/ds-test/src/",
    "modules/withdrawal-manager-cyclical/modules/forge-std/:ds-test/=modules/withdrawal-manager-cyclical/modules/forge-std/lib/ds-test/src/",
    "modules/withdrawal-manager-queue/modules/forge-std/:ds-test/=modules/withdrawal-manager-queue/modules/forge-std/lib/ds-test/src/",
    "modules/withdrawal-manager-queue/modules/forge-std/:ds-test/=modules/withdrawal-manager-queue/modules/forge-std/lib/ds-test/src/",
    "modules/erc20-helper/:contract-test-utils/=modules/erc20-helper/lib/contract-test-utils/contracts/",
    "modules/erc20-helper/:contract-test-utils/=modules/erc20-helper/lib/contract-test-utils/contracts/",
    "@openzeppelin/contracts/=modules/syrup-utils/modules/open-zeppelin/contracts/",
    "address-registry/=modules/address-registry/contracts/",
    "allocation-strategy/=modules/allocation-strategy/",
    "contract-test-utils/=modules/erc20-helper/lib/contract-test-utils/contracts/",
    "defi-strategies/=modules/defi-strategies/",
    "ds-test/=modules/globals/modules/forge-std/lib/ds-test/src/",
    "dss-interfaces/=modules/syrup-utils/modules/lite-psm/lib/dss-test/lib/dss-interfaces/src/",
    "dss-test/=modules/syrup-utils/modules/lite-psm/lib/dss-test/src/",
    "erc20-helper/=modules/erc20-helper/src/",
    "erc20/=modules/erc20/",
    "erc4626-tests/=modules/syrup-utils/modules/open-zeppelin/lib/erc4626-tests/",
    "forge-std/=modules/forge-std/src/",
    "strategy-manager/=modules/strategy-manager/",
    "syrup-utils/=modules/syrup-utils/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.