2021-02-13 09:11:50 +00:00
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
|
2021-05-11 16:16:23 +00:00
|
|
|
/**
|
|
|
|
* @title Fee.
|
|
|
|
* @dev Calculate Fee.
|
|
|
|
*/
|
|
|
|
|
2021-02-13 09:11:50 +00:00
|
|
|
import { DSMath } from "../../common/math.sol";
|
|
|
|
import { Basic } from "../../common/basic.sol";
|
|
|
|
|
|
|
|
abstract contract FeeResolver is DSMath, Basic {
|
|
|
|
/**
|
|
|
|
* @dev Calculate fee
|
2021-05-07 16:36:52 +00:00
|
|
|
* @notice Calculates fee on a given amount
|
2021-03-21 12:45:29 +00:00
|
|
|
* @param amount token amount to caculate fee.
|
|
|
|
* @param fee fee percentage. Eg: 1% => 1e17, 100% => 1e18.
|
|
|
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
|
|
|
* @param setId Set total amount at this ID in `InstaMemory` Contract.
|
|
|
|
* @param setIdFee Set only fee amount at this ID in `InstaMemory` Contract.
|
2021-02-13 09:11:50 +00:00
|
|
|
*/
|
|
|
|
function calculateFee(
|
|
|
|
uint amount,
|
|
|
|
uint fee,
|
|
|
|
uint getId,
|
|
|
|
uint setId,
|
|
|
|
uint setIdFee
|
|
|
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
|
|
|
uint _amt = getUint(getId, amount);
|
|
|
|
|
|
|
|
uint feeAmt = wmul(_amt, fee);
|
|
|
|
|
|
|
|
uint totalAmt = add(_amt, feeAmt);
|
|
|
|
|
|
|
|
setUint(setId, totalAmt);
|
|
|
|
setUint(setIdFee, feeAmt);
|
|
|
|
}
|
2021-03-21 12:45:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Calculate amount minus fee
|
2021-05-07 16:36:52 +00:00
|
|
|
* @notice Calculates amount minus fee
|
2021-03-21 12:45:29 +00:00
|
|
|
* @param amount token amount to caculate fee.
|
|
|
|
* @param fee fee percentage. Eg: 1% => 1e17, 100% => 1e18.
|
|
|
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
|
|
|
* @param setIdAmtMinusFee Set amount minus fee amount at this ID in `InstaMemory` Contract.
|
|
|
|
* @param setIdFee Set only fee amount at this ID in `InstaMemory` Contract.
|
|
|
|
*/
|
|
|
|
function calculateAmtMinusFee(
|
|
|
|
uint amount,
|
|
|
|
uint fee,
|
|
|
|
uint getId,
|
|
|
|
uint setIdAmtMinusFee,
|
|
|
|
uint setIdFee
|
|
|
|
) external payable {
|
|
|
|
uint _amt = getUint(getId, amount);
|
|
|
|
|
|
|
|
uint feeAmt = wmul(_amt, fee);
|
|
|
|
uint amountMinusFee = sub(_amt, feeAmt);
|
|
|
|
|
|
|
|
setUint(setIdAmtMinusFee, amountMinusFee);
|
|
|
|
setUint(setIdFee, feeAmt);
|
|
|
|
}
|
2021-02-13 09:11:50 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 12:26:22 +00:00
|
|
|
contract ConnectV2Fee is FeeResolver {
|
2021-02-13 09:11:50 +00:00
|
|
|
string public constant name = "Fee-v1";
|
|
|
|
}
|