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 d3a6bbd commit 4963d56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 19 additions & 11 deletions contracts/extensions/FeeTaker.sol
Original file line number Diff line number Diff line change
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,6 +171,24 @@ contract FeeTaker is IPostInteraction, AmountGetterWithFee, Ownable {
return _isWhitelistedGetterImpl(whitelistData, taker);
}

/**
* @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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/limit-order-protocol-contract",
"version": "4.2.2",
"version": "4.2.3",
"description": "1inch Limit Order Protocol",
"repository": {
"type": "git",
Expand Down

0 comments on commit 4963d56

Please sign in to comment.