Skip to content

Commit

Permalink
feat: add settlementPeriod to the pool
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavaparoksham committed Jan 20, 2025
1 parent 1033581 commit 3a32e52
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
22 changes: 21 additions & 1 deletion src/interfaces/IAssetPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ interface IAssetPool {
* @notice Enum representing the current state of the pool's operational cycle
* @param ACTIVE Normal operation state where users can deposit and withdraw
* @param REBALANCING State during which LPs adjust their reserve positions
* @param SETTLEMENT State during which rebalance is finalization.
*/
enum CycleState {
ACTIVE,
REBALANCING
REBALANCING,
SETTLEMENT
}

// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -105,6 +107,12 @@ interface IAssetPool {
*/
event RebalanceTimeUpdated(uint256 newRebalanceTime);

/**
* @notice Emitted when the settlement period duration is updated
* @param newSettlementTime New duration for settlement periods
*/
event SettlementTimeUpdated(uint256 newSettlementTime);

/**
* @notice Emitted when a rebalance period is initiated
* @param cycleIndex Current operational cycle index
Expand Down Expand Up @@ -250,6 +258,7 @@ interface IAssetPool {
* @return _cycleIndex Current operational cycle index
* @return _nextRebalanceStartDate Start time of next rebalance
* @return _nextRebalanceEndDate End time of next rebalance
* @return _nextCycleStartDate Start time of next operational cycle
* @return _assetPrice Current price of the asset
*/
function getGeneralInfo() external view returns (
Expand All @@ -258,6 +267,7 @@ interface IAssetPool {
uint256 _cycleIndex,
uint256 _nextRebalanceStartDate,
uint256 _nextRebalanceEndDate,
uint256 _nextCycleStartDate,
uint256 _assetPrice
);

Expand Down Expand Up @@ -319,6 +329,11 @@ interface IAssetPool {
*/
function nextRebalanceEndDate() external view returns (uint256);

/**
* @notice Returns the start time of the next operational cycle
*/
function nextCycleStartDate() external view returns (uint256);

/**
* @notice Returns the duration of operational cycles
*/
Expand All @@ -329,6 +344,11 @@ interface IAssetPool {
*/
function rebalanceTime() external view returns (uint256);

/**
* @notice Returns the duration of settlement periods
*/
function settlementTime() external view returns (uint256);

/**
* @notice Returns the total balance of reserve tokens
*/
Expand Down
8 changes: 6 additions & 2 deletions src/interfaces/IAssetPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ interface IAssetPoolFactory {
* @param oracle Address of the oracle used for asset price feeds.
* @param cycleLength Duration of a single investment cycle in seconds.
* @param rebalancingPeriod Duration of the rebalancing period within a cycle in seconds.
* @param settlmentPeriod Duration of the settlement period within a cycle in seconds.
*/
event AssetPoolCreated(
address indexed pool,
string assetSymbol,
address depositToken,
address oracle,
uint256 cycleLength,
uint256 rebalancingPeriod
uint256 rebalancingPeriod,
uint256 settlmentPeriod
);

/**
Expand Down Expand Up @@ -59,6 +61,7 @@ interface IAssetPoolFactory {
* @param oracle Address of the oracle providing asset price feeds.
* @param cycleLength Length of each investment cycle in seconds.
* @param rebalancingPeriod Rebalancing period length within a cycle in seconds.
* @param settlmentPeriod Settlement period length within a cycle in seconds.
* @return address The address of the newly created asset pool.
*/
function createPool(
Expand All @@ -67,7 +70,8 @@ interface IAssetPoolFactory {
string memory assetSymbol,
address oracle,
uint256 cycleLength,
uint256 rebalancingPeriod
uint256 rebalancingPeriod,
uint256 settlmentPeriod
) external returns (address);

/**
Expand Down
26 changes: 26 additions & 0 deletions src/protocol/AssetPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
*/
uint256 public nextRebalanceEndDate;

/**
* @notice Timestamp when the next cycle is scheduled to start.
*/
uint256 public nextCycleStartDate;

/**
* @notice Duration of each operational cycle in seconds.
*/
Expand All @@ -74,6 +79,11 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
*/
uint256 public rebalanceTime;

/**
* @notice Duration of the settlement period in seconds.
*/
uint256 public settlementTime;

/**
* @notice Total reserve token balance in the pool.
*/
Expand Down Expand Up @@ -177,6 +187,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
address _lpRegistry,
uint256 _cyclePeriod,
uint256 _rebalancingPeriod,
uint256 _settlementPeriod,
address _owner
) Ownable(_owner) {
if (_reserveToken == address(0) || _assetOracle == address(0) || _lpRegistry == address(0))
Expand All @@ -189,8 +200,10 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
cycleState = CycleState.ACTIVE;
cycleTime = _cyclePeriod;
rebalanceTime = _rebalancingPeriod;
settlementTime = _settlementPeriod;
nextRebalanceStartDate = block.timestamp + _cyclePeriod;
nextRebalanceEndDate = nextRebalanceStartDate + _rebalancingPeriod;
nextCycleStartDate = nextRebalanceEndDate + _settlementPeriod;
}

// --------------------------------------------------------------------------------
Expand Down Expand Up @@ -436,6 +449,15 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
emit RebalanceTimeUpdated(newRebalanceTime);
}

/**
* @notice Updates the duration of the settlement period.
* @param newSettlementTime New settlement duration in seconds.
*/
function updateSettlementTime(uint256 newSettlementTime) external onlyOwner {
settlementTime = newSettlementTime;
emit SettlementTimeUpdated(newSettlementTime);
}

/**
* @notice Pauses the pool, disabling all user actions.
*/
Expand Down Expand Up @@ -484,6 +506,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
rebalancedLPs = 0;
nextRebalanceStartDate = block.timestamp + cycleTime;
nextRebalanceEndDate = nextRebalanceStartDate + rebalanceTime;
nextCycleStartDate = nextRebalanceEndDate + settlementTime;

emit CycleStarted(cycleIndex, block.timestamp);
}
Expand All @@ -499,6 +522,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
* @return _cycleIndex Current cycle index.
* @return _nextRebalanceStartDate Timestamp of the next rebalance start.
* @return _nextRebalanceEndDate Timestamp of the next rebalance end.
* @return _nextCycleStartDate Timestamp of the next cycle start.
* @return _assetPrice Current price of the asset.
*/
function getGeneralInfo() external view returns (
Expand All @@ -507,6 +531,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
uint256 _cycleIndex,
uint256 _nextRebalanceStartDate,
uint256 _nextRebalanceEndDate,
uint256 _nextCycleStartDate,
uint256 _assetPrice
) {
return (
Expand All @@ -515,6 +540,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
cycleIndex,
nextRebalanceStartDate,
nextRebalanceEndDate,
nextCycleStartDate,
assetOracle.assetPrice()
);
}
Expand Down
11 changes: 8 additions & 3 deletions src/protocol/AssetPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contract AssetPoolFactory is IAssetPoolFactory, Ownable {
* @param oracle Address of the oracle providing asset price feeds.
* @param cyclePeriod Length of each investment cycle in seconds.
* @param rebalancingPeriod Length of the rebalancing period within a cycle in seconds.
* @param settlementPeriod Length of the settlement period within a cycle in seconds.
* @return address The address of the newly created asset pool.
*/
function createPool(
Expand All @@ -49,13 +50,15 @@ contract AssetPoolFactory is IAssetPoolFactory, Ownable {
string memory assetSymbol,
address oracle,
uint256 cyclePeriod,
uint256 rebalancingPeriod
uint256 rebalancingPeriod,
uint256 settlementPeriod
) external onlyOwner returns (address) {
if (
depositToken == address(0) ||
oracle == address(0) ||
cyclePeriod == 0 ||
rebalancingPeriod >= cyclePeriod
rebalancingPeriod >= cyclePeriod ||
settlementPeriod >= cyclePeriod
) revert InvalidParams();

// Deploy a new AssetPool contract instance.
Expand All @@ -67,6 +70,7 @@ contract AssetPoolFactory is IAssetPoolFactory, Ownable {
address(lpRegistry),
cyclePeriod,
rebalancingPeriod,
settlementPeriod,
msg.sender
);

Expand All @@ -77,7 +81,8 @@ contract AssetPoolFactory is IAssetPoolFactory, Ownable {
depositToken,
oracle,
cyclePeriod,
rebalancingPeriod
rebalancingPeriod,
settlementPeriod
);

return address(pool);
Expand Down

0 comments on commit 3a32e52

Please sign in to comment.