-
Notifications
You must be signed in to change notification settings - Fork 4
Chore: Automate end start swapping #235
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
base: main
Are you sure you want to change the base?
Changes from 2 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,12 @@ import "../utils/interface/ILBP.sol"; | |
| */ | ||
| // solhint-disable-next-line max-states-count | ||
| contract LBPManager { | ||
| enum TaskState { | ||
| Waiting, | ||
| Started, | ||
| Ended | ||
| } | ||
| TaskState public state; | ||
| // Constants | ||
| uint256 private constant HUNDRED_PERCENT = 1e18; // Used in calculating the fee. | ||
|
|
||
|
|
@@ -192,7 +198,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 +240,47 @@ contract LBPManager { | |
| vault.joinPool(lbp.getPoolId(), address(this), address(this), request); | ||
| } | ||
|
|
||
| /** | ||
| * @dev start LBP just before one block | ||
| * @notice it can be invoked by anyone only once | ||
| */ | ||
| function startLbp() external { | ||
| uint256 startTime; | ||
| uint256 blockTime = 5 minutes; | ||
| bool isSwapEnabled = lbp.getSwapEnabled(); | ||
| (startTime, , ) = lbp.getGradualWeightUpdateParams(); | ||
| require( | ||
| !isSwapEnabled && state == TaskState.Waiting, | ||
| "LBPManager: swapping already active" | ||
|
||
| ); | ||
| require( | ||
| block.timestamp > startTime - blockTime, | ||
| "LBPManager: Only once block before start time" | ||
|
||
| ); | ||
| state = TaskState.Started; | ||
| lbp.setSwapEnabled(true); | ||
| } | ||
|
|
||
| /** | ||
| * @dev ends LBP just after one block | ||
| * @notice it can be invoked by anyone only once | ||
| */ | ||
| function endLbp() external { | ||
| uint256 endTime; | ||
| bool isSwapEnabled = lbp.getSwapEnabled(); | ||
| (, endTime, ) = lbp.getGradualWeightUpdateParams(); | ||
| require( | ||
| isSwapEnabled && state == TaskState.Started, | ||
| "LBPManager: swapping already active" | ||
|
||
| ); | ||
| require( | ||
| block.timestamp > endTime, | ||
| "LBPManager: Only once block before start time" | ||
|
||
| ); | ||
| state = TaskState.Ended; | ||
| 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
Contributor
Author
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
Contributor
Author
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 +349,7 @@ contract LBPManager { | |
| * @param _swapEnabled Enables/disables swapping. | ||
| */ | ||
| function setSwapEnabled(bool _swapEnabled) external onlyAdmin { | ||
| require(TaskState.Ended != state, "LBPManager: LBP ended"); | ||
|
||
| 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.