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

feat(multi-rewards): Add support for multi-reward Ubeswap farms #9

Merged
merged 3 commits into from
Feb 8, 2022

Conversation

jophish
Copy link
Collaborator

@jophish jophish commented Feb 8, 2022

Does what it says on the tin. This is untested, but does compile. The deploy script hasn't been updated since I don't even know if any MoolaStakingReward contracts are deployed on Alfajores, so you'll have to comment main out of the deploy script if you want to compile.

This definitely needs tests. Ideally, we spin up/tear down a local chain and deploy "dummy" contracts each time to test against for quicker iteration/validation. If getting that set up proves to be too much frontloaded overhead, a stopgap could be manually deploying contracts and testing on Alfajores, but that's obviously not a long-term solution.

}

assert(_paths.length == _rewardsTokens.length);
paths = _paths;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This copying of a dynamic nested array is weird... Solidity has (had? no idea...) a bunch of weird constraints around nested arrays. This does compile, but I'm not sure if we'll hit runtime errors or not.

revoBounty = IRevoBounty(_revoBounty);

stakingToken = IUniswapV2Pair(address(stakingRewards.stakingToken()));
stakingToken = IUniswapV2Pair(_stakingToken);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have to pass this in manually now rather than getting it from the stakingRewards contract, since the IMoolaStakingRewards interface does not publicly expose the stakingToken address. The actual implementation of MoolaStakingRewards does expose it publicly, but the interface does... We could just update the interface to expose the stakingToken address, but that feels a little weird to me.

_rewardsTokenBalances[0] = TokenAmount(rewardsToken, _interestEarned + _leftoverBalance);
// Annoyingly, the MoolaStakingRewards.earnedExternal method is not declared as a view, so we cannot declare this
// method as a view itself.
function previewBounty() external returns (TokenAmount[] memory) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is annoying... but not sure how to work around this.

Copy link
Contributor

Choose a reason for hiding this comment

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

does that mean it will cost gas now to call this? not great..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not necessarily? I think you can do an e.g., farmBotContract.methods.previewBounty().call() using web3 which will emulate the call locally which should be fine? Although not really sure to be honest.

Copy link
Contributor

@cajubelt cajubelt left a comment

Choose a reason for hiding this comment

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

asked for docs in 1 place but otherwise looks good!

contracts/farm-bot.sol Outdated Show resolved Hide resolved
path0 = _path0;
path1 = _path1;
function updatePaths(address[][2][] memory _paths) external onlyOwner {
paths = _paths;
Copy link
Contributor

Choose a reason for hiding this comment

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

should there be a check here to make sure the rewards tokens are still at the ends of the new paths?

Copy link
Contributor

Choose a reason for hiding this comment

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

otherwise the owner could force farm bots to buy an unrelated token, and drive up its price or something. kind of a weird threat model admittedly but easy enough to prevent

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 probably a good idea, although that check is not super trivial to implement. It's not obvious, but the claimRewards call where the swapping occurs will actually fail if the end tokens in the path don't align with the constituent tokens of the LP, since we won't have as much of token0/token1 as we say we do when calling the router's addLiquidity method. (I'm pretty sure this is true, not 100% 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.

#11

_rewardsTokenBalances[0] = TokenAmount(rewardsToken, _interestEarned + _leftoverBalance);
// Annoyingly, the MoolaStakingRewards.earnedExternal method is not declared as a view, so we cannot declare this
// method as a view itself.
function previewBounty() external returns (TokenAmount[] memory) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does that mean it will cost gas now to call this? not great..

contracts/farm-bot.sol Show resolved Hide resolved
contracts/farm-bot.sol Show resolved Hide resolved
contracts/farm-bot.sol Show resolved Hide resolved
contracts/farm-bot.sol Outdated Show resolved Hide resolved
@jophish jophish merged commit e936944 into main Feb 8, 2022
@jophish jophish deleted the jophish/multi-reward branch February 8, 2022 05:53
@jophish jophish mentioned this pull request Feb 8, 2022
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