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 farmer tax to contracts with TaxCollector #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

0xKiwi
Copy link

@0xKiwi 0xKiwi commented Aug 29, 2020

This PR adds a farmer tax of 1% from all farming contracts and adds a TaxCollector contract.

@0xKiwi 0xKiwi marked this pull request as ready for review September 1, 2020 23:46
Copy link

@tkporter tkporter left a comment

Choose a reason for hiding this comment

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

Nothing too thorough but some things I spotted :)

farmsToTax = farms;
}

function addFarm(address farm) external {
Copy link

Choose a reason for hiding this comment

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

This feels like it should be locked down, maybe just the beneficiary? Or maybe an owner? Otherwise anyone could create their own FarmPool with their own withdrawTax implementation that could do potentially do naughty things

}

function collectTaxes() external {
for (uint256 i = 0; i < farmsToTax.length; i++) {
Copy link

Choose a reason for hiding this comment

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

If farmsToTax is really large (unlikely, but still worth considering), this function could end up consuming a prohibitively large amount of gas, even to the point where this function could not be called. I think a good pattern could be to make this function collectAllTaxes and then have a separate collectTaxes(uint256 farmIndex) that can be used for collecting from specific farms

uniFactory = uniFactory_;
uniRouter = uniRouter_;
hamToken = HamToken(hamToken_);
beneficiary = beneficiary_;
Copy link

Choose a reason for hiding this comment

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

Wonder if the beneficiary should be able to change the beneficiary

for (uint256 i = 0; i < farmsToTax.length; i++) {
FarmPool(farmsToTax[i]).withdrawTax();
}
address uniswap_pair = UniswapV2Library.pairFor(uniFactory, weth, address(hamToken));
Copy link

Choose a reason for hiding this comment

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

small nit: change to camelCase?

(uint256 reserves1, uint256 reserves2, ) = pair.getReserves();
uint256 balance = hamToken.balanceOf(address(this));
uint256 amountOut = IUniswapV2Router01(uniRouter).getAmountOut(balance, reserves1, reserves2);
address[] memory path = new address[](2);
Copy link

Choose a reason for hiding this comment

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

nit: is it possible to pass an array literal to swapTokensForExactETH instead?

address[] memory path = new address[](2);
path[0] = address(hamToken);
path[1] = weth;
uint256[] memory amounts = IUniswapV2Router01(uniRouter).swapTokensForExactETH(balance, amountOut, path, beneficiary, block.timestamp);
Copy link

Choose a reason for hiding this comment

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

I'm curious why you'd want to even convert to eth here instead of just having the taxes remain as ham

address[] memory path = new address[](2);
path[0] = address(hamToken);
path[1] = weth;
uint256[] memory amounts = IUniswapV2Router01(uniRouter).swapTokensForExactETH(balance, amountOut, path, beneficiary, block.timestamp);
Copy link

Choose a reason for hiding this comment

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

I think balance and amountOut are flipped
https://uniswap.org/docs/v2/smart-contracts/router01/#swaptokensforexacteth

Anyways I think if you used https://uniswap.org/docs/v2/smart-contracts/router01/#swapexacttokensforeth you wouldn't have to worry about any getAmountOut voodoo up above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants