-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from kargakis/upgrade-to-latest
Bump to latest version
- Loading branch information
Showing
57 changed files
with
2,879 additions
and
258 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
// SPDX-License-Identifier: UNLICENSED | ||
|
||
// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth | ||
pragma solidity ^0.8.0; | ||
pragma solidity >=0.8.4 <=0.8.9; | ||
|
||
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol'; | ||
|
@@ -21,6 +21,7 @@ import './libraries/Modifiers.sol'; | |
|
||
/// @notice Also referred to as Batch-Contract (formerly BatchCollection) | ||
/// Contract that tokenizes retired/cancelled CO2 credits into NFTs via a claims process | ||
//slither-disable-next-line unprotected-upgrade | ||
contract CarbonOffsetBatches is | ||
ICarbonOffsetBatches, | ||
ERC721EnumerableUpgradeable, | ||
|
@@ -58,16 +59,25 @@ contract CarbonOffsetBatches is | |
); | ||
event BatchStatusUpdate(uint256 tokenId, RetirementStatus status); | ||
|
||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
// ---------------------------------------- | ||
// Upgradable related functions | ||
// ---------------------------------------- | ||
|
||
/// @dev Returns the current version of the smart contract | ||
function version() public pure returns (string memory) { | ||
function version() external pure returns (string memory) { | ||
return '1.2.0'; | ||
} | ||
|
||
function initialize(address _contractRegistry) public virtual initializer { | ||
function initialize(address _contractRegistry) | ||
external | ||
virtual | ||
initializer | ||
{ | ||
__Context_init_unchained(); | ||
__ERC721_init_unchained( | ||
'Toucan Protocol: Carbon Offset Batches', | ||
|
@@ -92,17 +102,17 @@ contract CarbonOffsetBatches is | |
|
||
/// @notice Emergency function to disable contract's core functionality | ||
/// @dev wraps _pause(), only Admin | ||
function pause() public virtual onlyBy(contractRegistry, owner()) { | ||
function pause() external virtual onlyBy(contractRegistry, owner()) { | ||
_pause(); | ||
} | ||
|
||
/// @dev unpause the system, wraps _unpause(), only Admin | ||
function unpause() public virtual onlyBy(contractRegistry, owner()) { | ||
function unpause() external virtual onlyBy(contractRegistry, owner()) { | ||
_unpause(); | ||
} | ||
|
||
function setToucanContractRegistry(address _address) | ||
public | ||
external | ||
virtual | ||
onlyOwner | ||
{ | ||
|
@@ -175,7 +185,7 @@ contract CarbonOffsetBatches is | |
|
||
/// @notice Function to reject Batch-NFTs, including a reason to be displayed to the user. | ||
function rejectWithComment(uint256 tokenId, string memory comment) | ||
public | ||
external | ||
virtual | ||
onlyVerifier | ||
whenNotPaused | ||
|
@@ -187,7 +197,7 @@ contract CarbonOffsetBatches is | |
/// @dev admin function to reject a previously approved batch | ||
/// Requires that the Batch-NFT has not been fractionalized yet | ||
function rejectApprovedWithComment(uint256 tokenId, string memory comment) | ||
public | ||
external | ||
virtual | ||
onlyOwner | ||
whenNotPaused | ||
|
@@ -238,7 +248,7 @@ contract CarbonOffsetBatches is | |
function confirmRetirementWithVintage( | ||
uint256 tokenId, | ||
uint256 projectVintageTokenId | ||
) public virtual onlyVerifier whenNotPaused { | ||
) external virtual onlyVerifier whenNotPaused { | ||
require( | ||
nftList[tokenId].status != RetirementStatus.Confirmed, | ||
'Batch retirement is already confirmed' | ||
|
@@ -261,7 +271,10 @@ contract CarbonOffsetBatches is | |
/// owner (deployer), in practice that is a multi-sig even before upgrade, | ||
/// and unsetting a bunch of serials via multi-sig is not practical. | ||
/// So instead we allow the verifiers to do it. | ||
function unsetSerialNumber(string memory serialNumber) public onlyVerifier { | ||
function unsetSerialNumber(string memory serialNumber) | ||
external | ||
onlyVerifier | ||
{ | ||
serialNumberApproved[serialNumber] = false; | ||
} | ||
|
||
|
@@ -297,7 +310,7 @@ contract CarbonOffsetBatches is | |
string memory serialNumber, | ||
uint256 quantity, | ||
string memory uri | ||
) public virtual whenNotPaused { | ||
) external virtual whenNotPaused { | ||
require( | ||
ownerOf(tokenId) == _msgSender() || | ||
hasRole(VERIFIER_ROLE, _msgSender()), | ||
|
@@ -391,7 +404,7 @@ contract CarbonOffsetBatches is | |
/// gas reasons: | ||
/// https://docs.soliditylang.org/en/latest/contracts.html#visibility-and-getters | ||
function getComments(uint256 tokenId) | ||
public | ||
external | ||
view | ||
virtual | ||
returns (string[] memory, address[] memory) | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth | ||
|
||
pragma solidity >=0.8.4 <0.9.0; | ||
pragma solidity >=0.8.4 <=0.8.14; | ||
|
||
enum RetirementStatus { | ||
Pending, // 0 | ||
|
This file contains 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth | ||
|
||
pragma solidity >=0.8.4 <0.9.0; | ||
pragma solidity >=0.8.4 <=0.8.14; | ||
|
||
/// @dev CarbonProject related data and attributes | ||
struct ProjectData { | ||
|
This file contains 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth | ||
|
||
pragma solidity >=0.8.4 <0.9.0; | ||
pragma solidity >=0.8.4 <=0.8.14; | ||
|
||
struct VintageData { | ||
/// @dev A human-readable string which differentiates this from other vintages in | ||
|
This file contains 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
// SPDX-License-Identifier: UNLICENSED | ||
|
||
// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth | ||
pragma solidity ^0.8.0; | ||
pragma solidity >=0.8.4 <=0.8.14; | ||
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol'; | ||
|
@@ -35,6 +35,8 @@ contract CarbonProjectVintages is | |
// Constants | ||
// ---------------------------------------- | ||
|
||
string public constant VERSION = '1.1.0'; | ||
|
||
/// @dev All roles related to Access Control | ||
bytes32 public constant MANAGER_ROLE = keccak256('MANAGER_ROLE'); | ||
|
||
|
@@ -55,7 +57,7 @@ contract CarbonProjectVintages is | |
// Upgradable related functions | ||
// ---------------------------------------- | ||
|
||
function initialize() public virtual initializer { | ||
function initialize() external virtual initializer { | ||
__Context_init_unchained(); | ||
__ERC721_init_unchained( | ||
'Toucan Protocol: Carbon Project Vintages', | ||
|
@@ -89,17 +91,17 @@ contract CarbonProjectVintages is | |
|
||
/// @notice Emergency function to disable contract's core functionality | ||
/// @dev wraps _pause(), only Admin | ||
function pause() public virtual onlyBy(contractRegistry, owner()) { | ||
function pause() external virtual onlyBy(contractRegistry, owner()) { | ||
_pause(); | ||
} | ||
|
||
/// @dev unpause the system, wraps _unpause(), only Admin | ||
function unpause() public virtual onlyBy(contractRegistry, owner()) { | ||
function unpause() external virtual onlyBy(contractRegistry, owner()) { | ||
_unpause(); | ||
} | ||
|
||
function setToucanContractRegistry(address _address) | ||
public | ||
external | ||
virtual | ||
onlyOwner | ||
{ | ||
|
@@ -108,29 +110,24 @@ contract CarbonProjectVintages is | |
|
||
/// @notice Adds a new carbon project-vintage along with attributes/data | ||
/// @dev vintages can be added by data-managers | ||
function addNewVintage( | ||
address to, | ||
uint256 projectTokenId, | ||
string memory name, | ||
uint64 startTime, | ||
uint64 endTime, | ||
uint64 totalVintageQuantity, | ||
bool isCorsiaCompliant, | ||
bool isCCPcompliant, | ||
string memory coBenefits, | ||
string memory correspAdjustment, | ||
string memory additionalCertification, | ||
string memory uri | ||
) external virtual override onlyManagers whenNotPaused returns (uint256) { | ||
checkProjectTokenExists(contractRegistry, projectTokenId); | ||
function addNewVintage(address to, VintageData memory _vintageData) | ||
external | ||
virtual | ||
override | ||
onlyManagers | ||
whenNotPaused | ||
returns (uint256) | ||
{ | ||
checkProjectTokenExists(contractRegistry, _vintageData.projectTokenId); | ||
|
||
require( | ||
pvToTokenId[projectTokenId][startTime] == 0, | ||
pvToTokenId[_vintageData.projectTokenId][_vintageData.startTime] == | ||
0, | ||
'Error: vintage already added' | ||
); | ||
|
||
require( | ||
startTime < endTime, | ||
_vintageData.startTime < _vintageData.endTime, | ||
'Error: vintage startTime must be less than endTime' | ||
); | ||
|
||
|
@@ -146,21 +143,16 @@ contract CarbonProjectVintages is | |
|
||
_mint(to, newItemId); | ||
|
||
vintageData[newItemId].name = name; | ||
vintageData[newItemId].startTime = startTime; | ||
vintageData[newItemId].endTime = endTime; | ||
vintageData[newItemId].projectTokenId = projectTokenId; | ||
vintageData[newItemId].totalVintageQuantity = totalVintageQuantity; | ||
vintageData[newItemId].isCorsiaCompliant = isCorsiaCompliant; | ||
vintageData[newItemId].isCCPcompliant = isCCPcompliant; | ||
vintageData[newItemId].coBenefits = coBenefits; | ||
vintageData[newItemId].correspAdjustment = correspAdjustment; | ||
vintageData[newItemId] | ||
.additionalCertification = additionalCertification; | ||
vintageData[newItemId].uri = uri; | ||
|
||
emit ProjectVintageMinted(to, newItemId, projectTokenId, startTime); | ||
pvToTokenId[projectTokenId][startTime] = newItemId; | ||
vintageData[newItemId] = _vintageData; | ||
emit ProjectVintageMinted( | ||
to, | ||
newItemId, | ||
_vintageData.projectTokenId, | ||
_vintageData.startTime | ||
); | ||
pvToTokenId[_vintageData.projectTokenId][ | ||
_vintageData.startTime | ||
] = newItemId; | ||
|
||
return newItemId; | ||
} | ||
|
@@ -182,29 +174,12 @@ contract CarbonProjectVintages is | |
/// except the sensitive `projectId` | ||
function updateProjectVintage( | ||
uint256 tokenId, | ||
// uint256 projectTokenId, // @dev commented out because very sensitive data, better via separate function | ||
string memory name, | ||
uint64 startTime, | ||
uint64 endTime, | ||
uint64 totalVintageQuantity, | ||
bool isCorsiaCompliant, | ||
bool isCCPcompliant, | ||
string memory coBenefits, | ||
string memory correspAdjustment, | ||
string memory additionalCertification, | ||
string memory uri | ||
VintageData memory _vintageData | ||
) external virtual onlyManagers whenNotPaused { | ||
require(_exists(tokenId), 'Project not yet minted'); | ||
vintageData[tokenId].name = name; | ||
vintageData[tokenId].startTime = startTime; | ||
vintageData[tokenId].endTime = endTime; | ||
vintageData[tokenId].totalVintageQuantity = totalVintageQuantity; | ||
vintageData[tokenId].isCorsiaCompliant = isCorsiaCompliant; | ||
vintageData[tokenId].isCCPcompliant = isCCPcompliant; | ||
vintageData[tokenId].coBenefits = coBenefits; | ||
vintageData[tokenId].correspAdjustment = correspAdjustment; | ||
vintageData[tokenId].additionalCertification = additionalCertification; | ||
vintageData[tokenId].uri = uri; | ||
// @dev very sensitive data, better update via separate function | ||
_vintageData.projectTokenId = vintageData[tokenId].projectTokenId; | ||
vintageData[tokenId] = _vintageData; | ||
|
||
emit ProjectVintageUpdated(tokenId); | ||
} | ||
|
This file contains 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.toucan.earth | ||
|
||
// Storage contract for CarbonProjects | ||
pragma solidity >=0.8.4 <0.9.0; | ||
pragma solidity >=0.8.4 <=0.8.14; | ||
|
||
import './CarbonProjectVintageTypes.sol'; | ||
|
||
|
Oops, something went wrong.