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

Make FeeHandler able to distribute tokens #10247

Merged
merged 22 commits into from
Apr 12, 2023

Conversation

martinvol
Copy link
Contributor

@martinvol martinvol commented Apr 6, 2023

Description

Makes FeeHandler able to burn just a fraction of the fees (rather than 100%) and send it to the distribution. Please not this is not a production ready implementation, and as nonMento tokens will not be available in the short term, burning nonMento tokens is not fully supported (code is written but not properly tested). Some other features are also pending further testing, like rate limits.

Other changes

Describe any minor or "drive-by" changes here.

Tested

An explanation of how the changes were tested or an explanation as to why they don't need to be.

Related issues

  • Fixes #[issue number here]

Backwards compatibility

Brief explanation of why these changes are/are not backwards compatible.

Documentation

The set of community facing docs that have been added/modified because of this change

@martinvol martinvol requested a review from a team as a code owner April 6, 2023 15:40
@martinvol martinvol requested a review from a team April 6, 2023 15:40
.fromFixed();
celo.burn(balanceToBurn);

tokenState.toDistribute = balanceToProcess - balanceToBurn;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also add tokenState.toDistribute back ?

tokenState.toDistribute = tokenState.toDistribute + balanceToProcess - balanceToBurn;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

forgot the +=, nice catch


return
totalAmount
.subtract((price.multiply(maxSlippageFraction)).multiply(amountFraction))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we can remove the inner brackets

.subtract(price.multiply(maxSlippageFraction).multiply(amountFraction))

// }

// TODO move this to abstract class
function calculateMinAmount(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this method is identical in MentoFeeHandlerSeller and UniswapFeeHandlerSeller we could extract it to library

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix after merging

require(routerAddresses[sellTokenAddress].length > 0, "routerAddresses should be non empty");

// IERC20 token = IERC20(sellTokenAddress);
uint256 balanceToBurn = IERC20(sellTokenAddress).balanceOf(address(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check whether the balanceToBurn > 0 ?

Copy link
Contributor Author

@martinvol martinvol Apr 11, 2023

Choose a reason for hiding this comment

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

This contract assumes a bunch of checks were done by FeeHandler.sol, so those checks would be redundant.

emit ReceivedQuote(poolAddress, wouldGet);
if (wouldGet > bestRouterQuote) {
bestRouterQuote = wouldGet;
bestRouterIndex = i;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of saving bestRouterIndex we could save

bestRouterAddress
bestRouter

In such case we wouldn't have to retrieve it from storage on line 89 again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great point, this piece of code is not currently in use, so will fix after merging

@martinvol martinvol requested a review from a team as a code owner April 11, 2023 16:05
@martinvol martinvol merged commit af86d18 into martinvol/ultraGreen Apr 12, 2023
@martinvol martinvol deleted the martinvol/feeHandlerCleanup branch April 12, 2023 12:39
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