From f94975b68fc7cb0e8ee2f745abd332689c37b019 Mon Sep 17 00:00:00 2001 From: Joseph Bergeron Date: Sun, 13 Feb 2022 15:47:53 -0500 Subject: [PATCH] Calculate additional bounties --- contracts/FeeOnlyBounty.sol | 9 +++++++++ contracts/IRevoBounty.sol | 5 +++++ contracts/farm-bot.sol | 17 ++++++++++++++--- contracts/mocks/MockRevoBounty.sol | 4 ++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/contracts/FeeOnlyBounty.sol b/contracts/FeeOnlyBounty.sol index 672fd3f..8836267 100644 --- a/contracts/FeeOnlyBounty.sol +++ b/contracts/FeeOnlyBounty.sol @@ -52,6 +52,15 @@ contract FeeOnlyBounty is Owned, IRevoBounty { } } + function calculateAdditionalBountyFee(TokenAmount[] memory _interestAccrued) + external + view + override + returns (TokenAmount[] memory output) + { + return new TokenAmount[](0); // intentionally returns empty list + } + function calculateBountyFee(TokenAmount[] memory _interestAccrued) external view diff --git a/contracts/IRevoBounty.sol b/contracts/IRevoBounty.sol index acbc594..582acc8 100644 --- a/contracts/IRevoBounty.sol +++ b/contracts/IRevoBounty.sol @@ -13,6 +13,11 @@ interface IRevoBounty { view returns (TokenAmount[] memory); + function calculateAdditionalBountyFee(TokenAmount[] calldata interestAccrued) + external + view + returns (TokenAmount[] memory); + function calculateReserveFee(TokenAmount[] calldata interestAccrued) external view diff --git a/contracts/farm-bot.sol b/contracts/farm-bot.sol index 93a6c34..4280b2f 100644 --- a/contracts/farm-bot.sol +++ b/contracts/farm-bot.sol @@ -202,10 +202,11 @@ contract FarmBot is ERC20, AccessControl { return tokenBalance; } - // convenience method for anyone considering calling claimRewards (who may want to compare bounty to gas cost) + // Private method used to calculate what tokens would be available for reinvestment if claimRewards were called + // right now. // 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) { + function calculateRewards() private returns (TokenAmount[] memory) { uint256[] memory _leftoverBalances = new uint256[]( rewardsTokens.length ); @@ -238,8 +239,18 @@ contract FarmBot is ERC20, AccessControl { _interestEarned[i] + _leftoverBalances[i] ); } + return _rewardsTokenBalances; + } - return revoBounty.calculateBountyFee(_rewardsTokenBalances); + // convenience methods for anyone considering calling claimRewards (who may want to compare bounty to gas cost) + function previewAdditionalBounty() external returns (TokenAmount[] memory) { + TokenAmount[] memory _rewardsTokenBalances = calculateRewards(); + return revoBounty.calculateAdditionalBountyFee(_rewardsTokenBalances); + } + + function previewBounty() external returns (TokenAmount[] memory) { + TokenAmount[] memory _rewardsTokenBalances = calculateRewards(); + return revoBounty.calculateBountyFee(_rewardsTokenBalances); } // Figure out best-case scenario amount of token we can get and swap diff --git a/contracts/mocks/MockRevoBounty.sol b/contracts/mocks/MockRevoBounty.sol index e6523f9..79be3d2 100644 --- a/contracts/mocks/MockRevoBounty.sol +++ b/contracts/mocks/MockRevoBounty.sol @@ -17,6 +17,10 @@ contract MockRevoBounty is IRevoBounty { return bounties; } + function calculateAdditionalBountyFee(TokenAmount[] calldata interestAccrued) external override view returns (TokenAmount[] memory) { + return new TokenAmount[](0); + } + function calculateReserveFee(TokenAmount[] calldata interestAccrued) external override view returns (TokenAmount[] memory) { return bounties; }