-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: Automate end start swapping #235
base: main
Are you sure you want to change the base?
Changes from all commits
5fea4ec
95f2ac5
79c52d2
0fa28ea
049ac52
19455a4
cfff0f1
27dbbb3
302a3df
4b4386e
1b50cfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,17 @@ import "../utils/interface/ILBP.sol"; | |
*/ | ||
// solhint-disable-next-line max-states-count | ||
contract LBPManager { | ||
/* | ||
Waiting:- current time < start time - 5 minutes, swapping is disabled | ||
Started:- start time - 5 minutes <= current time < endTime, swapping enabled, can also be updated by admin | ||
Ended:- current time > end time, swapping disableds | ||
*/ | ||
enum TaskState { | ||
Waiting, | ||
Started, | ||
Ended | ||
} | ||
TaskState public state; | ||
// Constants | ||
uint256 private constant HUNDRED_PERCENT = 1e18; // Used in calculating the fee. | ||
|
||
|
@@ -180,7 +191,6 @@ contract LBPManager { | |
*/ | ||
function initializeLBP(address _sender) external onlyAdmin { | ||
// solhint-disable-next-line reason-string | ||
require(initialized == true, "LBPManager: LBPManager not initialized"); | ||
require(!poolFunded, "LBPManager: pool already funded"); | ||
poolFunded = true; | ||
|
||
|
@@ -192,7 +202,7 @@ contract LBPManager { | |
startWeights, | ||
swapFeePercentage, | ||
address(this), | ||
true // SwapEnabled is set to true at pool creation. | ||
false // SwapEnabled is set to true at pool creation. | ||
) | ||
); | ||
|
||
|
@@ -234,6 +244,45 @@ contract LBPManager { | |
vault.joinPool(lbp.getPoolId(), address(this), address(this), request); | ||
} | ||
|
||
/** | ||
* @dev start LBP before 5 minutes of start time | ||
* @notice it can be invoked by anyone only once | ||
*/ | ||
function startLbp() external { | ||
uint256 startTime; | ||
uint256 buffer = 5 minutes; | ||
bool isSwapEnabled = lbp.getSwapEnabled(); | ||
(startTime, , ) = lbp.getGradualWeightUpdateParams(); | ||
require(state == TaskState.Waiting, "LBPManager: started"); | ||
require( | ||
block.timestamp > startTimeEndTime[0] - buffer, | ||
"LBPManager: not the right time" | ||
); | ||
state = TaskState.Started; | ||
if (!isSwapEnabled) { | ||
lbp.setSwapEnabled(true); | ||
} | ||
} | ||
|
||
/** | ||
* @dev ends LBP once end time is reached | ||
* @notice it can be invoked by anyone only once | ||
*/ | ||
function endLbp() external { | ||
uint256 endTime; | ||
bool isSwapEnabled = lbp.getSwapEnabled(); | ||
(, endTime, ) = lbp.getGradualWeightUpdateParams(); | ||
require(state == TaskState.Started, "LBPManager: !started or ended"); | ||
require( | ||
block.timestamp >= startTimeEndTime[1], | ||
"LBPManager: after >= end time" | ||
); | ||
state = TaskState.Ended; | ||
if (isSwapEnabled) { | ||
lbp.setSwapEnabled(false); | ||
} | ||
} | ||
|
||
/** | ||
* @dev Exit pool or remove liquidity from pool. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This documentation is wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. documentation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation on the line linked to this comment. "Exit pool or remove liquidity from pool." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That documentation is completely wrong for setSwapEnabled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, This documentation is for |
||
* @param _receiver Address of the liquidity receiver, after exiting the LBP. | ||
|
@@ -302,6 +351,11 @@ contract LBPManager { | |
* @param _swapEnabled Enables/disables swapping. | ||
*/ | ||
function setSwapEnabled(bool _swapEnabled) external onlyAdmin { | ||
require( | ||
block.timestamp >= startTimeEndTime[0] && | ||
block.timestamp < startTimeEndTime[1], | ||
"LBPManager: only between start time and end time" | ||
); | ||
lbp.setSwapEnabled(_swapEnabled); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.