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

RewardsManager test refactor and cleanup #718

Merged
merged 18 commits into from
Apr 3, 2023
Merged

Conversation

ith-harvey
Copy link
Contributor

@ith-harvey ith-harvey commented Mar 30, 2023

Description of change

High level

  • Refactored RewardsManager.t.sol into Rewards/RewardsManager.t.sol & Rewards/RewadsDSTestPlus.t.sol

@ith-harvey ith-harvey changed the base branch from master to develop March 30, 2023 18:53
assertEq(bETimestamp, timestamp);
assertEq(bEInterest, interest);
assertEq(bEBurned, burned);
assertEq(burned, tokensToBurn);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MikeHathaway I was curious on how you would reccomend I compare these. The equation should be rewardsToClaimer + rewardsToUpdater = burned * 0.9 is that correct?

Copy link
Collaborator

@MikeHathaway MikeHathaway Mar 30, 2023

Choose a reason for hiding this comment

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

Not quite. The claimer has a 5% claim factor, and the updaters have a 5% claim factor, but the claim must actually be made so it's unclear how much rewards will actually be distributed. Also, there's a bit of a first come first serve element as total rewards are capped at burned * 0.8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a discussion with Mike I deceided to not go through the cumbersome effort of attempting to compute the rewards in _assertBurn(). Updated things accordingly.

/***********************/

// need to retrieve the position managers index set since positionIndexes are stored unordered in EnnumerableSets
secondIndexes = _positionManager.getPositionIndexes(tokenIdOne); //TODO: investigate why commenting this out or keeping it doesn't do anything
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MikeHathaway noticing that by removing this, the function still passes. Wanted to confirm I'm not missing something here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should need that line in order to pass as otherwise it should attempt to make the same set of movements that were made in the previous movement (secondIndexes) not updated. The comment is about getting the current order from the contract since the contract's order won't maintain order

Copy link
Contributor Author

@ith-harvey ith-harvey Mar 31, 2023

Choose a reason for hiding this comment

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

I am able to pass without this line in the tests... Here are the two outputs:

commented out, uses original secondIndexes variable above:

secondIndexes[0] = 2556;
        secondIndexes[1] = 2557;
        secondIndexes[2] = 2558;
        secondIndexes[3] = 2559;
        secondIndexes[4] = 2560;

Tests still pass / no change needed if I comment it out.

uncommented:

Logs:
  secondInd[0]: 2559
  secondInd[1]: 2556
  secondInd[2]: 2557
  secondInd[3]: 2558

I will uncomment them as requested but want you to know it doesn't have an effect on the test.

@ith-harvey ith-harvey marked this pull request as ready for review March 31, 2023 23:55
@ith-harvey ith-harvey changed the title Rew man test cleanup RewardsManager test refactor and cleanup Apr 1, 2023
Copy link
Contributor

@EdNoepel EdNoepel left a comment

Choose a reason for hiding this comment

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

Few comments, but looks good.





Copy link
Contributor

Choose a reason for hiding this comment

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

nit: doge says "much blank, very whitespace"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

; ) 🐶 that he does. Fixed -> a636196

uint256 tokenId,
uint256 reward,
uint256[] memory epochsClaimed
) internal {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed -> a636196

deal(address(quote), minter, mintAmount * indexes.length);

// approve tokens
collateral.approve(address(pool), type(uint256).max);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the minter need collateral?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope! fixed -> a636196

uint256 randomIndex = randomInRange(0, copyOfArray.length - i - 1);
subsetArray[i] = copyOfArray[randomIndex];
copyOfArray[randomIndex] = copyOfArray[copyOfArray.length - i - 1];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This algorithm copies an element from the back of the array into the random index you plucked from copyOfArray? Is this a strategy to avoid duplicates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This existed in the previous versions of the tests... I merely copied it over.

After some review it looks like it does in fact limit duplicates from existing in the subsetArray ill be it in a very confusing way.

Also noticed that randomInRange appears to not reproduce random results when I tested it in a unit test...

However I think this work should be done in a separate PR as it's outside of scope of this change. Let me know if you see it differently.

Copy link
Collaborator

@MikeHathaway MikeHathaway left a comment

Choose a reason for hiding this comment

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

LGTM. Much cleaner like this

@ith-harvey ith-harvey merged commit 492e80a into develop Apr 3, 2023
@ith-harvey ith-harvey deleted the rew-man-test-cleanup branch April 11, 2023 17:14
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.

3 participants