-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Lima
committed
Sep 14, 2023
1 parent
d7da0d9
commit d493d6c
Showing
1 changed file
with
30 additions
and
74 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/securit | |
* @dev This contract is used to manage NFTs rentals, powered by ERC7432 Non-Fungible Token Roles | ||
* @author Orium Network Team - [email protected] | ||
*/ | ||
contract OriumRentalProtocol is Initializable, OwnableUpgradeable, PausableUpgradeable { | ||
contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradeable { | ||
/// @dev 100 ether is 100% | ||
uint256 public constant MAX_PERCENTAGE = 100 ether; | ||
uint256 public constant MAX_PERCENTAGE = 100 ether; | ||
/// @dev 2.5 ether is 2.5% | ||
uint256 public constant DEFAULT_FEE_PERCENTAGE = 2.5 ether; | ||
/// @dev rolesRegistry is a ERC7432 contract | ||
|
@@ -24,13 +24,13 @@ contract OriumRentalProtocol is Initializable, OwnableUpgradeable, PausableUpgra | |
uint256 public maxDeadline; | ||
|
||
/// @dev tokenAddress => feePercentageInWei | ||
mapping(address => uint256) public feesPerCollection; | ||
mapping(address => uint256) public feePerCollection; | ||
|
||
/// @dev tokenAddress => collectionFeeInfo | ||
mapping(address => CollectionFeeInfo) public collectionFeeInfo; | ||
/// @dev tokenAddress => royaltyInfo | ||
mapping(address => RoyaltyInfo) public royaltyInfo; | ||
|
||
/// @dev Collection fee info. Used to charge fees for the creator. | ||
struct CollectionFeeInfo { | ||
/// @dev Royalty info. Used to charge fees for the creator. | ||
struct RoyaltyInfo { | ||
address creator; | ||
uint256 feePercentageInWei; | ||
address treasury; | ||
|
@@ -53,54 +53,8 @@ contract OriumRentalProtocol is Initializable, OwnableUpgradeable, PausableUpgra | |
transferOwnership(_owner); | ||
} | ||
|
||
/** | ||
* @notice Transfer fees to the marketplace and the creator. | ||
* @dev If the creator is address(0), the collection will not have a creator fee. | ||
* @param _tokenAddress The address of the collection. | ||
* @param _lender The address of the lender. | ||
* @param _feeToken The address of the token used to pay the fees. | ||
* @param _feeAmount The amount of fees. | ||
*/ | ||
function _chargeFee(address _tokenAddress, address _lender, address _feeToken, uint256 _feeAmount) internal { | ||
// TODO: With this logic a collection can't have a fee of 0. How to handle this? | ||
uint256 _marketplaceFeePercentage = feesPerCollection[_tokenAddress] == 0 | ||
? DEFAULT_FEE_PERCENTAGE | ||
: feesPerCollection[_tokenAddress]; | ||
uint256 _marketplaceFee = _valueFromPercentage(_marketplaceFeePercentage, _feeAmount); | ||
require( | ||
IERC20(_feeToken).transferFrom(msg.sender, address(this), _marketplaceFee), | ||
"OriumRentalProtocol: Marketplace fee transfer failed" | ||
); | ||
|
||
// Charge the fee to the maker | ||
uint256 _makerFee = _feeAmount - _marketplaceFee; | ||
require( | ||
IERC20(_feeToken).transferFrom(msg.sender, _lender, _makerFee), | ||
"OriumRentalProtocol: Lender fee transfer failed" | ||
); | ||
|
||
// Charge the fee to the creator | ||
address _creator = collectionFeeInfo[_tokenAddress].creator; | ||
if (_creator == address(0)) return; | ||
|
||
uint256 _creatorFeePercentage = collectionFeeInfo[_tokenAddress].feePercentageInWei; | ||
if (_creatorFeePercentage == 0) return; | ||
|
||
uint256 _creatorFee = _valueFromPercentage(_creatorFeePercentage, _feeAmount); | ||
require( | ||
IERC20(_feeToken).transferFrom(msg.sender, collectionFeeInfo[_tokenAddress].treasury, _creatorFee), | ||
"OriumRentalProtocol: Creator fee transfer failed" | ||
); | ||
} | ||
|
||
/** | ||
* @notice Calculates the fee amount. | ||
* @dev The fee amount is calculated as the percentage of the amount. | ||
* @param _percentage The percentage in wei. | ||
* @param _amount The amount. | ||
*/ | ||
function _valueFromPercentage(uint256 _percentage, uint256 _amount) internal pure returns (uint256) { | ||
return (_amount * _percentage) / MAX_PERCENTAGE; | ||
function getMarketplaceFee(address _tokenAddress) public view returns (uint256) { | ||
return feePerCollection[_tokenAddress] == 0 ? DEFAULT_FEE_PERCENTAGE : feePerCollection[_tokenAddress]; | ||
} | ||
|
||
/** | ||
|
@@ -126,51 +80,53 @@ contract OriumRentalProtocol is Initializable, OwnableUpgradeable, PausableUpgra | |
* @param _feePercentageInWei The fee percentage in wei. | ||
*/ | ||
function setMarketplaceFeeForCollection(address _tokenAddress, uint256 _feePercentageInWei) external onlyOwner { | ||
require( | ||
_feePercentageInWei <= MAX_PERCENTAGE, | ||
"OriumRentalProtocol: Fee percentage cannot be greater than 100%" | ||
); | ||
feesPerCollection[_tokenAddress] = _feePercentageInWei; | ||
require(_feePercentageInWei <= MAX_PERCENTAGE, "OriumMarketplace: Fee percentage cannot be greater than 100%"); | ||
feePerCollection[_tokenAddress] = _feePercentageInWei; | ||
} | ||
|
||
// TODO: Using the same function for the operator and the creator maybe is not ideal. Split it in two? | ||
// TODO: Should this function have the whenNotPaused modifier? | ||
/** | ||
* @notice Sets the collection fee info. | ||
* @notice Sets the royalty info. | ||
* @dev If the creator is address(0), the collection will not have a creator fee. | ||
* @dev Only owner can associate a collection with a creator. | ||
* @param _creator The address of the creator. | ||
* @param _tokenAddress The address of the collection. | ||
* @param _feePercentageInWei The fee percentage in wei. If the fee is 0, the creator fee will be disabled. | ||
* @param _royaltyPercentageInWei The royalty percentage in wei. If the fee is 0, the creator fee will be disabled. | ||
* @param _treasury The address where the fees will be sent. If the treasury is address(0), the fees will be burned. | ||
*/ | ||
function setCollectionFeeInfo( | ||
function setRoyaltyInfo( | ||
address _creator, | ||
address _tokenAddress, | ||
uint256 _feePercentageInWei, | ||
uint256 _royaltyPercentageInWei, | ||
address _treasury | ||
) external { | ||
require( | ||
msg.sender == collectionFeeInfo[_tokenAddress].creator || msg.sender == owner(), | ||
"OriumRentalProtocol: Only creator or operator can set collection fee info" | ||
msg.sender == royaltyInfo[_tokenAddress].creator || msg.sender == owner(), | ||
"OriumMarketplace: Only creator or operator can set royalty info" | ||
); | ||
require( | ||
_royaltyPercentageInWei <= MAX_PERCENTAGE, | ||
"OriumMarketplace: Royalty percentage cannot be greater than 100%" | ||
); | ||
|
||
require( | ||
_feePercentageInWei <= MAX_PERCENTAGE, | ||
"OriumRentalProtocol: Fee percentage cannot be greater than 100%" | ||
_royaltyPercentageInWei + getMarketplaceFee(_tokenAddress) <= MAX_PERCENTAGE, | ||
"OriumMarketplace: Royalty percentage + marketplace fee cannot be greater than 100%" | ||
); | ||
|
||
collectionFeeInfo[_tokenAddress] = CollectionFeeInfo({ | ||
royaltyInfo[_tokenAddress] = RoyaltyInfo({ | ||
creator: _creator, | ||
feePercentageInWei: _feePercentageInWei, | ||
treasury: _treasury // TODO: we are not checking if the treasury is address(0), should we? (maybe the creator wants to burn the fees) | ||
feePercentageInWei: _royaltyPercentageInWei, | ||
treasury: _treasury | ||
}); | ||
} | ||
|
||
/** | ||
* @notice Sets the maximum deadline. | ||
* @dev Only owner can set the maximum deadline. | ||
* @param _maxDeadline The maximum deadline. | ||
*/ | ||
function setMaxDeadline(uint256 _maxDeadline) external onlyOwner { | ||
maxDeadline = _maxDeadline; // TODO: Setting deadline to 0 would freeze the protocol. Should we allow this? | ||
require(_maxDeadline > 0, "OriumMarketplace: Deadline cannot be 0"); | ||
maxDeadline = _maxDeadline; | ||
} | ||
} |