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 and test privileged rewards notifier role #12

Merged
merged 1 commit into from
Jan 14, 2024
Merged

Conversation

apbendi
Copy link
Collaborator

@apbendi apbendi commented Jan 4, 2024

This PR makes the notifyRewardsAmount a permissioned method which can only be updated by the an immutable rewards notifier that is set at deployment. It also adds a full set of tests for the notifyRewardsAmount method, which was previously untested.

@wildmolasses wildmolasses changed the title Add and test priveleged rewards notifier role Add and test privileged rewards notifier role Jan 4, 2024
Copy link
Collaborator

@alexkeating alexkeating left a comment

Choose a reason for hiding this comment

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

Looks good, I have some comments in the previous pr that are related. Also, I left a couple comments with some potential strengthening of tests.

test/UniStaker.t.sol Outdated Show resolved Hide resolved
test/UniStaker.t.sol Outdated Show resolved Hide resolved
@apbendi apbendi force-pushed the notifier branch 2 times, most recently from 1274ad0 to 728ed1f Compare January 10, 2024 02:36
Copy link
Collaborator

@wildmolasses wildmolasses left a comment

Choose a reason for hiding this comment

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

lgtm, one nit

view
returns (uint256 _boundedRewardAmount)
{
_boundedRewardAmount = bound(_rewardAmount, 200e6, 10_000_000e6);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: i don't love the lower bound of 200e6 because i don't know if it's suggested or enforced in the external contracts. in practice is it presumed to be higher than 200e6?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we don't know the tokens that will be used for sure, it's hard to pick reasonable ranges here. You might say, "well shouldn't work for all values?". Unfortunately you can't do that, because like many DeFi protocols that involve any kind of ratio between token amounts, there's an embedded assumption about the "reasonable" ranges in which values will fall.

For many contracts, this one included, it's possible generate scenarios where the token(s) contract(s) chosen would break the protocol due to the proliferation of rounding errors that would occur. For example, tokens where HUGE balances or tiny balances might (i.e. literally 1 with no decimals) break things. And even if the protocol itself wouldn't break (because it rounds conservatively to favor the contract, it would make writing meaningful tests nearly impossible.

So, long way of saying, we can't really lower the bottom bound without breaking the 1% rounding assumption I baked into the test cases. But this got me thinking: we can open up the upper bound without breaking the tests, so I did.

FWIW, the reason I chose e6 here was to simulate USDC's ERC20, which is likely the lowest precision token that might actually be chosen at only 6 decimals. And 200 USDC is well below what the real threshold is liable to be set to. So for this particular project, the ranges chosen are probably safe to be considered realistic.

@apbendi apbendi changed the base branch from stake-earn to main January 13, 2024 23:36
@apbendi apbendi changed the base branch from main to stake-earn January 13, 2024 23:37
Copy link

Coverage after merging notifier into stake-earn will be

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   UniStaker.sol97.40%94.44%90.91%100%132
   V3FactoryOwner.sol100%100%100%100%

@apbendi apbendi merged commit ba52d23 into stake-earn Jan 14, 2024
4 checks passed
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