Skip to content

Commit

Permalink
rename some structs about tranche redemption and deposit
Browse files Browse the repository at this point in the history
Combine lastDepositTime in DepositRecord struct
  • Loading branch information
bin-57blocks committed Dec 28, 2023
1 parent c36cfbd commit b7aa652
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 262 deletions.
38 changes: 19 additions & 19 deletions contracts/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import {IPool} from "./interfaces/IPool.sol";
import {PoolConfig, PoolSettings, LPConfig} from "./PoolConfig.sol";
import {PoolConfigCache} from "./PoolConfigCache.sol";
import {IRedemptionHandler, RedemptionSummary} from "./interfaces/IRedemptionHandler.sol";
import {IRedemptionHandler, EpochRedemptionSummary} from "./interfaces/IRedemptionHandler.sol";
import {IPoolSafe} from "./interfaces/IPoolSafe.sol";
import {ITranchesPolicy} from "./interfaces/ITranchesPolicy.sol";
import {DEFAULT_DECIMALS_FACTOR, JUNIOR_TRANCHE, SENIOR_TRANCHE} from "./SharedDefs.sol";
Expand Down Expand Up @@ -102,8 +102,8 @@ contract EpochManager is PoolConfigCache, IEpochManager {
juniorTranche.totalSupply();

// get unprocessed redemption requests
RedemptionSummary memory seniorSummary = seniorTranche.currentRedemptionSummary();
RedemptionSummary memory juniorSummary = juniorTranche.currentRedemptionSummary();
EpochRedemptionSummary memory seniorSummary = seniorTranche.currentRedemptionSummary();
EpochRedemptionSummary memory juniorSummary = juniorTranche.currentRedemptionSummary();
uint256 unprocessedAmount;

if (seniorSummary.totalSharesRequested > 0 || juniorSummary.totalSharesRequested > 0) {
Expand Down Expand Up @@ -136,11 +136,11 @@ contract EpochManager is PoolConfigCache, IEpochManager {
function startNewEpoch() external {
poolConfig.onlyPool(msg.sender);

RedemptionSummary memory seniorEpoch = seniorTranche.currentRedemptionSummary();
EpochRedemptionSummary memory seniorEpoch = seniorTranche.currentRedemptionSummary();
if (seniorEpoch.totalSharesRequested > 0) {
seniorTranche.executeRedemptionSummary(seniorEpoch);
}
RedemptionSummary memory juniorEpoch = juniorTranche.currentRedemptionSummary();
EpochRedemptionSummary memory juniorEpoch = juniorTranche.currentRedemptionSummary();
if (juniorEpoch.totalSharesRequested > 0) {
juniorTranche.executeRedemptionSummary(juniorEpoch);
}
Expand Down Expand Up @@ -187,9 +187,9 @@ contract EpochManager is PoolConfigCache, IEpochManager {
*/
function _processEpoch(
uint96[2] memory tranchesAssets,
RedemptionSummary memory seniorSummary,
EpochRedemptionSummary memory seniorSummary,
uint256 seniorPrice,
RedemptionSummary memory juniorSummary,
EpochRedemptionSummary memory juniorSummary,
uint256 juniorPrice
) internal view {
// get available underlying token amount
Expand Down Expand Up @@ -228,27 +228,27 @@ contract EpochManager is PoolConfigCache, IEpochManager {
* @notice Processes redemption requests for the senior tranche
* @param tranchesAssets tranches assets indexed by SENIOR_TRANCHE or JUNIOR_TRANCHE
* @param lpTokenPrice the price of the senior LP tokens
* @param epochInfo epoch info for the senior tranche
* @param redemptionSummary epoch info for the senior tranche
* @param availableAmount the total amount available for redemption
* @dev this function is side-effectual and mutates the following incoming params:
* tranchesAssets: will be updated to reflect the remaining amount of assets in the senior tranche
* epochInfo: will be updated to reflect the latest redemption request states for the senior tranche
* redemptionSummary: will be updated to reflect the latest redemption request states for the senior tranche
*/
function _processSeniorRedemptionRequests(
uint96[2] memory tranchesAssets,
uint256 lpTokenPrice,
RedemptionSummary memory epochInfo,
EpochRedemptionSummary memory redemptionSummary,
uint256 availableAmount
) internal pure returns (uint256 remainingAmount) {
uint256 sharesToRedeem = epochInfo.totalSharesRequested;
uint256 sharesToRedeem = redemptionSummary.totalSharesRequested;
uint256 redemptionAmount = (sharesToRedeem * lpTokenPrice) / DEFAULT_DECIMALS_FACTOR;
if (availableAmount < redemptionAmount) {
redemptionAmount = availableAmount;
// TODO rounding error?
sharesToRedeem = (redemptionAmount * DEFAULT_DECIMALS_FACTOR) / lpTokenPrice;
}
epochInfo.totalSharesProcessed = uint96(sharesToRedeem);
epochInfo.totalAmountProcessed = uint96(redemptionAmount);
redemptionSummary.totalSharesProcessed = uint96(sharesToRedeem);
redemptionSummary.totalAmountProcessed = uint96(redemptionAmount);
availableAmount -= redemptionAmount;

tranchesAssets[SENIOR_TRANCHE] -= uint96(redemptionAmount);
Expand All @@ -262,17 +262,17 @@ contract EpochManager is PoolConfigCache, IEpochManager {
* @param tranchesAssets tranches assets indexed by SENIOR_ or JUNIOR_TRANCHE, i.e. tranches[0] is the
* senior tranche assets and tranches[1] is the junior tranche assets
* @param lpTokenPrice the price of the junior LP tokens
* @param epochInfo the list of epoch infos in each epoch for the junior tranche
* @param redemptionSummary the list of epoch infos in each epoch for the junior tranche
* @param availableAmount the total amount available for redemption
* @dev this function is side-effectual and mutates the following incoming params:
* tranchesAssets: will be updated to reflect the remaining amount of assets in the junior tranche
* epochInfo: will be updated to reflect the latest redemption request states for the senior tranche
* redemptionSummary: will be updated to reflect the latest redemption request states for the senior tranche
*/
function _processJuniorRedemptionRequests(
uint96[2] memory tranchesAssets,
uint256 lpTokenPrice,
uint256 maxSeniorJuniorRatio,
RedemptionSummary memory epochInfo,
EpochRedemptionSummary memory redemptionSummary,
uint256 availableAmount
) internal pure returns (uint256 remainingAmount) {
// Calculate the minimum amount of junior assets required to maintain the senior : junior ratio.
Expand All @@ -286,7 +286,7 @@ contract EpochManager is PoolConfigCache, IEpochManager {
: 0;
if (maxRedeemableAmount <= 0) return availableAmount;

uint256 sharesToRedeem = epochInfo.totalSharesRequested;
uint256 sharesToRedeem = redemptionSummary.totalSharesRequested;
uint256 redemptionAmount = (sharesToRedeem * lpTokenPrice) / DEFAULT_DECIMALS_FACTOR;
if (availableAmount < redemptionAmount) {
redemptionAmount = availableAmount;
Expand All @@ -298,8 +298,8 @@ contract EpochManager is PoolConfigCache, IEpochManager {
sharesToRedeem = (redemptionAmount * DEFAULT_DECIMALS_FACTOR) / lpTokenPrice;
}

epochInfo.totalSharesProcessed = uint96(sharesToRedeem);
epochInfo.totalAmountProcessed = uint96(redemptionAmount);
redemptionSummary.totalSharesProcessed = uint96(sharesToRedeem);
redemptionSummary.totalAmountProcessed = uint96(redemptionAmount);
availableAmount -= redemptionAmount;
tranchesAssets[JUNIOR_TRANCHE] -= uint96(redemptionAmount);

Expand Down
Loading

0 comments on commit b7aa652

Please sign in to comment.