Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SC-1369] private to internal #351

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions contracts/extensions/FeeTaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ contract FeeTaker is IPostInteraction, AmountGetterWithFee, Ownable {
*/
error InconsistentFee();

/**
* @dev The returned value is less than specified in order.takingAmount
*/
error ReceivedAmountToolow();

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
Expand Down Expand Up @@ -105,10 +110,7 @@ contract FeeTaker is IPostInteraction, AmountGetterWithFee, Ownable {
* 20 bytes — integrator fee recipient
* 20 bytes - protocol fee recipient
* 20 bytes — receiver of taking tokens (optional, if not set, maker is used)
* 2 bytes — integrator fee percentage (in 1e5)
* 1 bytes - integrator rev share percentage (in 1e2)
* 2 bytes — resolver fee percentage (in 1e5)
* bytes — whitelist structure determined by `_isWhitelistedPostInteractionImpl` implementation
* bytes - fees structure determined by `_getFeeAmounts` implementation
* bytes — custom data to call extra postInteraction (optional)
*/
function _postInteraction(
Expand All @@ -132,18 +134,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(order, taker, takingAmount, makingAmount, extraData);

if (order.receiver.get() == address(this)) {
if (order.takerAsset.get() == address(_WETH) && order.makerTraits.unwrapWeth()) {
Expand Down Expand Up @@ -181,6 +173,29 @@ 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.
* `extraData` consists of:
* 2 bytes — integrator fee percentage (in 1e5)
* 1 bytes - integrator rev share percentage (in 1e2)
* 2 bytes — resolver fee percentage (in 1e5)
* bytes — whitelist structure determined by `_isWhitelistedPostInteractionImpl` implementation
* Override this function if the calculation of integratorFee and protocolFee differs from the existing logic and requires a different parsing of extraData.
*/
function _getFeeAmounts(IOrderMixin.Order calldata /* order */, address taker, uint256 takingAmount, uint256 /* makingAmount */, 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