-
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
Merged
Merged
Protocol Fee Table #964
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8a9016c
feat: fee table implementation
0xlucian 808e1d8
Merge branch 'main' into 212-protocol-fee-table
0xlucian 526e081
fix: failing tests due to change in initialize function arguments
0xlucian 6379708
refactor: feetable implementation
0xlucian c279c7b
feat: feetable unit tests
0xlucian e15c6ba
lint: contracts
0xlucian 2277f97
fix: scripts linter
0xlucian a117dd1
format: tidy scripts
0xlucian 64b5119
fix: natspec interface ID
0xlucian 259ab1c
fix: integration test
0xlucian b374ad5
fix: script
0xlucian 2fa00fe
refactor: address PR comments and optimise code
0xlucian 3fd797d
format code
0xlucian 12ab32f
fix: IBsosonConfigHandler interface id
0xlucian ac14d32
refactor: update setProtocolFeeTable natspec
0xlucian d9e78dc
feat: add getFeePercentage(exhangeToken,price) function
0xlucian 1c09ace
refactor: address PR comments
0xlucian 1f8f486
fix: ProtocolFeeTable getter
0xlucian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,63 @@ 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 the price ranges are not in ascending order. | ||||||
* Reverts if any of the fee percentages value is above 100%. | ||||||
* | ||||||
* @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( | ||||||
levalleux-ludo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
address _tokenAddress, | ||||||
uint256[] calldata _priceRanges, | ||||||
uint256[] calldata _feePercentages | ||||||
) external override onlyRole(ADMIN) nonReentrant { | ||||||
levalleux-ludo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 +611,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 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. Makes sense. Fixed. |
||||||
} | ||||||
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. | ||||||
* | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
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.
Fixed. Good catch.