-
Notifications
You must be signed in to change notification settings - Fork 16
Migrated to OZ v5 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
8ad57a3
Migrated to OZ v5
KyrylR bed7a53
integrated with new versions of solarity and openzeppelin
aritkulova 9812e15
updated package-lock
aritkulova c382599
switched to custom errors
aritkulova 23ace8e
cleaned up
aritkulova 1118e7f
refactored error naming
aritkulova 764dc9a
renamed claimTopicKey to contextKey, claimTopic to handleTopic
aritkulova c9fe3e0
fixed typos
aritkulova b73bba0
fixed inits in example
aritkulova 58c7181
returned accidentally missing part
aritkulova aac0246
updated examples folder
aritkulova 8d8d53d
Added erc721 (#7)
aritkulova 554b25e
fixed typos
aritkulova cbfa65d
created IAssetF interface for Context and common errors
aritkulova 29e3462
added onlyInitializing to init functions
aritkulova 54539df
updated minimal solidity version to ^0.8.21
aritkulova e3fb73f
added storage buckets to the modules
aritkulova 4f42e86
updated the architecture diagram
aritkulova 8d67588
updated version to 0.3.0
aritkulova 93fd17f
added tokenURI to NFTF
aritkulova 759f311
updated diagram to capture ERC20 and ERC721
aritkulova 383263f
updated dependency
aritkulova c7aaa95
fixed diagram
aritkulova 3bccb9f
few fixes
Arvolear bede6ef
moved TokenF and NFTF contracts from core folder
aritkulova ce475a0
updated diagram
aritkulova 3442b57
calldata -> memory in public functions
aritkulova 04e3b12
TransferLimitsModule -> ERC20TransferLimitsModule
aritkulova 4829b56
EquityNFT -> LandNFT
aritkulova f3d61ec
added ERC721TransferLimitsModule
aritkulova dfc5a46
added LandERC721TransferLimitsModule to examples
aritkulova af81d51
added INFTF to supported interfaces
aritkulova d6b676a
updated scripts
aritkulova 8ecf012
added AbstractAssetF contract
aritkulova 798f81e
order consistency fix
aritkulova 8d39297
fixed ERC721TransferLimitsModule formula
aritkulova 9bddc87
cleaned up ERC721TransferLimitsModule test
aritkulova 6b1dead
review fix
aritkulova 80fa17b
updated diagram
aritkulova 5797088
fix
aritkulova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1 @@ | ||
| # Deployer private key | ||
| PRIVATE_KEY=YOUR PRIVATE KEY | ||
|
|
||
| # RPC Endpoints | ||
| INFURA_KEY=INFURA PROJECT ID | ||
|
|
||
| # Additional keys | ||
| ETHERSCAN_KEY=ETHERSCAN API KEY | ||
| BSCSCAN_KEY=BSCSCAN API KEY | ||
| POLYGONSCAN_KEY=POLYGONSCAN API KEY | ||
| AVALANCHE_KEY=AVALANCHE API KEY | ||
| COINMARKETCAP_KEY=COINMARKETCAP API KEY |
This file contains hidden or 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
aritkulova marked this conversation as resolved.
Show resolved
Hide resolved
aritkulova marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,301 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.21; | ||
|
|
||
| import {IERC721} from "@openzeppelin/contracts/interfaces/IERC721.sol"; | ||
| import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; | ||
| import {ERC721EnumerableUpgradeable, ERC721Upgradeable, IERC165} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol"; | ||
|
|
||
| import {Diamond} from "@solarity/solidity-lib/diamond/Diamond.sol"; | ||
|
|
||
| import {INFTF} from "./interfaces/INFTF.sol"; | ||
| import {IKYCCompliance} from "./interfaces/core/IKYCCompliance.sol"; | ||
| import {IRegulatoryCompliance} from "./interfaces/core/IRegulatoryCompliance.sol"; | ||
|
|
||
| import {AgentAccessControl, AccessControlUpgradeable} from "./core/AgentAccessControl.sol"; | ||
| import {NFTFStorage} from "./storages/NFTFStorage.sol"; | ||
| import {RegulatoryComplianceStorage} from "./storages/core/RegulatoryComplianceStorage.sol"; | ||
| import {KYCComplianceStorage} from "./storages/core/KYCComplianceStorage.sol"; | ||
|
|
||
| abstract contract NFTF is | ||
| INFTF, | ||
| NFTFStorage, | ||
| Diamond, | ||
| ERC721EnumerableUpgradeable, | ||
| AgentAccessControl | ||
| { | ||
| bytes4 public constant TRANSFER_SELECTOR = this.transfer.selector; | ||
| bytes4 public constant TRANSFER_FROM_SELECTOR = this.transferFrom.selector; | ||
| bytes4 public constant MINT_SELECTOR = this.mint.selector; | ||
| bytes4 public constant BURN_SELECTOR = this.burn.selector; | ||
| bytes4 public constant FORCED_TRANSFER_SELECTOR = this.forcedTransfer.selector; | ||
| bytes4 public constant RECOVERY_SELECTOR = this.recovery.selector; | ||
|
|
||
| function __NFTF_init( | ||
| address regulatoryCompliance_, | ||
| address kycCompliance_, | ||
| bytes memory initRegulatory_, | ||
| bytes memory initKYC_ | ||
| ) internal virtual onlyInitializing { | ||
| bytes4[] memory rComplianceSelectors_ = new bytes4[](6); | ||
| rComplianceSelectors_[0] = IRegulatoryCompliance.addRegulatoryModules.selector; | ||
| rComplianceSelectors_[1] = IRegulatoryCompliance.removeRegulatoryModules.selector; | ||
| rComplianceSelectors_[2] = IRegulatoryCompliance.transferred.selector; | ||
| rComplianceSelectors_[3] = IRegulatoryCompliance.canTransfer.selector; | ||
| rComplianceSelectors_[4] = RegulatoryComplianceStorage.getRegulatoryModules.selector; | ||
| rComplianceSelectors_[5] = RegulatoryComplianceStorage.getRegulatoryModulesCount.selector; | ||
|
|
||
| bytes4[] memory kycComplianceSelectors_ = new bytes4[](5); | ||
| kycComplianceSelectors_[0] = IKYCCompliance.addKYCModules.selector; | ||
| kycComplianceSelectors_[1] = IKYCCompliance.removeKYCModules.selector; | ||
| kycComplianceSelectors_[2] = IKYCCompliance.isKYCed.selector; | ||
| kycComplianceSelectors_[3] = KYCComplianceStorage.getKYCModules.selector; | ||
| kycComplianceSelectors_[4] = KYCComplianceStorage.getKYCModulesCount.selector; | ||
|
|
||
| Facet[] memory facets_ = new Facet[](2); | ||
| facets_[0] = Facet(regulatoryCompliance_, FacetAction.Add, rComplianceSelectors_); | ||
| facets_[1] = Facet(kycCompliance_, FacetAction.Add, kycComplianceSelectors_); | ||
|
|
||
| _diamondCut(facets_, address(0), ""); | ||
| _diamondCut(new Facet[](0), regulatoryCompliance_, initRegulatory_); | ||
| _diamondCut(new Facet[](0), kycCompliance_, initKYC_); | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function transfer(address to_, uint256 tokenId_) public virtual override { | ||
| _canTransfer(msg.sender, to_, tokenId_, address(0)); | ||
| _isKYCed(msg.sender, to_, tokenId_, address(0)); | ||
|
|
||
| super._transfer(msg.sender, to_, tokenId_); | ||
|
|
||
| _transferred(msg.sender, to_, tokenId_, address(0)); | ||
| } | ||
|
|
||
| /// @inheritdoc IERC721 | ||
| function transferFrom( | ||
| address from_, | ||
| address to_, | ||
| uint256 tokenId_ | ||
| ) public virtual override(ERC721Upgradeable, IERC721) { | ||
| _canTransfer(from_, to_, tokenId_, msg.sender); | ||
| _isKYCed(from_, to_, tokenId_, msg.sender); | ||
|
|
||
| super.transferFrom(from_, to_, tokenId_); | ||
|
|
||
| _transferred(from_, to_, tokenId_, msg.sender); | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function mint( | ||
| address account_, | ||
| uint256 tokenId_, | ||
| string memory tokenURI_ | ||
| ) public virtual override onlyRole(_mintRole()) { | ||
| _canTransfer(address(0), account_, tokenId_, msg.sender); | ||
| _isKYCed(address(0), account_, tokenId_, msg.sender); | ||
|
|
||
| super._mint(account_, tokenId_); | ||
| _setTokenURI(tokenId_, tokenURI_); | ||
|
|
||
| _transferred(address(0), account_, tokenId_, msg.sender); | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function burn(uint256 tokenId_) public virtual override onlyRole(_burnRole()) { | ||
| address account_ = _ownerOf(tokenId_); | ||
|
|
||
| _canTransfer(account_, address(0), tokenId_, msg.sender); | ||
| _isKYCed(account_, address(0), tokenId_, msg.sender); | ||
|
|
||
| super._burn(tokenId_); | ||
|
|
||
| _transferred(account_, address(0), tokenId_, msg.sender); | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function forcedTransfer( | ||
| address from_, | ||
| address to_, | ||
| uint256 tokenId_ | ||
| ) public virtual override onlyRole(_forcedTransferRole()) { | ||
| _canTransfer(from_, to_, tokenId_, msg.sender); | ||
| _isKYCed(from_, to_, tokenId_, msg.sender); | ||
|
|
||
| super._transfer(from_, to_, tokenId_); | ||
|
|
||
| _transferred(from_, to_, tokenId_, msg.sender); | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function recovery( | ||
| address oldAccount_, | ||
| address newAccount_ | ||
| ) public virtual override onlyRole(_recoveryRole()) { | ||
| uint256 oldBalance_ = balanceOf(oldAccount_); | ||
|
|
||
| for (uint256 i = oldBalance_; i > 0; --i) { | ||
| uint256 tokenId_ = tokenOfOwnerByIndex(oldAccount_, i - 1); | ||
|
|
||
| _canTransfer(oldAccount_, newAccount_, tokenId_, msg.sender); | ||
| _isKYCed(oldAccount_, newAccount_, tokenId_, msg.sender); | ||
|
|
||
| super._transfer(oldAccount_, newAccount_, tokenId_); | ||
|
|
||
| _transferred(oldAccount_, newAccount_, tokenId_, msg.sender); | ||
| } | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function diamondCut( | ||
| Facet[] memory modules_ | ||
| ) public virtual override onlyRole(_diamondCutRole()) { | ||
| diamondCut(modules_, address(0), ""); | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function diamondCut( | ||
| Facet[] memory modules_, | ||
| address initModule_, | ||
| bytes memory initData_ | ||
| ) public virtual override onlyRole(_diamondCutRole()) { | ||
| _diamondCut(modules_, initModule_, initData_); | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function setBaseURI(string memory baseURI_) public virtual override onlyRole(_uriRole()) { | ||
| _getNftFStorage().baseURI = baseURI_; | ||
| } | ||
|
|
||
| /// @inheritdoc INFTF | ||
| function setTokenURI( | ||
| uint256 tokenId_, | ||
| string memory tokenURI_ | ||
| ) public virtual override onlyRole(_uriRole()) { | ||
| _requireOwned(tokenId_); | ||
|
|
||
| _setTokenURI(tokenId_, tokenURI_); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc IERC721Metadata | ||
| * | ||
| * @dev | ||
| * If the token does not exist, an empty string is returned. | ||
| * If a tokenURI is set for the token, it will be returned. | ||
| * If a base URI is set, the concatenation of the base URI and tokenId is returned. | ||
| * Otherwise, an empty string is returned. | ||
| */ | ||
| function tokenURI( | ||
| uint256 tokenId_ | ||
| ) public view virtual override(IERC721Metadata, ERC721Upgradeable) returns (string memory) { | ||
| address owner_ = _ownerOf(tokenId_); | ||
|
|
||
| if (owner_ == address(0)) { | ||
| return ""; | ||
| } | ||
|
|
||
| NftFStorage storage $ = _getNftFStorage(); | ||
| string memory tokenURI_ = $.tokenURIs[tokenId_]; | ||
|
|
||
| if (bytes(tokenURI_).length > 0) { | ||
| return tokenURI_; | ||
| } | ||
|
|
||
| return super.tokenURI(tokenId_); | ||
| } | ||
|
|
||
| /// @inheritdoc IERC165 | ||
| function supportsInterface( | ||
| bytes4 interfaceId_ | ||
| ) | ||
| public | ||
| view | ||
| override(AccessControlUpgradeable, ERC721EnumerableUpgradeable, IERC165) | ||
| returns (bool) | ||
| { | ||
| return super.supportsInterface(interfaceId_); | ||
aritkulova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| function _setTokenURI(uint256 tokenId_, string memory tokenURI_) internal virtual { | ||
| NftFStorage storage $ = _getNftFStorage(); | ||
| $.tokenURIs[tokenId_] = tokenURI_; | ||
|
|
||
| emit MetadataUpdate(tokenId_); | ||
| } | ||
|
|
||
| function _transferred( | ||
| address from_, | ||
| address to_, | ||
| uint256 tokenId_, | ||
| address operator_ | ||
| ) internal virtual { | ||
| try | ||
| IRegulatoryCompliance(address(this)).transferred( | ||
| Context(bytes4(bytes(msg.data[:4])), from_, to_, 0, tokenId_, operator_, "") | ||
| ) | ||
| {} catch { | ||
| revert TransferredReverted(); | ||
| } | ||
| } | ||
|
|
||
| function _canTransfer( | ||
| address from_, | ||
| address to_, | ||
| uint256 tokenId_, | ||
| address operator_ | ||
| ) internal view virtual { | ||
| try | ||
| IRegulatoryCompliance(address(this)).canTransfer( | ||
| Context(bytes4(bytes(msg.data[:4])), from_, to_, 0, tokenId_, operator_, "") | ||
| ) | ||
| returns (bool canTransfer_) { | ||
| require(canTransfer_, CannotTransfer()); | ||
| } catch { | ||
| revert CanTransferReverted(); | ||
| } | ||
| } | ||
|
|
||
| function _isKYCed( | ||
| address from_, | ||
| address to_, | ||
| uint256 tokenId_, | ||
| address operator_ | ||
| ) internal view virtual { | ||
| try | ||
| IKYCCompliance(address(this)).isKYCed( | ||
| Context(bytes4(bytes(msg.data[:4])), from_, to_, 0, tokenId_, operator_, "") | ||
| ) | ||
| returns (bool isKYCed_) { | ||
| require(isKYCed_, NotKYCed()); | ||
| } catch { | ||
| revert IsKYCedReverted(); | ||
| } | ||
| } | ||
|
|
||
| function _baseURI() internal view virtual override returns (string memory) { | ||
| return _getNftFStorage().baseURI; | ||
| } | ||
|
|
||
| function _mintRole() internal view virtual returns (bytes32) { | ||
| return AGENT_ROLE; | ||
| } | ||
|
|
||
| function _burnRole() internal view virtual returns (bytes32) { | ||
| return AGENT_ROLE; | ||
| } | ||
|
|
||
| function _forcedTransferRole() internal view virtual returns (bytes32) { | ||
| return AGENT_ROLE; | ||
| } | ||
|
|
||
| function _recoveryRole() internal view virtual returns (bytes32) { | ||
| return AGENT_ROLE; | ||
| } | ||
|
|
||
| function _diamondCutRole() internal view virtual returns (bytes32) { | ||
| return AGENT_ROLE; | ||
| } | ||
|
|
||
| function _uriRole() internal view virtual returns (bytes32) { | ||
| return AGENT_ROLE; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.