From d4c807add7848403519866efb0220613d820c1a0 Mon Sep 17 00:00:00 2001 From: SatyamAgrawal Date: Mon, 26 Sep 2022 15:23:51 +0530 Subject: [PATCH 1/2] make contract upgradeable --- contracts/licenses/CantBeEvilUpgradeable.sol | 58 ++++++++++++++++++++ contracts/package.json | 3 +- package.json | 3 +- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 contracts/licenses/CantBeEvilUpgradeable.sol diff --git a/contracts/licenses/CantBeEvilUpgradeable.sol b/contracts/licenses/CantBeEvilUpgradeable.sol new file mode 100644 index 0000000..dfb31cd --- /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/contracts-upgradeable/utils/StringsUpgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol"; +import "@openzeppelin/contracts-upgradeable/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..fac2414 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/contracts-upgradeable": "^4.8.0-rc.1" }, "scripts": { "test": "hardhat test" diff --git a/package.json b/package.json index 7683675..704eca7 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "hardhat-gas-reporter": "^1.0.8" }, "dependencies": { - "@openzeppelin/contracts": "^4.7.2" + "@openzeppelin/contracts": "^4.7.2", + "@openzeppelin/contracts-upgradeable": "^4.8.0-rc.1" }, "scripts": { "test": "hardhat test" From e3f5a5c78a3b3b3c790dbce30ab9be45ad292a0a Mon Sep 17 00:00:00 2001 From: SatyamAgrawal Date: Tue, 11 Oct 2022 15:16:20 +0530 Subject: [PATCH 2/2] make contract workable for foundry remappings --- contracts/licenses/CantBeEvilUpgradeable.sol | 6 +++--- contracts/package.json | 2 +- package.json | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/licenses/CantBeEvilUpgradeable.sol b/contracts/licenses/CantBeEvilUpgradeable.sol index dfb31cd..72223c4 100644 --- a/contracts/licenses/CantBeEvilUpgradeable.sol +++ b/contracts/licenses/CantBeEvilUpgradeable.sol @@ -2,9 +2,9 @@ // a16z Contracts v0.0.1 (CantBeEvil.sol) pragma solidity ^0.8.13; -import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; +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 { diff --git a/contracts/package.json b/contracts/package.json index fac2414..5ab07c8 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -7,7 +7,7 @@ ], "dependencies": { "@openzeppelin/contracts": "^4.7.2", - "@openzeppelin/contracts-upgradeable": "^4.8.0-rc.1" + "@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 704eca7..f4f8bfd 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,12 @@ "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/contracts": "^4.7.2", - "@openzeppelin/contracts-upgradeable": "^4.8.0-rc.1" + "@openzeppelin-upgradeable/contracts": "npm:@openzeppelin/contracts-upgradeable@^4.8.0-rc.1", + "@openzeppelin/contracts": "^4.7.2" }, "scripts": { "test": "hardhat test"