MirrorgateFeeLibraryV01.sol 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: BUSL-1.1
  2. pragma solidity 0.7.6;
  3. pragma abicoder v2;
  4. import "../interfaces/IMirrorgateFeeLibrary.sol";
  5. import "../Pool.sol";
  6. import "../Factory.sol";
  7. // libraries
  8. import "@openzeppelin/contracts/math/SafeMath.sol";
  9. contract MirrorgateFeeLibraryV01 is IMirrorgateFeeLibrary, Ownable, ReentrancyGuard {
  10. using SafeMath for uint256;
  11. uint256 public constant BP_DENOMINATOR = 10000;
  12. constructor(address _factory) {
  13. require(_factory != address(0x0), "FeeLibrary: Factory cannot be 0x0");
  14. factory = Factory(_factory);
  15. }
  16. //---------------------------------------------------------------------------
  17. // VARIABLES
  18. Factory public factory;
  19. uint256 public lpFeeBP; // fee basis points for lp holders
  20. uint256 public protocolFeeBP; // fee basis points for xMirrorgate
  21. uint256 public eqFeeBP; // fee basis points for eqFeeBP
  22. uint256 public eqRewardBP; // fee basis points for eqRewardBP
  23. //---------------------------------------------------------------------------
  24. // EVENTS
  25. event FeesUpdated(uint256 lpFeeBP, uint256 protocolFeeBP);
  26. function getFees(
  27. uint256, /*_srcPoolId*/
  28. uint256, /*_dstPoolId*/
  29. uint16, /*_dstChainId*/
  30. address, /*_from*/
  31. uint256 _amountSD
  32. ) external view override returns (Pool.SwapObj memory s) {
  33. // calculate the xMirrorgate Fee.
  34. s.protocolFee = _amountSD.mul(protocolFeeBP).div(BP_DENOMINATOR);
  35. // calculate the LP fee. booked at remote
  36. s.lpFee = _amountSD.mul(lpFeeBP).div(BP_DENOMINATOR);
  37. // calculate the equilibrium Fee and reward
  38. s.eqFee = _amountSD.mul(eqFeeBP).div(BP_DENOMINATOR);
  39. s.eqReward = _amountSD.mul(eqRewardBP).div(BP_DENOMINATOR);
  40. return s;
  41. }
  42. function setFees(
  43. uint256 _lpFeeBP,
  44. uint256 _protocolFeeBP,
  45. uint256 _eqFeeBP,
  46. uint256 _eqRewardBP
  47. ) external onlyOwner {
  48. require(_lpFeeBP.add(_protocolFeeBP).add(_eqFeeBP).add(_eqRewardBP) <= BP_DENOMINATOR, "FeeLibrary: sum fees > 100%");
  49. require(eqRewardBP <= eqFeeBP, "FeeLibrary: eq fee param incorrect");
  50. lpFeeBP = _lpFeeBP;
  51. protocolFeeBP = _protocolFeeBP;
  52. eqFeeBP = _eqFeeBP;
  53. eqRewardBP = _eqRewardBP;
  54. emit FeesUpdated(lpFeeBP, protocolFeeBP);
  55. }
  56. function getVersion() external pure override returns (string memory) {
  57. return "1.0.0";
  58. }
  59. }