文件 1 的 8:ERC20.sol
pragma solidity ^0.8.7;
import { IERC20 } from "./interfaces/IERC20.sol";
contract ERC20 is IERC20 {
string public override name;
string public override symbol;
uint8 public immutable override decimals;
uint256 public override totalSupply;
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
bytes32 public constant override PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint256) public override nonces;
constructor(string memory name_, string memory symbol_, uint8 decimals_) {
name = name_;
symbol = symbol_;
decimals = decimals_;
}
function approve(address spender_, uint256 amount_) public virtual override returns (bool success_) {
_approve(msg.sender, spender_, amount_);
return true;
}
function decreaseAllowance(address spender_, uint256 subtractedAmount_) public virtual override returns (bool success_) {
_decreaseAllowance(msg.sender, spender_, subtractedAmount_);
return true;
}
function increaseAllowance(address spender_, uint256 addedAmount_) public virtual override returns (bool success_) {
_approve(msg.sender, spender_, allowance[msg.sender][spender_] + addedAmount_);
return true;
}
function permit(address owner_, address spender_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) public virtual override {
require(deadline_ >= block.timestamp, "ERC20:P:EXPIRED");
require(
uint256(s_) <= uint256(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) &&
(v_ == 27 || v_ == 28),
"ERC20:P:MALLEABLE"
);
unchecked {
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(abi.encode(PERMIT_TYPEHASH, owner_, spender_, amount_, nonces[owner_]++, deadline_))
)
);
address recoveredAddress = ecrecover(digest, v_, r_, s_);
require(recoveredAddress == owner_ && owner_ != address(0), "ERC20:P:INVALID_SIGNATURE");
}
_approve(owner_, spender_, amount_);
}
function transfer(address recipient_, uint256 amount_) public virtual override returns (bool success_) {
_transfer(msg.sender, recipient_, amount_);
return true;
}
function transferFrom(address owner_, address recipient_, uint256 amount_) public virtual override returns (bool success_) {
_decreaseAllowance(owner_, msg.sender, amount_);
_transfer(owner_, recipient_, amount_);
return true;
}
function DOMAIN_SEPARATOR() public view override returns (bytes32 domainSeparator_) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
block.chainid,
address(this)
)
);
}
function _approve(address owner_, address spender_, uint256 amount_) internal {
emit Approval(owner_, spender_, allowance[owner_][spender_] = amount_);
}
function _burn(address owner_, uint256 amount_) internal {
balanceOf[owner_] -= amount_;
unchecked { totalSupply -= amount_; }
emit Transfer(owner_, address(0), amount_);
}
function _decreaseAllowance(address owner_, address spender_, uint256 subtractedAmount_) internal {
uint256 spenderAllowance = allowance[owner_][spender_];
if (spenderAllowance != type(uint256).max) {
_approve(owner_, spender_, spenderAllowance - subtractedAmount_);
}
}
function _mint(address recipient_, uint256 amount_) internal {
totalSupply += amount_;
unchecked { balanceOf[recipient_] += amount_; }
emit Transfer(address(0), recipient_, amount_);
}
function _transfer(address owner_, address recipient_, uint256 amount_) internal {
balanceOf[owner_] -= amount_;
unchecked { balanceOf[recipient_] += amount_; }
emit Transfer(owner_, recipient_, amount_);
}
}
文件 2 的 8:ERC20Helper.sol
pragma solidity ^0.8.7;
import { IERC20Like } from "./interfaces/IERC20Like.sol";
library ERC20Helper {
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 (!_call(token_, abi.encodeWithSelector(IERC20Like.approve.selector, spender_, uint256(0)))) return false;
if (amount_ == uint256(0)) return true;
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)));
}
}
文件 3 的 8:IERC20.sol
pragma solidity ^0.8.7;
interface IERC20 {
event Approval(address indexed owner_, address indexed spender_, uint256 amount_);
event Transfer(address indexed owner_, address indexed recipient_, uint256 amount_);
function approve(address spender_, uint256 amount_) external returns (bool success_);
function decreaseAllowance(address spender_, uint256 subtractedAmount_) external returns (bool success_);
function increaseAllowance(address spender_, uint256 addedAmount_) external returns (bool success_);
function permit(address owner_, address spender_, uint amount_, uint deadline_, uint8 v_, bytes32 r_, bytes32 s_) external;
function transfer(address recipient_, uint256 amount_) external returns (bool success_);
function transferFrom(address owner_, address recipient_, uint256 amount_) external returns (bool success_);
function allowance(address owner_, address spender_) external view returns (uint256 allowance_);
function balanceOf(address account_) external view returns (uint256 balance_);
function decimals() external view returns (uint8 decimals_);
function DOMAIN_SEPARATOR() external view returns (bytes32 domainSeparator_);
function name() external view returns (string memory name_);
function nonces(address owner_) external view returns (uint256 nonce_);
function PERMIT_TYPEHASH() external view returns (bytes32 permitTypehash_);
function symbol() external view returns (string memory symbol_);
function totalSupply() external view returns (uint256 totalSupply_);
}
文件 4 的 8:IERC20Like.sol
pragma solidity ^0.8.7;
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_);
}
文件 5 的 8:IERC4626.sol
pragma solidity 0.8.7;
import { IERC20 } from "../../modules/erc20/contracts/interfaces/IERC20.sol";
interface IERC4626 is IERC20 {
event Deposit(address indexed caller_, address indexed owner_, uint256 assets_, uint256 shares_);
event Withdraw(address indexed caller_, address indexed receiver_, address indexed owner_, uint256 assets_, uint256 shares_);
function asset() external view returns (address asset_);
function deposit(uint256 assets_, address receiver_) external returns (uint256 shares_);
function mint(uint256 shares_, address receiver_) external returns (uint256 assets_);
function redeem(uint256 shares_, address receiver_, address owner_) external returns (uint256 assets_);
function withdraw(uint256 assets_, address receiver_, address owner_) external returns (uint256 shares_);
function convertToAssets(uint256 shares_) external view returns (uint256 assets_);
function convertToShares(uint256 assets_) external view returns (uint256 shares_);
function maxDeposit(address receiver_) external view returns (uint256 assets_);
function maxMint(address receiver_) external view returns (uint256 shares_);
function maxRedeem(address owner_) external view returns (uint256 shares_);
function maxWithdraw(address owner_) external view returns (uint256 assets_);
function previewDeposit(uint256 assets_) external view returns (uint256 shares_);
function previewMint(uint256 shares_) external view returns (uint256 assets_);
function previewRedeem(uint256 shares_) external view returns (uint256 assets_);
function previewWithdraw(uint256 assets_) external view returns (uint256 shares_);
function totalAssets() external view returns (uint256 totalAssets_);
}
文件 6 的 8:IPool.sol
pragma solidity 0.8.7;
import { IERC20 } from "../../modules/erc20/contracts/interfaces/IERC20.sol";
import { IERC4626 } from "./IERC4626.sol";
interface IPool is IERC20, IERC4626 {
event BootstrapMintPerformed(address indexed caller_, address indexed receiver_, uint256 assets_, uint256 shares_, uint256 bootStrapMintAmount_);
event OwnershipAccepted(address indexed previousOwner_, address indexed newOwner_);
event PendingOwnerSet(address indexed owner_, address indexed pendingOwner_);
event RedemptionRequested(address indexed owner_, uint256 shares_, uint256 escrowedShares_);
event SharesRemoved(address indexed owner_, uint256 shares_);
event WithdrawRequested(address indexed owner_, uint256 assets_, uint256 escrowedShares_);
function BOOTSTRAP_MINT() external view returns (uint256 bootstrapMint_);
function manager() external view returns (address manager_);
function depositWithPermit(uint256 assets_, address receiver_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) external returns (uint256 shares_);
function mintWithPermit(uint256 shares_, address receiver_, uint256 maxAssets_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) external returns (uint256 assets_);
function removeShares(uint256 shares_, address owner_) external returns (uint256 sharesReturned_);
function requestWithdraw(uint256 assets_, address owner_) external returns (uint256 escrowShares_);
function requestRedeem(uint256 shares_, address owner_) external returns (uint256 escrowShares_);
function balanceOfAssets(address account_) external view returns (uint256 assets_);
function convertToExitAssets(uint256 shares_) external view returns (uint256 assets_);
function convertToExitShares(uint256 assets_) external view returns (uint256 shares_);
function unrealizedLosses() external view returns (uint256 unrealizedLosses_);
}
文件 7 的 8:Interfaces.sol
pragma solidity 0.8.7;
interface IERC20Like {
function balanceOf(address account_) external view returns (uint256 balance_);
function decimals() external view returns (uint8 decimals_);
function totalSupply() external view returns (uint256 totalSupply_);
}
interface ILoanManagerLike {
function acceptNewTerms(
address loan_,
address refinancer_,
uint256 deadline_,
bytes[] calldata calls_
) external;
function assetsUnderManagement() external view returns (uint256 assetsUnderManagement_);
function claim(address loan_, bool hasSufficientCover_) external;
function finishCollateralLiquidation(address loan_) external returns (uint256 remainingLosses_, uint256 serviceFee_);
function fund(address loan_) external;
function removeLoanImpairment(address loan_, bool isGovernor_) external;
function setAllowedSlippage(address collateralAsset_, uint256 allowedSlippage_) external;
function setMinRatio(address collateralAsset_, uint256 minRatio_) external;
function impairLoan(address loan_, bool isGovernor_) external;
function triggerDefault(address loan_, address liquidatorFactory_) external returns (bool liquidationComplete_, uint256 remainingLosses_, uint256 platformFees_);
function unrealizedLosses() external view returns (uint256 unrealizedLosses_);
}
interface ILoanManagerInitializerLike {
function encodeArguments(address pool_) external pure returns (bytes memory calldata_);
function decodeArguments(bytes calldata calldata_) external pure returns (address pool_);
}
interface ILiquidatorLike {
function collateralRemaining() external view returns (uint256 collateralRemaining_);
function liquidatePortion(uint256 swapAmount_, uint256 maxReturnAmount_, bytes calldata data_) external;
function pullFunds(address token_, address destination_, uint256 amount_) external;
function setCollateralRemaining(uint256 collateralAmount_) external;
}
interface IMapleGlobalsLike {
function bootstrapMint(address asset_) external view returns (uint256 bootstrapMint_);
function getLatestPrice(address asset_) external view returns (uint256 price_);
function governor() external view returns (address governor_);
function isBorrower(address account_) external view returns (bool isBorrower_);
function isFactory(bytes32 factoryId_, address factory_) external view returns (bool isValid_);
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 isValidScheduledCall(address caller_, address contract_, bytes32 functionId_, bytes calldata callData_) external view returns (bool isValid_);
function platformManagementFeeRate(address poolManager_) external view returns (uint256 platformManagementFeeRate_);
function maxCoverLiquidationPercent(address poolManager_) external view returns (uint256 maxCoverLiquidationPercent_);
function migrationAdmin() external view returns (address migrationAdmin_);
function minCoverAmount(address poolManager_) external view returns (uint256 minCoverAmount_);
function mapleTreasury() external view returns (address mapleTreasury_);
function ownedPoolManager(address poolDelegate_) external view returns (address poolManager_);
function protocolPaused() external view returns (bool protocolPaused_);
function transferOwnedPoolManager(address fromPoolDelegate_, address toPoolDelegate_) external;
function unscheduleCall(address caller_, bytes32 functionId_, bytes calldata callData_) external;
}
interface IMapleLoanLike {
function acceptLender() external;
function acceptNewTerms(address refinancer_, uint256 deadline_, bytes[] calldata calls_) external returns (bytes32 refinanceCommitment_);
function batchClaimFunds(uint256[] memory amounts_, address[] memory destinations_) external;
function borrower() external view returns (address borrower_);
function claimFunds(uint256 amount_, address destination_) external;
function collateral() external view returns (uint256 collateral);
function collateralAsset() external view returns(address asset_);
function feeManager() external view returns (address feeManager_);
function fundsAsset() external view returns (address asset_);
function fundLoan(address lender_) external returns (uint256 fundsLent_);
function getClosingPaymentBreakdown() external view returns (
uint256 principal_,
uint256 interest_,
uint256 delegateServiceFee_,
uint256 platformServiceFee_
);
function getNextPaymentDetailedBreakdown() external view returns (
uint256 principal_,
uint256[3] memory interest_,
uint256[2] memory fees_
);
function getNextPaymentBreakdown() external view returns (
uint256 principal_,
uint256 interest_,
uint256 fees_
);
function getUnaccountedAmount(address asset_) external view returns (uint256 unaccountedAmount_);
function gracePeriod() external view returns (uint256 gracePeriod_);
function interestRate() external view returns (uint256 interestRate_);
function isImpaired() external view returns (bool isImpaired_);
function lateFeeRate() external view returns (uint256 lateFeeRate_);
function lender() external view returns (address lender_);
function nextPaymentDueDate() external view returns (uint256 nextPaymentDueDate_);
function originalNextPaymentDueDate() external view returns (uint256 originalNextPaymentDueDate_);
function paymentInterval() external view returns (uint256 paymentInterval_);
function paymentsRemaining() external view returns (uint256 paymentsRemaining_);
function principal() external view returns (uint256 principal_);
function principalRequested() external view returns (uint256 principalRequested_);
function refinanceInterest() external view returns (uint256 refinanceInterest_);
function removeLoanImpairment() external;
function repossess(address destination_) external returns (uint256 collateralRepossessed_, uint256 fundsRepossessed_);
function setPendingLender(address pendingLender_) external;
function skim(address token_, address destination_) external returns (uint256 skimmed_);
function impairLoan() external;
function unimpairedPaymentDueDate() external view returns (uint256 unimpairedPaymentDueDate_);
}
interface IMapleLoanV3Like {
function acceptLender() external;
function getNextPaymentBreakdown() external view returns (uint256 principal_, uint256 interest_, uint256, uint256);
function nextPaymentDueDate() external view returns (uint256 nextPaymentDueDate_);
function paymentInterval() external view returns (uint256 paymentInterval_);
function principal() external view returns (uint256 principal_);
function refinanceInterest() external view returns (uint256 refinanceInterest_);
function setPendingLender(address pendingLender_) external;
}
interface IMapleProxyFactoryLike {
function mapleGlobals() external view returns (address mapleGlobals_);
}
interface ILoanFactoryLike {
function isLoan(address loan_) external view returns (bool isLoan_);
}
interface IPoolDelegateCoverLike {
function moveFunds(uint256 amount_, address recipient_) external;
}
interface IPoolLike is IERC20Like {
function allowance(address owner_, address spender_) external view returns (uint256 allowance_);
function asset() external view returns (address asset_);
function convertToAssets(uint256 shares_) external view returns (uint256 assets_);
function convertToExitAssets(uint256 shares_) external view returns (uint256 assets_);
function convertToExitShares(uint256 assets_) external view returns (uint256 shares_);
function deposit(uint256 assets_, address receiver_) external returns (uint256 shares_);
function manager() external view returns (address manager_);
function previewDeposit(uint256 assets_) external view returns (uint256 shares_);
function previewMint(uint256 shares_) external view returns (uint256 assets_);
function processExit(uint256 shares_, uint256 assets_, address receiver_, address owner_) external;
function redeem(uint256 shares_, address receiver_, address owner_) external returns (uint256 assets_);
}
interface IPoolManagerLike {
function addLoanManager(address loanManager_) external;
function canCall(bytes32 functionId_, address caller_, bytes memory data_) external view returns (bool canCall_, string memory errorMessage_);
function convertToExitShares(uint256 assets_) external view returns (uint256 shares_);
function claim(address loan_) external;
function delegateManagementFeeRate() external view returns (uint256 delegateManagementFeeRate_);
function fund(uint256 principalAmount_, address loan_, address loanManager_) external;
function getEscrowParams(address owner_, uint256 shares_) external view returns (uint256 escrowShares_, address escrow_);
function globals() external view returns (address globals_);
function hasSufficientCover() external view returns (bool hasSufficientCover_);
function loanManager() external view returns (address loanManager_);
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 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 poolDelegate() external view returns (address poolDelegate_);
function poolDelegateCover() external view returns (address poolDelegateCover_);
function removeLoanManager(address loanManager_) external;
function removeShares(uint256 shares_, address owner_) external returns (uint256 sharesReturned_);
function requestRedeem(uint256 shares_, address owner_, address sender_) external;
function requestWithdraw(uint256 shares_, uint256 assets_, address owner_, address sender_) external;
function setWithdrawalManager(address withdrawalManager_) external;
function totalAssets() external view returns (uint256 totalAssets_);
function unrealizedLosses() external view returns (uint256 unrealizedLosses_);
function withdrawalManager() external view returns (address withdrawalManager_);
}
interface IWithdrawalManagerInitializerLike {
function encodeArguments(address pool_, uint256 cycleDuration_, uint256 windowDuration_) external pure returns (bytes memory calldata_);
function decodeArguments(bytes calldata calldata_) external pure returns (address pool_, uint256 cycleDuration_, uint256 windowDuration_);
}
interface IWithdrawalManagerLike {
function addShares(uint256 shares_, address owner_) external;
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_);
}
文件 8 的 8:Pool.sol
pragma solidity 0.8.7;
import { ERC20 } from "../modules/erc20/contracts/ERC20.sol";
import { ERC20Helper } from "../modules/erc20-helper/src/ERC20Helper.sol";
import { IPoolManagerLike } from "./interfaces/Interfaces.sol";
import { IERC20, IPool } from "./interfaces/IPool.sol";
contract Pool is IPool, ERC20 {
uint256 public immutable override BOOTSTRAP_MINT;
address public override asset;
address public override manager;
uint256 private _locked = 1;
constructor(
address manager_,
address asset_,
address destination_,
uint256 bootstrapMint_,
uint256 initialSupply_,
string memory name_,
string memory symbol_
)
ERC20(name_, symbol_, ERC20(asset_).decimals())
{
require((manager = manager_) != address(0), "P:C:ZERO_MANAGER");
require((asset = asset_) != address(0), "P:C:ZERO_ASSET");
if (initialSupply_ != 0) {
_mint(destination_, initialSupply_);
}
BOOTSTRAP_MINT = bootstrapMint_;
require(ERC20Helper.approve(asset_, manager_, type(uint256).max), "P:C:FAILED_APPROVE");
}
modifier checkCall(bytes32 functionId_) {
( bool success_, string memory errorMessage_ ) = IPoolManagerLike(manager).canCall(functionId_, msg.sender, msg.data[4:]);
require(success_, errorMessage_);
_;
}
modifier nonReentrant() {
require(_locked == 1, "P:LOCKED");
_locked = 2;
_;
_locked = 1;
}
function deposit(uint256 assets_, address receiver_) external override nonReentrant checkCall("P:deposit") returns (uint256 shares_) {
_mint(shares_ = previewDeposit(assets_), assets_, receiver_, msg.sender);
}
function depositWithPermit(
uint256 assets_,
address receiver_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
)
external override nonReentrant checkCall("P:depositWithPermit") returns (uint256 shares_)
{
ERC20(asset).permit(msg.sender, address(this), assets_, deadline_, v_, r_, s_);
_mint(shares_ = previewDeposit(assets_), assets_, receiver_, msg.sender);
}
function mint(uint256 shares_, address receiver_) external override nonReentrant checkCall("P:mint") returns (uint256 assets_) {
_mint(shares_, assets_ = previewMint(shares_), receiver_, msg.sender);
}
function mintWithPermit(
uint256 shares_,
address receiver_,
uint256 maxAssets_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
)
external override nonReentrant checkCall("P:mintWithPermit") returns (uint256 assets_)
{
require((assets_ = previewMint(shares_)) <= maxAssets_, "P:MWP:INSUFFICIENT_PERMIT");
ERC20(asset).permit(msg.sender, address(this), maxAssets_, deadline_, v_, r_, s_);
_mint(shares_, assets_, receiver_, msg.sender);
}
function redeem(uint256 shares_, address receiver_, address owner_) external override nonReentrant checkCall("P:redeem") returns (uint256 assets_) {
uint256 redeemableShares_;
( redeemableShares_, assets_ ) = IPoolManagerLike(manager).processRedeem(shares_, owner_, msg.sender);
_burn(redeemableShares_, assets_, receiver_, owner_, msg.sender);
}
function withdraw(uint256 assets_, address receiver_, address owner_) external override nonReentrant checkCall("P:withdraw") returns (uint256 shares_) {
( shares_, assets_ ) = IPoolManagerLike(manager).processWithdraw(assets_, owner_, msg.sender);
_burn(shares_, assets_, receiver_, owner_, msg.sender);
}
function transfer(
address recipient_,
uint256 amount_
)
public override(IERC20, ERC20) checkCall("P:transfer") returns (bool success_)
{
success_ = super.transfer(recipient_, amount_);
}
function transferFrom(
address owner_,
address recipient_,
uint256 amount_
)
public override(IERC20, ERC20) checkCall("P:transferFrom") returns (bool success_)
{
success_ = super.transferFrom(owner_, recipient_, amount_);
}
function removeShares(uint256 shares_, address owner_) external override nonReentrant checkCall("P:removeShares") returns (uint256 sharesReturned_) {
if (msg.sender != owner_) _decreaseAllowance(owner_, msg.sender, shares_);
emit SharesRemoved(
owner_,
sharesReturned_ = IPoolManagerLike(manager).removeShares(shares_, owner_)
);
}
function requestRedeem(uint256 shares_, address owner_) external override nonReentrant checkCall("P:requestRedeem") returns (uint256 escrowedShares_) {
emit RedemptionRequested(
owner_,
shares_,
escrowedShares_ = _requestRedeem(shares_, owner_)
);
}
function requestWithdraw(uint256 assets_, address owner_) external override nonReentrant checkCall("P:requestWithdraw") returns (uint256 escrowedShares_) {
emit WithdrawRequested(
owner_,
assets_,
escrowedShares_ = _requestWithdraw(assets_, owner_)
);
}
function _burn(uint256 shares_, uint256 assets_, address receiver_, address owner_, address caller_) internal {
require(receiver_ != address(0), "P:B:ZERO_RECEIVER");
if (shares_ == 0) return;
if (caller_ != owner_) {
_decreaseAllowance(owner_, caller_, shares_);
}
_burn(owner_, shares_);
emit Withdraw(caller_, receiver_, owner_, assets_, shares_);
require(ERC20Helper.transfer(asset, receiver_, assets_), "P:B:TRANSFER");
}
function _divRoundUp(uint256 numerator_, uint256 divisor_) internal pure returns (uint256 result_) {
result_ = (numerator_ + divisor_ - 1) / divisor_;
}
function _mint(uint256 shares_, uint256 assets_, address receiver_, address caller_) internal {
require(receiver_ != address(0), "P:M:ZERO_RECEIVER");
require(shares_ != uint256(0), "P:M:ZERO_SHARES");
require(assets_ != uint256(0), "P:M:ZERO_ASSETS");
if (totalSupply == 0 && BOOTSTRAP_MINT != 0) {
_mint(address(0), BOOTSTRAP_MINT);
emit BootstrapMintPerformed(caller_, receiver_, assets_, shares_, BOOTSTRAP_MINT);
shares_ -= BOOTSTRAP_MINT;
}
_mint(receiver_, shares_);
emit Deposit(caller_, receiver_, assets_, shares_);
require(ERC20Helper.transferFrom(asset, caller_, address(this), assets_), "P:M:TRANSFER_FROM");
}
function _requestRedeem(uint256 shares_, address owner_) internal returns (uint256 escrowShares_) {
address destination_;
( escrowShares_, destination_ ) = IPoolManagerLike(manager).getEscrowParams(owner_, shares_);
if (msg.sender != owner_) {
_decreaseAllowance(owner_, msg.sender, escrowShares_);
}
if (escrowShares_ != 0 && destination_ != address(0)) {
_transfer(owner_, destination_, escrowShares_);
}
IPoolManagerLike(manager).requestRedeem(escrowShares_, owner_, msg.sender);
}
function _requestWithdraw(uint256 assets_, address owner_) internal returns (uint256 escrowShares_) {
address destination_;
( escrowShares_, destination_ ) = IPoolManagerLike(manager).getEscrowParams(owner_, convertToExitShares(assets_));
if (msg.sender != owner_) {
_decreaseAllowance(owner_, msg.sender, escrowShares_);
}
if (escrowShares_ != 0 && destination_ != address(0)) {
_transfer(owner_, destination_, escrowShares_);
}
IPoolManagerLike(manager).requestWithdraw(escrowShares_, assets_, owner_, msg.sender);
}
function balanceOfAssets(address account_) external view override returns (uint256 balanceOfAssets_) {
balanceOfAssets_ = convertToAssets(balanceOf[account_]);
}
function maxDeposit(address receiver_) external view override returns (uint256 maxAssets_) {
maxAssets_ = IPoolManagerLike(manager).maxDeposit(receiver_);
}
function maxMint(address receiver_) external view override returns (uint256 maxShares_) {
maxShares_ = IPoolManagerLike(manager).maxMint(receiver_);
}
function maxRedeem(address owner_) external view override returns (uint256 maxShares_) {
maxShares_ = IPoolManagerLike(manager).maxRedeem(owner_);
}
function maxWithdraw(address owner_) external view override returns (uint256 maxAssets_) {
maxAssets_ = IPoolManagerLike(manager).maxWithdraw(owner_);
}
function previewRedeem(uint256 shares_) external view override returns (uint256 assets_) {
assets_ = IPoolManagerLike(manager).previewRedeem(msg.sender, shares_);
}
function previewWithdraw(uint256 assets_) external view override returns (uint256 shares_) {
shares_ = IPoolManagerLike(manager).previewWithdraw(msg.sender, assets_);
}
function convertToAssets(uint256 shares_) public view override returns (uint256 assets_) {
uint256 totalSupply_ = totalSupply;
assets_ = totalSupply_ == 0 ? shares_ : (shares_ * totalAssets()) / totalSupply_;
}
function convertToExitAssets(uint256 shares_) public view override returns (uint256 assets_) {
uint256 totalSupply_ = totalSupply;
assets_ = totalSupply_ == 0 ? shares_ : shares_ * (totalAssets() - unrealizedLosses()) / totalSupply_;
}
function convertToShares(uint256 assets_) public view override returns (uint256 shares_) {
uint256 totalSupply_ = totalSupply;
shares_ = totalSupply_ == 0 ? assets_ : (assets_ * totalSupply_) / totalAssets();
}
function convertToExitShares(uint256 amount_) public view override returns (uint256 shares_) {
shares_ = _divRoundUp(amount_ * totalSupply, totalAssets() - unrealizedLosses());
}
function previewDeposit(uint256 assets_) public view override returns (uint256 shares_) {
shares_ = convertToShares(assets_);
}
function previewMint(uint256 shares_) public view override returns (uint256 assets_) {
uint256 totalSupply_ = totalSupply;
assets_ = totalSupply_ == 0 ? shares_ : _divRoundUp(shares_ * totalAssets(), totalSupply_);
}
function totalAssets() public view override returns (uint256 totalAssets_) {
totalAssets_ = IPoolManagerLike(manager).totalAssets();
}
function unrealizedLosses() public view override returns (uint256 unrealizedLosses_) {
unrealizedLosses_ = IPoolManagerLike(manager).unrealizedLosses();
}
}
{
"compilationTarget": {
"contracts/Pool.sol": "Pool"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":contract-test-utils/=modules/contract-test-utils/contracts/",
":erc20-helper/=modules/erc20-helper/src/",
":erc20/=modules/erc20/",
":maple-proxy-factory/=modules/maple-proxy-factory/",
":proxy-factory/=modules/maple-proxy-factory/modules/proxy-factory/"
]
}
[{"inputs":[{"internalType":"address","name":"manager_","type":"address"},{"internalType":"address","name":"asset_","type":"address"},{"internalType":"address","name":"destination_","type":"address"},{"internalType":"uint256","name":"bootstrapMint_","type":"uint256"},{"internalType":"uint256","name":"initialSupply_","type":"uint256"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":true,"internalType":"address","name":"spender_","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller_","type":"address"},{"indexed":true,"internalType":"address","name":"receiver_","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets_","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares_","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bootStrapMintAmount_","type":"uint256"}],"name":"BootstrapMintPerformed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller_","type":"address"},{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets_","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares_","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner_","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner_","type":"address"}],"name":"OwnershipAccepted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":true,"internalType":"address","name":"pendingOwner_","type":"address"}],"name":"PendingOwnerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares_","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"escrowedShares_","type":"uint256"}],"name":"RedemptionRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares_","type":"uint256"}],"name":"SharesRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":true,"internalType":"address","name":"recipient_","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller_","type":"address"},{"indexed":true,"internalType":"address","name":"receiver_","type":"address"},{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets_","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares_","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner_","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets_","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"escrowedShares_","type":"uint256"}],"name":"WithdrawRequested","type":"event"},{"inputs":[],"name":"BOOTSTRAP_MINT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"domainSeparator_","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success_","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account_","type":"address"}],"name":"balanceOfAssets","outputs":[{"internalType":"uint256","name":"balanceOfAssets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"name":"convertToExitAssets","outputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"convertToExitShares","outputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender_","type":"address"},{"internalType":"uint256","name":"subtractedAmount_","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"success_","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"},{"internalType":"uint256","name":"deadline_","type":"uint256"},{"internalType":"uint8","name":"v_","type":"uint8"},{"internalType":"bytes32","name":"r_","type":"bytes32"},{"internalType":"bytes32","name":"s_","type":"bytes32"}],"name":"depositWithPermit","outputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender_","type":"address"},{"internalType":"uint256","name":"addedAmount_","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"success_","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver_","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"maxAssets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver_","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"maxShares_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner_","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"maxShares_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner_","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"maxAssets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"},{"internalType":"uint256","name":"maxAssets_","type":"uint256"},{"internalType":"uint256","name":"deadline_","type":"uint256"},{"internalType":"uint8","name":"v_","type":"uint8"},{"internalType":"bytes32","name":"r_","type":"bytes32"},{"internalType":"bytes32","name":"s_","type":"bytes32"}],"name":"mintWithPermit","outputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"spender_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"uint256","name":"deadline_","type":"uint256"},{"internalType":"uint8","name":"v_","type":"uint8"},{"internalType":"bytes32","name":"r_","type":"bytes32"},{"internalType":"bytes32","name":"s_","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"},{"internalType":"address","name":"owner_","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"},{"internalType":"address","name":"owner_","type":"address"}],"name":"removeShares","outputs":[{"internalType":"uint256","name":"sharesReturned_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares_","type":"uint256"},{"internalType":"address","name":"owner_","type":"address"}],"name":"requestRedeem","outputs":[{"internalType":"uint256","name":"escrowedShares_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets_","type":"uint256"},{"internalType":"address","name":"owner_","type":"address"}],"name":"requestWithdraw","outputs":[{"internalType":"uint256","name":"escrowedShares_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"totalAssets_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success_","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"recipient_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success_","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unrealizedLosses","outputs":[{"internalType":"uint256","name":"unrealizedLosses_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets_","type":"uint256"},{"internalType":"address","name":"receiver_","type":"address"},{"internalType":"address","name":"owner_","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]