Skip to content
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

upgradable #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions contracts/licenses/CantBeEvil.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,20 @@
// a16z Contracts v0.0.1 (CantBeEvil.sol)
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "./ICantBeEvil.sol";
import "./LicenseVersion.sol";
import "./CantBeEvilBase.sol";

enum LicenseVersion {
CBE_CC0,
CBE_ECR,
CBE_NECR,
CBE_NECR_HS,
CBE_PR,
CBE_PR_HS
}

contract CantBeEvil is ERC165, ICantBeEvil {
contract CantBeEvil is CantBeEvilBase, ERC165 {
using Strings for uint;
string internal constant _BASE_LICENSE_URI = "ar://_D9kN1WrNWbCq55BSAGRbTB4bS3v8QAPTYmBThSbX3A/";
LicenseVersion public licenseVersion; // return string
constructor(LicenseVersion _licenseVersion) {
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(ERC165) 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";
}
}
32 changes: 32 additions & 0 deletions contracts/licenses/CantBeEvilBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
// a16z Contracts v0.0.1 (CantBeEvil.sol)
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/utils/Strings.sol";
import "./ICantBeEvil.sol";
import "./LicenseVersion.sol";


abstract contract CantBeEvilBase is ICantBeEvil {
using Strings for uint;
string internal constant _BASE_LICENSE_URI = "ar://_D9kN1WrNWbCq55BSAGRbTB4bS3v8QAPTYmBThSbX3A/";
LicenseVersion public licenseVersion; // return string

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 _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";
}
}
26 changes: 26 additions & 0 deletions contracts/licenses/CantBeEvilUpgradable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
// a16z Contracts v0.0.1 (CantBeEvil.sol)
pragma solidity ^0.8.13;

import "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
import "./ICantBeEvil.sol";
import "./LicenseVersion.sol";
import "./CantBeEvilBase.sol";


contract CantBeEvilUpgradable is CantBeEvilBase, ERC165Upgradeable {
// solhint-disable-next-line func-name-mixedcase
function __CantBeEvil_init(LicenseVersion _licenseVersion)
internal
onlyInitializing
{
__ERC165_init();
licenseVersion = _licenseVersion;
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable) returns (bool) {
return
interfaceId == type(ICantBeEvil).interfaceId ||
super.supportsInterface(interfaceId);
}
}
12 changes: 12 additions & 0 deletions contracts/licenses/LicenseVersion.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
// a16z Contracts v0.0.1 (CantBeEvil.sol)
pragma solidity ^0.8.13;

enum LicenseVersion {
CBE_CC0,
CBE_ECR,
CBE_NECR,
CBE_NECR_HS,
CBE_PR,
CBE_PR_HS
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.7.3"
},
"scripts": {
"test": "hardhat test"
Expand Down
Loading