-
Notifications
You must be signed in to change notification settings - Fork 4
/
FeeAccount.sol
58 lines (45 loc) · 2.24 KB
/
FeeAccount.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
/* Contract to collect fees from system
TODO: calculateExchangeFee + Exchange params and setters
*/
pragma solidity 0.4.24;
import "./generic/SafeMath.sol";
import "./generic/SystemAccount.sol";
import "./interfaces/TransferFeeInterface.sol";
contract FeeAccount is SystemAccount, TransferFeeInterface {
using SafeMath for uint256;
struct TransferFee {
uint pt; // in parts per million (ppm) , ie. 2,000 = 0.2%
uint min; // with base unit of augmint token, eg. 2 decimals for token, eg. 310 = 3.1 ACE
uint max; // with base unit of augmint token, eg. 2 decimals for token, eg. 310 = 3.1 ACE
}
TransferFee public transferFee;
event TransferFeesChanged(uint transferFeePt, uint transferFeeMin, uint transferFeeMax);
constructor(address permissionGranterContract, uint transferFeePt, uint transferFeeMin, uint transferFeeMax)
public SystemAccount(permissionGranterContract) {
transferFee = TransferFee(transferFeePt, transferFeeMin, transferFeeMax);
}
function () external payable { // solhint-disable-line no-empty-blocks
// to accept ETH sent into feeAccount (defaulting fee in ETH )
}
function setTransferFees(uint transferFeePt, uint transferFeeMin, uint transferFeeMax)
external restrict("StabilityBoard") {
transferFee = TransferFee(transferFeePt, transferFeeMin, transferFeeMax);
emit TransferFeesChanged(transferFeePt, transferFeeMin, transferFeeMax);
}
function calculateTransferFee(address from, address to, uint amount) external view returns (uint256 fee) {
if (!permissions[from]["NoTransferFee"] && !permissions[to]["NoTransferFee"]) {
fee = amount.mul(transferFee.pt).div(1000000);
if (fee > transferFee.max) {
fee = transferFee.max;
} else if (fee < transferFee.min) {
fee = transferFee.min;
}
}
return fee;
}
function calculateExchangeFee(uint weiAmount) external view returns (uint256 weiFee) {
/* TODO: to be implemented and use in Exchange.sol. always revert for now */
require(weiAmount != weiAmount, "not yet implemented");
weiFee = transferFee.max; // to silence compiler warnings until it's implemented
}
}