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 Simplified Harvester #2222

Merged
merged 23 commits into from
Oct 2, 2024
Merged

Add Simplified Harvester #2222

merged 23 commits into from
Oct 2, 2024

Conversation

shahthepro
Copy link
Collaborator

Code Change Checklist

To be completed before internal review begins:

  • The contract code is complete
  • Executable deployment file
  • Fork tests that test after the deployment file runs
  • Unit tests *if needed
  • The owner has done a full checklist review of the code + tests

Internal review:

  • Two approvals by internal reviewers

Deploy checklist

Two reviewers complete the following checklist:

- [ ] All deployed contracts are listed in the deploy PR's description
- [ ] Deployed contract's verified code (and all dependencies) match the code in master
- [ ] The transactions that interacted with the newly deployed contract match the deploy script.
- [ ] Governance proposal matches the deploy script
- [ ] Smoke tests pass after fork test execution of the governance proposal

Copy link

github-actions bot commented Sep 9, 2024

Warnings
⚠️ 👀 This PR needs at least 2 reviewers

Generated by 🚫 dangerJS against 3f2c37b

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 0% with 62 lines in your changes missing coverage. Please review.

Project coverage is 53.50%. Comparing base (d0bafdc) to head (3f2c37b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
contracts/contracts/harvest/OETHBaseHarvester.sol 0.00% 62 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2222      +/-   ##
==========================================
- Coverage   54.32%   53.50%   -0.83%     
==========================================
  Files          78       79       +1     
  Lines        4009     4071      +62     
  Branches     1047      816     -231     
==========================================
  Hits         2178     2178              
- Misses       1828     1890      +62     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

openzeppelin-code bot commented Sep 9, 2024

Add Simplified Harvester

Generated at commit: 1ac651be2d9f4640c09eac242b532fb6aee99f87

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
3
3
0
18
42
66
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

* sends it to the Strategist multisig.
* Anyone can call it.
*/
function harvest() external {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor thing - anyone can call harvest.

If we are trying to operate by using harvestAndSwap(), harvest() being before called would cancel the swap or remove most of the areo from being swappable. Over any given time range we'd probably be operating either in auto harvest() mode, or in manual harvestAndSwap() mode, but overlapping both calls.

It's probably not worth adding any complications around locking out harvest though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that's a good point. I was thinking if we need to schedule harvest on Defender, we need this method to be publicly callable.

Also, if the contract doesn't have enough AERO for the swap, the strategist can do transfer to this contract in the same multisig tx (and it will swap & refund any leftover AERO back to the strategist)

Copy link
Member

Choose a reason for hiding this comment

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

I would argue that it is worth adding a "harvestEnabled" boolean settable by the strategist. This way we can disable the public callable harvest function when required. I know it is additional complexity - which I also don't like.

But just 1 malicious actor is required and they can disable the convenient harvestAndSwap function for us (by calling harvest()) and we need to perform swapping and distributing the fees manually. Granted there is little incentive for anyone to be doing such a thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a valid concern. However I don't think calling harvest() before we do a harvestAndSwap disables us from using that function. We can always transfer AERO to that contract in the same tx as harvestAndSwap to use it.

I'm trying to avoid any sort of storage variables to not mess up the storage layout when we start inheriting AbstractHarvester in future. One alternative I can think of is:

  • in harvestAndSwap, when there isn't enough funds in the contracts, it can do a transferFrom(strategist, address(this)) for the difference. This means that strategist has to approve the Harvester contract to move AERO on its behalf but that should be fine I guess.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have went ahead made the change to transferFrom, let me know if you have any further comments/suggestion on this one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just made the harvest() method permissioned in addition to the above change. This concern should no longer be there

Copy link
Member

@sparrowDom sparrowDom left a comment

Choose a reason for hiding this comment

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

Left a couple of comments

* sends it to the Strategist multisig.
* Anyone can call it.
*/
function harvest() external {
Copy link
Member

Choose a reason for hiding this comment

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

I would argue that it is worth adding a "harvestEnabled" boolean settable by the strategist. This way we can disable the public callable harvest function when required. I know it is additional complexity - which I also don't like.

But just 1 malicious actor is required and they can disable the convenient harvestAndSwap function for us (by calling harvest()) and we need to perform swapping and distributing the fees manually. Granted there is little incentive for anyone to be doing such a thing.

@shahthepro shahthepro marked this pull request as ready for review September 12, 2024 12:05
if (aeroBalance < aeroToSwap) {
// Transfer in balance from the multisig as needed
// slither-disable-next-line unchecked-transfer arbitrary-send-erc20
aero.safeTransferFrom(
Copy link
Contributor

@clement-ux clement-ux Sep 12, 2024

Choose a reason for hiding this comment

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

I understand why you added this, but this seems a bit over-engineering to me. I would rather completely remove the public harvest() and keep only the ones that have the restricted call, to prevent front-running.

However, as I don't know what the project requirements are and this doesn't seem to be unsafe, I have no problem keeping it like this.

Has this been considered to create a new role, only for simple harvest, and grant this role to a OZ Relayer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Has this been considered to create a new role, only for simple harvest, and grant this role to a OZ Relayer?

Yep, that's an option. However, I didn't wanna complicate the storage layout. Sooner or later, we want the harvester to inherit from AbstractHarvester like on mainnet.

Thinking of it, I guess one option is to completely discard this contract and proxy when we plan to make that transition instead of trying to upgrade the implementation at that time

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a good idea indeed!

clement-ux
clement-ux previously approved these changes Sep 26, 2024
Copy link
Contributor

@clement-ux clement-ux left a comment

Choose a reason for hiding this comment

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

Permissioned harvest() looks way safer like this.
LGTM!

sparrowDom
sparrowDom previously approved these changes Sep 30, 2024
@shahthepro shahthepro dismissed stale reviews from sparrowDom and clement-ux via b6e40aa September 30, 2024 14:22
clement-ux
clement-ux previously approved these changes Sep 30, 2024
Copy link
Contributor

@clement-ux clement-ux left a comment

Choose a reason for hiding this comment

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

LGTM 👍

sparrowDom
sparrowDom previously approved these changes Sep 30, 2024
Copy link
Member

@sparrowDom sparrowDom left a comment

Choose a reason for hiding this comment

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

LGTM

* [OETHb] Deploy 015 - Harvester

* Update slither DB
@shahthepro shahthepro dismissed stale reviews from sparrowDom and clement-ux via 3f2c37b October 2, 2024 10:01
@shahthepro shahthepro merged commit 44559cf into master Oct 2, 2024
11 of 14 checks passed
@shahthepro shahthepro deleted the shah/simplified-harvester branch October 2, 2024 10:01
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.

4 participants