Skip to content
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

Add thoughts for possibility of start earning #18

Closed
wants to merge 2 commits into from

Conversation

toninorair
Copy link
Contributor

No description provided.

Copy link

LCOV of commit da7d764 during Forge Coverage #79

Summary coverage rate:
  lines......: 20.5% (27 of 132 lines)
  functions..: 17.0% (8 of 47 functions)
  branches...: no data found

Files changed coverage rate:
                           |Lines       |Functions  |Branches    
  Filename                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================
  src/WrappedM.sol         |13.9%    108|11.4%    35|    -      0

⛔ The code coverage is too low: 20.45. Expected at least 95.

@deluca-mike deluca-mike force-pushed the feat/fixes-suggestions branch 4 times, most recently from f5f3f4c to 1ad5b73 Compare June 27, 2024 14:36
@toninorair toninorair marked this pull request as draft July 1, 2024 14:26
Copy link
Member

@PierrickGT PierrickGT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue I see with being able to start/stop when the wrapper is earning, is the difficulty to account for earned WM between earning and non earning period.
For example:

  • at t0, the wrapper is earning and one user starts earning WM and we record the index at which he started earning
  • at t1, the wrapper stops earning but the user is still earning and nobody calls stopEarningFor on behalf of the user
  • at t2, the wrapper starts earning again, the user then decide to claim their yield. Since they haven't claimed or stopped earning before, their last recorded index is the one at t0 and the current index is the one at t2, so they can claim all the yield between t0 and t2 when they should only be able to claim the yield between t0 and t1.

One fix could be to store two indexes:

  • the one when startEarningM was last called
  • the one when stopEarningM was last called

This way, you could claim the yield between t0 and t1 as well as the yield between t2 and a future t3 but not in between t1 and t2. That being said, if you haven't claimed before stopEarningM is called again, you would forfeit any yield you haven't claimed.

src/WrappedM.sol Show resolved Hide resolved
@@ -89,7 +117,7 @@ contract WrappedM is IWrappedM, Migratable, ERC20Extended {
_addTotalEarningSupply(rawBalance_, currentIndex_);
}

function stopEarningFor(address account_) external {
function stopEarningFor(address account_) external onlyWhenEarner {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think onlyWhenEarner is necessary since you can't be earning if the wrapper hasn't been earning in the past and you should be able to stop earning if the wrapper is not earning anymore.

Suggested change
function stopEarningFor(address account_) external onlyWhenEarner {
function stopEarningFor(address account_) external {

@@ -48,6 +57,22 @@ contract WrappedM is IWrappedM, Migratable, ERC20Extended {

/* ============ Interactive Functions ============ */

function wrap(address destination_, uint256 amount_) external onlyWhenEarner {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users should be able to wrap even if the wrapper is not currently earning.

Suggested change
function wrap(address destination_, uint256 amount_) external onlyWhenEarner {
function wrap(address destination_, uint256 amount_) external {

uint128 public lastIndexOfTotalEarningSupply;

modifier onlyWhenEarner() {
if (isEarner == true) revert NotInEarnerState();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isEarner == true) revert NotInEarnerState();
if (!isEarner) revert NotInEarnerState();

Base automatically changed from feat/fixes-suggestions to feat/test-cleanup July 2, 2024 16:54
Base automatically changed from feat/test-cleanup to main July 2, 2024 17:02
@toninorair toninorair closed this Jul 3, 2024
@toninorair
Copy link
Contributor Author

One issue I see with being able to start/stop when the wrapper is earning, is the difficulty to account for earned WM between earning and non earning period. For example:

  • at t0, the wrapper is earning and one user starts earning WM and we record the index at which he started earning
  • at t1, the wrapper stops earning but the user is still earning and nobody calls stopEarningFor on behalf of the user
  • at t2, the wrapper starts earning again, the user then decide to claim their yield. Since they haven't claimed or stopped earning before, their last recorded index is the one at t0 and the current index is the one at t2, so they can claim all the yield between t0 and t2 when they should only be able to claim the yield between t0 and t1.

One fix could be to store two indexes:

  • the one when startEarningM was last called
  • the one when stopEarningM was last called

This way, you could claim the yield between t0 and t1 as well as the yield between t2 and a future t3 but not in between t1 and t2. That being said, if you haven't claimed before stopEarningM is called again, you would forfeit any yield you haven't claimed.

good idea, worth experimenting with it for the next version

@toninorair toninorair deleted the feat/thoughts-for-start-earning branch July 3, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants