diff --git a/packages/contracts/.gitignore b/packages/contracts/.gitignore index 03944dc4..348dbc4f 100644 --- a/packages/contracts/.gitignore +++ b/packages/contracts/.gitignore @@ -4,3 +4,5 @@ node_modules #Hardhat files cache artifacts +.openzeppelin/* +workspace.code-workspace \ No newline at end of file diff --git a/packages/contracts/contracts/identity/NonFungibleRegistryEnumerableUpgradeable.sol b/packages/contracts/contracts/identity/NonFungibleRegistryEnumerableUpgradeable.sol index 0ac1f894..a0e2b6fe 100644 --- a/packages/contracts/contracts/identity/NonFungibleRegistryEnumerableUpgradeable.sol +++ b/packages/contracts/contracts/identity/NonFungibleRegistryEnumerableUpgradeable.sol @@ -94,9 +94,10 @@ contract NonFungibleRegistryEnumerableUpgradeable is address public burnAddress; /// @notice The amount in basis points of registrationFee to send to the burnAddress account - /// @notice This variable must be less than or equal to 10000 + /// @notice This variable must be less than or equal to 10000 / burnDenom uint256 public burnFee; + /** @dev address of primary NFR registry required for participation * if the primaryRegistry is address(0), then this variable is ignored * if the primaryRegistry is an ERC721, then the recipient of an NFI must @@ -125,6 +126,10 @@ contract NonFungibleRegistryEnumerableUpgradeable is /// @dev The REGISTRAR_ROLE_ADMIN curates the address with REGISTRAR_ROLE permissions bytes32 public constant REGISTRAR_ROLE_ADMIN = keccak256("REGISTRAR_ROLE_ADMIN"); + + /// @notice used to calculate burn % in calculating royaltyAmount + uint constant burnDenom = 10000; + /** * @dev Emitted when updateLabel is called successfully */ @@ -143,7 +148,7 @@ contract NonFungibleRegistryEnumerableUpgradeable is /// @custom:oz-upgrades-unsafe-allow constructor constructor() initializer {} - /// @notice initialize is called once on the creation of an upgradable proxy + /// @notice initialize is called once on the creation of an upgradable proxy. /// @dev can only be called once due to the initializer modifier /// @param name_ name to be given to the Non Fungible Registry /// @param symbol_ shorthand symbol to be given to the Non Fungible Registry @@ -273,7 +278,8 @@ contract NonFungibleRegistryEnumerableUpgradeable is _createLabeledToken(to, label, registrationData, tokenId); - uint256 burnAmount = registrationFee * burnFee / 10000; + uint256 burnAmount = calculateRoyalty(registrationFee); + IERC20Upgradeable(registrationToken).transfer(burnAddress, burnAmount); // the fee stays with the token, not the token owner identityStakes[tokenId] = Fee(registrationToken, registrationFee-burnAmount); @@ -443,12 +449,16 @@ contract NonFungibleRegistryEnumerableUpgradeable is } } + function calculateRoyalty(uint256 salePrice) internal view returns(uint256 amount) { + amount = salePrice * burnFee / burnDenom; + } + function royaltyInfo(uint256 tokenId, uint256 salePrice) external view override(IERC2981Upgradeable) returns (address receiver, uint256 royaltyAmount) { - royaltyAmount = salePrice * burnFee / 10000; + royaltyAmount = calculateRoyalty(salePrice); receiver = burnAddress; } diff --git a/packages/contracts/contracts/identity/NonFungibleRegistryUpgradeable.sol b/packages/contracts/contracts/identity/NonFungibleRegistryUpgradeable.sol index d2e21ec7..fdc837d9 100644 --- a/packages/contracts/contracts/identity/NonFungibleRegistryUpgradeable.sol +++ b/packages/contracts/contracts/identity/NonFungibleRegistryUpgradeable.sol @@ -92,7 +92,7 @@ contract NonFungibleRegistryUpgradeable is address public burnAddress; /// @notice The amount in basis points of registrationFee to send to the burnAddress account - /// @notice This variable must be less than or equal to 10000 + /// @notice This variable must be less than or equal to 10000 / burnDenom uint256 public burnFee; /** @dev address of primary NFR registry required for participation @@ -123,6 +123,8 @@ contract NonFungibleRegistryUpgradeable is /// @dev The REGISTRAR_ROLE_ADMIN curates the address with REGISTRAR_ROLE permissions bytes32 public constant REGISTRAR_ROLE_ADMIN = keccak256("REGISTRAR_ROLE_ADMIN"); + /// @notice used to calculate burn % in calculating royaltyAmount + uint constant burnDenom = 10000; /** * @dev Emitted when updateLabel is called successfully */ @@ -270,7 +272,7 @@ contract NonFungibleRegistryUpgradeable is _createLabeledToken(to, label, registrationData, tokenId); - uint256 burnAmount = registrationFee * burnFee / 10000; + uint256 burnAmount = calculateRoyalty(registrationFee); IERC20Upgradeable(registrationToken).transfer(burnAddress, burnAmount); // the fee stays with the token, not the token owner identityStakes[tokenId] = Fee(registrationToken, registrationFee-burnAmount); @@ -440,12 +442,17 @@ contract NonFungibleRegistryUpgradeable is } } + function calculateRoyalty(uint256 salePrice) internal view returns(uint256 amount) { + amount = salePrice * burnFee / burnDenom; + } + + function royaltyInfo(uint256 tokenId, uint256 salePrice) external view override(IERC2981Upgradeable) returns (address receiver, uint256 royaltyAmount) { - royaltyAmount = salePrice * burnFee / 10000; + royaltyAmount = calculateRoyalty(salePrice); receiver = burnAddress; } diff --git a/packages/contracts/hardhat.config.js b/packages/contracts/hardhat.config.js index c4954db0..3044d1f5 100644 --- a/packages/contracts/hardhat.config.js +++ b/packages/contracts/hardhat.config.js @@ -54,6 +54,14 @@ module.exports = { chainId: 31337, url: "http://127.0.0.1:8569", }, + dev_ganache: { + accounts: { + accountsBalance: "10000000000000000000000", + mnemonic, + }, + chainId: 1337, + url: "http://127.0.0.1:7545" + }, DevNet: { accounts: { mnemonic,