Skip to content

Commit

Permalink
add _getFeeAmounts
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenSwen committed Jan 30, 2025
1 parent a95f611 commit e493044
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions contracts/extensions/FeeTaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract FeeTaker is IPostInteraction, AmountGetterWithFee, Ownable {
using UniERC20 for IERC20;
using MakerTraitsLib for MakerTraits;

bytes1 internal constant _CUSTOM_RECEIVER_FLAG = 0x01;
bytes1 private constant _CUSTOM_RECEIVER_FLAG = 0x01;

/**
* @dev The caller is not the limit order protocol contract.
Expand All @@ -43,8 +43,8 @@ contract FeeTaker is IPostInteraction, AmountGetterWithFee, Ownable {
*/
error InconsistentFee();

address internal immutable _LIMIT_ORDER_PROTOCOL;
address internal immutable _WETH;
address private immutable _LIMIT_ORDER_PROTOCOL;
address private immutable _WETH;
/// @notice Contract address whose tokens allow filling limit orders with a fee for resolvers that are outside the whitelist
IERC20 internal immutable _ACCESS_TOKEN;

Expand Down Expand Up @@ -132,18 +132,8 @@ contract FeeTaker is IPostInteraction, AmountGetterWithFee, Ownable {
receiver = address(bytes20(extraData));
extraData = extraData[20:];
}
(bool isWhitelisted, uint256 integratorFee, uint256 integratorShare, uint256 resolverFee, bytes calldata tail) = _parseFeeData(extraData, taker, _isWhitelistedPostInteractionImpl);
if (!isWhitelisted && _ACCESS_TOKEN.balanceOf(taker) == 0) revert OnlyWhitelistOrAccessToken();

uint256 integratorFeeAmount;
uint256 protocolFeeAmount;

{
uint256 denominator = _BASE_1E5 + integratorFee + resolverFee;
uint256 integratorFeeTotal = Math.mulDiv(takingAmount, integratorFee, denominator);
integratorFeeAmount = Math.mulDiv(integratorFeeTotal, integratorShare, _BASE_1E2);
protocolFeeAmount = Math.mulDiv(takingAmount, resolverFee, denominator) + integratorFeeTotal - integratorFeeAmount;
}
(uint256 integratorFeeAmount, uint256 protocolFeeAmount, bytes calldata tail) = _getFeeAmounts(taker, takingAmount, extraData);

if (order.receiver.get() == address(this)) {
if (order.takerAsset.get() == address(_WETH) && order.makerTraits.unwrapWeth()) {
Expand Down Expand Up @@ -181,7 +171,25 @@ contract FeeTaker is IPostInteraction, AmountGetterWithFee, Ownable {
return _isWhitelistedGetterImpl(whitelistData, taker);
}

function _sendEth(address target, uint256 amount) internal {
/**
* @dev Calculates fee amounts depending on whether the taker is in the whitelist and whether they have an _ACCESS_TOKEN.
* Override this function if the calculation of integratorFee and protocolFee differs from the existing logic and requires a different parsing of extraData.
*/
function _getFeeAmounts(address taker, uint256 takingAmount, bytes calldata extraData) internal virtual returns (uint256 integratorFeeAmount, uint256 protocolFeeAmount, bytes calldata tail) {
bool isWhitelisted;
uint256 integratorFee;
uint256 integratorShare;
uint256 resolverFee;
(isWhitelisted, integratorFee, integratorShare, resolverFee, tail) = _parseFeeData(extraData, taker, _isWhitelistedPostInteractionImpl);
if (!isWhitelisted && _ACCESS_TOKEN.balanceOf(taker) == 0) revert OnlyWhitelistOrAccessToken();

uint256 denominator = _BASE_1E5 + integratorFee + resolverFee;
uint256 integratorFeeTotal = Math.mulDiv(takingAmount, integratorFee, denominator);
integratorFeeAmount = Math.mulDiv(integratorFeeTotal, integratorShare, _BASE_1E2);
protocolFeeAmount = Math.mulDiv(takingAmount, resolverFee, denominator) + integratorFeeTotal - integratorFeeAmount;
}

function _sendEth(address target, uint256 amount) private {
(bool success, ) = target.call{value: amount}("");
if (!success) {
revert EthTransferFailed();
Expand Down

0 comments on commit e493044

Please sign in to comment.