-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoyaltyFeeManager.sol
50 lines (43 loc) · 1.85 KB
/
RoyaltyFeeManager.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC165, IERC2981} from "@openzeppelin/contracts/interfaces/IERC2981.sol";
import {IRoyaltyFeeManager} from "./interfaces/IRoyaltyFeeManager.sol";
import {IRoyaltyFeeRegistry} from "./interfaces/IRoyaltyFeeRegistry.sol";
/**
* @title RoyaltyFeeManager
* @notice It handles the logic to check and transfer royalty fees (if any).
*/
contract RoyaltyFeeManager is IRoyaltyFeeManager, Ownable {
// https://eips.ethereum.org/EIPS/eip-2981
bytes4 public constant INTERFACE_ID_ERC2981 = 0x2a55205a;
IRoyaltyFeeRegistry public immutable royaltyFeeRegistry;
/**
* @notice Constructor
* @param _royaltyFeeRegistry address of the RoyaltyFeeRegistry
*/
constructor(address _royaltyFeeRegistry) {
royaltyFeeRegistry = IRoyaltyFeeRegistry(_royaltyFeeRegistry);
}
/**
* @notice Calculate royalty fee and get recipient
* @param collection address of the NFT contract
* @param tokenId tokenId
* @param amount amount to transfer
*/
function calculateRoyaltyFeeAndGetRecipient(
address collection,
uint256 tokenId,
uint256 amount
) external view override returns (address, uint256) {
// 1. Check if there is a royalty info in the system
(address receiver, uint256 royaltyAmount) = royaltyFeeRegistry.royaltyInfo(collection, amount);
// 2. If the receiver is address(0), fee is null, check if it supports the ERC2981 interface
if ((receiver == address(0)) || (royaltyAmount == 0)) {
if (IERC165(collection).supportsInterface(INTERFACE_ID_ERC2981)) {
(receiver, royaltyAmount) = IERC2981(collection).royaltyInfo(tokenId, amount);
}
}
return (receiver, royaltyAmount);
}
}