{"sources":{"MaplePool.sol":{"content":"// SPDX-License-Identifier: BUSL-1.1\r\npragma solidity =0.8.7 ^0.8.7;\r\n\r\n// contracts/interfaces/Interfaces.sol\r\n\r\ninterface IERC20Like_0 {\r\n\r\n    function allowance(address owner_, address spender_) external view returns (uint256 allowance_);\r\n\r\n    function balanceOf(address account_) external view returns (uint256 balance_);\r\n\r\n    function totalSupply() external view returns (uint256 totalSupply_);\r\n\r\n}\r\n\r\ninterface IGlobalsLike {\r\n\r\n    function bootstrapMint(address asset_) external view returns (uint256 bootstrapMint_);\r\n\r\n    function governor() external view returns (address governor_);\r\n\r\n    function isFunctionPaused(bytes4 sig_) external view returns (bool isFunctionPaused_);\r\n\r\n    function isInstanceOf(bytes32 instanceId_, address instance_) external view returns (bool isInstance_);\r\n\r\n    function isPoolAsset(address asset_) external view returns (bool isPoolAsset_);\r\n\r\n    function isPoolDelegate(address account_) external view returns (bool isPoolDelegate_);\r\n\r\n    function isPoolDeployer(address poolDeployer_) external view returns (bool isPoolDeployer_);\r\n\r\n    function isValidScheduledCall(address caller_, address contract_, bytes32 functionId_, bytes calldata callData_)\r\n        external view\r\n        returns (bool isValid_);\r\n\r\n    function mapleTreasury() external view returns (address mapleTreasury_);\r\n\r\n    function maxCoverLiquidationPercent(address poolManager_) external view returns (uint256 maxCoverLiquidationPercent_);\r\n\r\n    function migrationAdmin() external view returns (address migrationAdmin_);\r\n\r\n    function minCoverAmount(address poolManager_) external view returns (uint256 minCoverAmount_);\r\n\r\n    function operationalAdmin() external view returns (address operationalAdmin_);\r\n\r\n    function ownedPoolManager(address poolDelegate_) external view returns (address poolManager_);\r\n\r\n    function securityAdmin() external view returns (address securityAdmin_);\r\n\r\n    function transferOwnedPoolManager(address fromPoolDelegate_, address toPoolDelegate_) external;\r\n\r\n    function unscheduleCall(address caller_, bytes32 functionId_, bytes calldata callData_) external;\r\n\r\n}\r\n\r\ninterface ILoanManagerLike {\r\n\r\n    function assetsUnderManagement() external view returns (uint256 assetsUnderManagement_);\r\n\r\n    function finishCollateralLiquidation(address loan_) external returns (uint256 remainingLosses_, uint256 serviceFee_);\r\n\r\n    function triggerDefault(address loan_, address liquidatorFactory_)\r\n        external\r\n        returns (bool liquidationComplete_, uint256 remainingLosses_, uint256 platformFees_);\r\n\r\n    function unrealizedLosses() external view returns (uint256 unrealizedLosses_);\r\n\r\n}\r\n\r\ninterface ILoanLike {\r\n\r\n    function lender() external view returns (address lender_);\r\n\r\n}\r\n\r\ninterface IMapleProxyFactoryLike {\r\n\r\n    function isInstance(address instance_) external view returns (bool isInstance_);\r\n\r\n    function mapleGlobals() external view returns (address mapleGlobals_);\r\n\r\n}\r\n\r\ninterface IPoolDelegateCoverLike {\r\n\r\n    function moveFunds(uint256 amount_, address recipient_) external;\r\n\r\n}\r\n\r\ninterface IPoolLike is IERC20Like_0 {\r\n\r\n    function convertToExitShares(uint256 assets_) external view returns (uint256 shares_);\r\n\r\n    function previewDeposit(uint256 assets_) external view returns (uint256 shares_);\r\n\r\n    function previewMint(uint256 shares_) external view returns (uint256 assets_);\r\n\r\n}\r\n\r\ninterface IPoolManagerLike {\r\n\r\n    function addLoanManager(address loanManagerFactory_) external returns (address loanManager_);\r\n\r\n    function canCall(bytes32 functionId_, address caller_, bytes memory data_)\r\n        external view\r\n        returns (bool canCall_, string memory errorMessage_);\r\n\r\n    function completeConfiguration() external;\r\n\r\n    function getEscrowParams(address owner_, uint256 shares_) external view returns (uint256 escrowShares_, address escrow_);\r\n\r\n    function maxDeposit(address receiver_) external view returns (uint256 maxAssets_);\r\n\r\n    function maxMint(address receiver_) external view returns (uint256 maxShares_);\r\n\r\n    function maxRedeem(address owner_) external view returns (uint256 maxShares_);\r\n\r\n    function maxWithdraw(address owner_) external view returns (uint256 maxAssets_);\r\n\r\n    function pool() external view returns (address pool_);\r\n\r\n    function poolDelegateCover() external view returns (address poolDelegateCover_);\r\n\r\n    function previewRedeem(address owner_, uint256 shares_) external view returns (uint256 assets_);\r\n\r\n    function previewWithdraw(address owner_, uint256 assets_) external view returns (uint256 shares_);\r\n\r\n    function processRedeem(uint256 shares_, address owner_, address sender_)\r\n        external\r\n        returns (uint256 redeemableShares_, uint256 resultingAssets_);\r\n\r\n    function processWithdraw(uint256 assets_, address owner_, address sender_)\r\n        external\r\n        returns (uint256 redeemableShares_, uint256 resultingAssets_);\r\n\r\n    function removeShares(uint256 shares_, address owner_) external returns (uint256 sharesReturned_);\r\n\r\n    function requestRedeem(uint256 shares_, address owner_, address sender_) external;\r\n\r\n    function requestWithdraw(uint256 shares_, uint256 assets_, address owner_, address sender_) external;\r\n\r\n    function setDelegateManagementFeeRate(uint256 delegateManagementFeeRate_) external;\r\n\r\n    function setLiquidityCap(uint256 liquidityCap_) external;\r\n\r\n    function setPoolPermissionManager(address poolPermissionManager_) external;\r\n\r\n    function setWithdrawalManager(address withdrawalManager_) external;\r\n\r\n    function totalAssets() external view returns (uint256 totalAssets_);\r\n\r\n    function unrealizedLosses() external view returns (uint256 unrealizedLosses_);\r\n\r\n}\r\n\r\ninterface IPoolPermissionManagerLike {\r\n\r\n    function hasPermission(address poolManager, address caller, bytes32 functionId) external view returns (bool allowed);\r\n\r\n    function hasPermission(address poolManager, address[] calldata caller, bytes32 functionId) external view returns (bool allowed);\r\n\r\n}\r\n\r\ninterface IWithdrawalManagerLike {\r\n\r\n    function addShares(uint256 shares_, address owner_) external;\r\n\r\n    function factory() external view returns (address factory_);\r\n\r\n    function isInExitWindow(address owner_) external view returns (bool isInExitWindow_);\r\n\r\n    function lockedLiquidity() external view returns (uint256 lockedLiquidity_);\r\n\r\n    function lockedShares(address owner_) external view returns (uint256 lockedShares_);\r\n\r\n    function previewRedeem(address owner_, uint256 shares) external view returns (uint256 redeemableShares, uint256 resultingAssets_);\r\n\r\n    function previewWithdraw(address owner_, uint256 assets_) external view returns (uint256 redeemableAssets_, uint256 resultingShares_);\r\n\r\n    function processExit(uint256 shares_, address account_) external returns (uint256 redeemableShares_, uint256 resultingAssets_);\r\n\r\n    function removeShares(uint256 shares_, address owner_) external returns (uint256 sharesReturned_);\r\n\r\n}\r\n\r\n// modules/erc20/contracts/interfaces/IERC20.sol\r\n\r\n/// @title Interface of the ERC20 standard as defined in the EIP, including EIP-2612 permit functionality.\r\ninterface IERC20 {\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Events                                                                                                                         ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev   Emitted when one account has set the allowance of another account over their tokens.\r\n     *  @param owner_   Account that tokens are approved from.\r\n     *  @param spender_ Account that tokens are approved for.\r\n     *  @param amount_  Amount of tokens that have been approved.\r\n     */\r\n    event Approval(address indexed owner_, address indexed spender_, uint256 amount_);\r\n\r\n    /**\r\n     *  @dev   Emitted when tokens have moved from one account to another.\r\n     *  @param owner_     Account that tokens have moved from.\r\n     *  @param recipient_ Account that tokens have moved to.\r\n     *  @param amount_    Amount of tokens that have been transferred.\r\n     */\r\n    event Transfer(address indexed owner_, address indexed recipient_, uint256 amount_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** External Functions                                                                                                             ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    Function that allows one account to set the allowance of another account over their tokens.\r\n     *          Emits an {Approval} event.\r\n     *  @param  spender_ Account that tokens are approved for.\r\n     *  @param  amount_  Amount of tokens that have been approved.\r\n     *  @return success_ Boolean indicating whether the operation succeeded.\r\n     */\r\n    function approve(address spender_, uint256 amount_) external returns (bool success_);\r\n\r\n    /**\r\n     *  @dev    Function that allows one account to decrease the allowance of another account over their tokens.\r\n     *          Emits an {Approval} event.\r\n     *  @param  spender_          Account that tokens are approved for.\r\n     *  @param  subtractedAmount_ Amount to decrease approval by.\r\n     *  @return success_          Boolean indicating whether the operation succeeded.\r\n     */\r\n    function decreaseAllowance(address spender_, uint256 subtractedAmount_) external returns (bool success_);\r\n\r\n    /**\r\n     *  @dev    Function that allows one account to increase the allowance of another account over their tokens.\r\n     *          Emits an {Approval} event.\r\n     *  @param  spender_     Account that tokens are approved for.\r\n     *  @param  addedAmount_ Amount to increase approval by.\r\n     *  @return success_     Boolean indicating whether the operation succeeded.\r\n     */\r\n    function increaseAllowance(address spender_, uint256 addedAmount_) external returns (bool success_);\r\n\r\n    /**\r\n     *  @dev   Approve by signature.\r\n     *  @param owner_    Owner address that signed the permit.\r\n     *  @param spender_  Spender of the permit.\r\n     *  @param amount_   Permit approval spend limit.\r\n     *  @param deadline_ Deadline after which the permit is invalid.\r\n     *  @param v_        ECDSA signature v component.\r\n     *  @param r_        ECDSA signature r component.\r\n     *  @param s_        ECDSA signature s component.\r\n     */\r\n    function permit(address owner_, address spender_, uint amount_, uint deadline_, uint8 v_, bytes32 r_, bytes32 s_) external;\r\n\r\n    /**\r\n     *  @dev    Moves an amount of tokens from `msg.sender` to a specified account.\r\n     *          Emits a {Transfer} event.\r\n     *  @param  recipient_ Account that receives tokens.\r\n     *  @param  amount_    Amount of tokens that are transferred.\r\n     *  @return success_   Boolean indicating whether the operation succeeded.\r\n     */\r\n    function transfer(address recipient_, uint256 amount_) external returns (bool success_);\r\n\r\n    /**\r\n     *  @dev    Moves a pre-approved amount of tokens from a sender to a specified account.\r\n     *          Emits a {Transfer} event.\r\n     *          Emits an {Approval} event.\r\n     *  @param  owner_     Account that tokens are moving from.\r\n     *  @param  recipient_ Account that receives tokens.\r\n     *  @param  amount_    Amount of tokens that are transferred.\r\n     *  @return success_   Boolean indicating whether the operation succeeded.\r\n     */\r\n    function transferFrom(address owner_, address recipient_, uint256 amount_) external returns (bool success_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** View Functions                                                                                                                 ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    Returns the allowance that one account has given another over their tokens.\r\n     *  @param  owner_     Account that tokens are approved from.\r\n     *  @param  spender_   Account that tokens are approved for.\r\n     *  @return allowance_ Allowance that one account has given another over their tokens.\r\n     */\r\n    function allowance(address owner_, address spender_) external view returns (uint256 allowance_);\r\n\r\n    /**\r\n     *  @dev    Returns the amount of tokens owned by a given account.\r\n     *  @param  account_ Account that owns the tokens.\r\n     *  @return balance_ Amount of tokens owned by a given account.\r\n     */\r\n    function balanceOf(address account_) external view returns (uint256 balance_);\r\n\r\n    /**\r\n     *  @dev    Returns the decimal precision used by the token.\r\n     *  @return decimals_ The decimal precision used by the token.\r\n     */\r\n    function decimals() external view returns (uint8 decimals_);\r\n\r\n    /**\r\n     *  @dev    Returns the signature domain separator.\r\n     *  @return domainSeparator_ The signature domain separator.\r\n     */\r\n    function DOMAIN_SEPARATOR() external view returns (bytes32 domainSeparator_);\r\n\r\n    /**\r\n     *  @dev    Returns the name of the token.\r\n     *  @return name_ The name of the token.\r\n     */\r\n    function name() external view returns (string memory name_);\r\n\r\n    /**\r\n      *  @dev    Returns the nonce for the given owner.\r\n      *  @param  owner_  The address of the owner account.\r\n      *  @return nonce_ The nonce for the given owner.\r\n     */\r\n    function nonces(address owner_) external view returns (uint256 nonce_);\r\n\r\n    /**\r\n     *  @dev    Returns the permit type hash.\r\n     *  @return permitTypehash_ The permit type hash.\r\n     */\r\n    function PERMIT_TYPEHASH() external view returns (bytes32 permitTypehash_);\r\n\r\n    /**\r\n     *  @dev    Returns the symbol of the token.\r\n     *  @return symbol_ The symbol of the token.\r\n     */\r\n    function symbol() external view returns (string memory symbol_);\r\n\r\n    /**\r\n     *  @dev    Returns the total amount of tokens in existence.\r\n     *  @return totalSupply_ The total amount of tokens in existence.\r\n     */\r\n    function totalSupply() external view returns (uint256 totalSupply_);\r\n\r\n}\r\n\r\n// modules/erc20-helper/src/interfaces/IERC20Like.sol\r\n\r\n/// @title Interface of the ERC20 standard as needed by ERC20Helper.\r\ninterface IERC20Like_1 {\r\n\r\n    function approve(address spender_, uint256 amount_) external returns (bool success_);\r\n\r\n    function transfer(address recipient_, uint256 amount_) external returns (bool success_);\r\n\r\n    function transferFrom(address owner_, address recipient_, uint256 amount_) external returns (bool success_);\r\n\r\n}\r\n\r\n// contracts/interfaces/IERC4626.sol\r\n\r\n/// @title A standard for tokenized Vaults with a single underlying ERC-20 token.\r\ninterface IERC4626 is IERC20 {\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Events                                                                                                                         ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev   `caller_` has exchanged `assets_` for `shares_` and transferred them to `owner_`.\r\n     *         MUST be emitted when assets are deposited via the `deposit` or `mint` methods.\r\n     *  @param caller_ The caller of the function that emitted the `Deposit` event.\r\n     *  @param owner_  The owner of the shares.\r\n     *  @param assets_ The amount of assets deposited.\r\n     *  @param shares_ The amount of shares minted.\r\n     */\r\n    event Deposit(address indexed caller_, address indexed owner_, uint256 assets_, uint256 shares_);\r\n\r\n    /**\r\n     *  @dev   `caller_` has exchanged `shares_`, owned by `owner_`, for `assets_`, and transferred them to `receiver_`.\r\n     *         MUST be emitted when assets are withdrawn via the `withdraw` or `redeem` methods.\r\n     *  @param caller_   The caller of the function that emitted the `Withdraw` event.\r\n     *  @param receiver_ The receiver of the assets.\r\n     *  @param owner_    The owner of the shares.\r\n     *  @param assets_   The amount of assets withdrawn.\r\n     *  @param shares_   The amount of shares burned.\r\n     */\r\n    event Withdraw(address indexed caller_, address indexed receiver_, address indexed owner_, uint256 assets_, uint256 shares_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** State Variables                                                                                                                ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    The address of the underlying asset used by the Vault.\r\n     *          MUST be a contract that implements the ERC-20 standard.\r\n     *          MUST NOT revert.\r\n     *  @return asset_ The address of the underlying asset.\r\n     */\r\n    function asset() external view returns (address asset_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** State Changing Functions                                                                                                       ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    Mints `shares_` to `receiver_` by depositing `assets_` into the Vault.\r\n     *          MUST emit the {Deposit} event.\r\n     *          MUST revert if all of the assets cannot be deposited (due to insufficient approval, deposit limits, slippage, etc).\r\n     *  @param  assets_   The amount of assets to deposit.\r\n     *  @param  receiver_ The receiver of the shares.\r\n     *  @return shares_   The amount of shares minted.\r\n     */\r\n    function deposit(uint256 assets_, address receiver_) external returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Mints `shares_` to `receiver_` by depositing `assets_` into the Vault.\r\n     *          MUST emit the {Deposit} event.\r\n     *          MUST revert if all of shares cannot be minted (due to insufficient approval, deposit limits, slippage, etc).\r\n     *  @param  shares_   The amount of shares to mint.\r\n     *  @param  receiver_ The receiver of the shares.\r\n     *  @return assets_   The amount of assets deposited.\r\n     */\r\n    function mint(uint256 shares_, address receiver_) external returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Burns `shares_` from `owner_` and sends `assets_` to `receiver_`.\r\n     *          MUST emit the {Withdraw} event.\r\n     *          MUST revert if all of the shares cannot be redeemed (due to insufficient shares, withdrawal limits, slippage, etc).\r\n     *  @param  shares_   The amount of shares to redeem.\r\n     *  @param  receiver_ The receiver of the assets.\r\n     *  @param  owner_    The owner of the shares.\r\n     *  @return assets_   The amount of assets sent to the receiver.\r\n     */\r\n    function redeem(uint256 shares_, address receiver_, address owner_) external returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Burns `shares_` from `owner_` and sends `assets_` to `receiver_`.\r\n     *          MUST emit the {Withdraw} event.\r\n     *          MUST revert if all of the assets cannot be withdrawn (due to insufficient assets, withdrawal limits, slippage, etc).\r\n     *  @param  assets_   The amount of assets to withdraw.\r\n     *  @param  receiver_ The receiver of the assets.\r\n     *  @param  owner_    The owner of the assets.\r\n     *  @return shares_   The amount of shares burned from the owner.\r\n     */\r\n    function withdraw(uint256 assets_, address receiver_, address owner_) external returns (uint256 shares_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** View Functions                                                                                                                 ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    The amount of `assets_` the `shares_` are currently equivalent to.\r\n     *          MUST NOT be inclusive of any fees that are charged against assets in the Vault.\r\n     *          MUST NOT reflect slippage or other on-chain conditions when performing the actual exchange.\r\n     *          MUST NOT show any variations depending on the caller.\r\n     *          MUST NOT revert.\r\n     *  @param  shares_ The amount of shares to convert.\r\n     *  @return assets_ The amount of equivalent assets.\r\n     */\r\n    function convertToAssets(uint256 shares_) external view returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    The amount of `shares_` the `assets_` are currently equivalent to.\r\n     *          MUST NOT be inclusive of any fees that are charged against assets in the Vault.\r\n     *          MUST NOT reflect slippage or other on-chain conditions when performing the actual exchange.\r\n     *          MUST NOT show any variations depending on the caller.\r\n     *          MUST NOT revert.\r\n     *  @param  assets_ The amount of assets to convert.\r\n     *  @return shares_ The amount of equivalent shares.\r\n     */\r\n    function convertToShares(uint256 assets_) external view returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Maximum amount of `assets_` that can be deposited on behalf of the `receiver_` through a `deposit` call.\r\n     *          MUST return a limited value if the receiver is subject to any limits, or the maximum value otherwise.\r\n     *          MUST NOT revert.\r\n     *  @param  receiver_ The receiver of the assets.\r\n     *  @return assets_   The maximum amount of assets that can be deposited.\r\n     */\r\n    function maxDeposit(address receiver_) external view returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Maximum amount of `shares_` that can be minted on behalf of the `receiver_` through a `mint` call.\r\n     *          MUST return a limited value if the receiver is subject to any limits, or the maximum value otherwise.\r\n     *          MUST NOT revert.\r\n     *  @param  receiver_ The receiver of the shares.\r\n     *  @return shares_   The maximum amount of shares that can be minted.\r\n     */\r\n    function maxMint(address receiver_) external view returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Maximum amount of `shares_` that can be redeemed from the `owner_` through a `redeem` call.\r\n     *          MUST return a limited value if the owner is subject to any limits, or the total amount of owned shares otherwise.\r\n     *          MUST NOT revert.\r\n     *  @param  owner_  The owner of the shares.\r\n     *  @return shares_ The maximum amount of shares that can be redeemed.\r\n     */\r\n    function maxRedeem(address owner_) external view returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Maximum amount of `assets_` that can be withdrawn from the `owner_` through a `withdraw` call.\r\n     *          MUST return a limited value if the owner is subject to any limits, or the total amount of owned assets otherwise.\r\n     *          MUST NOT revert.\r\n     *  @param  owner_  The owner of the assets.\r\n     *  @return assets_ The maximum amount of assets that can be withdrawn.\r\n     */\r\n    function maxWithdraw(address owner_) external view returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given current on-chain conditions.\r\n     *          MUST return as close to and no more than the exact amount of shares that would be minted in a `deposit` call in the same transaction.\r\n     *          MUST NOT account for deposit limits like those returned from `maxDeposit` and should always act as though the deposit would be accepted.\r\n     *  @param  assets_ The amount of assets to deposit.\r\n     *  @return shares_ The amount of shares that would be minted.\r\n     */\r\n    function previewDeposit(uint256 assets_) external view returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given current on-chain conditions.\r\n     *          MUST return as close to and no fewer than the exact amount of assets that would be deposited in a `mint` call in the same transaction.\r\n     *          MUST NOT account for mint limits like those returned from `maxMint` and should always act as though the minting would be accepted.\r\n     *  @param  shares_ The amount of shares to mint.\r\n     *  @return assets_ The amount of assets that would be deposited.\r\n     */\r\n    function previewMint(uint256 shares_) external view returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Allows an on-chain or off-chain user to simulate the effects of their redemption at the current block, given current on-chain conditions.\r\n     *          MUST return as close to and no more than the exact amount of assets that would be withdrawn in a `redeem` call in the same transaction.\r\n     *          MUST NOT account for redemption limits like those returned from `maxRedeem` and should always act as though the redemption would be accepted.\r\n     *  @param  shares_ The amount of shares to redeem.\r\n     *  @return assets_ The amount of assets that would be withdrawn.\r\n     */\r\n    function previewRedeem(uint256 shares_) external view returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, given current on-chain conditions.\r\n     *          MUST return as close to and no fewer than the exact amount of shares that would be burned in a `withdraw` call in the same transaction.\r\n     *          MUST NOT account for withdrawal limits like those returned from `maxWithdraw` and should always act as though the withdrawal would be accepted.\r\n     *  @param  assets_ The amount of assets to withdraw.\r\n     *  @return shares_ The amount of shares that would be redeemed.\r\n     */\r\n    function previewWithdraw(uint256 assets_) external view returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Total amount of the underlying asset that is managed by the Vault.\r\n     *          SHOULD include compounding that occurs from any yields.\r\n     *          MUST NOT revert.\r\n     *  @return totalAssets_ The total amount of assets the Vault manages.\r\n     */\r\n    function totalAssets() external view returns (uint256 totalAssets_);\r\n\r\n}\r\n\r\n// modules/erc20/contracts/ERC20.sol\r\n\r\n/*\r\n    ███████╗██████╗  ██████╗    ██████╗  ██████╗\r\n    ██╔════╝██╔══██╗██╔════╝    ╚════██╗██╔═████╗\r\n    █████╗  ██████╔╝██║          █████╔╝██║██╔██║\r\n    ██╔══╝  ██╔══██╗██║         ██╔═══╝ ████╔╝██║\r\n    ███████╗██║  ██║╚██████╗    ███████╗╚██████╔╝\r\n    ╚══════╝╚═╝  ╚═╝ ╚═════╝    ╚══════╝ ╚═════╝\r\n*/\r\n\r\n/**\r\n *  @title Modern ERC-20 implementation.\r\n *  @dev   Acknowledgements to Solmate, OpenZeppelin, and DSS for inspiring this code.\r\n */\r\ncontract ERC20 is IERC20 {\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** ERC-20                                                                                                                         ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    string public override name;\r\n    string public override symbol;\r\n\r\n    uint8 public immutable override decimals;\r\n\r\n    uint256 public override totalSupply;\r\n\r\n    mapping(address => uint256) public override balanceOf;\r\n\r\n    mapping(address => mapping(address => uint256)) public override allowance;\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** ERC-2612                                                                                                                       ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    // PERMIT_TYPEHASH = keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\r\n    bytes32 public constant override PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;\r\n\r\n    mapping(address => uint256) public override nonces;\r\n\r\n    /**\r\n     *  @param name_     The name of the token.\r\n     *  @param symbol_   The symbol of the token.\r\n     *  @param decimals_ The decimal precision used by the token.\r\n     */\r\n    constructor(string memory name_, string memory symbol_, uint8 decimals_) {\r\n        name     = name_;\r\n        symbol   = symbol_;\r\n        decimals = decimals_;\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** External Functions                                                                                                             ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function approve(address spender_, uint256 amount_) public virtual override returns (bool success_) {\r\n        _approve(msg.sender, spender_, amount_);\r\n        return true;\r\n    }\r\n\r\n    function decreaseAllowance(address spender_, uint256 subtractedAmount_) public virtual override returns (bool success_) {\r\n        _decreaseAllowance(msg.sender, spender_, subtractedAmount_);\r\n        return true;\r\n    }\r\n\r\n    function increaseAllowance(address spender_, uint256 addedAmount_) public virtual override returns (bool success_) {\r\n        _approve(msg.sender, spender_, allowance[msg.sender][spender_] + addedAmount_);\r\n        return true;\r\n    }\r\n\r\n    function permit(address owner_, address spender_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)\r\n        public virtual override\r\n    {\r\n        require(deadline_ >= block.timestamp, \"ERC20:P:EXPIRED\");\r\n\r\n        // Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\r\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}.\r\n        require(\r\n            uint256(s_) <= uint256(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) &&\r\n            (v_ == 27 || v_ == 28),\r\n            \"ERC20:P:MALLEABLE\"\r\n        );\r\n\r\n        // Nonce realistically cannot overflow.\r\n        unchecked {\r\n            bytes32 digest_ = keccak256(\r\n                abi.encodePacked(\r\n                    \"\\x19\\x01\",\r\n                    DOMAIN_SEPARATOR(),\r\n                    keccak256(abi.encode(PERMIT_TYPEHASH, owner_, spender_, amount_, nonces[owner_]++, deadline_))\r\n                )\r\n            );\r\n\r\n            address recoveredAddress_ = ecrecover(digest_, v_, r_, s_);\r\n\r\n            require(recoveredAddress_ == owner_ && owner_ != address(0), \"ERC20:P:INVALID_SIGNATURE\");\r\n        }\r\n\r\n        _approve(owner_, spender_, amount_);\r\n    }\r\n\r\n    function transfer(address recipient_, uint256 amount_) public virtual override returns (bool success_) {\r\n        _transfer(msg.sender, recipient_, amount_);\r\n        return true;\r\n    }\r\n\r\n    function transferFrom(address owner_, address recipient_, uint256 amount_) public virtual override returns (bool success_) {\r\n        _decreaseAllowance(owner_, msg.sender, amount_);\r\n        _transfer(owner_, recipient_, amount_);\r\n        return true;\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** View Functions                                                                                                                 ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function DOMAIN_SEPARATOR() public view override returns (bytes32 domainSeparator_) {\r\n        return keccak256(\r\n            abi.encode(\r\n                keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\r\n                keccak256(bytes(name)),\r\n                keccak256(bytes(\"1\")),\r\n                block.chainid,\r\n                address(this)\r\n            )\r\n        );\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Internal Functions                                                                                                             ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function _approve(address owner_, address spender_, uint256 amount_) internal {\r\n        emit Approval(owner_, spender_, allowance[owner_][spender_] = amount_);\r\n    }\r\n\r\n    function _burn(address owner_, uint256 amount_) internal {\r\n        balanceOf[owner_] -= amount_;\r\n\r\n        // Cannot underflow because a user's balance will never be larger than the total supply.\r\n        unchecked { totalSupply -= amount_; }\r\n\r\n        emit Transfer(owner_, address(0), amount_);\r\n    }\r\n\r\n    function _decreaseAllowance(address owner_, address spender_, uint256 subtractedAmount_) internal {\r\n        uint256 spenderAllowance = allowance[owner_][spender_];  // Cache to memory.\r\n\r\n        if (spenderAllowance != type(uint256).max) {\r\n            _approve(owner_, spender_, spenderAllowance - subtractedAmount_);\r\n        }\r\n    }\r\n\r\n    function _mint(address recipient_, uint256 amount_) internal {\r\n        totalSupply += amount_;\r\n\r\n        // Cannot overflow because totalSupply would first overflow in the statement above.\r\n        unchecked { balanceOf[recipient_] += amount_; }\r\n\r\n        emit Transfer(address(0), recipient_, amount_);\r\n    }\r\n\r\n    function _transfer(address owner_, address recipient_, uint256 amount_) internal {\r\n        balanceOf[owner_] -= amount_;\r\n\r\n        // Cannot overflow because minting prevents overflow of totalSupply, and sum of user balances == totalSupply.\r\n        unchecked { balanceOf[recipient_] += amount_; }\r\n\r\n        emit Transfer(owner_, recipient_, amount_);\r\n    }\r\n\r\n}\r\n\r\n// modules/erc20-helper/src/ERC20Helper.sol\r\n\r\n/**\r\n * @title Small Library to standardize erc20 token interactions.\r\n */\r\nlibrary ERC20Helper {\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Internal Functions                                                                                                             ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function transfer(address token_, address to_, uint256 amount_) internal returns (bool success_) {\r\n        return _call(token_, abi.encodeWithSelector(IERC20Like_1.transfer.selector, to_, amount_));\r\n    }\r\n\r\n    function transferFrom(address token_, address from_, address to_, uint256 amount_) internal returns (bool success_) {\r\n        return _call(token_, abi.encodeWithSelector(IERC20Like_1.transferFrom.selector, from_, to_, amount_));\r\n    }\r\n\r\n    function approve(address token_, address spender_, uint256 amount_) internal returns (bool success_) {\r\n        // If setting approval to zero fails, return false.\r\n        if (!_call(token_, abi.encodeWithSelector(IERC20Like_1.approve.selector, spender_, uint256(0)))) return false;\r\n\r\n        // If `amount_` is zero, return true as the previous step already did this.\r\n        if (amount_ == uint256(0)) return true;\r\n\r\n        // Return the result of setting the approval to `amount_`.\r\n        return _call(token_, abi.encodeWithSelector(IERC20Like_1.approve.selector, spender_, amount_));\r\n    }\r\n\r\n    function _call(address token_, bytes memory data_) private returns (bool success_) {\r\n        if (token_.code.length == uint256(0)) return false;\r\n\r\n        bytes memory returnData;\r\n        ( success_, returnData ) = token_.call(data_);\r\n\r\n        return success_ && (returnData.length == uint256(0) || abi.decode(returnData, (bool)));\r\n    }\r\n\r\n}\r\n\r\n// contracts/interfaces/IMaplePool.sol\r\n\r\ninterface IMaplePool is IERC20, IERC4626 {\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Events                                                                                                                         ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev   Initial shares amount was minted to the zero address to prevent the first depositor frontrunning exploit.\r\n     *  @param caller_              The caller of the function that emitted the `BootstrapMintPerformed` event.\r\n     *  @param receiver_            The user that was minted the shares.\r\n     *  @param assets_              The amount of assets deposited.\r\n     *  @param shares_              The amount of shares that would have been minted to the user if it was not the first deposit.\r\n     *  @param bootStrapMintAmount_ The amount of shares that was minted to the zero address to protect the first depositor.\r\n     */\r\n    event BootstrapMintPerformed(\r\n        address indexed caller_,\r\n        address indexed receiver_,\r\n        uint256 assets_,\r\n        uint256 shares_,\r\n        uint256 bootStrapMintAmount_\r\n    );\r\n\r\n    /**\r\n     *  @dev   `newOwner_` has accepted the transferral of RDT ownership from `previousOwner_`.\r\n     *  @param previousOwner_ The previous RDT owner.\r\n     *  @param newOwner_      The new RDT owner.\r\n     */\r\n    event OwnershipAccepted(address indexed previousOwner_, address indexed newOwner_);\r\n\r\n    /**\r\n     *  @dev   `owner_` has set the new pending owner of RDT to `pendingOwner_`.\r\n     *  @param owner_        The current RDT owner.\r\n     *  @param pendingOwner_ The new pending RDT owner.\r\n     */\r\n    event PendingOwnerSet(address indexed owner_, address indexed pendingOwner_);\r\n\r\n    /**\r\n     *  @dev   A new redemption request has been made.\r\n     *  @param owner_          The owner of shares.\r\n     *  @param shares_         The amount of shares requested to redeem.\r\n     *  @param escrowedShares_ The amount of shares actually escrowed for this withdrawal request.\r\n     */\r\n    event RedemptionRequested(address indexed owner_, uint256 shares_, uint256 escrowedShares_);\r\n\r\n    /**\r\n     *  @dev   Shares have been removed.\r\n     *  @param owner_  The owner of shares.\r\n     *  @param shares_ The amount of shares requested to be removed.\r\n     */\r\n    event SharesRemoved(address indexed owner_, uint256 shares_);\r\n\r\n    /**\r\n     *  @dev   A new withdrawal request has been made.\r\n     *  @param owner_          The owner of shares.\r\n     *  @param assets_         The amount of assets requested to withdraw.\r\n     *  @param escrowedShares_ The amount of shares actually escrowed for this withdrawal request.\r\n     */\r\n    event WithdrawRequested(address indexed owner_, uint256 assets_, uint256 escrowedShares_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** State Variables                                                                                                                ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    The amount of shares that will be burned during the first deposit/mint.\r\n     *  @return bootstrapMint_ The amount of shares to be burned.\r\n     */\r\n    function BOOTSTRAP_MINT() external view returns (uint256 bootstrapMint_);\r\n\r\n    /**\r\n     *  @dev    The address of the account that is allowed to update the vesting schedule.\r\n     *  @return manager_ The address of the pool manager.\r\n     */\r\n    function manager() external view returns (address manager_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** LP Functions                                                                                                                   ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    Does a ERC4626 `deposit` with a ERC-2612 `permit`.\r\n     *  @param  assets_   The amount of `asset` to deposit.\r\n     *  @param  receiver_ The receiver of the shares.\r\n     *  @param  deadline_ The timestamp after which the `permit` signature is no longer valid.\r\n     *  @param  v_        ECDSA signature v component.\r\n     *  @param  r_        ECDSA signature r component.\r\n     *  @param  s_        ECDSA signature s component.\r\n     *  @return shares_   The amount of shares minted.\r\n     */\r\n    function depositWithPermit(uint256 assets_, address receiver_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)\r\n        external returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Does a ERC4626 `mint` with a ERC-2612 `permit`.\r\n     *  @param  shares_    The amount of `shares` to mint.\r\n     *  @param  receiver_  The receiver of the shares.\r\n     *  @param  maxAssets_ The maximum amount of assets that can be taken, as per the permit.\r\n     *  @param  deadline_  The timestamp after which the `permit` signature is no longer valid.\r\n     *  @param  v_         ECDSA signature v component.\r\n     *  @param  r_         ECDSA signature r component.\r\n     *  @param  s_         ECDSA signature s component.\r\n     *  @return assets_    The amount of shares deposited.\r\n     */\r\n    function mintWithPermit(uint256 shares_, address receiver_, uint256 maxAssets_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)\r\n        external returns (uint256 assets_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Withdrawal Request Functions                                                                                                   ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    Removes shares from the withdrawal mechanism, can only be called after the beginning of the withdrawal window has passed.\r\n     *  @param  shares_         The amount of shares to redeem.\r\n     *  @param  owner_          The owner of the shares.\r\n     *  @return sharesReturned_ The amount of shares withdrawn.\r\n     */\r\n    function removeShares(uint256 shares_, address owner_) external returns (uint256 sharesReturned_);\r\n\r\n    /**\r\n     *  @dev    Requests a redemption of shares from the pool.\r\n     *  @param  shares_       The amount of shares to redeem.\r\n     *  @param  owner_        The owner of the shares.\r\n     *  @return escrowShares_ The amount of shares sent to escrow.\r\n     */\r\n    function requestRedeem(uint256 shares_, address owner_) external returns (uint256 escrowShares_);\r\n\r\n    /**\r\n     *  @dev    Requests a withdrawal of assets from the pool.\r\n     *  @param  assets_       The amount of assets to withdraw.\r\n     *  @param  owner_        The owner of the shares.\r\n     *  @return escrowShares_ The amount of shares sent to escrow.\r\n     */\r\n    function requestWithdraw(uint256 assets_, address owner_) external returns (uint256 escrowShares_);\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** View Functions                                                                                                                 ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    /**\r\n     *  @dev    Returns the amount of underlying assets owned by the specified account.\r\n     *  @param  account_ Address of the account.\r\n     *  @return assets_  Amount of assets owned.\r\n     */\r\n    function balanceOfAssets(address account_) external view returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Returns the amount of exit assets for the input amount.\r\n     *  @param  shares_ The amount of shares to convert to assets.\r\n     *  @return assets_ Amount of assets able to be exited.\r\n     */\r\n    function convertToExitAssets(uint256 shares_) external view returns (uint256 assets_);\r\n\r\n    /**\r\n     *  @dev    Returns the amount of exit shares for the input amount.\r\n     *  @param  assets_ The amount of assets to convert to shares.\r\n     *  @return shares_ Amount of shares able to be exited.\r\n     */\r\n    function convertToExitShares(uint256 assets_) external view returns (uint256 shares_);\r\n\r\n    /**\r\n     *  @dev    Returns the amount unrealized losses.\r\n     *  @return unrealizedLosses_ Amount of unrealized losses.\r\n     */\r\n    function unrealizedLosses() external view returns (uint256 unrealizedLosses_);\r\n\r\n}\r\n\r\n// contracts/MaplePool.sol\r\n\r\n/*\r\n\r\n    ███╗   ███╗ █████╗ ██████╗ ██╗     ███████╗    ██████╗  ██████╗  ██████╗ ██╗\r\n    ████╗ ████║██╔══██╗██╔══██╗██║     ██╔════╝    ██╔══██╗██╔═══██╗██╔═══██╗██║\r\n    ██╔████╔██║███████║██████╔╝██║     █████╗      ██████╔╝██║   ██║██║   ██║██║\r\n    ██║╚██╔╝██║██╔══██║██╔═══╝ ██║     ██╔══╝      ██╔═══╝ ██║   ██║██║   ██║██║\r\n    ██║ ╚═╝ ██║██║  ██║██║     ███████╗███████╗    ██║     ╚██████╔╝╚██████╔╝███████╗\r\n    ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝     ╚══════╝╚══════╝    ╚═╝      ╚═════╝  ╚═════╝ ╚══════╝\r\n\r\n*/\r\n\r\ncontract MaplePool is IMaplePool, ERC20 {\r\n\r\n    uint256 public immutable override BOOTSTRAP_MINT;\r\n\r\n    address public override asset;    // Underlying ERC-20 asset handled by the ERC-4626 contract.\r\n    address public override manager;  // Address of the contract that manages administrative functionality.\r\n\r\n    uint256 private _locked = 1;  // Used when checking for reentrancy.\r\n\r\n    constructor(\r\n        address manager_,\r\n        address asset_,\r\n        address destination_,\r\n        uint256 bootstrapMint_,\r\n        uint256 initialSupply_,\r\n        string memory name_,\r\n        string memory symbol_\r\n    )\r\n        ERC20(name_, symbol_, ERC20(asset_).decimals())\r\n    {\r\n        require((manager = manager_) != address(0), \"P:C:ZERO_MANAGER\");\r\n        require((asset   = asset_)   != address(0), \"P:C:ZERO_ASSET\");\r\n\r\n        if (initialSupply_ != 0) {\r\n            _mint(destination_, initialSupply_);\r\n        }\r\n\r\n        BOOTSTRAP_MINT = bootstrapMint_;\r\n\r\n        require(ERC20Helper.approve(asset_, manager_, type(uint256).max), \"P:C:FAILED_APPROVE\");\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Modifiers                                                                                                                      ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    modifier checkCall(bytes32 functionId_) {\r\n        ( bool success_, string memory errorMessage_ ) = IPoolManagerLike(manager).canCall(functionId_, msg.sender, msg.data[4:]);\r\n\r\n        require(success_, errorMessage_);\r\n\r\n        _;\r\n    }\r\n\r\n    modifier nonReentrant() {\r\n        require(_locked == 1, \"P:LOCKED\");\r\n\r\n        _locked = 2;\r\n\r\n        _;\r\n\r\n        _locked = 1;\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** LP Functions                                                                                                                   ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function deposit(uint256 assets_, address receiver_) external override nonReentrant checkCall(\"P:deposit\") returns (uint256 shares_) {\r\n        _mint(shares_ = previewDeposit(assets_), assets_, receiver_, msg.sender);\r\n    }\r\n\r\n    function depositWithPermit(\r\n        uint256 assets_,\r\n        address receiver_,\r\n        uint256 deadline_,\r\n        uint8   v_,\r\n        bytes32 r_,\r\n        bytes32 s_\r\n    )\r\n        external override nonReentrant checkCall(\"P:depositWithPermit\") returns (uint256 shares_)\r\n    {\r\n        ERC20(asset).permit(msg.sender, address(this), assets_, deadline_, v_, r_, s_);\r\n        _mint(shares_ = previewDeposit(assets_), assets_, receiver_, msg.sender);\r\n    }\r\n\r\n    function mint(uint256 shares_, address receiver_) external override nonReentrant checkCall(\"P:mint\") returns (uint256 assets_) {\r\n        _mint(shares_, assets_ = previewMint(shares_), receiver_, msg.sender);\r\n    }\r\n\r\n    function mintWithPermit(\r\n        uint256 shares_,\r\n        address receiver_,\r\n        uint256 maxAssets_,\r\n        uint256 deadline_,\r\n        uint8   v_,\r\n        bytes32 r_,\r\n        bytes32 s_\r\n    )\r\n        external override nonReentrant checkCall(\"P:mintWithPermit\") returns (uint256 assets_)\r\n    {\r\n        require((assets_ = previewMint(shares_)) <= maxAssets_, \"P:MWP:INSUFFICIENT_PERMIT\");\r\n\r\n        ERC20(asset).permit(msg.sender, address(this), maxAssets_, deadline_, v_, r_, s_);\r\n        _mint(shares_, assets_, receiver_, msg.sender);\r\n    }\r\n\r\n    function redeem(uint256 shares_, address receiver_, address owner_)\r\n        external override nonReentrant checkCall(\"P:redeem\") returns (uint256 assets_)\r\n    {\r\n        uint256 redeemableShares_;\r\n        ( redeemableShares_, assets_ ) = IPoolManagerLike(manager).processRedeem(shares_, owner_, msg.sender);\r\n        _burn(redeemableShares_, assets_, receiver_, owner_, msg.sender);\r\n    }\r\n\r\n    function withdraw(uint256 assets_, address receiver_, address owner_)\r\n        external override nonReentrant checkCall(\"P:withdraw\") returns (uint256 shares_)\r\n    {\r\n        ( shares_, assets_ ) = IPoolManagerLike(manager).processWithdraw(assets_, owner_, msg.sender);\r\n        _burn(shares_, assets_, receiver_, owner_, msg.sender);\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** ERC-20 Overridden Functions                                                                                                    ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function transfer(\r\n        address recipient_,\r\n        uint256 amount_\r\n    )\r\n        public override(IERC20, ERC20) checkCall(\"P:transfer\") returns (bool success_)\r\n    {\r\n        success_ = super.transfer(recipient_, amount_);\r\n    }\r\n\r\n    function transferFrom(\r\n        address owner_,\r\n        address recipient_,\r\n        uint256 amount_\r\n    )\r\n        public override(IERC20, ERC20) checkCall(\"P:transferFrom\") returns (bool success_)\r\n    {\r\n        success_ = super.transferFrom(owner_, recipient_, amount_);\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Withdrawal Request Functions                                                                                                   ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function removeShares(uint256 shares_, address owner_)\r\n        external override nonReentrant checkCall(\"P:removeShares\") returns (uint256 sharesReturned_)\r\n    {\r\n        if (msg.sender != owner_) _decreaseAllowance(owner_, msg.sender, shares_);\r\n\r\n        emit SharesRemoved(\r\n            owner_,\r\n            sharesReturned_ = IPoolManagerLike(manager).removeShares(shares_, owner_)\r\n        );\r\n    }\r\n\r\n    function requestRedeem(uint256 shares_, address owner_)\r\n        external override nonReentrant checkCall(\"P:requestRedeem\") returns (uint256 escrowedShares_)\r\n    {\r\n        emit RedemptionRequested(\r\n            owner_,\r\n            shares_,\r\n            escrowedShares_ = _requestRedeem(shares_, owner_)\r\n        );\r\n    }\r\n\r\n    function requestWithdraw(uint256 assets_, address owner_)\r\n        external override nonReentrant checkCall(\"P:requestWithdraw\") returns (uint256 escrowedShares_)\r\n    {\r\n        emit WithdrawRequested(\r\n            owner_,\r\n            assets_,\r\n            escrowedShares_ = _requestWithdraw(assets_, owner_)\r\n        );\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Internal Functions                                                                                                             ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function _burn(uint256 shares_, uint256 assets_, address receiver_, address owner_, address caller_) internal {\r\n        require(receiver_ != address(0), \"P:B:ZERO_RECEIVER\");\r\n\r\n        if (shares_ == 0) return;\r\n\r\n        if (caller_ != owner_) {\r\n            _decreaseAllowance(owner_, caller_, shares_);\r\n        }\r\n\r\n        _burn(owner_, shares_);\r\n\r\n        emit Withdraw(caller_, receiver_, owner_, assets_, shares_);\r\n\r\n        require(ERC20Helper.transfer(asset, receiver_, assets_), \"P:B:TRANSFER\");\r\n    }\r\n\r\n    function _divRoundUp(uint256 numerator_, uint256 divisor_) internal pure returns (uint256 result_) {\r\n        result_ = (numerator_ + divisor_ - 1) / divisor_;\r\n    }\r\n\r\n    function _mint(uint256 shares_, uint256 assets_, address receiver_, address caller_) internal {\r\n        require(receiver_ != address(0), \"P:M:ZERO_RECEIVER\");\r\n        require(shares_   != uint256(0), \"P:M:ZERO_SHARES\");\r\n        require(assets_   != uint256(0), \"P:M:ZERO_ASSETS\");\r\n\r\n        if (totalSupply == 0 && BOOTSTRAP_MINT != 0) {\r\n            _mint(address(0), BOOTSTRAP_MINT);\r\n\r\n            emit BootstrapMintPerformed(caller_, receiver_, assets_, shares_, BOOTSTRAP_MINT);\r\n\r\n            shares_ -= BOOTSTRAP_MINT;\r\n        }\r\n\r\n        _mint(receiver_, shares_);\r\n\r\n        emit Deposit(caller_, receiver_, assets_, shares_);\r\n\r\n        require(ERC20Helper.transferFrom(asset, caller_, address(this), assets_), \"P:M:TRANSFER_FROM\");\r\n    }\r\n\r\n    function _requestRedeem(uint256 shares_, address owner_) internal returns (uint256 escrowShares_) {\r\n        address destination_;\r\n\r\n        ( escrowShares_, destination_ ) = IPoolManagerLike(manager).getEscrowParams(owner_, shares_);\r\n\r\n        if (msg.sender != owner_) {\r\n            _decreaseAllowance(owner_, msg.sender, escrowShares_);\r\n        }\r\n\r\n        if (escrowShares_ != 0 && destination_ != address(0)) {\r\n            _transfer(owner_, destination_, escrowShares_);\r\n        }\r\n\r\n        IPoolManagerLike(manager).requestRedeem(escrowShares_, owner_, msg.sender);\r\n    }\r\n\r\n    function _requestWithdraw(uint256 assets_, address owner_) internal returns (uint256 escrowShares_) {\r\n        address destination_;\r\n\r\n        ( escrowShares_, destination_ ) = IPoolManagerLike(manager).getEscrowParams(owner_, convertToExitShares(assets_));\r\n\r\n        if (msg.sender != owner_) {\r\n            _decreaseAllowance(owner_, msg.sender, escrowShares_);\r\n        }\r\n\r\n        if (escrowShares_ != 0 && destination_ != address(0)) {\r\n            _transfer(owner_, destination_, escrowShares_);\r\n        }\r\n\r\n        IPoolManagerLike(manager).requestWithdraw(escrowShares_, assets_, owner_, msg.sender);\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** External View Functions                                                                                                        ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function balanceOfAssets(address account_) external view override returns (uint256 balanceOfAssets_) {\r\n        balanceOfAssets_ = convertToAssets(balanceOf[account_]);\r\n    }\r\n\r\n    function maxDeposit(address receiver_) external view override returns (uint256 maxAssets_) {\r\n        maxAssets_ = IPoolManagerLike(manager).maxDeposit(receiver_);\r\n    }\r\n\r\n    function maxMint(address receiver_) external view override returns (uint256 maxShares_) {\r\n        maxShares_ = IPoolManagerLike(manager).maxMint(receiver_);\r\n    }\r\n\r\n    function maxRedeem(address owner_) external view override returns (uint256 maxShares_) {\r\n        maxShares_ = IPoolManagerLike(manager).maxRedeem(owner_);\r\n    }\r\n\r\n    function maxWithdraw(address owner_) external view override returns (uint256 maxAssets_) {\r\n        maxAssets_ = IPoolManagerLike(manager).maxWithdraw(owner_);\r\n    }\r\n\r\n    function previewRedeem(uint256 shares_) external view override returns (uint256 assets_) {\r\n        assets_ = IPoolManagerLike(manager).previewRedeem(msg.sender, shares_);\r\n    }\r\n\r\n    function previewWithdraw(uint256 assets_) external view override returns (uint256 shares_) {\r\n        shares_ = IPoolManagerLike(manager).previewWithdraw(msg.sender, assets_);\r\n    }\r\n\r\n    /**************************************************************************************************************************************/\r\n    /*** Public View Functions                                                                                                          ***/\r\n    /**************************************************************************************************************************************/\r\n\r\n    function convertToAssets(uint256 shares_) public view override returns (uint256 assets_) {\r\n        uint256 totalSupply_ = totalSupply;\r\n\r\n        assets_ = totalSupply_ == 0 ? shares_ : (shares_ * totalAssets()) / totalSupply_;\r\n    }\r\n\r\n    function convertToExitAssets(uint256 shares_) public view override returns (uint256 assets_) {\r\n        uint256 totalSupply_ = totalSupply;\r\n\r\n        assets_ = totalSupply_ == 0 ? shares_ : shares_ * (totalAssets() - unrealizedLosses()) / totalSupply_;\r\n    }\r\n\r\n    function convertToShares(uint256 assets_) public view override returns (uint256 shares_) {\r\n        uint256 totalSupply_ = totalSupply;\r\n\r\n        shares_ = totalSupply_ == 0 ? assets_ : (assets_ * totalSupply_) / totalAssets();\r\n    }\r\n\r\n    function convertToExitShares(uint256 amount_) public view override returns (uint256 shares_) {\r\n        shares_ = _divRoundUp(amount_ * totalSupply, totalAssets() - unrealizedLosses());\r\n    }\r\n\r\n    function previewDeposit(uint256 assets_) public view override returns (uint256 shares_) {\r\n        // As per https://eips.ethereum.org/EIPS/eip-4626#security-considerations,\r\n        // it should round DOWN if it’s calculating the amount of shares to issue to a user, given an amount of assets provided.\r\n        shares_ = convertToShares(assets_);\r\n    }\r\n\r\n    function previewMint(uint256 shares_) public view override returns (uint256 assets_) {\r\n        uint256 totalSupply_ = totalSupply;\r\n\r\n        // As per https://eips.ethereum.org/EIPS/eip-4626#security-considerations,\r\n        // it should round UP if it’s calculating the amount of assets a user must provide, to be issued a given amount of shares.\r\n        assets_ = totalSupply_ == 0 ? shares_ : _divRoundUp(shares_ * totalAssets(), totalSupply_);\r\n    }\r\n\r\n    function totalAssets() public view override returns (uint256 totalAssets_) {\r\n        totalAssets_ = IPoolManagerLike(manager).totalAssets();\r\n    }\r\n\r\n    function unrealizedLosses() public view override returns (uint256 unrealizedLosses_) {\r\n        unrealizedLosses_ = IPoolManagerLike(manager).unrealizedLosses();\r\n    }\r\n\r\n}"}},"matchId":"2807114","creationMatch":"match","runtimeMatch":"match","verifiedAt":"2024-08-08T16:35:01Z","match":"match","chainId":"1","address":"0x80ac24aA929eaF5013f6436cdA2a7ba190f5Cc0b"}