-
Notifications
You must be signed in to change notification settings - Fork 8
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
Protocol Fee Table #964
base: main
Are you sure you want to change the base?
Protocol Fee Table #964
Changes from 14 commits
8a9016c
808e1d8
526e081
6379708
c279c7b
e15c6ba
2277f97
a117dd1
64b5119
259ab1c
b374ad5
2fa00fe
3fd797d
12ab32f
ac14d32
d9e78dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,12 +22,16 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase { | |||||
* | ||||||
* @param _addresses - struct of Boson Protocol addresses (Boson Token (ERC-20) contract, treasury, and Voucher contract) | ||||||
* @param _limits - struct with Boson Protocol limits | ||||||
* @param _fees - struct of Boson Protocol fees | ||||||
* @param defaultFeePercentage - efault percentage that will be taken as a fee from the net of a Boson Protocol exchange. | ||||||
* @param flatBosonFee - flat fee taken for exchanges in $BOSON | ||||||
* @param buyerEscalationDepositPercentage - buyer escalation deposit percentage | ||||||
*/ | ||||||
function initialize( | ||||||
ProtocolLib.ProtocolAddresses calldata _addresses, | ||||||
ProtocolLib.ProtocolLimits calldata _limits, | ||||||
ProtocolLib.ProtocolFees calldata _fees | ||||||
uint256 defaultFeePercentage, | ||||||
uint256 flatBosonFee, | ||||||
uint256 buyerEscalationDepositPercentage | ||||||
) public onlyUninitialized(type(IBosonConfigHandler).interfaceId) { | ||||||
// Register supported interfaces | ||||||
DiamondLib.addSupportedInterface(type(IBosonConfigHandler).interfaceId); | ||||||
|
@@ -38,10 +42,10 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase { | |||||
setTreasuryAddress(_addresses.treasury); | ||||||
setVoucherBeaconAddress(_addresses.voucherBeacon); | ||||||
setPriceDiscoveryAddress(_addresses.priceDiscovery); | ||||||
setProtocolFeePercentage(_fees.percentage); | ||||||
setProtocolFeeFlatBoson(_fees.flatBoson); | ||||||
setProtocolFeePercentage(defaultFeePercentage); // this sets the default fee percentage if fee table is not configured for the exchange token | ||||||
setProtocolFeeFlatBoson(flatBosonFee); | ||||||
setMaxEscalationResponsePeriod(_limits.maxEscalationResponsePeriod); | ||||||
setBuyerEscalationDepositPercentage(_fees.buyerEscalationDepositPercentage); | ||||||
setBuyerEscalationDepositPercentage(buyerEscalationDepositPercentage); | ||||||
setMaxTotalOfferFeePercentage(_limits.maxTotalOfferFeePercentage); | ||||||
setMaxRoyaltyPercentage(_limits.maxRoyaltyPercentage); | ||||||
setMaxResolutionPeriod(_limits.maxResolutionPeriod); | ||||||
|
@@ -226,14 +230,62 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase { | |||||
} | ||||||
|
||||||
/** | ||||||
* @notice Gets the protocol fee percentage. | ||||||
* @notice Sets the feeTable for a specific token given price ranges and fee tiers for | ||||||
* the corresponding price ranges. | ||||||
* | ||||||
* @return the protocol fee percentage | ||||||
* Reverts if the number of fee percentages does not match the number of price ranges. | ||||||
* Reverts if token is Zero address. | ||||||
0xlucian marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* | ||||||
* @dev Caller must have ADMIN role. | ||||||
* | ||||||
* @param _tokenAddress - the address of the token | ||||||
* @param _priceRanges - array of token price ranges | ||||||
* @param _feePercentages - array of fee percentages corresponding to each price range | ||||||
*/ | ||||||
function setProtocolFeeTable( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I want to "update" a range for an existing token in the fee table, I need to know the existing ranges and values for it. |
||||||
address _tokenAddress, | ||||||
uint256[] calldata _priceRanges, | ||||||
uint256[] calldata _feePercentages | ||||||
) external override onlyRole(ADMIN) nonReentrant { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we allow _tokenAddress to be the Boson Token, we may break the rule saying that Boson Token is a flat fee. |
||||||
if (_priceRanges.length != _feePercentages.length) revert ArrayLengthMismatch(); | ||||||
// Clear existing price ranges and percentage tiers | ||||||
delete protocolFees().tokenPriceRanges[_tokenAddress]; | ||||||
delete protocolFees().tokenFeePercentages[_tokenAddress]; | ||||||
|
||||||
if (_priceRanges.length != 0) { | ||||||
setTokenPriceRanges(_tokenAddress, _priceRanges); | ||||||
setTokenFeePercentages(_tokenAddress, _feePercentages); | ||||||
} | ||||||
emit FeeTableUpdated(_tokenAddress, _priceRanges, _feePercentages, msgSender()); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @notice Gets the default protocol fee percentage. | ||||||
* | ||||||
* @return the default protocol fee percentage | ||||||
*/ | ||||||
function getProtocolFeePercentage() external view override returns (uint256) { | ||||||
return protocolFees().percentage; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @notice Retrieves the protocol fee percentage for a given token and price. | ||||||
* | ||||||
* @dev This function calculates the protocol fee based on the token and price. | ||||||
* If the token has a custom fee table, it applies the corresponding fee percentage | ||||||
* for the price range. If the token does not have a custom fee table, it falls back | ||||||
* to the default protocol fee percentage. If the exchange token is BOSON, | ||||||
* this function returns the flatBoson fee | ||||||
* | ||||||
* @param _exchangeToken - The address of the token being used for the exchange. | ||||||
* @param _price - The price of the item or service in the exchange. | ||||||
* | ||||||
* @return The protocol fee amount based on the token and the price. | ||||||
*/ | ||||||
function getProtocolFee(address _exchangeToken, uint256 _price) external view override returns (uint256) { | ||||||
return _getProtocolFee(_exchangeToken, _price); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @notice Sets the flat protocol fee for exchanges in $BOSON. | ||||||
* | ||||||
|
@@ -558,6 +610,33 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase { | |||||
return address(DiamondLib.diamondStorage().accessController); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @notice Sets the price ranges for a specific token. | ||||||
* | ||||||
* @param _tokenAddress - the address of the token | ||||||
* @param _priceRanges - array of price ranges for the token | ||||||
*/ | ||||||
function setTokenPriceRanges(address _tokenAddress, uint256[] calldata _priceRanges) internal { | ||||||
for (uint256 i = 1; i < _priceRanges.length; ++i) { | ||||||
if (_priceRanges[i] < _priceRanges[i - 1]) revert NonAscendingOrder(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I don't think it makes sense to accept 2 successive ranges with the same value |
||||||
} | ||||||
protocolFees().tokenPriceRanges[_tokenAddress] = _priceRanges; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @notice Sets the fee percentages for a specific token and price ranges. | ||||||
* | ||||||
* @param _tokenAddress - the address of the token | ||||||
* @param _feePercentages - array of fee percentages corresponding to each price range | ||||||
*/ | ||||||
function setTokenFeePercentages(address _tokenAddress, uint256[] calldata _feePercentages) internal { | ||||||
// Set the fee percentages for the token | ||||||
for (uint256 i; i < _feePercentages.length; ++i) { | ||||||
checkMaxPercententage(_feePercentages[i]); | ||||||
} | ||||||
protocolFees().tokenFeePercentages[_tokenAddress] = _feePercentages; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @notice Checks that supplied value is not 0. | ||||||
* | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should give the same result saving a few instruction/gas (at least 1 if() assessment)