-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroyalties.sol
More file actions
218 lines (181 loc) · 6.81 KB
/
royalties.sol
File metadata and controls
218 lines (181 loc) · 6.81 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface ERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address account, uint256 amount) external;
}
interface ERC721 {
function ownerOf(uint256 tokenId) external returns (address);
}
/// @title Royalties for Non-Fungible Tokens
/// @dev Contract for the split between community royalties and dev royalties
///
contract Royalties is Ownable {
uint256 public communityClaimed = 0;
uint256 public creatorClaimed = 0;
uint256 public creatorRoyalties = 10; // percentage from total NFT price
uint256 public communityRoyalties = 0; // percentage from total NFT price
uint256 public collectionSize = 10000;
address public tokenFeesAddress;
address public creatorAddress;
mapping(uint256 => uint256) private communityClaims;
mapping(address => uint256) private addressClaims;
event CommunityClaimed(uint256 tokenID);
event CreatorClaimed(uint256 amount);
event Received(address, uint);
constructor() {
tokenFeesAddress = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
creatorAddress = 0xAEff790029DeBf3B956A65Fa915097347Ef63eb6;
}
receive() external payable {
emit Received(msg.sender, msg.value);
}
/// @dev set royalties address (weth)
function setTokenFeesAddress(address _tokenFeesAddress) external onlyOwner {
tokenFeesAddress = _tokenFeesAddress;
}
/// @dev set creator address, can be another contract
function setCreatorAddress(address _creatorAddress) external onlyOwner {
creatorAddress = _creatorAddress;
}
/// @dev set only smaller collection size, can't increase size
function setCollectionSize(uint256 _collectionSize) external onlyOwner {
require(
_collectionSize < collectionSize,
"Cannot increase collection size"
);
collectionSize = _collectionSize;
}
/// @dev set creator royalties
function setCreatorRoyalties(uint256 _creatorRoyalties) external onlyOwner {
creatorRoyalties = _creatorRoyalties;
}
/// @dev get total royalties
/// @return total royalties
function getTotalRoyalties() public view returns (uint256) {
return creatorRoyalties ;
}
function getRoyalties() public view returns (uint256) {
return (creatorRoyalties);
}
/// @dev get total collected
/// @return total collected
function getTotalCollected() public view returns (uint256) {
uint256 balance = ERC20(tokenFeesAddress).balanceOf(address(this));
return balance + creatorClaimed;
}
/// @dev get creator balance
/// @return creator total balance
function getCreatorBalance() public view returns (uint256) {
uint256 _creatorRoyalties = (creatorRoyalties * 100) /
getTotalRoyalties();
return (getTotalCollected() * _creatorRoyalties) / 100 - creatorClaimed;
}
/// @dev get address tot claims
/// @return address total claims
function getAddressClaims(address account) public view returns (uint256) {
return addressClaims[account];
}
/// @dev claim creator royalties
function claimCreator() external {
uint256 balance = getCreatorBalance();
require(balance > 0, "No balance to claim");
creatorClaimed = creatorClaimed + balance;
ERC20(tokenFeesAddress).transfer(creatorAddress, balance);
uint256 native = address(this).balance;
(bool os, ) = payable(creatorAddress).call{value: native}("");
require(os);
emit CreatorClaimed(balance);
}
function withdraw() external {
uint256 balance = address(this).balance;
(bool os, ) = payable(creatorAddress).call{value: balance}("");
require(os);
}
}