Skip to content

Commit 4a0fe8f

Browse files
nkrishangkumaryash90Krishang Nadgauda
authored
Add missing Natspec comments for contract/extension (#202)
* natspec for Permissions and PermissionsEnumerable * natspec for BatchMintMetada and ContractMetadata * natspec for DelayedReveal, PlatformFee, PrimarySale * natspec for Royalty, TokenStore, TokenBundle * forge updates * run prettier * add missing comments + docs update Co-authored-by: Yash <kumaryashcse@gmail.com> Co-authored-by: Krishang Nadgauda <nkrishang@Krishangs-MacBook-Pro.local>
1 parent b4100e7 commit 4a0fe8f

38 files changed

+892
-674
lines changed

contracts/extension/BatchMintMetadata.sol

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
pragma solidity ^0.8.0;
33

44
/**
5-
* The `BatchMintMetadata` is a contract extension for any base NFT contract. It lets the smart contract
6-
* using this extension set metadata for `n` number of NFTs all at once. This is enabled by storing a single
7-
* base URI for a batch of `n` NFTs, where the metadata for each NFT in a relevant batch is `baseURI/tokenId`.
5+
* @title Batch-mint Metadata
6+
* @notice The `BatchMintMetadata` is a contract extension for any base NFT contract. It lets the smart contract
7+
* using this extension set metadata for `n` number of NFTs all at once. This is enabled by storing a single
8+
* base URI for a batch of `n` NFTs, where the metadata for each NFT in a relevant batch is `baseURI/tokenId`.
89
*/
910

1011
contract BatchMintMetadata {
@@ -14,12 +15,20 @@ contract BatchMintMetadata {
1415
/// @dev Mapping from id of a batch of tokens => to base URI for the respective batch of tokens.
1516
mapping(uint256 => string) private baseURI;
1617

17-
/// @dev Returns the number of batches of tokens having the same baseURI.
18+
/**
19+
* @notice Returns the count of batches of NFTs.
20+
* @dev Each batch of tokens has an in ID and an associated `baseURI`.
21+
* See {batchIds}.
22+
*/
1823
function getBaseURICount() public view returns (uint256) {
1924
return batchIds.length;
2025
}
2126

22-
/// @dev Returns the id for the batch of tokens the given tokenId belongs to.
27+
/**
28+
* @notice Returns the ID for the batch of tokens the given tokenId belongs to.
29+
* @dev See {getBaseURICount}.
30+
* @param _index ID of a token.
31+
*/
2332
function getBatchIdAtIndex(uint256 _index) public view returns (uint256) {
2433
if (_index >= getBaseURICount()) {
2534
revert("Invalid index");

contracts/extension/ContractMetadata.sol

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ pragma solidity ^0.8.0;
44
import "./interface/IContractMetadata.sol";
55

66
/**
7-
* Thirdweb's `ContractMetadata` is a contract extension for any base contracts. It lets you set a metadata URI
8-
* for you contract.
9-
*
10-
* Additionally, `ContractMetadata` is necessary for NFT contracts that want royalties to get distributed on OpenSea.
7+
* @title Contract Metadata
8+
* @notice Thirdweb's `ContractMetadata` is a contract extension for any base contracts. It lets you set a metadata URI
9+
* for you contract.
10+
* Additionally, `ContractMetadata` is necessary for NFT contracts that want royalties to get distributed on OpenSea.
1111
*/
1212

1313
abstract contract ContractMetadata is IContractMetadata {
14-
/// @dev Contract level metadata.
14+
/// @notice Returns the contract metadata URI.
1515
string public override contractURI;
1616

17-
/// @dev Lets a contract admin set the URI for contract-level metadata.
17+
/**
18+
* @notice Lets a contract admin set the URI for contract-level metadata.
19+
* @dev Caller should be authorized to setup contractURI, e.g. contract admin.
20+
* See {_canSetContractURI}.
21+
* Emits {ContractURIUpdated Event}.
22+
*
23+
* @param _uri keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
24+
*/
1825
function setContractURI(string memory _uri) external override {
1926
if (!_canSetContractURI()) {
2027
revert("Not authorized");

contracts/extension/DelayedReveal.sol

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ pragma solidity ^0.8.0;
44
import "./interface/IDelayedReveal.sol";
55

66
/**
7-
* Thirdweb's `DelayedReveal` is a contract extension for base NFT contracts. It lets you create batches of
8-
* 'delayed-reveal' NFTs. You can learn more about the usage of delayed reveal NFTs here - https://blog.thirdweb.com/delayed-reveal-nfts
7+
* @title Delayed Reveal
8+
* @notice Thirdweb's `DelayedReveal` is a contract extension for base NFT contracts. It lets you create batches of
9+
* 'delayed-reveal' NFTs. You can learn more about the usage of delayed reveal NFTs here - https://blog.thirdweb.com/delayed-reveal-nfts
910
*/
1011

1112
abstract contract DelayedReveal is IDelayedReveal {
@@ -17,7 +18,17 @@ abstract contract DelayedReveal is IDelayedReveal {
1718
encryptedBaseURI[_batchId] = _encryptedBaseURI;
1819
}
1920

20-
/// @dev Returns the decrypted i.e. revealed URI for a batch of tokens.
21+
/**
22+
* @notice Returns revealed URI for a batch of NFTs.
23+
* @dev Reveal encrypted base URI for `_batchId` with caller/admin's `_key` used for encryption.
24+
* Reverts if there's no encrypted URI for `_batchId`.
25+
* See {encryptDecrypt}.
26+
*
27+
* @param _batchId ID of the batch for which URI is being revealed.
28+
* @param _key Secure key used by caller/admin for encryption of baseURI.
29+
*
30+
* @return revealedURI Decrypted base URI.
31+
*/
2132
function getRevealURI(uint256 _batchId, bytes calldata _key) public view returns (string memory revealedURI) {
2233
bytes memory encryptedURI = encryptedBaseURI[_batchId];
2334
if (encryptedURI.length == 0) {
@@ -27,7 +38,16 @@ abstract contract DelayedReveal is IDelayedReveal {
2738
revealedURI = string(encryptDecrypt(encryptedURI, _key));
2839
}
2940

30-
/// @dev See: https://ethereum.stackexchange.com/questions/69825/decrypt-message-on-chain
41+
/**
42+
* @notice Encrypt/decrypt data on chain.
43+
* @dev Encrypt/decrypt given `data` with `key`. Uses inline assembly.
44+
* See: https://ethereum.stackexchange.com/questions/69825/decrypt-message-on-chain
45+
*
46+
* @param data Bytes of data to encrypt/decrypt.
47+
* @param key Secure key used by caller for encryption/decryption.
48+
*
49+
* @return result Output after encryption/decryption of given data.
50+
*/
3151
function encryptDecrypt(bytes memory data, bytes calldata key) public pure override returns (bytes memory result) {
3252
// Store data length on stack for later use
3353
uint256 length = data.length;
@@ -63,7 +83,11 @@ abstract contract DelayedReveal is IDelayedReveal {
6383
}
6484
}
6585

66-
/// @dev Returns whether the relvant batch of NFTs is subject to a delayed reveal.
86+
/**
87+
* @notice Returns whether the relvant batch of NFTs is subject to a delayed reveal.
88+
* @dev Returns `true` if `_batchId`'s base URI is encrypted.
89+
* @param _batchId ID of a batch of NFTs.
90+
*/
6791
function isEncryptedBatch(uint256 _batchId) public view returns (bool) {
6892
return encryptedBaseURI[_batchId].length > 0;
6993
}

contracts/extension/Multicall.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import "./interface/IMulticall.sol";
1313
*/
1414
contract Multicall is IMulticall {
1515
/**
16-
* @dev Receives and executes a batch of function calls on this contract.
16+
* @notice Receives and executes a batch of function calls on this contract.
17+
* @dev Receives and executes a batch of function calls on this contract.
18+
*
19+
* @param data The bytes data that makes up the batch of function calls to execute.
20+
* @return results The bytes data that makes up the result of the batch of function calls executed.
1721
*/
1822
function multicall(bytes[] calldata data) external virtual override returns (bytes[] memory results) {
1923
results = new bytes[](data.length);

contracts/extension/Ownable.sol

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ pragma solidity ^0.8.0;
44
import "./interface/IOwnable.sol";
55

66
/**
7-
* Thirdweb's `Ownable` is a contract extension to be used with any base contract. It exposes functions for setting and reading
8-
* who the 'owner' of the inheriting smart contract is, and lets the inheriting contract perform conditional logic that uses
9-
* information about who the contract's owner is.
7+
* @title Ownable
8+
* @notice Thirdweb's `Ownable` is a contract extension to be used with any base contract. It exposes functions for setting and reading
9+
* who the 'owner' of the inheriting smart contract is, and lets the inheriting contract perform conditional logic that uses
10+
* information about who the contract's owner is.
1011
*/
1112

1213
abstract contract Ownable is IOwnable {
@@ -21,12 +22,17 @@ abstract contract Ownable is IOwnable {
2122
_;
2223
}
2324

24-
/// @dev Returns the owner of the contract.
25+
/**
26+
* @notice Returns the owner of the contract.
27+
*/
2528
function owner() public view override returns (address) {
2629
return _owner;
2730
}
2831

29-
/// @dev Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.
32+
/**
33+
* @notice Lets an authorized wallet set a new owner for the contract.
34+
* @param _newOwner The address to set as the new owner of the contract.
35+
*/
3036
function setOwner(address _newOwner) external override {
3137
if (!_canSetOwner()) {
3238
revert("Not authorized");

contracts/extension/Permissions.sol

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,51 @@ pragma solidity ^0.8.0;
44
import "./interface/IPermissions.sol";
55
import "../lib/TWStrings.sol";
66

7+
/**
8+
* @title Permissions
9+
* @dev This contracts provides extending-contracts with role-based access control mechanisms
10+
*/
711
contract Permissions is IPermissions {
12+
/// @dev Map from keccak256 hash of a role => a map from address => whether address has role.
813
mapping(bytes32 => mapping(address => bool)) private _hasRole;
14+
15+
/// @dev Map from keccak256 hash of a role to role admin. See {getRoleAdmin}.
916
mapping(bytes32 => bytes32) private _getRoleAdmin;
1017

18+
/// @dev Default admin role for all roles. Only accounts with this role can grant/revoke other roles.
1119
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
1220

21+
/// @dev Modifier that checks if an account has the specified role; reverts otherwise.
1322
modifier onlyRole(bytes32 role) {
1423
_checkRole(role, msg.sender);
1524
_;
1625
}
1726

27+
/**
28+
* @notice Checks whether an account has a particular role.
29+
* @dev Returns `true` if `account` has been granted `role`.
30+
*
31+
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
32+
* @param account Address of the account for which the role is being checked.
33+
*/
1834
function hasRole(bytes32 role, address account) public view override returns (bool) {
1935
return _hasRole[role][account];
2036
}
2137

38+
/**
39+
* @notice Checks whether an account has a particular role;
40+
* role restrictions can be swtiched on and off.
41+
*
42+
* @dev Returns `true` if `account` has been granted `role`.
43+
* Role restrictions can be swtiched on and off:
44+
* - If address(0) has ROLE, then the ROLE restrictions
45+
* don't apply.
46+
* - If address(0) does not have ROLE, then the ROLE
47+
* restrictions will apply.
48+
*
49+
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
50+
* @param account Address of the account for which the role is being checked.
51+
*/
2252
function hasRoleWithSwitch(bytes32 role, address account) public view returns (bool) {
2353
if (!_hasRole[role][address(0)]) {
2454
return _hasRole[role][account];
@@ -27,10 +57,25 @@ contract Permissions is IPermissions {
2757
return true;
2858
}
2959

60+
/**
61+
* @notice Returns the admin role that controls the specified role.
62+
* @dev See {grantRole} and {revokeRole}.
63+
* To change a role's admin, use {_setRoleAdmin}.
64+
*
65+
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
66+
*/
3067
function getRoleAdmin(bytes32 role) external view override returns (bytes32) {
3168
return _getRoleAdmin[role];
3269
}
3370

71+
/**
72+
* @notice Grants a role to an account, if not previously granted.
73+
* @dev Caller must have admin role for the `role`.
74+
* Emits {RoleGranted Event}.
75+
*
76+
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
77+
* @param account Address of the account to which the role is being granted.
78+
*/
3479
function grantRole(bytes32 role, address account) public virtual override {
3580
_checkRole(_getRoleAdmin[role], msg.sender);
3681
if (_hasRole[role][account]) {
@@ -39,35 +84,55 @@ contract Permissions is IPermissions {
3984
_setupRole(role, account);
4085
}
4186

87+
/**
88+
* @notice Revokes role from an account.
89+
* @dev Caller must have admin role for the `role`.
90+
* Emits {RoleRevoked Event}.
91+
*
92+
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
93+
* @param account Address of the account from which the role is being revoked.
94+
*/
4295
function revokeRole(bytes32 role, address account) public virtual override {
4396
_checkRole(_getRoleAdmin[role], msg.sender);
4497
_revokeRole(role, account);
4598
}
4699

100+
/**
101+
* @notice Revokes role from the account.
102+
* @dev Caller must have the `role`, with caller being the same as `account`.
103+
* Emits {RoleRevoked Event}.
104+
*
105+
* @param role keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE")
106+
* @param account Address of the account from which the role is being revoked.
107+
*/
47108
function renounceRole(bytes32 role, address account) public virtual override {
48109
if (msg.sender != account) {
49110
revert("Can only renounce for self");
50111
}
51112
_revokeRole(role, account);
52113
}
53114

115+
/// @dev Sets `adminRole` as `role`'s admin role.
54116
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
55117
bytes32 previousAdminRole = _getRoleAdmin[role];
56118
_getRoleAdmin[role] = adminRole;
57119
emit RoleAdminChanged(role, previousAdminRole, adminRole);
58120
}
59121

122+
/// @dev Sets up `role` for `account`
60123
function _setupRole(bytes32 role, address account) internal virtual {
61124
_hasRole[role][account] = true;
62125
emit RoleGranted(role, account, msg.sender);
63126
}
64127

128+
/// @dev Revokes `role` from `account`
65129
function _revokeRole(bytes32 role, address account) internal virtual {
66130
_checkRole(role, account);
67131
delete _hasRole[role][account];
68132
emit RoleRevoked(role, account, msg.sender);
69133
}
70134

135+
/// @dev Checks `role` for `account`. Reverts with a message including the required role.
71136
function _checkRole(bytes32 role, address account) internal view virtual {
72137
if (!_hasRole[role][account]) {
73138
revert(
@@ -83,6 +148,7 @@ contract Permissions is IPermissions {
83148
}
84149
}
85150

151+
/// @dev Checks `role` for `account`. Reverts with a message including the required role.
86152
function _checkRoleWithSwitch(bytes32 role, address account) internal view virtual {
87153
if (!hasRoleWithSwitch(role, account)) {
88154
revert(

0 commit comments

Comments
 (0)