bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 35쪽
_MANAGER_QUEUE_FACTORY`).
* `strategyFactories` - Array of strategy factory addresses (e.g., LoanManager factory, external strategy factories).
* `strategyDeploymentData` - Strategy-specific encoded deployment data for each factory.
* `asset` - The main asset that the pool denominates in.
* `poolPermissionManager`.
* `name` and `symbol` for identification of the pool shares token.
* Configuration params:
* `initialSupply` - The initial supply of pool tokens used during Pool deployment
Note: In the queue-based deployer, additional Pool parameters such as `liquidityCap`, `delegateManagementFeeRate`, `poolPermissionManager`, and `withdrawalManager` are set post-deployment via `PoolManager` admin functions (typically by Governor or Operational Admin) after activation.
## Pool Activation
Before the Pool can start accepting deposits and operating, the Governor or Operational Admin needs to call `activatePoolManager` in Globals. This will activate the Pool. This allows the Governor or Operational Admin to set up fee parameters, default parameters, and ensure that the requisite cover has been posted by the Pool Delegate before running the Pool.
Deprecated: The cyclical Withdrawal Manager has been deprecated. New pools should use the Withdrawal Manager (Queue).
# PoolManager: Smart Contract Reference
## Overview
Since the Pool contract holds the ERC-20 token logic that tracks the value of all the Liquidity Provider's positions, it was prioritized to be made immutable. In order to balance the benefits of immutability and be able to incorporate the flexibility to build into the future, a modular architecture was introduced. The PoolManager is the true "central" contract of a Pool ecosystem of contracts. The PoolManager holds all administrative functionality, aggregates all accounting information, and allows for a high degree of configuration. The PoolManager manages with the following contracts:
* Pool
* PoolDelegateCover
* WithdrawalManager
* LoanManager (can be multiple)
The relationship between the Pool and PoolManager is currently one-to-one, however due to the architecture a PoolManager could technically manage multiple ERC-4626 Pool contracts and manage their accounting. This allows for more sophisticated LP options to become available in the future if needed.
The Pool is not aware of any of the LoanManagers or the WithdrawalManager, so these contracts can be changed in the future as seen fit (can only be changeable to contracts that have been vetted by the protocol smart contracts team and the DAO).
In addition, in future iterations of the protocol, this will allow newly deployed pools to be configured from a suite of LoanManager and WithdrawalManager contracts to meet pool requirements.
## Administrative Functions
Core configuration is gated to protocol admins (Governor, Operational Admin or Pool Delegate) or only allowed prior to initial configuration.
* `setDelegateManagementFeeRate`
* `setLiquidityCap`
* `setPoolPermissionManager`
* `setWithdrawalManager`
* `addStrategy`
* `setIsStrategy`
Additionally, the PoolManager stores relevant module addresses:
* List of `loanManagers`
* The `withdrawalManager`
* The `poolDelegateCover` contract
## Funds Asset Approval
One important thing to note is that the PoolManager contract has approval to transfer Pool cash. This is done to minimize the need for internal contract calls in a few functions like funding and refinance. The approval is done when the pool is deployed and cannot be revoked. There is a limitation on the movement of cash by the Pool Delegate, which is governed by the WithdrawalManager. The current implementation of the WithdrawalManager prevents Pool Delegates from moving cash that is currently earmarked for withdrawals.
# Accounting
# Pool Accounting
## Total Pool Value (`totalAssets`)
Total pool value is represented using `totalAssets`.
This value is calculated using the following equation:
$$
\begin{align} \nonumber totalAssets = cash + \sum{assetsUnderManagement\_{strategies}} \end{align}
$$
where:
$$
\begin{align} \nonumber assetsUnderManagement = \sum\Big({outstandingPrincipal\_{loan}} + {outstandingInterest\_{loan}}\Big) \end{align}
$$
where:
$$
\begin{align} \nonumber outstandingInterest(t) = accountedInterest + issuanceRate \times (t - domainStart) \end{align}
$$
The relationship between the Pool, PoolManager, and LoanManagers regarding value representation is shown in the diagram below.
<div align="center"><img src="https://github.com/user-attachments/assets/4b64a334-57c5-4746-bbbc-f9d6c41e7940" alt="" height="500"></div>
## Unrealized Losses
`unrealizedLosses` is an accounting variable that represents a "paper loss". The Pool Delegate and Governor both have the ability to "impair" a strategy and represent a paper loss in the pool. `unrealizedLosses` is also incremented during an active collateral liquidation in a Loan. `unrealizedLosses` is used to prevent large liquidity events in situations where it is public knowledge that a Pool will incur a loss in the future.
In the case the unrealizedLosses > 0, there are two exchange rates that are maintained, one for deposits and one for withdrawals. This is to prevent malicious depositors from taking advantage of a situation where they know that paper loss will be removed. Consider a situation where there is a single loan outstanding for $900k with $10k of outstanding interest, and there is 100k of cash in the pool. The `totalSupply` of LP tokens is 1m. In this situation, the effective exchange rate is:
$$
\large \begin{align} \nonumber exchangeRate &= \frac{totalAssets}{totalSupply} \ \nonumber exchangeRate &= \frac{900000 + 100000 + 10000}{1000000} \ \nonumber exchangeRate &= 1.01 \end{align}
$$
After impairing the loan, `unrealizedLosses` gets set to 910k. Now, with `unrealizedLosses` considered, the exchange rate becomes:
$$
\large \begin{align} \nonumber exchangeRate &= \frac{totalAssets}{totalSupply} \ \nonumber exchangeRate &= \frac{900000 + 100000 + 10000 - 910000}{1000000} \ \nonumber exchangeRate &= 0.1 \end{align}
$$
Without the two exchange rate model, a depositor could deposit $1m at a 0.1 exchange rate and get 10m shares. Once `unrealizedLosses` was removed, their shares would be worth $10.1m.
For this reason, two exchange rates are maintained during an unrealizedLosses scenario. This accomplishes two things:
1. Discourages withdrawals - LPs are incentivized to wait until the strategy either:
2. Defaults - Cover and collateral will increase exchange rate
3. Pays back - The original exchange rate is restored.
4. Discourages deposits - During a scenario where a default is imminent, it is in future LPs' best interest to wait until the borrower either defaults or pays back their loan before entering the pool.
# Pool Exchange Rates
## Overview
Each Maple Pool has two exchange rates, one for deposits and one for withdrawals which can be seen in `convertToAssets`, `convertToExitAssets`, `convertToShares` and `convertToExitShares` functions.
The difference is because when withdrawing assets from a pool the protocol takes into account `unrealizedLosses` ([more info here](/technical-resources/pools/accounting/pool-accounting)) which can be thought of as a paper loss due to a Loan impairment. As a result the withdrawal exchange rate needs to take any `unrealizedLosses` into account to stop LPs front running any losses, this design makes any losses more equitable across all LPs. The reason that two exchange rates must be maintained in the case of an unrealized loss is that a new LP can take advantage of an impairment being removed by depositing right before the unrealizedLoss is reduced. This reduction results in a significant discrete increase in the exchange rate, which can be exploited by a savvy depositor. For this reason, the deposit exchange rate does not recognize the unrealized loss while the withdrawal rate does.
To highlight the difference first let us look at a deposit specific exchange rate functions `convertToShares`.
#### `convertToAssets`
This exchange rate function helps an LP determine how much of the Pool Asset is required to mint a specific number of shares.
$$
\large \begin{align} \nonumber exchangeRate = \frac{totalAssets}{totalSupply} \end{align}
$$
But note that `unrealizedLosses` is not used here.
#### `convertToExitAssets`
This exchange rate function helps an LP determine how much of the Pool Assets an LP can withdraw for a specific number of shares.
$$
\large \begin{align} \nonumber exchangeRate = \frac{totalAssets-unrealizedLosses}{totalSupply} \end{align}
$$
## Example
Below is an example of how the exchange rates work in an impair + default scenario. If one exchange rate was used during this process, a depositor could have deposited at a 0.6 exchange rate and withdrawn at a 0.8 exchange rate soon after. This would be an unfair distribution of funds as that depositor would earn a portion of the proceeds from cover and collateral liquidation as profit, rather than experiencing it as a reduction in loss.
```
# Pre-Impairment
totalAssets = 1100
totalSupply = 1000
unrealizedLosses = 0
Deposit exchange rate = 1.1
Withdraw exchange rate = 1.1
# Post-Impairment (Pre-Default)
totalAssets = 1100
totalSupply = 1000
unrealizedLosses = 500
Deposit exchange rate = 1.1
Withdraw exchange rate = 0.6
# Post-Default
totalAssets = 800
totalSupply = 1000
unrealizedLosses = 0
Deposit exchange rate = 0.8
Withdraw exchange rate = 0.8
```
# Strategies
The Loan Managers act as primary yield generating strategies for the Maple protocol whereas the additional DeFi strategies are secondary sources of yield.
# Fixed Term Loan Manager
# Overview
## Assets Under Management (AUM)
The FixedTermLoanManager interacts with FixedTermLoans on behalf of the PoolManager and represents these Loans' outstanding value with the `assetsUnderManagement` function. This function returns the outstanding principal of all loans plus the outstanding interest.
$$
\large \begin{align} \nonumber assetsUnderManagement = outstandingPrincipal + outstandingInterest \end{align}
$$
## Outstanding Principal
The outstanding principal component of AUM in the FixedTermLoanManager is represented by the `principalOut` state variable. This variable is incremented and decremented based on the actions of individual Loans and is equal to the sum of principal balance on all outstanding Loans.
$$
\large \begin{align} \nonumber principalOut = \sum{principal\_{loan}} \end{align}
$$
## Outstanding Interest
### Introduction
Outstanding interest in the FixedTermLoanManager has to represent the current aggregate value of the outstanding interest in all loans in the most accurate and efficient way possible. Interest in FixedTermLoans is represented as fixed amounts owed at a given date. For example, a $1m loan with 12% interest and a 30 day payment interval would be shown as:
$$
\large \begin{align} \nonumber interest = 1e6 \times 0.12 \times \frac{30}{365} = 9863.01 \end{align}
$$
This amount of $9863.01$ would be due exactly 30 days from when the loan gets funded.
### Naive Approach
Using this information, the current value of interest in the FixedTermLoan at any given time can be represented with the following equation:
$$
\large \begin{align} \nonumber interest(t) = interestDue \times \frac{t - paymentIntervalStart}{paymentIntervalLength} \end{align}
$$
So in an easier example, with a loan that expects $1000 on day 20, the value on day 9 would be:
$$
\large \begin{align} \nonumber interest(9) = 1000 \times \frac{9-0}{20} = 450 \end{align}
$$
Expanding on this concept, the naive calculation of the outstanding interest of all loans would be:
$$
\large \begin{align} \nonumber interest(t) = \sum \Big(interestDue\_{loan} \times \frac{t - paymentIntervalStart\_{loan}}{paymentInterval\_{loan}}\Big) \end{align}
$$
### Optimized Approach (Aggregated Issuance)
In a system managing many loans at once, calculating the outstanding interest by summing the values naively is prohibitively expensive. In order to represent this value more efficiently, an alternative approach was taken. By saving the values from Loans during interactions and using them in an aggregate expression, a piecewise linear function can be constructed to represent the value of outstanding interest at any given time. This function consists of four parameters:
1. `issuanceRate`: Units of `fundsAsset` per second being earned as interest for all outstanding loans.
2. `accountedInterest`: "Snapshotted" value of outstanding interest saved at each point the function parameters are updated.
3. `domainStart`: The timestamp marking beginning of the domain in which the interest accrual expression is valid (called the "issuance domain"). Set to `block.timestamp` after each update.
4. `domainEnd`: The timestamp marking the end of the issuance domain.
The equation for outstanding interest is shown below:
$$
\large \begin{align} \nonumber outstandingInterest(t) = accountedInterest + issuanceRate \times (t - domainStart) \end{align}
$$
where:
$$
\large \begin{align} \nonumber domainStart \le t \le domainEnd \end{align}
$$
# Claims
The `claim` function in the LoanManager is called atomically after every payment that is made against Loans. The `claim` function is designed to:
1. Consolidate and update past accounting of outstanding interest for all Loans in the LoanManager.
2. Handle accounting of the payment that was just made within the LoanManager.
3. Disburse funds from the payment to the Pool, Pool Delegate, and MapleTreasury.
4. Calculate the interest accrual parameters based on the next scheduled payment in the Loan.
5. Update the global accounting formula in the LoanManager to start accruing interest into the future.
Below is a flowchart demonstrating how the claim function handles all of this logic.
<figure><img src="https://user-images.githubusercontent.com/44272939/196696564-3c8cf4b0-bbc0-48b4-99b4-2b7c92f4609e.svg" alt=""><figcaption></figcaption></figure>
# Advance Payment Accounting
## Overview
Whenever any interaction is made with a `Fixed Term Loan` from the `FixedTermLoanManager`, `_advanceGlobalPaymentAccounting` is called. The purpose of this function is to account all Loans' outstanding interest and to represent the current state at the current timestamp.
For all of the below examples, the following abbreviations are used:
* $$AI$$: `accountedInterest`
* $$IR$$: `issuanceRate`
* $$DS$$: `domainStart`
* $$DE$$: `domainEnd`
For all of the below examples, $accountedInterest$ starts as the following:
$$
\large \begin{align} \nonumber AI\_{pre-AGPA} = \Big(IR\_1 \times (DE\_0 - DS\_0)\Big) + \Big(IR\_{1+2} \times (DE\_1 - DS\_1)\Big) \end{align}
$$
## Example 1: Call before `domainEnd`
In this example, the payment is made before the `domainEnd`, so no payments are removed from the sorted list.
$$
\large \begin{align} \nonumber AI\_{post-AGPA} = AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (t\_{payment} - DS\_2)\Big) \end{align}
$$

## Example 2: Call after `domainEnd`, before Loan 2 Payment Due Date
In this example, the payment is made after the `domainEnd`, so Loan 1 is removed from the sorted list and `domainEnd` is updated.
$$
\large \begin{align} \nonumber AI\_{post-AGPA} = AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (DE\_2 - DS\_2)\Big) + \Big(IR\_{2+3} \times (t\_{payment} - DS\_3)\Big) \end{align}
$$

## Example 3: Call after `domainEnd`, before Loan 3 Payment Due Date
In this example, the payment is made after the `domainEnd` and Loan 2's payment due date, so Loans 1 and 2 are removed from the sorted list and `domainEnd` is updated.
$$
\large \begin{align} \nonumber AI\_{post-AGPA} = \&AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (DE\_2 - DS\_2)\Big) + \ &\Big(IR\_{2+3} \times (DE\_3 - DS\_3)\Big) + \Big(IR\_{3} \times (t\_{payment} - DS\_4)\Big) \end{align}
$$

## Example 4: Call after `domainEnd`, after Loan 3 Payment Due Date
In this example, the payment is made after the `domainEnd`, Loan 2, and Loan 3's payment due dates, so Loans 1, 2 and 3 are removed from the sorted list and `domainEnd` is updated.
$$
\begin{align} \nonumber AI\_{post-AGPA} = \&AI\_{pre-AGPA} + \Big(IR\_{1+2+3} \times (DE\_2 - DS\_2)\Big) + \Big(IR\_{2+3} \times (DE\_3 - DS\_3)\Big) + \ &\Big(IR\_{3} \times (DE\_4 - DS\_4)\Big) + \Big(0 \times (t\_{payment} - DS\_5)\Big) \end{align}
$$

# Accounting Examples
## Overview
This section is intended to demonstrate multiple scenarios with loans to show how value is represented with `totalAssets`. During each payment, accounting state in the Fixed Term Manager contract is changed in the following way:
1. `accountedInterest` is decreased. This is because the $$outstandingInterest$$ portion of `assetsUnderManagement` must discretely decrease when a payment is made.
2. `domainStart` is updated to the current timestamp.
3. `issuanceRate` is updated based on the resulting state.
4. `domainEnd` is set to the next earliest payment due date.
5. Cash is sent to the pool.
**Note 1**: For all of the below examples, only interest is being paid so outstanding principal (`principalOut`) remains constant.
**Note 2**: For the purpose of simplicity, `issuanceRate` is represented as $$units/day$$ in the equations below. In reality, it is represented as $$units \times 1e30 / second$$.
**Note 3**: None of the below diagrams are to scale.
## Example 1: Single Loan - On Time Payment
In this example, there is a single Loan that makes a payment at the exact timestamp at which the payment is due. The payment is for 5000 units of `fundsAsset`.
It can be seen that during this transaction, outstanding interest accounting gets updated as follows:
$$
\large \begin{align} \nonumber accountedInterest &= accountedInterest - 5000 \ \nonumber issuanceRate &= \frac{5000}{20-10} = 500 \ \nonumber domainStart &= 10 \ \nonumber domainEnd &= 20 \end{align}
$$
`totalAssets` accounting gets updated as follows:
$$
\large \begin{align} \nonumber outstandingInterest &= outstandingInterest - 5000 \ \nonumber cash &= cash + 5000 \ \nonumber totalAssets &= totalAssets \ \end{align}
$$
Since the payment was made at the exact time that it was due, the outstanding interest exactly equaled the actual interest paid, so no discrete change in `totalAssets` is observed.
<div align="center"><img src="https://user-images.githubusercontent.com/44272939/196064820-c3189a40-4f62-46db-a5d3-8d214fb161e2.svg" alt="" height="1000"></div>
## Example 2: Single Loan - Early Payment
In this example, there is a single Loan that makes an early payment, two days before the payment is due. The interest due is 5000 units, but since the payment is made on day 8, only 4000 units have accrued in the LoanManager accounting.
It can be seen that during this transaction, outstanding interest accounting gets updated as follows:
$$
\large \begin{align} \nonumber accountedInterest &= accountedInterest - 4000 \ \nonumber issuanceRate &= \frac{5000}{20-8} = 416.67 \ \nonumber domainStart &= 8 \ \nonumber domainEnd &= 20 \end{align}
$$
`totalAssets` accounting gets updated as follows:
$$
\large \begin{align} \nonumber outstandingInterest &= outstandingInterest - 4000 \ \nonumber cash &= cash + 5000 \ \nonumber totalAssets &= totalAssets + 1000 \ \end{align}
$$
When a payment is made early, there is a discrete increase in `totalAssets` since the cash balance in the pool increases more than the outstanding interest that was represented when the payment was made.
<div align="center"><img src프로젝트로 돌아가기