-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeeManager.sol
75 lines (59 loc) · 2.15 KB
/
FeeManager.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "hardhat/console.sol";
import "./escrow/IWegaERC20Escrow.sol";
import "./escrow/IEscrow.sol";
import "./roles/WegaProtocolAdminRole.sol";
import "./events/IFeeManagerEvents.sol";
import "./IFeeManager.sol";
import "./utils/Distribution.sol";
import "./games/IWega.sol";
/**
* @title GameController (MVP)
* @author @RasenGUY @Daosourced.
* Fee manager contract that handles the attribution of fees
*/
contract FeeManager is WegaProtocolAdminRole, IFeeManager, IFeeManagerEvents, UUPSUpgradeable {
using Distribution for uint256;
/**@notice fee applier to feeRule */
mapping(address => FeeConfig) internal _feeRules;
function initialize() public initializer {
__UUPSUpgradeable_init();
__FeeManager_init();
}
function __FeeManager_init() internal onlyInitializing {
__FeeManager_init_unchained();
__WegaProtocolAdminRole_init();
}
function __FeeManager_init_unchained() internal onlyInitializing {}
function _setFeeConfig(FeeConfig memory config) internal {
_feeRules[config.applier] = config;
emit SetFeeRule(config.applier, config.feeTaker, config.feeShare);
}
function setFeeConfigs(FeeConfig[] memory configs) external onlyWegaProtocolAdmin {
for(uint i = 0; i < configs.length; i++) {
_setFeeConfig(configs[i]);
}
}
function calculateFeesForTransfer(
address applier,
uint256 transferAmount
) external view override returns (
address feeTaker,
uint256 feeAmount,
uint256 sendAmount
) {
FeeConfig memory config = getFeeRule(applier);
feeAmount = transferAmount.calculateShare(config.feeShare);
feeTaker = config.feeTaker;
sendAmount = transferAmount - feeAmount;
}
function shouldApplyFees(address applier) public view override returns (bool shouldApply) {
return getFeeRule(applier).shouldApply;
}
function getFeeRule(address applier) public view returns (FeeConfig memory feeRule) {
feeRule = _feeRules[applier];
}
function _authorizeUpgrade(address newImplementation) internal onlyOwner override {}
}