Skip to content

Commit

Permalink
feat: burn assetTokens once rebalance has ended
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavaparoksham committed Jan 16, 2025
1 parent 73279cf commit 254ddee
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/protocol/AssetPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
* @param rebalancePrice Price at which the rebalance was executed
* @param isDeposit True if depositing stable, false if withdrawing
*
* ToDo: lpLiquidty should be bassed on how much being asset being rebalanced during the cycle
* ToDo: lpLiquidty should be based on how much being asset being rebalanced during the cycle
* ToDo: Need to handle the case when LP doesn't rebalance within the rebalance window
*/

function rebalancePool(address lp, uint256 rebalancePrice, uint256 amount, bool isDeposit) external onlyLP {
Expand All @@ -221,7 +222,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
if (block.timestamp > nextRebalanceEndDate) revert RebalancingExpired();
uint256 lpLiquidity = lpRegistry.getLPLiquidity(address(this), lp);

_validateRebalancing(lp, rebalancePrice, amount, isDeposit);
_validateRebalancing(lp, amount, isDeposit);

cycleWeightedSum[cycleIndex] += rebalancePrice * lpLiquidity;

Expand All @@ -242,6 +243,9 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
// If all LPs have rebalanced, start next cycle
if (rebalancedLPs == lpRegistry.getLPCount(address(this))) {
uint256 totalLiquidity = lpRegistry.getTotalLPLiquidity(address(this));
uint256 assetBalance = assetToken.balanceOf(address(this));
uint256 reserveBalanceInAssetToken = assetToken.reserveBalanceOf(address(this));
assetToken.burn(address(this), assetBalance, reserveBalanceInAssetToken);
cycleRebalancePrice[cycleIndex] = cycleWeightedSum[cycleIndex] / totalLiquidity;
_startNewCycle();
}
Expand Down Expand Up @@ -278,7 +282,7 @@ contract AssetPool is IAssetPool, Ownable, Pausable {
}

// Internal functions
function _validateRebalancing(address lp, uint256 rebalancePrice, uint256 amount, bool isDeposit) internal view {
function _validateRebalancing(address lp, uint256 amount, bool isDeposit) internal view {
uint256 lpLiquidity = lpRegistry.getLPLiquidity(address(this), lp);
require(lpLiquidity > 0, "Insufficient LP liquidity");

Expand Down

0 comments on commit 254ddee

Please sign in to comment.