-
Notifications
You must be signed in to change notification settings - Fork 1
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
Remove discounted fee calculation logic from Deployers and Farm factory updates #22
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9e348e0
Updated BaseFarmDeployer
arcantheon 78937d7
Updated other deployers
arcantheon df00a85
Updated farm factory
arcantheon 45acf80
Updated param in function getFees
arcantheon f2b4696
Updated Readme
arcantheon 06b706b
getFeeParams external call updates
arcantheon 5536a65
Merge branch 'dev' into wip/deployer-upgrades
mehultuteja 115cd26
Fixed test cases
mehultuteja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,92 +5,56 @@ import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeE | |
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import {IFarmFactory} from "./interfaces/IFarmFactory.sol"; | ||
|
||
/// @title BaseFarmDeployer contract of Demeter Protocol | ||
/// @notice Exposes base functionalities which will be useful in every deployer | ||
/// @author Sperax Foundation | ||
abstract contract BaseFarmDeployer is Ownable { | ||
using SafeERC20 for IERC20; | ||
|
||
address public constant SPA = 0x5575552988A3A80504bBaeB1311674fCFd40aD4B; | ||
address public constant USDS = 0xD74f5255D557944cf7Dd0E45FF521520002D5748; | ||
address public immutable factory; | ||
// Stores the address of farmImplementation. | ||
address public farmImplementation; | ||
uint256 public discountedFee; | ||
|
||
event FarmCreated(address farm, address creator, address indexed admin); | ||
event FeeCollected(address indexed creator, address token, uint256 amount, bool indexed claimable); | ||
event FeeCollected(address indexed creator, address token, uint256 amount); | ||
event FarmImplementationUpdated(address newFarmImplementation); | ||
event DiscountedFeeUpdated(uint256 oldDiscountedFee, uint256 newDiscountedFee); | ||
|
||
// Custom Errors | ||
error InvalidTokenPair(); | ||
error InvalidAddress(); | ||
|
||
constructor(address _factory) { | ||
_isNonZeroAddr(_factory); | ||
factory = _factory; | ||
} | ||
|
||
/// @notice Update farm implementation's address | ||
/// @dev only callable by owner | ||
/// @param _newFarmImplementation New farm implementation's address | ||
function updateFarmImplementation(address _newFarmImplementation) external onlyOwner { | ||
farmImplementation = _newFarmImplementation; | ||
emit FarmImplementationUpdated(_newFarmImplementation); | ||
} | ||
|
||
/// @notice An external function to update discountOnSpaUSDsFarms | ||
/// @param _discountedFee New desired discount on Spa/ USDs farms | ||
/// @dev _discountedFee cannot be more than 100 | ||
function updateDiscountedFee(uint256 _discountedFee) external onlyOwner { | ||
emit DiscountedFeeUpdated(discountedFee, _discountedFee); | ||
discountedFee = _discountedFee; | ||
} | ||
|
||
/// @notice A public view function to calculate fees | ||
/// @param _tokenA address of token A | ||
/// @param _tokenB address of token B | ||
/// @notice Order does not matter | ||
/// @return Fees to be paid in feeToken set in FarmFactory (mostly USDs) | ||
function calculateFees(address _tokenA, address _tokenB) external view returns (address, address, uint256, bool) { | ||
_isNonZeroAddr(_tokenA); | ||
_isNonZeroAddr(_tokenB); | ||
if (_tokenA == _tokenB) { | ||
revert InvalidTokenPair(); | ||
} | ||
return _calculateFees(_tokenA, _tokenB); | ||
/// @notice A public view function to get fees from Farm Factory | ||
/// @return feeReceiver of feeToken in feeAmount | ||
function getFees(address _deployerAccount) | ||
public | ||
view | ||
returns (address feeReceiver, address feeToken, uint256 feeAmount) | ||
{ | ||
(feeReceiver, feeToken, feeAmount) = IFarmFactory(factory).getFeeParams(_deployerAccount); | ||
} | ||
|
||
/// @notice Collect fee and transfer it to feeReceiver. | ||
/// @dev Function fetches all the fee params from sfarmFactory. | ||
function _collectFee(address _tokenA, address _tokenB) internal virtual { | ||
(address feeReceiver, address feeToken, uint256 feeAmount, bool claimable) = _calculateFees(_tokenA, _tokenB); | ||
/// @dev Function fetches all the fee params from farmFactory. | ||
function _collectFee() internal virtual { | ||
// Here msg.sender would be the deployer/creator of the farm which will be checked in privileged deployer list | ||
(address feeReceiver, address feeToken, uint256 feeAmount) = getFees(msg.sender); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly call the IFarmFactory() contract. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved 06b706b |
||
if (feeAmount != 0) { | ||
IERC20(feeToken).safeTransferFrom(msg.sender, feeReceiver, feeAmount); | ||
emit FeeCollected(msg.sender, feeToken, feeAmount, claimable); | ||
emit FeeCollected(msg.sender, feeToken, feeAmount); | ||
} | ||
} | ||
|
||
/// @notice An internal function to calculate fees | ||
/// @notice and return feeReceiver, feeToken, feeAmount and claimable | ||
function _calculateFees(address _tokenA, address _tokenB) internal view returns (address, address, uint256, bool) { | ||
(address feeReceiver, address feeToken, uint256 feeAmount) = IFarmFactory(factory).getFeeParams(); | ||
if (IFarmFactory(factory).isPrivilegedDeployer(msg.sender)) { | ||
// No fees for privileged deployers | ||
feeAmount = 0; | ||
return (feeReceiver, feeToken, feeAmount, false); | ||
} | ||
if (_checkToken(_tokenA) || _checkToken(_tokenB)) { | ||
// DiscountedFee if either of the token is SPA or USDs | ||
// This fees is claimable | ||
return (feeReceiver, feeToken, discountedFee, true); | ||
} else { | ||
// No discount because neither of the token is SPA or USDs | ||
return (feeReceiver, feeToken, feeAmount, false); | ||
} | ||
} | ||
|
||
/// @notice Check if a token is either SPA | USDs. | ||
/// @param _token Address of the desired token. | ||
function _checkToken(address _token) internal pure returns (bool) { | ||
return _token == SPA || _token == USDS; | ||
} | ||
|
||
/// @notice Validate address | ||
function _isNonZeroAddr(address _addr) internal pure { | ||
if (_addr == address(0)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark this function as external
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved 06b706b