From 3a32e52febac42e68b1020d66eda116ba4530571 Mon Sep 17 00:00:00 2001 From: eagle Date: Mon, 20 Jan 2025 17:48:51 +0530 Subject: [PATCH] feat: add settlementPeriod to the pool --- src/interfaces/IAssetPool.sol | 22 +++++++++++++++++++++- src/interfaces/IAssetPoolFactory.sol | 8 ++++++-- src/protocol/AssetPool.sol | 26 ++++++++++++++++++++++++++ src/protocol/AssetPoolFactory.sol | 11 ++++++++--- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/interfaces/IAssetPool.sol b/src/interfaces/IAssetPool.sol index 7e57df1..7259c45 100644 --- a/src/interfaces/IAssetPool.sol +++ b/src/interfaces/IAssetPool.sol @@ -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 } // -------------------------------------------------------------------------------- @@ -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 @@ -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 ( @@ -258,6 +267,7 @@ interface IAssetPool { uint256 _cycleIndex, uint256 _nextRebalanceStartDate, uint256 _nextRebalanceEndDate, + uint256 _nextCycleStartDate, uint256 _assetPrice ); @@ -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 */ @@ -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 */ diff --git a/src/interfaces/IAssetPoolFactory.sol b/src/interfaces/IAssetPoolFactory.sol index 72587e7..071fcff 100644 --- a/src/interfaces/IAssetPoolFactory.sol +++ b/src/interfaces/IAssetPoolFactory.sol @@ -19,6 +19,7 @@ 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, @@ -26,7 +27,8 @@ interface IAssetPoolFactory { address depositToken, address oracle, uint256 cycleLength, - uint256 rebalancingPeriod + uint256 rebalancingPeriod, + uint256 settlmentPeriod ); /** @@ -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( @@ -67,7 +70,8 @@ interface IAssetPoolFactory { string memory assetSymbol, address oracle, uint256 cycleLength, - uint256 rebalancingPeriod + uint256 rebalancingPeriod, + uint256 settlmentPeriod ) external returns (address); /** diff --git a/src/protocol/AssetPool.sol b/src/protocol/AssetPool.sol index 9f933a5..f83a9ec 100644 --- a/src/protocol/AssetPool.sol +++ b/src/protocol/AssetPool.sol @@ -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. */ @@ -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. */ @@ -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)) @@ -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; } // -------------------------------------------------------------------------------- @@ -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. */ @@ -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); } @@ -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 ( @@ -507,6 +531,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable { uint256 _cycleIndex, uint256 _nextRebalanceStartDate, uint256 _nextRebalanceEndDate, + uint256 _nextCycleStartDate, uint256 _assetPrice ) { return ( @@ -515,6 +540,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable { cycleIndex, nextRebalanceStartDate, nextRebalanceEndDate, + nextCycleStartDate, assetOracle.assetPrice() ); } diff --git a/src/protocol/AssetPoolFactory.sol b/src/protocol/AssetPoolFactory.sol index 4180d79..d6c57c6 100644 --- a/src/protocol/AssetPoolFactory.sol +++ b/src/protocol/AssetPoolFactory.sol @@ -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( @@ -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. @@ -67,6 +70,7 @@ contract AssetPoolFactory is IAssetPoolFactory, Ownable { address(lpRegistry), cyclePeriod, rebalancingPeriod, + settlementPeriod, msg.sender ); @@ -77,7 +81,8 @@ contract AssetPoolFactory is IAssetPoolFactory, Ownable { depositToken, oracle, cyclePeriod, - rebalancingPeriod + rebalancingPeriod, + settlementPeriod ); return address(pool);