diff --git a/contracts/licenses/CantBeEvilUpgradeable.sol b/contracts/licenses/CantBeEvilUpgradeable.sol new file mode 100644 index 0000000..72223c4 --- /dev/null +++ b/contracts/licenses/CantBeEvilUpgradeable.sol @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: MIT +// a16z Contracts v0.0.1 (CantBeEvil.sol) +pragma solidity ^0.8.13; + +import "@openzeppelin-upgradeable/contracts/utils/StringsUpgradeable.sol"; +import "@openzeppelin-upgradeable/contracts/utils/introspection/ERC165Upgradeable.sol"; +import "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol"; +import "./ICantBeEvil.sol"; + +enum LicenseVersion { + CBE_CC0, + CBE_ECR, + CBE_NECR, + CBE_NECR_HS, + CBE_PR, + CBE_PR_HS +} + +contract CantBeEvilUpgradeable is Initializable, ERC165Upgradeable, ICantBeEvil { + using StringsUpgradeable for uint; + + string internal constant _BASE_LICENSE_URI = "ar://_D9kN1WrNWbCq55BSAGRbTB4bS3v8QAPTYmBThSbX3A/"; + LicenseVersion public licenseVersion; // return string + + // solhint-disable func-name-mixedcase + function __CantBeEvil_init(LicenseVersion _licenseVersion) internal onlyInitializing { + __CantBeEvil_init_unchained(_licenseVersion); + } + + // solhint-disable func-name-mixedcase + function __CantBeEvil_init_unchained(LicenseVersion _licenseVersion) internal onlyInitializing { + licenseVersion = _licenseVersion; + } + + function getLicenseURI() public view returns (string memory) { + return string.concat(_BASE_LICENSE_URI, uint(licenseVersion).toString()); + } + + function getLicenseName() public view returns (string memory) { + return _getLicenseVersionKeyByValue(licenseVersion); + } + + function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable) returns (bool) { + return + interfaceId == type(ICantBeEvil).interfaceId || + super.supportsInterface(interfaceId); + } + + function _getLicenseVersionKeyByValue(LicenseVersion _licenseVersion) internal pure returns (string memory) { + require(uint8(_licenseVersion) <= 6); + if (LicenseVersion.CBE_CC0 == _licenseVersion) return "CBE_CC0"; + if (LicenseVersion.CBE_ECR == _licenseVersion) return "CBE_ECR"; + if (LicenseVersion.CBE_NECR == _licenseVersion) return "CBE_NECR"; + if (LicenseVersion.CBE_NECR_HS == _licenseVersion) return "CBE_NECR_HS"; + if (LicenseVersion.CBE_PR == _licenseVersion) return "CBE_PR"; + else return "CBE_PR_HS"; + } +} diff --git a/contracts/package.json b/contracts/package.json index 0cf12bb..5ab07c8 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -6,7 +6,8 @@ "**/*.sol" ], "dependencies": { - "@openzeppelin/contracts": "^4.7.2" + "@openzeppelin/contracts": "^4.7.2", + "@openzeppelin-upgradeable/contracts": "npm:@openzeppelin/contracts-upgradeable@^4.8.0-rc.1" }, "scripts": { "test": "hardhat test" diff --git a/package.json b/package.json index 7683675..f4f8bfd 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "dotenv": "^16.0.1", "ethereum-waffle": "^3.4.4", "ethers": "^5.6.8", - "hardhat": "^2.9.6", + "hardhat": "2.9.6", "hardhat-gas-reporter": "^1.0.8" }, "dependencies": { + "@openzeppelin-upgradeable/contracts": "npm:@openzeppelin/contracts-upgradeable@^4.8.0-rc.1", "@openzeppelin/contracts": "^4.7.2" }, "scripts": {